| 
									
										
										
										
											2012-03-10 20:11:23 +08:00
										 |  |  | #!/usr/bin/env node
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-03-12 04:50:55 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2012-03-10 20:11:23 +08:00
										 |  |  | var path = require("path"); | 
					
						
							| 
									
										
										
										
											2012-08-06 03:52:00 +08:00
										 |  |  | // Local version replace global one
 | 
					
						
							|  |  |  | try { | 
					
						
							|  |  |  | 	var localWebpack = require.resolve(path.join(process.cwd(), "node_modules", "webpack", "bin", "webpack.js")); | 
					
						
							| 
									
										
										
										
											2015-04-29 05:09:04 +08:00
										 |  |  | 	if(__filename !== localWebpack) { | 
					
						
							| 
									
										
										
										
											2012-08-06 03:52:00 +08:00
										 |  |  | 		return require(localWebpack); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } catch(e) {} | 
					
						
							| 
									
										
										
										
											2016-01-15 02:40:04 +08:00
										 |  |  | var yargs = require("yargs") | 
					
						
							| 
									
										
										
										
											2012-08-06 03:52:00 +08:00
										 |  |  | 	.usage("webpack " + require("../package.json").version + "\n" + | 
					
						
							| 
									
										
										
										
											2016-01-15 02:40:04 +08:00
										 |  |  | 		"Usage: https://webpack.github.io/docs/cli.html\n" + | 
					
						
							|  |  |  | 		"Usage without config file: webpack <entry> [<entry>] <output>\n" + | 
					
						
							|  |  |  | 		"Usage with config file: webpack"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | require("./config-yargs")(yargs); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var DISPLAY_GROUP = "Stats options:"; | 
					
						
							| 
									
										
										
										
											2016-09-21 04:41:28 +08:00
										 |  |  | var BASIC_GROUP = "Basic options:"; | 
					
						
							| 
									
										
										
										
											2016-01-15 02:40:04 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | yargs.options({ | 
					
						
							|  |  |  | 	"json": { | 
					
						
							|  |  |  | 		type: "boolean", | 
					
						
							|  |  |  | 		alias: "j", | 
					
						
							|  |  |  | 		describe: "Prints the result as JSON." | 
					
						
							|  |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2016-09-21 04:41:28 +08:00
										 |  |  | 	"progress": { | 
					
						
							|  |  |  | 		type: "boolean", | 
					
						
							|  |  |  | 		describe: "Print compilation progress in percentage", | 
					
						
							|  |  |  | 		group: BASIC_GROUP | 
					
						
							|  |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2016-01-15 02:40:04 +08:00
										 |  |  | 	"color": { | 
					
						
							|  |  |  | 		type: "boolean", | 
					
						
							| 
									
										
										
										
											2016-07-24 06:14:23 +08:00
										 |  |  | 		alias: "colors", | 
					
						
							|  |  |  | 		default: function supportsColor() { | 
					
						
							|  |  |  | 			return require("supports-color"); | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2016-01-15 02:40:04 +08:00
										 |  |  | 		group: DISPLAY_GROUP, | 
					
						
							|  |  |  | 		describe: "Enables/Disables colors on the console" | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	"sort-modules-by": { | 
					
						
							|  |  |  | 		type: "string", | 
					
						
							|  |  |  | 		group: DISPLAY_GROUP, | 
					
						
							|  |  |  | 		describe: "Sorts the modules list by property in module" | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	"sort-chunks-by": { | 
					
						
							|  |  |  | 		type: "string", | 
					
						
							|  |  |  | 		group: DISPLAY_GROUP, | 
					
						
							|  |  |  | 		describe: "Sorts the chunks list by property in chunk" | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	"sort-assets-by": { | 
					
						
							|  |  |  | 		type: "string", | 
					
						
							|  |  |  | 		group: DISPLAY_GROUP, | 
					
						
							|  |  |  | 		describe: "Sorts the assets list by property in asset" | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	"hide-modules": { | 
					
						
							|  |  |  | 		type: "boolean", | 
					
						
							|  |  |  | 		group: DISPLAY_GROUP, | 
					
						
							|  |  |  | 		describe: "Hides info about modules" | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	"display-exclude": { | 
					
						
							|  |  |  | 		type: "string", | 
					
						
							|  |  |  | 		group: DISPLAY_GROUP, | 
					
						
							|  |  |  | 		describe: "Exclude modules in the output" | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	"display-modules": { | 
					
						
							|  |  |  | 		type: "boolean", | 
					
						
							|  |  |  | 		group: DISPLAY_GROUP, | 
					
						
							|  |  |  | 		describe: "Display even excluded modules in the output" | 
					
						
							|  |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2016-12-14 19:03:24 +08:00
										 |  |  | 	"display-max-modules": { | 
					
						
							|  |  |  | 		type: "number", | 
					
						
							|  |  |  | 		group: DISPLAY_GROUP, | 
					
						
							|  |  |  | 		describe: "Sets the maximum number of visible modules in output" | 
					
						
							|  |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2016-01-15 02:40:04 +08:00
										 |  |  | 	"display-chunks": { | 
					
						
							|  |  |  | 		type: "boolean", | 
					
						
							|  |  |  | 		group: DISPLAY_GROUP, | 
					
						
							|  |  |  | 		describe: "Display chunks in the output" | 
					
						
							|  |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 	"display-entrypoints": { | 
					
						
							|  |  |  | 		type: "boolean", | 
					
						
							|  |  |  | 		group: DISPLAY_GROUP, | 
					
						
							|  |  |  | 		describe: "Display entry points in the output" | 
					
						
							|  |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2016-01-15 02:40:04 +08:00
										 |  |  | 	"display-origins": { | 
					
						
							|  |  |  | 		type: "boolean", | 
					
						
							|  |  |  | 		group: DISPLAY_GROUP, | 
					
						
							|  |  |  | 		describe: "Display origins of chunks in the output" | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	"display-cached": { | 
					
						
							|  |  |  | 		type: "boolean", | 
					
						
							|  |  |  | 		group: DISPLAY_GROUP, | 
					
						
							|  |  |  | 		describe: "Display also cached modules in the output" | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	"display-cached-assets": { | 
					
						
							|  |  |  | 		type: "boolean", | 
					
						
							|  |  |  | 		group: DISPLAY_GROUP, | 
					
						
							|  |  |  | 		describe: "Display also cached assets in the output" | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	"display-reasons": { | 
					
						
							|  |  |  | 		type: "boolean", | 
					
						
							|  |  |  | 		group: DISPLAY_GROUP, | 
					
						
							|  |  |  | 		describe: "Display reasons about module inclusion in the output" | 
					
						
							|  |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2016-12-14 19:03:24 +08:00
										 |  |  | 	"display-depth": { | 
					
						
							|  |  |  | 		type: "boolean", | 
					
						
							|  |  |  | 		group: DISPLAY_GROUP, | 
					
						
							|  |  |  | 		describe: "Display distance from entry point for each module" | 
					
						
							|  |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2016-06-29 07:17:15 +08:00
										 |  |  | 	"display-used-exports": { | 
					
						
							|  |  |  | 		type: "boolean", | 
					
						
							|  |  |  | 		group: DISPLAY_GROUP, | 
					
						
							|  |  |  | 		describe: "Display information about used exports in modules (Tree Shaking)" | 
					
						
							|  |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2016-09-07 17:45:41 +08:00
										 |  |  | 	"display-provided-exports": { | 
					
						
							|  |  |  | 		type: "boolean", | 
					
						
							|  |  |  | 		group: DISPLAY_GROUP, | 
					
						
							|  |  |  | 		describe: "Display information about exports provided from modules" | 
					
						
							|  |  |  | 	}, | 
					
						
							| 
									
										
										
										
											2016-01-15 02:40:04 +08:00
										 |  |  | 	"display-error-details": { | 
					
						
							|  |  |  | 		type: "boolean", | 
					
						
							|  |  |  | 		group: DISPLAY_GROUP, | 
					
						
							|  |  |  | 		describe: "Display details about errors" | 
					
						
							|  |  |  | 	}, | 
					
						
							|  |  |  | 	"verbose": { | 
					
						
							|  |  |  | 		type: "boolean", | 
					
						
							|  |  |  | 		group: DISPLAY_GROUP, | 
					
						
							|  |  |  | 		describe: "Show more details" | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var argv = yargs.argv; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if(argv.verbose) { | 
					
						
							|  |  |  | 	argv["display-reasons"] = true; | 
					
						
							| 
									
										
										
										
											2016-12-14 19:03:24 +08:00
										 |  |  | 	argv["display-depth"] = true; | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 	argv["display-entrypoints"] = true; | 
					
						
							| 
									
										
										
										
											2016-06-29 07:17:15 +08:00
										 |  |  | 	argv["display-used-exports"] = true; | 
					
						
							| 
									
										
										
										
											2016-09-09 20:31:02 +08:00
										 |  |  | 	argv["display-provided-exports"] = true; | 
					
						
							| 
									
										
										
										
											2016-01-15 02:40:04 +08:00
										 |  |  | 	argv["display-error-details"] = true; | 
					
						
							|  |  |  | 	argv["display-modules"] = true; | 
					
						
							|  |  |  | 	argv["display-cached"] = true; | 
					
						
							|  |  |  | 	argv["display-cached-assets"] = true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var options = require("./convert-argv")(yargs, argv); | 
					
						
							| 
									
										
										
										
											2012-04-03 22:26:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | function ifArg(name, fn, init) { | 
					
						
							|  |  |  | 	if(Array.isArray(argv[name])) { | 
					
						
							|  |  |  | 		if(init) init(); | 
					
						
							|  |  |  | 		argv[name].forEach(fn); | 
					
						
							| 
									
										
										
										
											2015-05-10 20:18:12 +08:00
										 |  |  | 	} else if(typeof argv[name] !== "undefined") { | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		if(init) init(); | 
					
						
							|  |  |  | 		fn(argv[name], -1); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-03-10 20:11:23 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-14 22:34:45 +08:00
										 |  |  | function processOptions(options) { | 
					
						
							|  |  |  | 	// process Promise
 | 
					
						
							|  |  |  | 	if(typeof options.then === "function") { | 
					
						
							|  |  |  | 		options.then(processOptions).catch(function(err) { | 
					
						
							|  |  |  | 			console.error(err.stack || err); | 
					
						
							| 
									
										
										
										
											2017-01-05 05:33:00 +08:00
										 |  |  | 			process.exit(1); // eslint-disable-line
 | 
					
						
							| 
									
										
										
										
											2015-11-14 22:34:45 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2012-09-25 22:45:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-11 17:51:58 +08:00
										 |  |  | 	var firstOptions = [].concat(options)[0]; | 
					
						
							|  |  |  | 	var statsPresetToOptions = require("../lib/Stats.js").presetToOptions; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-11 17:51:58 +08:00
										 |  |  | 	var outputOptions = options.stats; | 
					
						
							| 
									
										
										
										
											2017-01-11 17:51:58 +08:00
										 |  |  | 	if(typeof outputOptions === "boolean" || typeof outputOptions === "string") | 
					
						
							|  |  |  | 		outputOptions = statsPresetToOptions(outputOptions); | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		outputOptions = {}; | 
					
						
							|  |  |  | 	outputOptions = Object.create(outputOptions); | 
					
						
							|  |  |  | 	if(Array.isArray(options) && !outputOptions.children) { | 
					
						
							|  |  |  | 		outputOptions.children = options.map(o => o.stats); | 
					
						
							| 
									
										
										
										
											2016-04-19 10:06:36 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-11-14 22:34:45 +08:00
										 |  |  | 	if(typeof outputOptions.context === "undefined") | 
					
						
							|  |  |  | 		outputOptions.context = firstOptions.context; | 
					
						
							| 
									
										
										
										
											2012-03-10 20:11:23 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-14 22:34:45 +08:00
										 |  |  | 	ifArg("json", function(bool) { | 
					
						
							|  |  |  | 		if(bool) | 
					
						
							|  |  |  | 			outputOptions.json = bool; | 
					
						
							|  |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2014-09-15 17:46:33 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-14 22:34:45 +08:00
										 |  |  | 	if(typeof outputOptions.colors === "undefined") | 
					
						
							|  |  |  | 		outputOptions.colors = require("supports-color"); | 
					
						
							| 
									
										
										
										
											2015-05-22 04:43:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-14 22:34:45 +08:00
										 |  |  | 	ifArg("sort-modules-by", function(value) { | 
					
						
							|  |  |  | 		outputOptions.modulesSort = value; | 
					
						
							| 
									
										
										
										
											2013-02-19 18:11:43 +08:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-14 22:34:45 +08:00
										 |  |  | 	ifArg("sort-chunks-by", function(value) { | 
					
						
							|  |  |  | 		outputOptions.chunksSort = value; | 
					
						
							| 
									
										
										
										
											2013-02-19 18:11:43 +08:00
										 |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2014-01-21 23:24:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-14 22:34:45 +08:00
										 |  |  | 	ifArg("sort-assets-by", function(value) { | 
					
						
							|  |  |  | 		outputOptions.assetsSort = value; | 
					
						
							| 
									
										
										
										
											2014-01-21 23:24:17 +08:00
										 |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2014-01-23 22:31:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-14 22:34:45 +08:00
										 |  |  | 	ifArg("display-exclude", function(value) { | 
					
						
							|  |  |  | 		outputOptions.exclude = value; | 
					
						
							| 
									
										
										
										
											2014-01-23 22:31:40 +08:00
										 |  |  | 	}); | 
					
						
							| 
									
										
										
										
											2014-05-17 06:00:11 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-14 22:34:45 +08:00
										 |  |  | 	if(!outputOptions.json) { | 
					
						
							|  |  |  | 		if(typeof outputOptions.cached === "undefined") | 
					
						
							|  |  |  | 			outputOptions.cached = false; | 
					
						
							|  |  |  | 		if(typeof outputOptions.cachedAssets === "undefined") | 
					
						
							|  |  |  | 			outputOptions.cachedAssets = false; | 
					
						
							| 
									
										
										
										
											2014-08-28 17:04:48 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-14 22:34:45 +08:00
										 |  |  | 		ifArg("display-chunks", function(bool) { | 
					
						
							|  |  |  | 			outputOptions.modules = !bool; | 
					
						
							|  |  |  | 			outputOptions.chunks = bool; | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2015-02-05 06:20:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 		ifArg("display-entrypoints", function(bool) { | 
					
						
							|  |  |  | 			outputOptions.entrypoints = bool; | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-14 22:34:45 +08:00
										 |  |  | 		ifArg("display-reasons", function(bool) { | 
					
						
							|  |  |  | 			outputOptions.reasons = bool; | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2012-03-16 20:59:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-14 19:03:24 +08:00
										 |  |  | 		ifArg("display-depth", function(bool) { | 
					
						
							|  |  |  | 			outputOptions.depth = bool; | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-29 07:17:15 +08:00
										 |  |  | 		ifArg("display-used-exports", function(bool) { | 
					
						
							|  |  |  | 			outputOptions.usedExports = bool; | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-09 20:31:02 +08:00
										 |  |  | 		ifArg("display-provided-exports", function(bool) { | 
					
						
							|  |  |  | 			outputOptions.providedExports = bool; | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-14 22:34:45 +08:00
										 |  |  | 		ifArg("display-error-details", function(bool) { | 
					
						
							|  |  |  | 			outputOptions.errorDetails = bool; | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-02-14 17:07:42 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-14 22:34:45 +08:00
										 |  |  | 		ifArg("display-origins", function(bool) { | 
					
						
							|  |  |  | 			outputOptions.chunkOrigins = bool; | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2012-09-19 00:40:48 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-14 19:03:24 +08:00
										 |  |  | 		ifArg("display-max-modules", function(value) { | 
					
						
							|  |  |  | 			outputOptions.maxModules = value; | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-14 22:34:45 +08:00
										 |  |  | 		ifArg("display-cached", function(bool) { | 
					
						
							|  |  |  | 			if(bool) | 
					
						
							|  |  |  | 				outputOptions.cached = true; | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2015-08-09 18:37:38 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-14 22:34:45 +08:00
										 |  |  | 		ifArg("display-cached-assets", function(bool) { | 
					
						
							|  |  |  | 			if(bool) | 
					
						
							|  |  |  | 				outputOptions.cachedAssets = true; | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-12-14 19:03:24 +08:00
										 |  |  | 		if(!outputOptions.exclude) | 
					
						
							| 
									
										
										
										
											2015-11-14 22:34:45 +08:00
										 |  |  | 			outputOptions.exclude = ["node_modules", "bower_components", "jam", "components"]; | 
					
						
							| 
									
										
										
										
											2016-12-14 19:03:24 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if(argv["display-modules"]) { | 
					
						
							|  |  |  | 			outputOptions.maxModules = Infinity; | 
					
						
							|  |  |  | 			outputOptions.exclude = undefined; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-11-14 22:34:45 +08:00
										 |  |  | 	} else { | 
					
						
							|  |  |  | 		if(typeof outputOptions.chunks === "undefined") | 
					
						
							|  |  |  | 			outputOptions.chunks = true; | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 		if(typeof outputOptions.entrypoints === "undefined") | 
					
						
							|  |  |  | 			outputOptions.entrypoints = true; | 
					
						
							| 
									
										
										
										
											2015-11-14 22:34:45 +08:00
										 |  |  | 		if(typeof outputOptions.modules === "undefined") | 
					
						
							|  |  |  | 			outputOptions.modules = true; | 
					
						
							|  |  |  | 		if(typeof outputOptions.chunkModules === "undefined") | 
					
						
							|  |  |  | 			outputOptions.chunkModules = true; | 
					
						
							|  |  |  | 		if(typeof outputOptions.reasons === "undefined") | 
					
						
							|  |  |  | 			outputOptions.reasons = true; | 
					
						
							|  |  |  | 		if(typeof outputOptions.cached === "undefined") | 
					
						
							|  |  |  | 			outputOptions.cached = true; | 
					
						
							|  |  |  | 		if(typeof outputOptions.cachedAssets === "undefined") | 
					
						
							|  |  |  | 			outputOptions.cachedAssets = true; | 
					
						
							| 
									
										
										
										
											2014-02-26 16:36:49 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-11-14 22:34:45 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	ifArg("hide-modules", function(bool) { | 
					
						
							|  |  |  | 		if(bool) { | 
					
						
							|  |  |  | 			outputOptions.modules = false; | 
					
						
							|  |  |  | 			outputOptions.chunkModules = false; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	var webpack = require("../lib/webpack.js"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Error.stackTraceLimit = 30; | 
					
						
							|  |  |  | 	var lastHash = null; | 
					
						
							| 
									
										
										
										
											2016-09-20 03:51:28 +08:00
										 |  |  | 	var compiler; | 
					
						
							|  |  |  | 	try { | 
					
						
							|  |  |  | 		compiler = webpack(options); | 
					
						
							|  |  |  | 	} catch(e) { | 
					
						
							|  |  |  | 		var WebpackOptionsValidationError = require("../lib/WebpackOptionsValidationError"); | 
					
						
							|  |  |  | 		if(e instanceof WebpackOptionsValidationError) { | 
					
						
							|  |  |  | 			if(argv.color) | 
					
						
							|  |  |  | 				console.error("\u001b[1m\u001b[31m" + e.message + "\u001b[39m\u001b[22m"); | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 				console.error(e.message); | 
					
						
							| 
									
										
										
										
											2016-11-21 08:00:25 +08:00
										 |  |  | 			process.exit(1); // eslint-disable-line no-process-exit
 | 
					
						
							| 
									
										
										
										
											2016-09-20 03:51:28 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		throw e; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-11-14 22:34:45 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-10 06:48:37 +08:00
										 |  |  | 	if(argv.progress) { | 
					
						
							|  |  |  | 		var ProgressPlugin = require("../lib/ProgressPlugin"); | 
					
						
							|  |  |  | 		compiler.apply(new ProgressPlugin({ | 
					
						
							|  |  |  | 			profile: argv.profile | 
					
						
							|  |  |  | 		})); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-14 22:34:45 +08:00
										 |  |  | 	function compilerCallback(err, stats) { | 
					
						
							| 
									
										
										
										
											2016-12-14 19:03:24 +08:00
										 |  |  | 		if(!options.watch || err) { | 
					
						
							| 
									
										
										
										
											2015-11-14 22:34:45 +08:00
										 |  |  | 			// Do not keep cache anymore
 | 
					
						
							|  |  |  | 			compiler.purgeInputFileSystem(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if(err) { | 
					
						
							|  |  |  | 			lastHash = null; | 
					
						
							|  |  |  | 			console.error(err.stack || err); | 
					
						
							|  |  |  | 			if(err.details) console.error(err.details); | 
					
						
							| 
									
										
										
										
											2016-12-14 19:03:24 +08:00
										 |  |  | 			process.exit(1); // eslint-disable-line
 | 
					
						
							| 
									
										
										
										
											2015-11-14 22:34:45 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		if(outputOptions.json) { | 
					
						
							|  |  |  | 			process.stdout.write(JSON.stringify(stats.toJson(outputOptions), null, 2) + "\n"); | 
					
						
							|  |  |  | 		} else if(stats.hash !== lastHash) { | 
					
						
							|  |  |  | 			lastHash = stats.hash; | 
					
						
							|  |  |  | 			process.stdout.write(stats.toString(outputOptions) + "\n"); | 
					
						
							| 
									
										
										
										
											2014-02-26 16:36:28 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-11-28 23:57:01 +08:00
										 |  |  | 		if(!options.watch && stats.hasErrors()) { | 
					
						
							| 
									
										
										
										
											2014-02-26 16:36:28 +08:00
										 |  |  | 			process.on("exit", function() { | 
					
						
							| 
									
										
										
										
											2015-11-14 23:32:54 +08:00
										 |  |  | 				process.exit(2); // eslint-disable-line
 | 
					
						
							| 
									
										
										
										
											2014-02-26 16:36:28 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-03-06 04:48:29 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-11-14 22:34:45 +08:00
										 |  |  | 	if(options.watch) { | 
					
						
							|  |  |  | 		var primaryOptions = !Array.isArray(options) ? options : options[0]; | 
					
						
							|  |  |  | 		var watchOptions = primaryOptions.watchOptions || primaryOptions.watch || {}; | 
					
						
							|  |  |  | 		if(watchOptions.stdin) { | 
					
						
							| 
									
										
										
										
											2016-12-30 00:10:41 +08:00
										 |  |  | 			process.stdin.on("end", function() { | 
					
						
							| 
									
										
										
										
											2015-11-14 22:34:45 +08:00
										 |  |  | 				process.exit(0); // eslint-disable-line
 | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 			process.stdin.resume(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		compiler.watch(watchOptions, compilerCallback); | 
					
						
							| 
									
										
										
										
											2016-12-30 00:10:41 +08:00
										 |  |  | 		console.log("\nWebpack is watching the files…\n"); | 
					
						
							| 
									
										
										
										
											2015-11-14 22:34:45 +08:00
										 |  |  | 	} else | 
					
						
							|  |  |  | 		compiler.run(compilerCallback); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-10 20:18:12 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2015-11-14 22:34:45 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | processOptions(options); |