2014-09-21 54 views
8

所以 - 我想要在一个应用程序中的typeahead玩。ember-cli增加依赖关系与鲍尔

我得到一个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 

从阅读的文档 - 与亭子安装和添加的行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 ...

它没有工作...

+0

typeahead.bundle.min.js应该包含bloodhound。尝试删除bloodhound.js导入 – 2014-09-21 17:37:32

+0

仍然收到错误:/ – iwayneo 2014-09-21 17:43:40

+0

@drorb我已经修正了这个问题,并在github上添加了一个回购显示问题... – iwayneo 2014-09-22 15:16:46

回答

5

你没有分享你的Brocfile.js,但我有类似的问题,当我已经在该文件的末尾module.exports = app.toTree();行后添加依赖关系。有关这方面的文档是not terribly clear,但module.exports = app.toTree();应始终在Brocfile.js中最后。尝试在此行上方移动app.import()声明,并且事情应该正常工作。

更新

拉下你的回购协议,我注意到的几个问题。首先,您需要将--save-dev传递给您的bower安装bootstrap和typeahead.js,以便在其他人拉下您的repo时安装这些安装程序。这将增加像这样的部分,将bower.json:

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

我还添加了"Bloodhound": true到.jshintrc的prefdef部分,以避免对构建jshint错误:

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

您也可以取代你$参考index.jsEmber.$避免另一个jshint错误。

一旦我做到了这一点,我就可以运行ember serve并且可以在没有任何血猎问题的情况下加载应用程序。

+3

它的关键在于您需要在添加依赖关系后重新启动服务器 – iwayneo 2014-09-23 11:45:08

+0

是的,那也是:) – Dhaulagiri 2014-09-23 14:40:05