2014-09-21 5 views
8

Quindi - Voglio giocare con typeahead in un'app ember.ember-cli aggiungendo dipendenze con il pergolato

ottengo un cli applicazione installato e funzionante quindi corro

bower install typeahead.js 

posso vedere che il codice è stato messo in bower_components.

ho quindi aggiungere il seguente alla 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(); 

Tuttavia non funziona - ho

Uncaught ReferenceError: Bloodhound is not defined 

Dalla lettura dei documenti - installazione con gazebo e aggiungendo le linee nel il brocfile dovrebbe essere sufficiente per soddisfarlo? Sto leggendo male o è un bug?

ho creato un repo GIT pubblico che dimostra questo problema:

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

Tutto quello che ho fatto è:

ember new bootstrap-test 
bower install bootstrap 

E poi ha aggiunto:

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

a il brockfile ...

Non ha funzionato ...

+0

typeahead.bundle.min.js dovrebbe contenere bloodhound. Prova a rimuovere il bloodhound.js import –

+0

Ancora ricevendo l'errore:/ – iwayneo

+0

@drorb Ho modificato la domanda e aggiunto un repository su github che mostra il problema ... – iwayneo

risposta

5

Non hai condividere la vostra Brocfile.js, ma ho avuto problemi simili quando ho dipendenze aggiunto dopo la linea di module.exports = app.toTree(); alla fine di quel file. La documentazione è not terribly clear su questo, ma module.exports = app.toTree(); dovrebbe sempre arrivare l'ultima volta in Brocfile.js. Prova a spostare la tua istruzione app.import() sopra questa riga e le cose dovrebbero funzionare correttamente.

Aggiornamento

Tirando il vostro repo ho notato alcuni problemi. Per prima cosa è necessario passare --save-dev alle installazioni di bower per bootstrap e typeahead.js in modo che possano essere installati quando gli altri abbattono il repository. Che aggiungere una sezione come questo per il vostro bower.json:

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

Ho anche aggiunto "Bloodhound": true alla sezione prefdef di .jshintrc per evitare errori jshint sulla costruzione:

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

Si può anche sostituire il vostro $ riferimenti in index.js con Ember.$ per evitare un altro errore jshint.

Una volta eseguita l'operazione, è stato possibile eseguire ember serve e caricare l'app senza problemi di Bloodhound.

+3

La chiave è che è necessario riavviare il server dopo aver aggiunto dipendenze – iwayneo

+0

Sì, anche questo :) – Dhaulagiri