@@ -18,22 +18,24 @@ module.exports = function(optimist, argv, convertOptions) {
1818 argv [ "optimize-occurence-order" ] = true ;
1919 }
2020
21- function ifArg ( name , fn , init ) {
21+ function ifArg ( name , fn , init , finalize ) {
2222 if ( Array . isArray ( argv [ name ] ) ) {
2323 if ( init ) init ( ) ;
2424 argv [ name ] . forEach ( fn ) ;
25+ if ( finalize ) finalize ( ) ;
2526 } else if ( typeof argv [ name ] != "undefined" ) {
2627 if ( init ) init ( ) ;
2728 fn ( argv [ name ] , - 1 ) ;
29+ if ( finalize ) finalize ( ) ;
2830 }
2931 }
3032
31- function ifArgPair ( name , fn , init ) {
33+ function ifArgPair ( name , fn , init , finalize ) {
3234 ifArg ( name , function ( content , idx ) {
3335 var i = content . indexOf ( "=" ) ;
3436 if ( i < 0 ) return fn ( null , content , idx ) ;
3537 else return fn ( content . substr ( 0 , i ) , content . substr ( i + 1 ) , idx ) ;
36- } , init ) ;
38+ } , init , finalize ) ;
3739 }
3840
3941 function ifBooleanArg ( name , fn ) {
@@ -139,14 +141,19 @@ module.exports = function(optimist, argv, convertOptions) {
139141 ensureArray ( options . module , "postLoaders" ) ;
140142 } ) ;
141143
144+ var defineObject ;
142145 ifArgPair ( "define" , function ( name , value ) {
143146 if ( name === null ) {
144147 name = value ;
145148 value = true ;
146149 }
147- options . define [ name ] = value ;
150+ defineObject [ name ] = value ;
148151 } , function ( ) {
149- ensureObject ( options , "define" ) ;
152+ defineObject = { }
153+ } , function ( ) {
154+ ensureArray ( options , "plugins" ) ;
155+ var DefinePlugin = require ( "../lib/DefinePlugin" ) ;
156+ options . plugins . push ( new DefinePlugin ( defineObject ) ) ;
150157 } ) ;
151158
152159 ifArg ( "output-path" , function ( value ) {
@@ -222,7 +229,12 @@ module.exports = function(optimist, argv, convertOptions) {
222229 options . watchDelay = value ;
223230 } ) ;
224231
225- mapArgToBoolean ( "hot" , "hot" ) ;
232+ ifBooleanArg ( "hot" , function ( ) {
233+ ensureArray ( options , "plugins" ) ;
234+ var HotModuleReplacementPlugin = require ( "../lib/HotModuleReplacementPlugin" ) ;
235+ options . plugins . push ( new HotModuleReplacementPlugin ( ) ) ;
236+ } ) ;
237+
226238 mapArgToBoolean ( "debug" , "debug" ) ;
227239
228240 ifBooleanArg ( "progress" , function ( ) {
@@ -279,45 +291,60 @@ module.exports = function(optimist, argv, convertOptions) {
279291 } ) ;
280292
281293 ifArg ( "optimize-max-chunks" , function ( value ) {
282- ensureObject ( options , "optimize" ) ;
283- options . optimize . maxChunks = parseInt ( value , 10 ) ;
294+ ensureArray ( options , "plugins" ) ;
295+ var LimitChunkCountPlugin = require ( "../lib/optimize/LimitChunkCountPlugin" ) ;
296+ options . plugins . push ( new LimitChunkCountPlugin ( {
297+ maxChunks : parseInt ( value , 10 )
298+ } ) ) ;
284299 } ) ;
285300
286301 ifArg ( "optimize-min-chunk-size" , function ( value ) {
287- ensureObject ( options , "optimize" ) ;
288- options . optimize . minChunkSize = parseInt ( value , 10 ) ;
302+ ensureArray ( options , "plugins" ) ;
303+ var LimitChunkSizePlugin = require ( "../lib/optimize/LimitChunkSizePlugin" ) ;
304+ options . plugins . push ( new LimitChunkSizePlugin ( parseInt ( value , 10 ) ) ) ;
289305 } ) ;
290306
291307 ifBooleanArg ( "optimize-minimize" , function ( ) {
292- ensureObject ( options , "optimize" ) ;
293- options . optimize . minimize = true ;
308+ ensureArray ( options , "plugins" ) ;
309+ var UglifyJsPlugin = require ( "../lib/optimize/UglifyJsPlugin" ) ;
310+ options . plugins . push ( new UglifyJsPlugin ( ) ) ;
294311 } ) ;
295312
296313 ifBooleanArg ( "optimize-occurence-order" , function ( ) {
297- ensureObject ( options , "optimize" ) ;
298- options . optimize . occurenceOrder = true ;
314+ ensureArray ( options , "plugins" ) ;
315+ var OccurenceOrderPlugin = require ( "../lib/optimize/OccurenceOrderPlugin" ) ;
316+ options . plugins . push ( new OccurenceOrderPlugin ( ) ) ;
299317 } ) ;
300318
301319 ifBooleanArg ( "optimize-dedupe" , function ( ) {
302- ensureObject ( options , "optimize" ) ;
303- options . optimize . dedupe = true ;
320+ ensureArray ( options , "plugins" ) ;
321+ var DedupePlugin = require ( "../lib/optimize/DedupePlugin" ) ;
322+ options . plugins . push ( new DedupePlugin ( ) ) ;
304323 } ) ;
305324
306325 ifArg ( "prefetch" , function ( request ) {
307- ensureArray ( options , "prefetch" ) ;
308- options . prefetch . push ( request ) ;
326+ ensureArray ( options , "plugins" ) ;
327+ var PrefetchPlugin = require ( "../lib/PrefetchPlugin" ) ;
328+ options . plugins . push ( new PrefetchPlugin ( request ) ) ;
309329 } ) ;
310330
311331 ifArg ( "provide" , function ( value ) {
312- ensureObject ( options , "provide " ) ;
332+ ensureArray ( options , "plugins " ) ;
313333 var idx = value . indexOf ( "=" ) ;
314334 if ( idx >= 0 ) {
315335 var name = value . substr ( 0 , idx ) ;
316336 value = value . substr ( idx + 1 ) ;
317337 } else {
318338 var name = value ;
319339 }
320- options . provide [ name ] = value ;
340+ var ProvidePlugin = require ( "../lib/ProvidePlugin" ) ;
341+ options . plugins . push ( new ProvidePlugin ( name , value ) ) ;
342+ } ) ;
343+
344+ ifBooleanArg ( "labeled-modules" , function ( ) {
345+ ensureArray ( options , "plugins" ) ;
346+ var LabeledModulesPlugin = require ( "../lib/dependencies/LabeledModulesPlugin" ) ;
347+ options . plugins . push ( new LabeledModulesPlugin ( ) ) ;
321348 } ) ;
322349
323350 ifArg ( "plugin" , function ( value ) {
0 commit comments