2014-09-21 56 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