diff --git a/package.json b/package.json index d6569f86..79a9d572 100644 --- a/package.json +++ b/package.json @@ -88,6 +88,7 @@ "eslint-plugin-react": "^6.2.0", "font-awesome": "^4.6.3", "glob": "^7.0.6", + "google-closure-compiler-js": "^20160828.0.1", "gulp": "^3.9.1", "jsdom": "^9.4.5", "mocha": "^3.0.2", diff --git a/webpack.config.js b/webpack.config.js index 6abaec77..bff60449 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -4,6 +4,8 @@ const assert = require('assert'); +const ClosureCompiler = require('google-closure-compiler-js').webpack; + const isRelease = process.env.NODE_ENV === 'production'; const KAREN_ENTRY_POINT = process.env.KAREN_ENTRY_POINT; @@ -59,6 +61,24 @@ else { ]); } +const webpackPlugins = []; +if (isRelease) { + // https://github.com/google/closure-compiler-js + const closure = new ClosureCompiler({ + options: { + languageIn: 'ECMASCRIPT6', + languageOut: 'ECMASCRIPT5_STRICT', + compilationLevel: 'SIMPLE', + warningLevel: 'VERBOSE', + + createSourceMap: true, + rewritePolyfills: false, + useTypesForOptimization: false, + }, + }); + webpackPlugins.push(closure); +} + module.exports = { bail: true, @@ -98,4 +118,6 @@ module.exports = { } ] }, + + plugins: webpackPlugins, };