Skip to content
This repository has been archived by the owner on Jul 9, 2021. It is now read-only.

Commit

Permalink
[fixed] jsWebCompile improved performance in development mode, advanc…
Browse files Browse the repository at this point in the history
…ed optimizations in production
  • Loading branch information
thealjey committed Oct 9, 2015
1 parent 9d0ab0b commit 84fa46e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 21 deletions.
8 changes: 5 additions & 3 deletions build/jsWebCompile.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,19 @@ 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
*
* @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';
*
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion docs/global.html
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,7 @@ <h5>Parameters:</h5>
</td>


<td class="description last">if true provides faster source map rebuilds, good for rapid development</td>
<td class="description last">if true the compilation time is greatly reduced, good for rapid development</td>
</tr>


Expand Down
34 changes: 19 additions & 15 deletions lib/jsWebCompile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,31 @@ 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
*
* @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';
*
Expand All @@ -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;

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
},
"peerDependencies": {
"babel-loader": "5.x",
"babel-runtime": "5.x",
"react-hot-loader": "1.x"
},
"devDependencies": {
Expand Down
10 changes: 8 additions & 2 deletions spec/jsWebCompileSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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));
Expand Down

0 comments on commit 84fa46e

Please sign in to comment.