Skip to content

Commit

Permalink
Merge pull request #41 from alexBaizeau/support-dce-babili
Browse files Browse the repository at this point in the history
Replace featureFlags inline by their values when minifying
  • Loading branch information
minichate committed May 29, 2017
2 parents ee0b406 + 720c51a commit a1efea5
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
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",
"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

0 comments on commit a1efea5

Please sign in to comment.