简体   繁体   中英

Ember-cli addon dev, how to differentiate addon dev from application dev

When you create an ember-cli addon, you are supposed to be able to run a dummy app.

If a component need to access it's vendor folder you access "public/" in production. While developping the ember app that use the addon you access :

app.options.project.nodeModulesPath + "/"+ this.name+"/vendor/"

However, when you run the ember-cli addon server (the dummy app) you need only "vendor/".

this.getEnv() will return developpement while developping an addon, or an app using the addon.

How can I, in index.js , differentiate app dev from addon dev ?

Suppose we are in the included hook, you can check this.isAddon() to determine where are you now. Say if you are in the consumer ember app now, you can then invoke path.dirname(require.resolve('ADDON_NAME/package.json')) to get the absolute path of your ember add-on.

One thing to notice, this.isAddon() might not a public API (though it's stable enough, it's still not listed in API doc). If you concerned about this, you can use this.parent.name() to achieve the same goal, when you run with the dummy app, this.parent.name() always returns dummy .

BTW, this.parent is the same thing as app.project where app is the first argument of included hook.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM