| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2015-12-30 00:44:55 +08:00
										 |  |  | var OptionsDefaulter = require("./OptionsDefaulter"); | 
					
						
							| 
									
										
										
										
											2016-01-07 06:02:25 +08:00
										 |  |  | var Template = require("./Template"); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-15 21:16:18 +08:00
										 |  |  | function WebpackOptionsDefaulter() { | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	OptionsDefaulter.call(this); | 
					
						
							|  |  |  | 	this.set("debug", false); | 
					
						
							|  |  |  | 	this.set("devtool", false); | 
					
						
							| 
									
										
										
										
											2014-03-21 23:08:35 +08:00
										 |  |  | 	this.set("cache", true); | 
					
						
							| 
									
										
										
										
											2013-02-26 20:31:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	this.set("context", process.cwd()); | 
					
						
							| 
									
										
										
										
											2013-02-14 00:00:07 +08:00
										 |  |  | 	this.set("target", "web"); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	this.set("output", {}); | 
					
						
							| 
									
										
										
										
											2013-02-26 20:31:05 +08:00
										 |  |  | 	this.set("node", {}); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	this.set("resolve", {}); | 
					
						
							|  |  |  | 	this.set("resolveLoader", {}); | 
					
						
							| 
									
										
										
										
											2013-02-26 20:31:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-11 23:08:22 +08:00
										 |  |  | 	this.set("module.unknownContextRequest", "."); | 
					
						
							| 
									
										
										
										
											2015-03-06 04:49:39 +08:00
										 |  |  | 	this.set("module.unknownContextRegExp", false); | 
					
						
							| 
									
										
										
										
											2014-03-11 23:08:22 +08:00
										 |  |  | 	this.set("module.unknownContextRecursive", true); | 
					
						
							|  |  |  | 	this.set("module.unknownContextCritical", true); | 
					
						
							|  |  |  | 	this.set("module.exprContextRequest", "."); | 
					
						
							| 
									
										
										
										
											2015-03-06 04:49:39 +08:00
										 |  |  | 	this.set("module.exprContextRegExp", false); | 
					
						
							| 
									
										
										
										
											2014-03-11 23:08:22 +08:00
										 |  |  | 	this.set("module.exprContextRecursive", true); | 
					
						
							|  |  |  | 	this.set("module.exprContextCritical", true); | 
					
						
							|  |  |  | 	this.set("module.wrappedContextRegExp", /.*/); | 
					
						
							|  |  |  | 	this.set("module.wrappedContextRecursive", true); | 
					
						
							|  |  |  | 	this.set("module.wrappedContextCritical", false); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-07 06:02:25 +08:00
										 |  |  | 	this.set("output.filename", "[name].js"); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	this.set("output.libraryTarget", "var"); | 
					
						
							|  |  |  | 	this.set("output.path", ""); | 
					
						
							| 
									
										
										
										
											2014-04-04 01:46:53 +08:00
										 |  |  | 	this.set("output.sourceMapFilename", "[file].map[query]"); | 
					
						
							| 
									
										
										
										
											2013-12-17 07:56:43 +08:00
										 |  |  | 	this.set("output.hotUpdateChunkFilename", "[id].[hash].hot-update.js"); | 
					
						
							|  |  |  | 	this.set("output.hotUpdateMainFilename", "[hash].hot-update.json"); | 
					
						
							| 
									
										
										
										
											2015-04-17 21:57:42 +08:00
										 |  |  | 	this.set("output.crossOriginLoading", false); | 
					
						
							| 
									
										
										
										
											2013-05-21 17:08:08 +08:00
										 |  |  | 	this.set("output.hashFunction", "md5"); | 
					
						
							|  |  |  | 	this.set("output.hashDigest", "hex"); | 
					
						
							|  |  |  | 	this.set("output.hashDigestLength", 20); | 
					
						
							| 
									
										
										
										
											2014-02-11 15:31:08 +08:00
										 |  |  | 	this.set("output.sourcePrefix", "\t"); | 
					
						
							| 
									
										
										
										
											2015-04-05 07:52:30 +08:00
										 |  |  | 	this.set("output.devtoolLineToLine", false); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-26 20:31:05 +08:00
										 |  |  | 	this.set("node.console", false); | 
					
						
							|  |  |  | 	this.set("node.process", true); | 
					
						
							|  |  |  | 	this.set("node.global", true); | 
					
						
							| 
									
										
										
										
											2015-03-06 04:46:54 +08:00
										 |  |  | 	this.set("node.Buffer", true); | 
					
						
							| 
									
										
										
										
											2015-01-07 01:20:45 +08:00
										 |  |  | 	this.set("node.setImmediate", true); | 
					
						
							| 
									
										
										
										
											2013-02-26 20:31:05 +08:00
										 |  |  | 	this.set("node.__filename", "mock"); | 
					
						
							|  |  |  | 	this.set("node.__dirname", "mock"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-02 07:18:25 +08:00
										 |  |  | 	this.set("resolve.modules", ["node_modules"]) | 
					
						
							|  |  |  | 	this.set("resolve.extensions", [".js", ".json"]) | 
					
						
							| 
									
										
										
										
											2016-01-04 04:42:56 +08:00
										 |  |  | 	this.set("resolveLoader.mainFields", ["loader", "main"]) | 
					
						
							| 
									
										
										
										
											2016-01-02 07:18:25 +08:00
										 |  |  | 	this.set("resolveLoader.extensions", [".js", ".json"]) | 
					
						
							|  |  |  | 	this.set("resolveLoader.moduleExtensions", ["-loader"]) | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | } | 
					
						
							|  |  |  | module.exports = WebpackOptionsDefaulter; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | WebpackOptionsDefaulter.prototype = Object.create(OptionsDefaulter.prototype); | 
					
						
							| 
									
										
										
										
											2014-02-13 18:02:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | WebpackOptionsDefaulter.prototype.constructor = WebpackOptionsDefaulter; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | WebpackOptionsDefaulter.prototype.process = function(options) { | 
					
						
							|  |  |  | 	OptionsDefaulter.prototype.process.call(this, options); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-02 07:18:25 +08:00
										 |  |  | 	if(options.resolve.aliasFields === undefined) { | 
					
						
							| 
									
										
										
										
											2014-02-13 18:02:31 +08:00
										 |  |  | 		if(options.target === "web" || options.target === "webworker") | 
					
						
							| 
									
										
										
										
											2016-01-02 07:18:25 +08:00
										 |  |  | 			options.resolve.aliasFields = ["browser"]; | 
					
						
							| 
									
										
										
										
											2014-02-13 18:02:31 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-02 07:18:25 +08:00
										 |  |  | 	if(options.resolve.mainFields === undefined) { | 
					
						
							|  |  |  | 		if(options.target === "web" || options.target === "webworker") | 
					
						
							|  |  |  | 			options.resolve.mainFields = ["browser", "web", "browserify", "main"]; | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			options.resolve.mainFields = ["main"]; | 
					
						
							| 
									
										
										
										
											2014-02-13 18:02:31 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-01-07 06:02:25 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	var outputOptions = options.output; | 
					
						
							|  |  |  | 	var filename = outputOptions.filename; | 
					
						
							|  |  |  | 	if(outputOptions.chunkFilename === undefined) | 
					
						
							|  |  |  | 		outputOptions.chunkFilename = filename.indexOf("[name]") >= 0 ? filename.replace("[name]", "[id]") : "[id]." + filename; | 
					
						
							|  |  |  | 	if(outputOptions.hotUpdateFunction === undefined) | 
					
						
							|  |  |  | 		outputOptions.hotUpdateFunction = Template.toIdentifier("webpackHotUpdate" + (outputOptions.library || "")); | 
					
						
							| 
									
										
										
										
											2015-01-22 03:25:25 +08:00
										 |  |  | }; |