7

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
Kevin Boucher
  • 16,426
  • 3
  • 48
  • 55
  • Possibly related, but unanswered: http://stackoverflow.com/questions/25654482/importing-dependencies-in-an-ember-cli-addon-for-a-component – Kevin Boucher Jul 16 '15 at 22:38

1 Answers1

7

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

tomasbasham
  • 1,695
  • 2
  • 18
  • 37
  • 2
    OK, so blueprints as a solution for this issue seems a bit unintuitive, but it is clear from the documentation that that is the intended way to handle this. However, the documentation appears to be incomplete as the consuming application still does not install the bower dependency from the addon. – Kevin Boucher Jul 20 '15 at 16:53
  • Update: What this _does_ do is add the dependency to the parent application. Which means any subsequent builds will require `npm install` thus adding the dependency. – Kevin Boucher Feb 17 '16 at 18:20