diff --git a/build/jsWebCompile.js b/build/jsWebCompile.js index d4454f6..b9fbb7f 100644 --- a/build/jsWebCompile.js +++ b/build/jsWebCompile.js @@ -24,10 +24,11 @@ var config = { test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader', - query: { optional: 'runtime', loose: 'all', cacheDirectory: true } + query: { optional: [], loose: 'all', cacheDirectory: true } }] } -}; +}, + productionTransformers = ['runtime', 'minification.deadCodeElimination', 'minification.constantFolding', 'minification.memberExpressionLiterals', 'minification.propertyLiterals', 'optimisation.react.inlineElements', 'optimisation.react.constantElements']; /** * Compiles JavaScript for the browser @@ -35,7 +36,7 @@ var config = { * @param {string} inPath - a full system path to the input file * @param {string} outPath - a full system path to the output file * @param {Function} callback - a callback function which accepts 1 argument: an array of error strings or null - * @param {boolean} [devMode=false] - if true provides faster source map rebuilds, good for rapid development + * @param {boolean} [devMode=false] - if true the compilation time is greatly reduced, good for rapid development * @example * import {jsWebCompile} from 'webcompiler'; * @@ -58,6 +59,7 @@ function jsWebCompile(inPath, outPath, callback) { config.output.path = parsed.dir; config.output.filename = parsed.base; config.devtool = (devMode ? 'eval-' : '') + 'source-map'; + config.module.loaders[0].query.optional = devMode ? [] : productionTransformers; (0, _webpack2['default'])(config, function (e, stats) { var jsonStats = undefined, errors = undefined; diff --git a/docs/global.html b/docs/global.html index e78add0..c7f289f 100644 --- a/docs/global.html +++ b/docs/global.html @@ -1179,7 +1179,7 @@
Parameters:
- if true provides faster source map rebuilds, good for rapid development + if true the compilation time is greatly reduced, good for rapid development diff --git a/lib/jsWebCompile.js b/lib/jsWebCompile.js index 2e80f1a..fc5efcc 100644 --- a/lib/jsWebCompile.js +++ b/lib/jsWebCompile.js @@ -4,20 +4,23 @@ import webpack from 'webpack'; import {parse} from 'path'; const config = { - cache: {}, - debug: true, - devtool: '', - entry: '', - output: {path: '', filename: ''}, - module: { - loaders: [{ - test: /\.js$/, - exclude: /node_modules/, - loader: 'babel-loader', - query: {optional: 'runtime', loose: 'all', cacheDirectory: true} - }] - } -}; + cache: {}, + debug: true, + devtool: '', + entry: '', + output: {path: '', filename: ''}, + module: { + loaders: [{ + test: /\.js$/, + exclude: /node_modules/, + loader: 'babel-loader', + query: {optional: [], loose: 'all', cacheDirectory: true} + }] + } + }, + productionTransformers = ['runtime', 'minification.deadCodeElimination', 'minification.constantFolding', + 'minification.memberExpressionLiterals', 'minification.propertyLiterals', 'optimisation.react.inlineElements', + 'optimisation.react.constantElements']; /** * Compiles JavaScript for the browser @@ -25,7 +28,7 @@ const config = { * @param {string} inPath - a full system path to the input file * @param {string} outPath - a full system path to the output file * @param {Function} callback - a callback function which accepts 1 argument: an array of error strings or null - * @param {boolean} [devMode=false] - if true provides faster source map rebuilds, good for rapid development + * @param {boolean} [devMode=false] - if true the compilation time is greatly reduced, good for rapid development * @example * import {jsWebCompile} from 'webcompiler'; * @@ -45,6 +48,7 @@ export default function jsWebCompile(inPath: string, outPath: string, callback: config.output.path = parsed.dir; config.output.filename = parsed.base; config.devtool = `${devMode ? 'eval-' : ''}source-map`; + config.module.loaders[0].query.optional = devMode ? [] : productionTransformers; webpack(config, function (e, stats) { let jsonStats, errors; diff --git a/package.json b/package.json index 0ef3923..2fe9c50 100644 --- a/package.json +++ b/package.json @@ -59,6 +59,7 @@ }, "peerDependencies": { "babel-loader": "5.x", + "babel-runtime": "5.x", "react-hot-loader": "1.x" }, "devDependencies": { diff --git a/spec/jsWebCompileSpec.js b/spec/jsWebCompileSpec.js index b098ca3..06c8d23 100644 --- a/spec/jsWebCompileSpec.js +++ b/spec/jsWebCompileSpec.js @@ -32,7 +32,13 @@ describe('jsWebCompile', function () { test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader', - query: {optional: 'runtime', loose: 'all', cacheDirectory: true} + query: { + optional: ['runtime', 'minification.deadCodeElimination', 'minification.constantFolding', + 'minification.memberExpressionLiterals', 'minification.propertyLiterals', + 'optimisation.react.inlineElements', 'optimisation.react.constantElements'], + loose: 'all', + cacheDirectory: true + } }] } }, jasmine.any(Function)); @@ -54,7 +60,7 @@ describe('jsWebCompile', function () { test: /\.js$/, exclude: /node_modules/, loader: 'babel-loader', - query: {optional: 'runtime', loose: 'all', cacheDirectory: true} + query: {optional: [], loose: 'all', cacheDirectory: true} }] } }, jasmine.any(Function));