Search code examples
ember.jsember-cliember-cli-addons

How should I import Bower dependencies from an Ember-cli addon into the consuming application?


I am successfully importing a jQuery plugin via Bower to be used in a component in an Ember-cli addon. However, this only works is because I defined a Bower dependency on this plugin in both the addon and the consuming application.

This seems like I'm doing it wrong. Why should the consuming application have to declare a dependency on a resource that should be provided with the addon?

The crux of the matter seems to be the app context when building. I can omit the Bower dependency in the consuming application if I use the following import statement in the addon's index.js file:

app.import('node_modules/my-ember-cli-addon/bower_components/jquery.stickyHooters/dist/jquery.stickyHooters.min.js');

... but this breaks when I build the addon as a stand-alone application. In that case, this path is required:

 app.import('bower_components/jquery.stickyHooters/dist/jquery.stickyHooters.min.js');

How this is intended to work?

  1. Declaring the Bower dependency in two places seems counter-intuitive
  2. I don't know how detect the app context in the index.js of the addon

Solution

  • Checkout ember-cli homepage on default blueprints. It describes how you can import a bower component package upon installing your addon.