javascript - In Webpack, how to enable a plugin according to command line parameters? -
following plugin property webpack.config.js
:
plugins: [ new webpack.provideplugin({ $: 'jquery', jquery: 'jquery' }), new webpack.optimize.occurenceorderplugin(), new webpack.defineplugin({ 'process.env': { 'node_env': json.stringify('production'), } }), new webpack.optimize.uglifyjsplugin({ compressor: { warnings: false } }), new compressionplugin({ asset: '{file}', algorithm: 'gzip', regexp: /\.js$|\.html$/, }) ],
sometimes want disable compressionplugin
while want enable it. however, looks clumsy create 2 webpack config files. wondering whether there way enable/disable plugin dynamically using command line parameters?
for example, great if can use webpack --disable-compression-plugin
disable compressionplugin
. have ideas this?
try yargs
npm module this:
npm install yargs --save-dev
in webpack.config.js
:
var webpack = require('webpack'); var yargs = require("yargs"); ... var argv = yargs .boolean("disable-compression-plugin") .argv; ... // use argv.disablecompressionplugin check option module.exports = { ... plugins: (function(argv) { var plugins = [ new webpack.provideplugin({ $: 'jquery', jquery: 'jquery' }), new webpack.optimize.occurenceorderplugin(), new webpack.defineplugin({ 'process.env': { 'node_env': json.stringify('production'), } }), new webpack.optimize.uglifyjsplugin({ compressor: { warnings: false } }) ]; // here option condition if (argv.disablecompressionplugin) { plugins.push(new compressionplugin({ asset: '{file}', algorithm: 'gzip', regexp: /\.js$|\.html$/, })); } return plugins; })(argv), ... };
Comments
Post a Comment