【问题标题】:ember-cli adding dependencies with bowerember-cli 使用 bower 添加依赖项
【发布时间】:2014-09-23 03:27:11
【问题描述】:

所以 - 我想在 ember 应用程序中使用 typeahead。

我启动并运行了一个 cli 应用程序,然后我运行

bower install typeahead.js

我可以看到代码已经放入 bower_components。

然后我将以下内容添加到 brocfile:

/* global require, module */

var EmberApp = require('ember-cli/lib/broccoli/ember-app');

var app = new EmberApp();

// Use `app.import` to add additional libraries to the generated
// output files.
//
// If you need to use different assets in different
// environments, specify an object as the first parameter. That
// object's keys should be the environment name and the values
// should be the asset to use in that environment.
//
// If the library that you are including contains AMD or ES6
// modules that you would like to import into your application
// please specify an object with the list of modules as keys
// along with the exports of each module as its value.

app.import('bower_components/typeahead.js/dist/typeahead.bundle.min.js');

module.exports = app.toTree();

但是它不起作用 - 我明白了

Uncaught ReferenceError: Bloodhound is not defined 

通过阅读文档 - 使用 bower 安装并在 brocfile 中添加行应该足以满足它吗?是我读错了还是这是一个错误?

我创建了一个显示此问题的公共 GIT 存储库:

https://github.com/wayne-o/ember-cli-bootstrap

我所做的只是:

ember new bootstrap-test
bower install bootstrap

然后添加:

app.import('bower_components/bootstrap/dist/css/bootstrap.css');
app.import('bower_components/bootstrap/dist/js/bootstrap.js');

到 brockfile...

没用……

【问题讨论】:

  • typeahead.bundle.min.js 应该包含寻血猎犬。尝试删除 Bloodhound.js 导入
  • 仍然收到错误:/
  • @drorb 我已经修改了问题并在 github 上添加了一个显示问题的 repo...
  • 更新了我的答案@iwayneo

标签: ember.js bower ember-cli


【解决方案1】:

您没有共享您的 Brocfile.js,但是当我在该文件末尾的 module.exports = app.toTree(); 行之后添加依赖项时,我遇到了类似的问题。文档是 not terribly clear 关于这个,但 module.exports = app.toTree(); 应该总是在 Brocfile.js 中排在最后。尝试将您的 app.import() 语句移到此行上方,一切都会正常运行。

更新

拉下你的回购我注意到了一些问题。首先,您需要将--save-dev 传递给您的Bower 安装,以便在其他人拉下您的存储库时安装它们。这会将这样的部分添加到您的 bower.json:

"devDependencies": {
   "bootstrap": "~3.2.0",
   "typeahead.js": "~0.10.5"
 }

我还在 .jshintrc 的 prefdef 部分添加了 "Bloodhound": true 以避免构建时出现 jshint 错误:

 "predef": {
    "document": true,
    "window": true,
    "-Promise": true,
    "Bloodhound": true
  },

您还可以将index.js 中的$ 引用替换为Ember.$,以避免另一个jshint 错误。

完成此操作后,我就可以运行 ember serve 并加载应用,而不会出现任何 Bloodhound 问题。

【讨论】:

  • 关键是添加依赖后需要重启服务器
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-06
  • 1970-01-01
  • 2013-08-18
相关资源
最近更新 更多