简体   繁体   中英

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.

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.

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.

You have multiple options:

  1. Don't exclude files or code, but disable with ember-feature-flags addon

Great addon: 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. They seem to strip the files in index.js#treeForAddon . 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

  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/

Hope this helps!

There are two possible options that would be helpful for you:

The quick way is to install Ember-Cli-Tree-Shaker . In your ember-cli-build.js file, you can include an [exclude] array of files paths always to remove. 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. Here's an example: https://github.com/kaliber5/ember-bootstrap/blob/master/index.js#L282

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