diff --git a/index.js b/index.js index 90dc228..b206382 100644 --- a/index.js +++ b/index.js @@ -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'); }, @@ -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; diff --git a/package.json b/package.json index 855030a..fc60516 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/yarn.lock b/yarn.lock index 4a88fe5..a9e26a9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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"