| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2017-01-03 00:45:44 +08:00
										 |  |  | "use strict"; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-03 00:45:44 +08:00
										 |  |  | const OptionsDefaulter = require("./OptionsDefaulter"); | 
					
						
							|  |  |  | const Template = require("./Template"); | 
					
						
							| 
									
										
										
										
											2013-02-26 20:31:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-03 00:45:44 +08:00
										 |  |  | class WebpackOptionsDefaulter extends OptionsDefaulter { | 
					
						
							|  |  |  | 	constructor() { | 
					
						
							|  |  |  | 		super(); | 
					
						
							|  |  |  | 		this.set("devtool", false); | 
					
						
							|  |  |  | 		this.set("cache", true); | 
					
						
							| 
									
										
										
										
											2013-02-26 20:31:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-03 00:45:44 +08:00
										 |  |  | 		this.set("context", process.cwd()); | 
					
						
							|  |  |  | 		this.set("target", "web"); | 
					
						
							| 
									
										
										
										
											2014-03-11 23:08:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-06 18:10:16 +08:00
										 |  |  | 		this.set("module", "call", value => Object.assign({}, value)); | 
					
						
							| 
									
										
										
										
											2017-01-03 00:45:44 +08:00
										 |  |  | 		this.set("module.unknownContextRequest", "."); | 
					
						
							|  |  |  | 		this.set("module.unknownContextRegExp", false); | 
					
						
							|  |  |  | 		this.set("module.unknownContextRecursive", true); | 
					
						
							|  |  |  | 		this.set("module.unknownContextCritical", true); | 
					
						
							|  |  |  | 		this.set("module.exprContextRequest", "."); | 
					
						
							|  |  |  | 		this.set("module.exprContextRegExp", false); | 
					
						
							|  |  |  | 		this.set("module.exprContextRecursive", true); | 
					
						
							|  |  |  | 		this.set("module.exprContextCritical", true); | 
					
						
							|  |  |  | 		this.set("module.wrappedContextRegExp", /.*/); | 
					
						
							|  |  |  | 		this.set("module.wrappedContextRecursive", true); | 
					
						
							|  |  |  | 		this.set("module.wrappedContextCritical", false); | 
					
						
							| 
									
										
										
										
											2017-02-23 05:31:46 +08:00
										 |  |  | 		this.set("module.strictExportPresence", false); | 
					
						
							| 
									
										
										
										
											2017-05-21 15:13:33 +08:00
										 |  |  | 		this.set("module.strictThisContextOnImports", false); | 
					
						
							| 
									
										
										
										
											2017-01-03 00:45:44 +08:00
										 |  |  | 		this.set("module.unsafeCache", true); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-03 00:45:44 +08:00
										 |  |  | 		this.set("output", "call", (value, options) => { | 
					
						
							|  |  |  | 			if(typeof value === "string") { | 
					
						
							|  |  |  | 				return { | 
					
						
							|  |  |  | 					filename: value | 
					
						
							|  |  |  | 				}; | 
					
						
							|  |  |  | 			} else if(typeof value !== "object") { | 
					
						
							|  |  |  | 				return {}; | 
					
						
							|  |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2017-09-06 18:10:16 +08:00
										 |  |  | 				return Object.assign({}, value); | 
					
						
							| 
									
										
										
										
											2017-01-03 00:45:44 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 		this.set("output.filename", "[name].js"); | 
					
						
							|  |  |  | 		this.set("output.chunkFilename", "make", (options) => { | 
					
						
							| 
									
										
										
										
											2017-02-05 08:12:01 +08:00
										 |  |  | 			const filename = options.output.filename; | 
					
						
							| 
									
										
										
										
											2017-01-03 00:45:44 +08:00
										 |  |  | 			return filename.indexOf("[name]") >= 0 ? filename.replace("[name]", "[id]") : "[id]." + filename; | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 		this.set("output.library", ""); | 
					
						
							|  |  |  | 		this.set("output.hotUpdateFunction", "make", (options) => { | 
					
						
							| 
									
										
										
										
											2017-01-11 17:51:58 +08:00
										 |  |  | 			return Template.toIdentifier("webpackHotUpdate" + options.output.library); | 
					
						
							| 
									
										
										
										
											2017-01-03 00:45:44 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 		this.set("output.jsonpFunction", "make", (options) => { | 
					
						
							| 
									
										
										
										
											2017-01-11 17:51:58 +08:00
										 |  |  | 			return Template.toIdentifier("webpackJsonp" + options.output.library); | 
					
						
							| 
									
										
										
										
											2017-01-03 00:45:44 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 		this.set("output.libraryTarget", "var"); | 
					
						
							|  |  |  | 		this.set("output.path", process.cwd()); | 
					
						
							|  |  |  | 		this.set("output.sourceMapFilename", "[file].map[query]"); | 
					
						
							|  |  |  | 		this.set("output.hotUpdateChunkFilename", "[id].[hash].hot-update.js"); | 
					
						
							|  |  |  | 		this.set("output.hotUpdateMainFilename", "[hash].hot-update.json"); | 
					
						
							|  |  |  | 		this.set("output.crossOriginLoading", false); | 
					
						
							| 
									
										
										
										
											2018-01-04 22:30:50 +08:00
										 |  |  | 		this.set("output.jsonpScriptType", "text/javascript"); | 
					
						
							| 
									
										
										
										
											2017-05-11 16:41:38 +08:00
										 |  |  | 		this.set("output.chunkLoadTimeout", 120000); | 
					
						
							| 
									
										
										
										
											2017-01-03 00:45:44 +08:00
										 |  |  | 		this.set("output.hashFunction", "md5"); | 
					
						
							|  |  |  | 		this.set("output.hashDigest", "hex"); | 
					
						
							|  |  |  | 		this.set("output.hashDigestLength", 20); | 
					
						
							|  |  |  | 		this.set("output.devtoolLineToLine", false); | 
					
						
							|  |  |  | 		this.set("output.strictModuleExceptionHandling", false); | 
					
						
							| 
									
										
										
										
											2013-02-26 20:31:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-06 23:15:03 +08:00
										 |  |  | 		this.set("node", "call", value => { | 
					
						
							|  |  |  | 			if(typeof value === "boolean") { | 
					
						
							|  |  |  | 				return value; | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				return Object.assign({}, value); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-01-03 00:45:44 +08:00
										 |  |  | 		this.set("node.console", false); | 
					
						
							|  |  |  | 		this.set("node.process", true); | 
					
						
							|  |  |  | 		this.set("node.global", true); | 
					
						
							|  |  |  | 		this.set("node.Buffer", true); | 
					
						
							|  |  |  | 		this.set("node.setImmediate", true); | 
					
						
							|  |  |  | 		this.set("node.__filename", "mock"); | 
					
						
							|  |  |  | 		this.set("node.__dirname", "mock"); | 
					
						
							| 
									
										
										
										
											2016-12-03 04:49:42 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-06 23:15:03 +08:00
										 |  |  | 		this.set("performance", "call", value => { | 
					
						
							|  |  |  | 			if(typeof value === "boolean") { | 
					
						
							|  |  |  | 				return value; | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				return Object.assign({}, value); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-01-03 00:45:44 +08:00
										 |  |  | 		this.set("performance.maxAssetSize", 250000); | 
					
						
							|  |  |  | 		this.set("performance.maxEntrypointSize", 250000); | 
					
						
							|  |  |  | 		this.set("performance.hints", false); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-06 18:10:16 +08:00
										 |  |  | 		this.set("resolve", "call", value => Object.assign({}, value)); | 
					
						
							| 
									
										
										
										
											2017-01-03 00:45:44 +08:00
										 |  |  | 		this.set("resolve.unsafeCache", true); | 
					
						
							|  |  |  | 		this.set("resolve.modules", ["node_modules"]); | 
					
						
							|  |  |  | 		this.set("resolve.extensions", [".js", ".json"]); | 
					
						
							| 
									
										
										
										
											2017-06-02 19:41:25 +08:00
										 |  |  | 		this.set("resolve.mainFiles", ["index"]); | 
					
						
							| 
									
										
										
										
											2017-01-03 00:45:44 +08:00
										 |  |  | 		this.set("resolve.aliasFields", "make", (options) => { | 
					
						
							|  |  |  | 			if(options.target === "web" || options.target === "webworker") | 
					
						
							|  |  |  | 				return ["browser"]; | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 				return []; | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 		this.set("resolve.mainFields", "make", (options) => { | 
					
						
							|  |  |  | 			if(options.target === "web" || options.target === "webworker") | 
					
						
							|  |  |  | 				return ["browser", "module", "main"]; | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 				return ["module", "main"]; | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-06-28 20:37:58 +08:00
										 |  |  | 		this.set("resolve.cacheWithContext", "make", (options) => { | 
					
						
							|  |  |  | 			return Array.isArray(options.resolve.plugins) && options.resolve.plugins.length > 0; | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-09-06 18:10:16 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		this.set("resolveLoader", "call", value => Object.assign({}, value)); | 
					
						
							| 
									
										
										
										
											2017-01-03 00:45:44 +08:00
										 |  |  | 		this.set("resolveLoader.unsafeCache", true); | 
					
						
							|  |  |  | 		this.set("resolveLoader.mainFields", ["loader", "main"]); | 
					
						
							|  |  |  | 		this.set("resolveLoader.extensions", [".js", ".json"]); | 
					
						
							| 
									
										
										
										
											2017-06-02 19:41:25 +08:00
										 |  |  | 		this.set("resolveLoader.mainFiles", ["index"]); | 
					
						
							| 
									
										
										
										
											2017-06-28 20:37:58 +08:00
										 |  |  | 		this.set("resolveLoader.cacheWithContext", "make", (options) => { | 
					
						
							|  |  |  | 			return Array.isArray(options.resolveLoader.plugins) && options.resolveLoader.plugins.length > 0; | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-01-03 00:45:44 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2014-02-13 18:02:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-03 00:45:44 +08:00
										 |  |  | module.exports = WebpackOptionsDefaulter; |