简体   繁体   English

灰烬插件vs普通包装

[英]Ember addon Vs normal package

I am trying to understand the differences between an Ember addon Vs normal package more from consuming side in my app. 我正在尝试从我的应用程序的消费方面更深入地了解Ember插件与常规软件包之间的差异。

So I would like to understand the following points; 因此,我想了解以下几点;

  1. 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 例如我们需要导入的内容,Brocfile更改等,这些如何在路由或控制器等内部的各个模块中使用?
  2. Is the installation process same for both ? 两者的安装过程是否相同? Can both of them live in any repo or registry (like npm or bower registry) 他们俩都可以住在任何回购或注册表中吗(例如npm或bower注册表)
  3. How or where do they reside in the build output ie in dist folder ? 它们如何或如何驻留在生成输出中,即dist文件夹中?
  4. How do we decide whether to package something as addon Vs normal package (this is more from a developer perspective)? 我们如何确定是否将某些东西打包为插件与常规打包(从开发人员的角度来看更多)?

You can also highlight any other significant differences. 您还可以突出显示任何其他重要差异。

Disclaimer: this is my understanding, but I have not built an addon myself, so I might have some misconceptions. 免责声明:这是我的理解,但是我自己还没有构建插件,因此我可能会有一些误解。

Ember addons are basically normal packages with some additional structure that makes them easier to integrate in an ember application. Ember插件基本上是普通的软件包,带有一些其他结构,使它们更易于集成到ember应用程序中。

  1. When using an Ember addon, you import things exactly like with any normal package. 使用Ember插件时,您可以像导入任何普通软件包一样完全导入内容。 The only difference comes from objects that need to be registered with the resolver (services, adapers, helpers, etc): they will be automatically detected, added to your project and registered. 唯一的区别是需要在解析器中注册的对象(服务,适配器,帮助程序等):它们将被自动检测,添加到您的项目中并进行注册。 This is why, after installing, say ember-notify , you can just Ember.inject.service('notify') in some component/controller and it will work. 这就是为什么在安装后说出ember-notify ,您只需在某些组件/控制器中使用Ember.inject.service('notify')就可以了。

    The details are for the addon author to choose. 详细信息供插件作者选择。 Usually, addons will register common objects that benefit from dependency injection (template helpers and services, mostly - though some addons define new injection types and come with some packaged, for instance ember-validations registers its validators ). 通常,插件会注册受益于依赖项注入的通用对象(主要是模板帮助程序和服务-尽管某些插件定义了新的注入类型并附带了一些打包的文件,例如ember-validations注册了其validators )。 For other functionalities, you import things normally ( import thing from 'addon/thing'; ). 对于其他功能,您通常会导入事物( import thing from 'addon/thing'; )。

  2. Ember addons are installed using npm (you find them in your project, under node_modules ). Ember插件使用npm安装(您可以在项目的node_modules下找到它们)。 You can even install them with npm yourself, just remember to add them to package.json so they are included by ember build . 您甚至可以自己使用npm安装它们,只需记住将它们添加到package.json以便它们被ember build包含。

  3. In the build output, they should simply be packaged, altogether, into assets/vendor.js . 在构建输出中,应该将它们简单地全部打包到assets/vendor.js

  4. I would say the rule of thumb should be: if it is ember-specific, make it an addon. 我要说的经验法则应该是:如果是特定于余烬的,则使其成为插件。 Otherwise, stick to normal package. 否则,请坚持正常包装。 But really, an ember addon is basically a normal package that has a specific layout. 但实际上,ember插件基本上是具有特定布局的常规软件包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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