我试图从我的应用程序的消费端更多地了解 Ember 插件与普通包之间的差异。
所以我想了解以下几点;
- Differences in consuming both ? like what do we need to import, Brocfile changes, etc How are these available to individual modules say inside a route or controller, etc
- Is the installation process same for both ? Can both of them live in any repo or registry (like npm or bower registry)
- How or where do they reside in the build output i.e. in dist folder ?
- How do we decide whether to package something as addon Vs normal package (this is more from a developer perspective)?
您还可以突出显示任何其他显着差异。
最佳答案
免责声明:这是我的理解,但我自己没有构建过插件,所以我可能会有一些误解。
Ember 插件基本上是普通的软件包,具有一些附加结构,使它们更容易集成到 ember 应用程序中。
使用 Ember 插件时,您可以像使用任何普通包一样导入内容。唯一的区别来自需要向解析器注册的对象(服务、适配器、帮助器等):它们将被自动检测、添加到您的项目并注册。这就是为什么在安装后,例如
ember-notify
,您只需在某些组件/ Controller 中Ember.inject.service('notify')
即可工作。详细信息由插件作者选择。通常,插件会注册受益于依赖注入(inject)的常见对象(大多数是模板帮助程序和服务 - 尽管某些插件定义了新的注入(inject)类型并附带了一些打包的内容,例如
ember-validations
注册其验证器
)。对于其他功能,您可以正常导入内容(import thing from 'addon/thing';
)。Ember 插件使用
npm
安装(您可以在项目的node_modules
下找到它们)。您甚至可以自己使用npm
安装它们,只需记住将它们添加到package.json
中,以便它们包含在ember build
中。在构建输出中,它们应该简单地一起打包到
assets/vendor.js
中。我想说的经验法则应该是:如果它是特定于 ember 的,则将其作为插件。否则,请坚持使用普通包装。但实际上,ember 插件基本上是一个具有特定布局的普通包。
关于javascript - Ember 插件与普通包的对比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33888296/