Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace featureFlags inline by their values when minifying #41

Merged
merged 1 commit into from
May 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = {

var checker = new VersionChecker(this);
checker.forEmber().assertAbove('2.9.0');

this.htmlbarsVersion = checker.for('ember-cli-htmlbars', 'npm');
},

Expand Down Expand Up @@ -57,6 +57,33 @@ module.exports = {
target.registry.add('htmlbars-ast-plugin', templateCompilerInstance);
},

setupPreprocessorRegistry: function(type, registry) {
registry.add('js', {
name: 'ember-cli-conditional-compile',
ext: 'js',
toTree: (tree) => this.transpileTree(tree)
});
},

/**
* Inline feature flags value so that babili's dead code elimintation plugin
* removes the code non reachable.
*/
transpileTree(tree, config) {
var esTranspiler = require('broccoli-babel-transpiler');
var inlineFeatureFlags = require('babel-plugin-inline-replace-variables');
var config = this.project.config(EmberApp.env());
if (!this.enableCompile) {
return tree;
}
return esTranspiler(tree, {
plugins: [
[ inlineFeatureFlags, config.featureFlags ]
]
});
},


postprocessTree: function(type, tree) {
if (type !== 'js') return tree;

Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
"loader.js": "4.2.3"
},
"dependencies": {
"babel-plugin-inline-replace-variables": "https://github.com/alexBaizeau/babel-plugin-inline-replace-variables.git#8d55becd00acca84b6f301ad346aeed9507949a3",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we can use 1.3.1 now :)

"broccoli-babel-transpiler": "^6.0.0",
"broccoli-funnel": "~1.1.0",
"broccoli-replace": "0.12.0",
"chalk": "~1.1.0",
Expand Down
10 changes: 10 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,12 @@ babel-plugin-inline-environment-variables@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/babel-plugin-inline-environment-variables/-/babel-plugin-inline-environment-variables-1.0.1.tgz#1f58ce91207ad6a826a8bf645fafe68ff5fe3ffe"

"babel-plugin-inline-replace-variables@https://github.com/alexBaizeau/babel-plugin-inline-replace-variables.git#8d55becd00acca84b6f301ad346aeed9507949a3":
version "1.3.0"
resolved "https://github.com/alexBaizeau/babel-plugin-inline-replace-variables.git#8d55becd00acca84b6f301ad346aeed9507949a3"
dependencies:
babylon "^6.17.0"

babel-plugin-jscript@^1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/babel-plugin-jscript/-/babel-plugin-jscript-1.0.4.tgz#8f342c38276e87a47d5fa0a8bd3d5eb6ccad8fcc"
Expand Down Expand Up @@ -848,6 +854,10 @@ babylon@^6.11.0, babylon@^6.15.0, babylon@^6.16.1:
version "6.16.1"
resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.16.1.tgz#30c5a22f481978a9e7f8cdfdf496b11d94b404d3"

babylon@^6.17.0:
version "6.17.1"
resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.17.1.tgz#17f14fddf361b695981fe679385e4f1c01ebd86f"

backbone@^1.1.2:
version "1.3.3"
resolved "https://registry.yarnpkg.com/backbone/-/backbone-1.3.3.tgz#4cc80ea7cb1631ac474889ce40f2f8bc683b2999"
Expand Down