npm linking the add-on into my project successfully adds the /vendor/qunit-assert-html.min.js to my apps /vendor folder but I can’t figure out how to make that available in my integration tests.
There’s a few ways to make dependencies available in your add-on: it’s either have to be a bower_components or vendor. Those are the ONLY two folders that you are allowed to include files from. It is possible to include node_modules or any other folder in your add-on, but there’s quite a few hoops to jump through to get there.
bower_components are standard installed through bower package manager, but because bower flattens dependency tree, your add-on has to instruct the dependent app to install it. You do this through a default blueprint. Don’t forget to add the dependency to your add-on’s bower.json too for dev purpose.
vendor follows the convention of vendor/package/file.js. I don’t think this is documented, but your vendor file MUST follow this convention for import to work correctly.
Including node_modules and other folders requires you to implement treeFor* hooks in your addon. These hooks are invoked by ember-cli to allow you to include additional broccoli trees in the build cycle. In order to include other folders, you have to use these hooks to move your files into the vendor/ folder, then import it again in the included hook.
I’m struggling with dependencies in an addon right now. Is there any documentation? This is a great summary but I need a little more help figuring out how to make all of the dependencies I’ll need play nice.
'use strict';
const EmberAddon = require('ember-cli/lib/broccoli/ember-addon');
module.exports = function(defaults) {
let app = new EmberAddon(defaults, {
// Add options here
});
/*
This build file specifies the options for the dummy test app of this
addon, located in `/tests/dummy`
This build file does *not* influence how the addon or the app using it
behave. You most likely want to be modifying `./index.js` or app's build file
*/
if (app.env === 'test') {
app.import('vendor/ember/ember-template-compiler.js');
}
return app.toTree();
};