我正在尝试创建我的第一个Ember AddOn,而我却陷入了将其导入Ember项目的困境。我已经创建了插件并像这样发布到github:
ember-cli$ ember addon test-addon
ember-cli$ cd test-addon
ember-cli/test-addon$ git remote add origin <github-url>
然后,从我的项目中,我安装了插件:
test-app$ ember install <github-url>
最后,尝试将其导入路线:
# app/rotues/index.coffee
import TestAddon from 'test-addon'
但是,我在控制台上收到此错误:
Uncaught Error: Could not find module `test-addon` imported from `test-app/routes/index`
我出错的任何想法?我可以在node_modules
目录中看到插件,但不能在bower_components
中看到。我认为(tm)这是我的问题,但我不确定我还需要做些什么来设置我的插件。
答案 0 :(得分:12)
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 app's package.json
and restart the ember-cli app server.
The easiest way to include a locally-developed addon is to use NPM's link
First run 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
ing it.
You'll still need to manually add it to your package.json
(required for ember-cli to find it when compiling your app) and run the default blueprint (if your addon has one).
If this doesn't seem to be working, check that you've created a package.json
in your addon with "ember-addon"
in the keywords
list (the default ember-cli addon blueprint should do this for you).