Skip to content

Commit

Permalink
Merge pull request #96 from calvin-fb/terser
Browse files Browse the repository at this point in the history
Add support for ember-cli-terser
  • Loading branch information
calvinlough authored Jan 17, 2022
2 parents 3697655 + 4aba745 commit da3d699
Show file tree
Hide file tree
Showing 4 changed files with 2,724 additions and 1,140 deletions.
14 changes: 10 additions & 4 deletions config/ember-try.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@ module.exports = {
name: 'with ember-cli-uglify 1.2.x',
npm: {
devDependencies: {
"ember-cli-uglify": "~1.2.0",
"ember-source": ">2.13"
"ember-cli-uglify": "~1.2.0"
}
}
},
{
name: 'with ember-cli-uglify 2.x',
npm: {
devDependencies: {
"ember-cli-uglify": "~2.0",
"ember-source": ">2.13"
"ember-cli-uglify": "~2.0"
}
}
},
{
name: 'with ember-cli-terser',
npm: {
devDependencies: {
'ember-cli-terser': '4.0'
}
}
}
Expand Down
42 changes: 23 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
var Funnel = require('broccoli-funnel');
var EmberApp = require('ember-cli/lib/broccoli/ember-app');
var merge = require('lodash.merge');
var replace = require('broccoli-replace');
var chalk = require('chalk');
var VersionChecker = require('ember-cli-version-checker');
var TemplateCompiler = require('./lib/template-compiler');
var hash = require('object-hash');
let Funnel = require('broccoli-funnel');
let EmberApp = require('ember-cli/lib/broccoli/ember-app');
let merge = require('lodash.merge');
let replace = require('broccoli-replace');
let chalk = require('chalk');
let VersionChecker = require('ember-cli-version-checker');
let TemplateCompiler = require('./lib/template-compiler');
let hash = require('object-hash');

module.exports = {
name: 'ember-cli-conditional-compile',
Expand All @@ -14,34 +14,38 @@ module.exports = {
init: function() {
this._super.init && this._super.init.apply(this, arguments);

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

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

included: function(app, parentAddon) {
var target = (parentAddon || app);
var config = this.project.config(target.env);
let target = (parentAddon || app);
let config = this.project.config(target.env);

var options = {
let options = {
options: {
compress: {
global_defs: config.featureFlags
}
}
};

if (this.uglifyVersion.satisfies('>= 2.0.0')) {
if (this.terserVersion.exists()) {
target.options = merge(target.options, { 'ember-cli-terser': { terser: options.options } });
this.enableCompile = target.options['ember-cli-terser'].enabled;
} else if (this.uglifyVersion.satisfies('>= 2.0.0')) {
target.options = merge(target.options, { 'ember-cli-uglify': { uglify: options.options } });
this.enableCompile = target.options['ember-cli-uglify'].enabled;
} else {
target.options.minifyJS = merge(target.options.minifyJS, options);
this.enableCompile = target.options.minifyJS.enabled;
}

var templateCompilerInstance = {
let templateCompilerInstance = {
name: 'conditional-compile-template',
plugin: TemplateCompiler(config.featureFlags)
}
Expand Down Expand Up @@ -76,15 +80,15 @@ module.exports = {
* removes the code non reachable.
*/
transpileTree(tree, config) {
var esTranspiler = require('broccoli-babel-transpiler');
var inlineFeatureFlags = require('babel-plugin-inline-replace-variables');
let esTranspiler = require('broccoli-babel-transpiler');
let 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 ]
[inlineFeatureFlags, config.featureFlags]
]
});
},
Expand All @@ -93,7 +97,7 @@ module.exports = {
postprocessTree: function(type, tree) {
if (type !== 'js') return tree;

var config = this.project.config(EmberApp.env());
let config = this.project.config(EmberApp.env());

if (!config.featureFlags) {
console.log(chalk.red(
Expand All @@ -103,7 +107,7 @@ module.exports = {
return tree;
}

var excludes = [];
let excludes = [];

Object.keys(config.featureFlags).map(function(flag) {
if (config.includeDirByFlag && !config.featureFlags[flag] && config.includeDirByFlag[flag]) {
Expand Down
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"lint": "eslint lib tests",
"start": "ember server",
"build": "ember build",
"test": "yarn lint && yarn test:node && ember try:testall",
"test": "yarn lint && yarn test:node && ember try:each",
"test:node": "mocha node-tests"
},
"repository": "https://github.com/minichate/ember-cli-conditional-compile.git",
Expand All @@ -26,17 +26,15 @@
"chai": "^4.2.0",
"co": "^4.6.0",
"common-tags": "^1.8.0",
"ember-cli": "~3.7.1",
"ember-cli": "^4.1.0",
"ember-cli-dependency-checker": "~3.1.0",
"ember-cli-eslint": "~5.1.0",
"ember-cli-htmlbars": "~3.0.1",
"ember-cli-htmlbars-inline-precompile": "~2.1.0",
"ember-cli-htmlbars": "6.0.1",
"ember-cli-inject-live-reload": "~2.0.1",
"ember-cli-qunit": "~4.4.0",
"ember-cli-release": "~1.0.0-beta.2",
"ember-cli-shims": "1.2.0",
"ember-cli-test-loader": "~2.2.0",
"ember-cli-uglify": "~2.1.0",
"ember-load-initializers": "2.0.0",
"ember-resolver": "~5.0.1",
"ember-source": "^3.7.2",
Expand Down
Loading

0 comments on commit da3d699

Please sign in to comment.