简体   繁体   English

如何在余烬构建中排除组件

[英]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.hbscomponent.hbs.jsthis.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-funnelember-cli-funnel ),该插件排除了component.hbs.js文件,但是我仍然可以在其中看到对component.hbsthis.route('component')的引用。 /dist文件夹中的已编译JS文件。

You have multiple options: 您有多种选择:

  1. Don't exclude files or code, but disable with ember-feature-flags addon 不排除文件或代码,而是使用ember-feature-flags插件禁用

Great addon: https://github.com/kategengler/ember-feature-flags 很棒的插件: https : //github.com/kategengler/ember-feature-flags

  1. Exclude files from the build 从构建中排除文件

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中放置用于开发/测试的资产

  1. Exclude code from the build 从构建中排除代码

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如何使用其功能标志(尽管我不确定他们是否使用defeatureifybabel-plugin-filter-imports )* Ember功能标志: https:// guides.emberjs.com/release/configuring-ember/feature-flags/

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.

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