How to import a newly created hadron addon?

I am trying to create my first Ember AddOn and I am stuck importing it into an Ember project. I created an addon and posted it on github as follows:

ember-cli$ ember addon test-addon ember-cli$ cd test-addon ember-cli/test-addon$ git remote add origin <github-url> 

Then from my project I install the addon:

 test-app$ ember install <github-url> 

And finally, try importing it into the route:

 # app/rotues/index.coffee import TestAddon from 'test-addon' 

But I get this error on the console:

 Uncaught Error: Could not find module `test-addon` imported from `test-app/routes/index` 

Any ideas I'm wrong about? I see the addon in the node_modules directory, but not in bower_components . I think (tm) this is my problem, but I'm not sure what else I need to do to configure my addon.

+6
source share
1 answer

TL; DR

 cd my-addon npm link cd /my/project/dir npm link my-addon ember g my-addon # run default blueprint 

Then add "my-addon": "*" to the devDependencies section of your package.json application and restart the ember-cli application server.

Longer answer

The easiest way to enable a locally developed addon is to use NPM link

First, run the npm link from the root of your addon project to register it with npm. Then running npm link <your-addon-name> will have the same effect as npm install .

You still need to manually add it to your package.json (necessary for ember-cli to find it when compiling your application) and run it by default (if your addon has one).

If this does not work, make sure you create package.json in your addon using "ember-addon" in the keywords list (by default, the ember-cli addon project should do this for you).

+11
source

Source: https://habr.com/ru/post/987957/


All Articles