[英]How to exclude a component in ember build
Short Explanation: 简短说明:
How to exclude all component.hbs
, component.hbs.js
and this.route('component)
mention in router.js
related to a component while ember build. 如何排除所有
component.hbs
, component.hbs.js
和this.route('component)
中提到router.js
有关,而烬构建一个组成部分。
Long Explanation: 详细说明:
Think that you have a component in your ember app which you want to be available only in the development environment ( lets not worry about how good this approach is, for now!! ) and must be removed while building for production. 认为您的ember应用程序中有一个组件,希望只在开发环境中可用 (现在不用担心这种方法的效果!! ),并且在进行生产时必须将其删除。
I have tried a few ember-cli
plugins ( broccoli-funnel , ember-cli-funnel ) which excludes component.hbs.js
file but I can still see the references to the component.hbs
and this.route('component')
in the compiled JS file in /dist
folder. 我已经尝试了一些
ember-cli
插件( broccoli-funnel , ember-cli-funnel ),该插件排除了component.hbs.js
文件,但是我仍然可以在其中看到对component.hbs
和this.route('component')
的引用。 /dist
文件夹中的已编译JS文件。
You have multiple options: 您有多种选择:
Great addon: https://github.com/kategengler/ember-feature-flags 很棒的插件: https : //github.com/kategengler/ember-feature-flags
As mentioned by pedro, you could checkout ember-composable-helpers
for that. 如pedro所述,您可以为此签出
ember-composable-helpers
。 They seem to strip the files in index.js#treeForAddon
. 他们似乎剥离了
index.js#treeForAddon
的文件。 https://github.com/DockYard/ember-composable-helpers/blob/master/index.js#L28-L33 https://github.com/DockYard/ember-composable-helpers/blob/master/index.js#L28-L33
This might also help: Place to put assets for dev/test in emberjs 这也可能会有所帮助: 在emberjs中放置用于开发/测试的资产
Might be a bit more complicated... you could checkout how Ember does it with their Feature Flags (although, I'm not sure if they use defeatureify
or babel-plugin-filter-imports
) * Ember Feature Flags: https://guides.emberjs.com/release/configuring-ember/feature-flags/ 可能会更复杂...您可以查看Ember如何使用其功能标志(尽管我不确定他们是否使用
defeatureify
或babel-plugin-filter-imports
)* Ember功能标志: https:// guides.emberjs.com/release/configuring-ember/feature-flags/
Defeatureify: https://github.com/thomasboyt/defeatureify/ 取消特征化: https : //github.com/thomasboyt/defeatureify/
https://github.com/ember-cli/babel-plugin-filter-imports https://github.com/ember-cli/babel-plugin-filter-imports
Hope this helps! 希望这可以帮助!
There are two possible options that would be helpful for you: 有两种可能的选项对您有帮助:
The quick way is to install Ember-Cli-Tree-Shaker . 快速的方法是安装Ember-Cli-Tree-Shaker 。 In your ember-cli-build.js file, you can include an
[exclude]
array of files paths always to remove. 在ember-cli-build.js文件中,您可以包括一个
[exclude]
文件路径数组,该文件路径始终要删除。 However, this is an experimental project, and follow all the disclaimers on the site. 但是,这是一个实验性项目,请遵循网站上的所有免责声明。
The longer, but potentially more stable, way to strip the component from the build, is to create an in-repo addon and in that addon's index.js
file, filter components in the treeForAddon()
and treeForAddonTemplates()
hooks. 从构建中剥离组件的一种较长但可能更稳定的方法是创建一个内部仓库插件,并在该插件的
index.js
文件中,过滤treeForAddon()
和treeForAddonTemplates()
挂钩中的组件。 Here's an example: https://github.com/kaliber5/ember-bootstrap/blob/master/index.js#L282 这是一个例子: https : //github.com/kaliber5/ember-bootstrap/blob/master/index.js#L282
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.