| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | /* | 
					
						
							| 
									
										
										
										
											2017-01-24 03:31:53 +08:00
										 |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | 	*/ | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const async = require("async"); | 
					
						
							| 
									
										
										
										
											2017-01-09 21:55:44 +08:00
										 |  |  | const crypto = require("crypto"); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | const Tapable = require("tapable"); | 
					
						
							|  |  |  | const EntryModuleNotFoundError = require("./EntryModuleNotFoundError"); | 
					
						
							|  |  |  | const ModuleNotFoundError = require("./ModuleNotFoundError"); | 
					
						
							|  |  |  | const ModuleDependencyWarning = require("./ModuleDependencyWarning"); | 
					
						
							| 
									
										
										
										
											2017-01-10 00:11:34 +08:00
										 |  |  | const ModuleDependencyError = require("./ModuleDependencyError"); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | const Module = require("./Module"); | 
					
						
							|  |  |  | const Chunk = require("./Chunk"); | 
					
						
							|  |  |  | const Entrypoint = require("./Entrypoint"); | 
					
						
							|  |  |  | const Stats = require("./Stats"); | 
					
						
							|  |  |  | const MainTemplate = require("./MainTemplate"); | 
					
						
							|  |  |  | const ChunkTemplate = require("./ChunkTemplate"); | 
					
						
							|  |  |  | const HotUpdateChunkTemplate = require("./HotUpdateChunkTemplate"); | 
					
						
							|  |  |  | const ModuleTemplate = require("./ModuleTemplate"); | 
					
						
							|  |  |  | const Dependency = require("./Dependency"); | 
					
						
							|  |  |  | const ChunkRenderError = require("./ChunkRenderError"); | 
					
						
							|  |  |  | const CachedSource = require("webpack-sources").CachedSource; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | function byId(a, b) { | 
					
						
							|  |  |  | 	if(a.id < b.id) return -1; | 
					
						
							|  |  |  | 	if(a.id > b.id) return 1; | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-08-18 19:35:57 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | function iterationBlockVariable(variables, fn) { | 
					
						
							| 
									
										
										
										
											2017-01-25 03:39:38 +08:00
										 |  |  | 	for(var indexVariable = 0; indexVariable < variables.length; indexVariable++) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 		var varDep = variables[indexVariable].dependencies; | 
					
						
							| 
									
										
										
										
											2017-01-25 03:39:38 +08:00
										 |  |  | 		for(var indexVDep = 0; indexVDep < varDep.length; indexVDep++) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 			fn(varDep[indexVDep]); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function iterationOfArrayCallback(arr, fn) { | 
					
						
							| 
									
										
										
										
											2017-01-25 03:39:38 +08:00
										 |  |  | 	for(var index = 0; index < arr.length; index++) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 		fn(arr[index]); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | class Compilation extends Tapable { | 
					
						
							|  |  |  | 	constructor(compiler) { | 
					
						
							|  |  |  | 		super(); | 
					
						
							|  |  |  | 		this.compiler = compiler; | 
					
						
							|  |  |  | 		this.resolvers = compiler.resolvers; | 
					
						
							|  |  |  | 		this.inputFileSystem = compiler.inputFileSystem; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		const options = this.options = compiler.options; | 
					
						
							|  |  |  | 		this.outputOptions = options && options.output; | 
					
						
							|  |  |  | 		this.bail = options && options.bail; | 
					
						
							|  |  |  | 		this.profile = options && options.profile; | 
					
						
							|  |  |  | 		this.performance = options && options.performance; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		this.mainTemplate = new MainTemplate(this.outputOptions); | 
					
						
							|  |  |  | 		this.chunkTemplate = new ChunkTemplate(this.outputOptions); | 
					
						
							|  |  |  | 		this.hotUpdateChunkTemplate = new HotUpdateChunkTemplate(this.outputOptions); | 
					
						
							|  |  |  | 		this.moduleTemplate = new ModuleTemplate(this.outputOptions); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		this.entries = []; | 
					
						
							|  |  |  | 		this.preparedChunks = []; | 
					
						
							|  |  |  | 		this.entrypoints = {}; | 
					
						
							|  |  |  | 		this.chunks = []; | 
					
						
							|  |  |  | 		this.namedChunks = {}; | 
					
						
							|  |  |  | 		this.modules = []; | 
					
						
							|  |  |  | 		this._modules = {}; | 
					
						
							|  |  |  | 		this.cache = null; | 
					
						
							|  |  |  | 		this.records = null; | 
					
						
							|  |  |  | 		this.nextFreeModuleIndex = undefined; | 
					
						
							|  |  |  | 		this.nextFreeModuleIndex2 = undefined; | 
					
						
							|  |  |  | 		this.additionalChunkAssets = []; | 
					
						
							|  |  |  | 		this.assets = {}; | 
					
						
							|  |  |  | 		this.errors = []; | 
					
						
							|  |  |  | 		this.warnings = []; | 
					
						
							|  |  |  | 		this.children = []; | 
					
						
							|  |  |  | 		this.dependencyFactories = new Map(); | 
					
						
							|  |  |  | 		this.dependencyTemplates = new Map(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-12-22 23:10:23 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	templatesPlugin(name, fn) { | 
					
						
							|  |  |  | 		this.mainTemplate.plugin(name, fn); | 
					
						
							|  |  |  | 		this.chunkTemplate.plugin(name, fn); | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-05-08 19:28:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	addModule(module, cacheGroup) { | 
					
						
							|  |  |  | 		const identifier = module.identifier(); | 
					
						
							|  |  |  | 		if(this._modules[identifier]) { | 
					
						
							|  |  |  | 			return false; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-26 03:39:24 +08:00
										 |  |  | 		const cacheName = (cacheGroup || "m") + identifier; | 
					
						
							|  |  |  | 		if(this.cache && this.cache[cacheName]) { | 
					
						
							|  |  |  | 			const cacheModule = this.cache[cacheName]; | 
					
						
							| 
									
										
										
										
											2013-02-01 01:00:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			let rebuild = true; | 
					
						
							|  |  |  | 			if(!cacheModule.error && cacheModule.cacheable && this.fileTimestamps && this.contextTimestamps) { | 
					
						
							|  |  |  | 				rebuild = cacheModule.needRebuild(this.fileTimestamps, this.contextTimestamps); | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-07-08 20:15:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			if(!rebuild) { | 
					
						
							|  |  |  | 				cacheModule.disconnect(); | 
					
						
							|  |  |  | 				this._modules[identifier] = cacheModule; | 
					
						
							|  |  |  | 				this.modules.push(cacheModule); | 
					
						
							|  |  |  | 				cacheModule.errors.forEach(err => this.errors.push(err), this); | 
					
						
							|  |  |  | 				cacheModule.warnings.forEach(err => this.warnings.push(err), this); | 
					
						
							|  |  |  | 				return cacheModule; | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				module.lastId = cacheModule.id; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		module.unbuild(); | 
					
						
							|  |  |  | 		this._modules[identifier] = module; | 
					
						
							|  |  |  | 		if(this.cache) { | 
					
						
							| 
									
										
										
										
											2017-01-26 03:39:24 +08:00
										 |  |  | 			this.cache[cacheName] = module; | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		this.modules.push(module); | 
					
						
							|  |  |  | 		return true; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	getModule(module) { | 
					
						
							|  |  |  | 		const identifier = module.identifier(); | 
					
						
							|  |  |  | 		return this._modules[identifier]; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	findModule(identifier) { | 
					
						
							|  |  |  | 		return this._modules[identifier]; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	buildModule(module, optional, origin, dependencies, thisCallback) { | 
					
						
							|  |  |  | 		this.applyPlugins1("build-module", module); | 
					
						
							|  |  |  | 		if(module.building) return module.building.push(thisCallback); | 
					
						
							|  |  |  | 		const building = module.building = [thisCallback]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		function callback(err) { | 
					
						
							|  |  |  | 			module.building = undefined; | 
					
						
							|  |  |  | 			building.forEach(cb => cb(err)); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 		module.build(this.options, this, this.resolvers.normal, this.inputFileSystem, (error) => { | 
					
						
							|  |  |  | 			var errors = module.errors; | 
					
						
							| 
									
										
										
										
											2017-01-25 03:39:38 +08:00
										 |  |  | 			for(var indexError = 0; indexError < errors.length; indexError++) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 				var err = errors[indexError]; | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 				err.origin = origin; | 
					
						
							|  |  |  | 				err.dependencies = dependencies; | 
					
						
							|  |  |  | 				if(optional) | 
					
						
							|  |  |  | 					this.warnings.push(err); | 
					
						
							|  |  |  | 				else | 
					
						
							|  |  |  | 					this.errors.push(err); | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			var warnings = module.warnings; | 
					
						
							| 
									
										
										
										
											2017-01-25 03:39:38 +08:00
										 |  |  | 			for(var indexWarning = 0; indexWarning < warnings.length; indexWarning++) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 				var war = warnings[indexWarning]; | 
					
						
							|  |  |  | 				war.origin = origin; | 
					
						
							|  |  |  | 				war.dependencies = dependencies; | 
					
						
							|  |  |  | 				this.warnings.push(war); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			module.dependencies.sort(Dependency.compare); | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 			if(error) { | 
					
						
							|  |  |  | 				this.applyPlugins2("failed-module", module, error); | 
					
						
							|  |  |  | 				return callback(error); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			this.applyPlugins1("succeed-module", module); | 
					
						
							|  |  |  | 			return callback(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-07-08 20:15:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	processModuleDependencies(module, callback) { | 
					
						
							|  |  |  | 		const dependencies = []; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		function addDependency(dep) { | 
					
						
							|  |  |  | 			for(let i = 0; i < dependencies.length; i++) { | 
					
						
							|  |  |  | 				if(dep.isEqualResource(dependencies[i][0])) { | 
					
						
							|  |  |  | 					return dependencies[i].push(dep); | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			dependencies.push([dep]); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		function addDependenciesBlock(block) { | 
					
						
							|  |  |  | 			if(block.dependencies) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 				iterationOfArrayCallback(block.dependencies, addDependency); | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			if(block.blocks) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 				iterationOfArrayCallback(block.blocks, addDependenciesBlock); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			if(block.variables) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 				iterationBlockVariable(block.variables, addDependency); | 
					
						
							| 
									
										
										
										
											2013-05-08 20:47:13 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		addDependenciesBlock(module); | 
					
						
							|  |  |  | 		this.addModuleDependencies(module, dependencies, this.bail, null, true, callback); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-05-08 19:28:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	addModuleDependencies(module, dependencies, bail, cacheGroup, recursive, callback) { | 
					
						
							|  |  |  | 		let _this = this; | 
					
						
							|  |  |  | 		const start = _this.profile && +new Date(); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-05 07:13:17 +08:00
										 |  |  | 		const factories = []; | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		for(let i = 0; i < dependencies.length; i++) { | 
					
						
							|  |  |  | 			const factory = _this.dependencyFactories.get(dependencies[i][0].constructor); | 
					
						
							|  |  |  | 			if(!factory) { | 
					
						
							|  |  |  | 				return callback(new Error(`No module factory available for dependency type: ${dependencies[i][0].constructor.name}`)); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			factories[i] = [factory, dependencies[i]]; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		async.forEach(factories, function iteratorFactory(item, callback) { | 
					
						
							|  |  |  | 			const dependencies = item[1]; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			const errorAndCallback = function errorAndCallback(err) { | 
					
						
							|  |  |  | 				err.origin = module; | 
					
						
							|  |  |  | 				_this.errors.push(err); | 
					
						
							|  |  |  | 				if(bail) { | 
					
						
							|  |  |  | 					callback(err); | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					callback(); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			}; | 
					
						
							|  |  |  | 			const warningAndCallback = function warningAndCallback(err) { | 
					
						
							|  |  |  | 				err.origin = module; | 
					
						
							|  |  |  | 				_this.warnings.push(err); | 
					
						
							|  |  |  | 				callback(); | 
					
						
							|  |  |  | 			}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			const factory = item[0]; | 
					
						
							|  |  |  | 			factory.create({ | 
					
						
							|  |  |  | 				contextInfo: { | 
					
						
							|  |  |  | 					issuer: module.nameForCondition && module.nameForCondition() | 
					
						
							|  |  |  | 				}, | 
					
						
							|  |  |  | 				context: module.context, | 
					
						
							|  |  |  | 				dependencies: dependencies | 
					
						
							|  |  |  | 			}, function factoryCallback(err, dependentModule) { | 
					
						
							|  |  |  | 				let afterFactory; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				function isOptional() { | 
					
						
							|  |  |  | 					return dependencies.filter(d => !d.optional).length === 0; | 
					
						
							| 
									
										
										
										
											2014-07-03 06:00:06 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 				function errorOrWarningAndCallback(err) { | 
					
						
							|  |  |  | 					if(isOptional()) { | 
					
						
							|  |  |  | 						return warningAndCallback(err); | 
					
						
							|  |  |  | 					} else { | 
					
						
							|  |  |  | 						return errorAndCallback(err); | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				function iterationDependencies(depend) { | 
					
						
							| 
									
										
										
										
											2017-01-25 03:39:38 +08:00
										 |  |  | 					for(var index = 0; index < depend.length; index++) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 						var dep = depend[index]; | 
					
						
							|  |  |  | 						dep.module = dependentModule; | 
					
						
							|  |  |  | 						dependentModule.addReason(module, dep); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 				if(err) { | 
					
						
							|  |  |  | 					return errorOrWarningAndCallback(new ModuleNotFoundError(module, err, dependencies)); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				if(!dependentModule) { | 
					
						
							|  |  |  | 					return process.nextTick(callback); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				if(_this.profile) { | 
					
						
							|  |  |  | 					if(!dependentModule.profile) { | 
					
						
							|  |  |  | 						dependentModule.profile = {}; | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 					afterFactory = +new Date(); | 
					
						
							|  |  |  | 					dependentModule.profile.factory = afterFactory - start; | 
					
						
							| 
									
										
										
										
											2013-05-08 20:47:13 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 				dependentModule.issuer = module; | 
					
						
							|  |  |  | 				const newModule = _this.addModule(dependentModule, cacheGroup); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 				if(!newModule) { // from cache
 | 
					
						
							|  |  |  | 					dependentModule = _this.getModule(dependentModule); | 
					
						
							| 
									
										
										
										
											2013-05-08 20:47:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 					if(dependentModule.optional) { | 
					
						
							|  |  |  | 						dependentModule.optional = isOptional(); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2013-05-08 19:28:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 					iterationDependencies(dependencies); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 					if(_this.profile) { | 
					
						
							|  |  |  | 						if(!module.profile) { | 
					
						
							|  |  |  | 							module.profile = {}; | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						const time = +new Date() - start; | 
					
						
							|  |  |  | 						if(!module.profile.dependencies || time > module.profile.dependencies) { | 
					
						
							|  |  |  | 							module.profile.dependencies = time; | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2015-02-05 06:21:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-04-04 05:39:58 +08:00
										 |  |  | 					return process.nextTick(callback); | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2013-05-08 19:28:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 				if(newModule instanceof Module) { | 
					
						
							|  |  |  | 					if(_this.profile) { | 
					
						
							|  |  |  | 						newModule.profile = dependentModule.profile; | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2014-07-03 06:00:06 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 					newModule.optional = isOptional(); | 
					
						
							|  |  |  | 					newModule.issuer = dependentModule.issuer; | 
					
						
							|  |  |  | 					dependentModule = newModule; | 
					
						
							| 
									
										
										
										
											2013-05-18 20:42:11 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 					iterationDependencies(dependencies); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 					if(_this.profile) { | 
					
						
							|  |  |  | 						const afterBuilding = +new Date(); | 
					
						
							|  |  |  | 						module.profile.building = afterBuilding - afterFactory; | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2013-05-08 20:47:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 					if(recursive) { | 
					
						
							|  |  |  | 						return process.nextTick(_this.processModuleDependencies.bind(_this, dependentModule, callback)); | 
					
						
							|  |  |  | 					} else { | 
					
						
							|  |  |  | 						return process.nextTick(callback); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 				dependentModule.optional = isOptional(); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 				iterationDependencies(dependencies); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 				_this.buildModule(dependentModule, isOptional(), module, dependencies, err => { | 
					
						
							|  |  |  | 					if(err) { | 
					
						
							|  |  |  | 						return errorOrWarningAndCallback(err); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2015-02-05 06:21:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 					if(_this.profile) { | 
					
						
							|  |  |  | 						const afterBuilding = +new Date(); | 
					
						
							|  |  |  | 						dependentModule.profile.building = afterBuilding - afterFactory; | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 					if(recursive) { | 
					
						
							|  |  |  | 						_this.processModuleDependencies(dependentModule, callback); | 
					
						
							|  |  |  | 					} else { | 
					
						
							|  |  |  | 						return callback(); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}, function finalCallbackAddModuleDependencies(err) { | 
					
						
							|  |  |  | 			// In V8, the Error objects keep a reference to the functions on the stack. These warnings &
 | 
					
						
							|  |  |  | 			// errors are created inside closures that keep a reference to the Compilation, so errors are
 | 
					
						
							|  |  |  | 			// leaking the Compilation object. Setting _this to null workarounds the following issue in V8.
 | 
					
						
							|  |  |  | 			// https://bugs.chromium.org/p/chromium/issues/detail?id=612191
 | 
					
						
							|  |  |  | 			_this = null; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			if(err) { | 
					
						
							|  |  |  | 				return callback(err); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			return process.nextTick(callback); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	_addModuleChain(context, dependency, onModule, callback) { | 
					
						
							|  |  |  | 		const start = this.profile && +new Date(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		const errorAndCallback = this.bail ? function errorAndCallback(err) { | 
					
						
							|  |  |  | 			callback(err); | 
					
						
							|  |  |  | 		} : function errorAndCallback(err) { | 
					
						
							|  |  |  | 			err.dependencies = [dependency]; | 
					
						
							|  |  |  | 			this.errors.push(err); | 
					
						
							|  |  |  | 			callback(); | 
					
						
							|  |  |  | 		}.bind(this); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if(typeof dependency !== "object" || dependency === null || !dependency.constructor) { | 
					
						
							|  |  |  | 			throw new Error("Parameter 'dependency' must be a Dependency"); | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		const moduleFactory = this.dependencyFactories.get(dependency.constructor); | 
					
						
							|  |  |  | 		if(!moduleFactory) { | 
					
						
							|  |  |  | 			throw new Error(`No dependency factory available for this dependency type: ${dependency.constructor.name}`); | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		moduleFactory.create({ | 
					
						
							|  |  |  | 			context: context, | 
					
						
							|  |  |  | 			dependencies: [dependency] | 
					
						
							|  |  |  | 		}, (err, module) => { | 
					
						
							|  |  |  | 			if(err) { | 
					
						
							|  |  |  | 				return errorAndCallback(new EntryModuleNotFoundError(err)); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			let afterFactory; | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-02-05 06:21:22 +08:00
										 |  |  | 			if(this.profile) { | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 				if(!module.profile) { | 
					
						
							|  |  |  | 					module.profile = {}; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				afterFactory = +new Date(); | 
					
						
							|  |  |  | 				module.profile.factory = afterFactory - start; | 
					
						
							| 
									
										
										
										
											2015-02-05 06:21:22 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			const result = this.addModule(module); | 
					
						
							|  |  |  | 			if(!result) { | 
					
						
							|  |  |  | 				module = this.getModule(module); | 
					
						
							| 
									
										
										
										
											2013-05-08 19:28:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 				onModule(module); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if(this.profile) { | 
					
						
							|  |  |  | 					const afterBuilding = +new Date(); | 
					
						
							|  |  |  | 					module.profile.building = afterBuilding - afterFactory; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				return callback(null, module); | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			if(result instanceof Module) { | 
					
						
							|  |  |  | 				if(this.profile) { | 
					
						
							|  |  |  | 					result.profile = module.profile; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				module = result; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				onModule(module); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				moduleReady.call(this); | 
					
						
							|  |  |  | 				return; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2015-05-11 00:43:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			onModule(module); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			this.buildModule(module, false, null, null, (err) => { | 
					
						
							|  |  |  | 				if(err) { | 
					
						
							|  |  |  | 					return errorAndCallback(err); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if(this.profile) { | 
					
						
							|  |  |  | 					const afterBuilding = +new Date(); | 
					
						
							|  |  |  | 					module.profile.building = afterBuilding - afterFactory; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 				moduleReady.call(this); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			function moduleReady() { | 
					
						
							|  |  |  | 				this.processModuleDependencies(module, err => { | 
					
						
							|  |  |  | 					if(err) { | 
					
						
							|  |  |  | 						return callback(err); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 					return callback(null, module); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	addEntry(context, entry, name, callback) { | 
					
						
							|  |  |  | 		const slot = { | 
					
						
							|  |  |  | 			name: name, | 
					
						
							|  |  |  | 			module: null | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 		this.preparedChunks.push(slot); | 
					
						
							|  |  |  | 		this._addModuleChain(context, entry, (module) => { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			entry.module = module; | 
					
						
							|  |  |  | 			this.entries.push(module); | 
					
						
							|  |  |  | 			module.issuer = null; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		}, (err, module) => { | 
					
						
							| 
									
										
										
										
											2015-05-11 00:43:47 +08:00
										 |  |  | 			if(err) { | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 				return callback(err); | 
					
						
							| 
									
										
										
										
											2015-05-11 00:43:47 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			if(module) { | 
					
						
							|  |  |  | 				slot.module = module; | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				const idx = this.preparedChunks.indexOf(slot); | 
					
						
							|  |  |  | 				this.preparedChunks.splice(idx, 1); | 
					
						
							| 
									
										
										
										
											2015-05-11 00:43:47 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			return callback(); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	prefetch(context, dependency, callback) { | 
					
						
							|  |  |  | 		this._addModuleChain(context, dependency, module => { | 
					
						
							| 
									
										
										
										
											2013-05-08 19:28:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			module.prefetched = true; | 
					
						
							|  |  |  | 			module.issuer = null; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		}, callback); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	rebuildModule(module, thisCallback) { | 
					
						
							|  |  |  | 		if(module.variables.length || module.blocks.length) | 
					
						
							|  |  |  | 			throw new Error("Cannot rebuild a complex module with variables or blocks"); | 
					
						
							|  |  |  | 		if(module.rebuilding) { | 
					
						
							|  |  |  | 			return module.rebuilding.push(thisCallback); | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		const rebuilding = module.rebuilding = [thisCallback]; | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		function callback(err) { | 
					
						
							|  |  |  | 			module.rebuilding = undefined; | 
					
						
							|  |  |  | 			rebuilding.forEach(cb => cb(err)); | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		const deps = module.dependencies.slice(); | 
					
						
							|  |  |  | 		this.buildModule(module, false, module, null, (err) => { | 
					
						
							|  |  |  | 			if(err) return callback(err); | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			this.processModuleDependencies(module, (err) => { | 
					
						
							|  |  |  | 				if(err) return callback(err); | 
					
						
							|  |  |  | 				deps.forEach(d => { | 
					
						
							|  |  |  | 					if(d.module && d.module.removeReason(module, d)) { | 
					
						
							|  |  |  | 						module.chunks.forEach(chunk => { | 
					
						
							|  |  |  | 							if(!d.module.hasReasonForChunk(chunk)) { | 
					
						
							|  |  |  | 								if(d.module.removeChunk(chunk)) { | 
					
						
							|  |  |  | 									this.removeChunkFromDependencies(d.module, chunk); | 
					
						
							|  |  |  | 								} | 
					
						
							|  |  |  | 							} | 
					
						
							|  |  |  | 						}); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 				callback(); | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	finish() { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 		var modules = this.modules; | 
					
						
							|  |  |  | 		this.applyPlugins1("finish-modules", modules); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-25 03:39:38 +08:00
										 |  |  | 		for(var index = 0; index < modules.length; index++) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 			var module = modules[index]; | 
					
						
							|  |  |  | 			this.reportDependencyErrorsAndWarnings(module, [module]); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	unseal() { | 
					
						
							|  |  |  | 		this.applyPlugins0("unseal"); | 
					
						
							|  |  |  | 		this.chunks.length = 0; | 
					
						
							|  |  |  | 		this.namedChunks = {}; | 
					
						
							|  |  |  | 		this.additionalChunkAssets.length = 0; | 
					
						
							|  |  |  | 		this.assets = {}; | 
					
						
							|  |  |  | 		this.modules.forEach(module => module.unseal()); | 
					
						
							| 
									
										
										
										
											2014-07-29 06:13:25 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-07-08 20:15:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	seal(callback) { | 
					
						
							|  |  |  | 		const self = this; | 
					
						
							|  |  |  | 		self.applyPlugins0("seal"); | 
					
						
							|  |  |  | 		self.nextFreeModuleIndex = 0; | 
					
						
							|  |  |  | 		self.nextFreeModuleIndex2 = 0; | 
					
						
							|  |  |  | 		self.preparedChunks.forEach(preparedChunk => { | 
					
						
							|  |  |  | 			const module = preparedChunk.module; | 
					
						
							|  |  |  | 			const chunk = self.addChunk(preparedChunk.name, module); | 
					
						
							|  |  |  | 			const entrypoint = self.entrypoints[chunk.name] = new Entrypoint(chunk.name); | 
					
						
							|  |  |  | 			entrypoint.unshiftChunk(chunk); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			chunk.addModule(module); | 
					
						
							|  |  |  | 			module.addChunk(chunk); | 
					
						
							|  |  |  | 			chunk.entryModule = module; | 
					
						
							|  |  |  | 			self.assignIndex(module); | 
					
						
							|  |  |  | 			self.assignDepth(module); | 
					
						
							|  |  |  | 			self.processDependenciesBlockForChunk(module, chunk); | 
					
						
							| 
									
										
										
										
											2014-07-29 06:13:25 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		self.sortModules(self.modules); | 
					
						
							|  |  |  | 		self.applyPlugins0("optimize"); | 
					
						
							| 
									
										
										
										
											2014-07-19 20:32:48 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		while(self.applyPluginsBailResult1("optimize-modules-basic", self.modules) || | 
					
						
							|  |  |  | 			self.applyPluginsBailResult1("optimize-modules", self.modules) || | 
					
						
							|  |  |  | 			self.applyPluginsBailResult1("optimize-modules-advanced", self.modules)); // eslint-disable-line no-extra-semi
 | 
					
						
							|  |  |  | 		self.applyPlugins1("after-optimize-modules", self.modules); | 
					
						
							| 
									
										
										
										
											2014-01-29 17:13:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		while(self.applyPluginsBailResult1("optimize-chunks-basic", self.chunks) || | 
					
						
							|  |  |  | 			self.applyPluginsBailResult1("optimize-chunks", self.chunks) || | 
					
						
							|  |  |  | 			self.applyPluginsBailResult1("optimize-chunks-advanced", self.chunks)); // eslint-disable-line no-extra-semi
 | 
					
						
							|  |  |  | 		self.applyPlugins1("after-optimize-chunks", self.chunks); | 
					
						
							| 
									
										
										
										
											2015-04-21 01:39:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		self.applyPluginsAsyncSeries("optimize-tree", self.chunks, self.modules, function sealPart2(err) { | 
					
						
							|  |  |  | 			if(err) { | 
					
						
							|  |  |  | 				return callback(err); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-09-03 20:16:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			self.applyPlugins2("after-optimize-tree", self.chunks, self.modules); | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			const shouldRecord = self.applyPluginsBailResult("should-record") !== false; | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			self.applyPlugins2("revive-modules", self.modules, self.records); | 
					
						
							|  |  |  | 			self.applyPlugins1("optimize-module-order", self.modules); | 
					
						
							|  |  |  | 			self.applyPlugins1("advanced-optimize-module-order", self.modules); | 
					
						
							|  |  |  | 			self.applyPlugins1("before-module-ids", self.modules); | 
					
						
							|  |  |  | 			self.applyPlugins1("module-ids", self.modules); | 
					
						
							|  |  |  | 			self.applyModuleIds(); | 
					
						
							|  |  |  | 			self.applyPlugins1("optimize-module-ids", self.modules); | 
					
						
							|  |  |  | 			self.applyPlugins1("after-optimize-module-ids", self.modules); | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			self.sortItemsWithModuleIds(); | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			self.applyPlugins2("revive-chunks", self.chunks, self.records); | 
					
						
							|  |  |  | 			self.applyPlugins1("optimize-chunk-order", self.chunks); | 
					
						
							|  |  |  | 			self.applyPlugins1("before-chunk-ids", self.chunks); | 
					
						
							|  |  |  | 			self.applyChunkIds(); | 
					
						
							|  |  |  | 			self.applyPlugins1("optimize-chunk-ids", self.chunks); | 
					
						
							|  |  |  | 			self.applyPlugins1("after-optimize-chunk-ids", self.chunks); | 
					
						
							| 
									
										
										
										
											2014-01-29 17:13:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			self.sortItemsWithChunkIds(); | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			if(shouldRecord) | 
					
						
							|  |  |  | 				self.applyPlugins2("record-modules", self.modules, self.records); | 
					
						
							|  |  |  | 			if(shouldRecord) | 
					
						
							|  |  |  | 				self.applyPlugins2("record-chunks", self.chunks, self.records); | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			self.applyPlugins0("before-hash"); | 
					
						
							|  |  |  | 			self.createHash(); | 
					
						
							|  |  |  | 			self.applyPlugins0("after-hash"); | 
					
						
							| 
									
										
										
										
											2014-01-29 17:13:28 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			if(shouldRecord) | 
					
						
							|  |  |  | 				self.applyPlugins1("record-hash", self.records); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			self.applyPlugins0("before-module-assets"); | 
					
						
							|  |  |  | 			self.createModuleAssets(); | 
					
						
							|  |  |  | 			if(self.applyPluginsBailResult("should-generate-chunk-assets") !== false) { | 
					
						
							|  |  |  | 				self.applyPlugins0("before-chunk-assets"); | 
					
						
							|  |  |  | 				self.createChunkAssets(); | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			self.applyPlugins1("additional-chunk-assets", self.chunks); | 
					
						
							|  |  |  | 			self.summarizeDependencies(); | 
					
						
							|  |  |  | 			if(shouldRecord) | 
					
						
							|  |  |  | 				self.applyPlugins2("record", self, self.records); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			self.applyPluginsAsync("additional-assets", err => { | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 				if(err) { | 
					
						
							|  |  |  | 					return callback(err); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 				self.applyPluginsAsync("optimize-chunk-assets", self.chunks, err => { | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 					if(err) { | 
					
						
							|  |  |  | 						return callback(err); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 					self.applyPlugins1("after-optimize-chunk-assets", self.chunks); | 
					
						
							|  |  |  | 					self.applyPluginsAsync("optimize-assets", self.assets, err => { | 
					
						
							|  |  |  | 						if(err) { | 
					
						
							|  |  |  | 							return callback(err); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						self.applyPlugins1("after-optimize-assets", self.assets); | 
					
						
							|  |  |  | 						if(self.applyPluginsBailResult("need-additional-seal")) { | 
					
						
							|  |  |  | 							self.unseal(); | 
					
						
							|  |  |  | 							return self.seal(callback); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 						return self.applyPluginsAsync("after-seal", callback); | 
					
						
							|  |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2016-10-18 02:26:22 +08:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	sortModules(modules) { | 
					
						
							|  |  |  | 		modules.sort((a, b) => { | 
					
						
							|  |  |  | 			if(a.index < b.index) return -1; | 
					
						
							|  |  |  | 			if(a.index > b.index) return 1; | 
					
						
							|  |  |  | 			return 0; | 
					
						
							| 
									
										
										
										
											2016-06-24 07:51:52 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-10 00:11:34 +08:00
										 |  |  | 	reportDependencyErrorsAndWarnings(module, blocks) { | 
					
						
							| 
									
										
										
										
											2017-01-25 03:39:38 +08:00
										 |  |  | 		for(var indexBlock = 0; indexBlock < blocks.length; indexBlock++) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 			var block = blocks[indexBlock]; | 
					
						
							|  |  |  | 			var dependencies = block.dependencies; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-25 03:39:38 +08:00
										 |  |  | 			for(var indexDep = 0; indexDep < dependencies.length; indexDep++) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 				var d = dependencies[indexDep]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 				const warnings = d.getWarnings(); | 
					
						
							|  |  |  | 				if(warnings) { | 
					
						
							| 
									
										
										
										
											2017-01-25 03:39:38 +08:00
										 |  |  | 					for(var indexWar = 0; indexWar < warnings.length; indexWar++) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 						var w = warnings[indexWar]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						var warning = new ModuleDependencyWarning(module, w, d.loc); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 						this.warnings.push(warning); | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 					} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-01-10 00:11:34 +08:00
										 |  |  | 				const errors = d.getErrors(); | 
					
						
							|  |  |  | 				if(errors) { | 
					
						
							| 
									
										
										
										
											2017-01-25 03:39:38 +08:00
										 |  |  | 					for(var indexErr = 0; indexErr < errors.length; indexErr++) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 						var e = errors[indexErr]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						var error = new ModuleDependencyError(module, e, d.loc); | 
					
						
							|  |  |  | 						this.errors.push(error); | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2017-01-10 00:11:34 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-10 00:11:34 +08:00
										 |  |  | 			this.reportDependencyErrorsAndWarnings(module, block.blocks); | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	addChunk(name, module, loc) { | 
					
						
							|  |  |  | 		if(name) { | 
					
						
							|  |  |  | 			if(Object.prototype.hasOwnProperty.call(this.namedChunks, name)) { | 
					
						
							| 
									
										
										
										
											2017-02-05 08:18:40 +08:00
										 |  |  | 				const chunk = this.namedChunks[name]; | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 				if(module) { | 
					
						
							|  |  |  | 					chunk.addOrigin(module, loc); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				return chunk; | 
					
						
							| 
									
										
										
										
											2014-06-04 03:03:21 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-01-24 20:32:58 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-02-05 08:18:40 +08:00
										 |  |  | 		const chunk = new Chunk(name, module, loc); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		this.chunks.push(chunk); | 
					
						
							|  |  |  | 		if(name) { | 
					
						
							|  |  |  | 			this.namedChunks[name] = chunk; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return chunk; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	assignIndex(module) { | 
					
						
							|  |  |  | 		const _this = this; | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 		const queue = [() => { | 
					
						
							|  |  |  | 			assignIndexToModule(module); | 
					
						
							|  |  |  | 		}]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		const iteratorAllDependencies = d => { | 
					
						
							|  |  |  | 			queue.push(() => assignIndexToDependency(d)); | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		function assignIndexToModule(module) { | 
					
						
							|  |  |  | 			// enter module
 | 
					
						
							|  |  |  | 			if(typeof module.index !== "number") { | 
					
						
							|  |  |  | 				module.index = _this.nextFreeModuleIndex++; | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 				// leave module
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 				queue.push(() => module.index2 = _this.nextFreeModuleIndex2++); | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 				// enter it as block
 | 
					
						
							|  |  |  | 				assignIndexToDependencyBlock(module); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		function assignIndexToDependency(dependency) { | 
					
						
							|  |  |  | 			if(dependency.module) { | 
					
						
							|  |  |  | 				queue.push(() => assignIndexToModule(dependency.module)); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		function assignIndexToDependencyBlock(block) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 			var allDependencies = []; | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			function iteratorDependency(d) { | 
					
						
							|  |  |  | 				allDependencies.push(d); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			function iteratorBlock(b) { | 
					
						
							|  |  |  | 				queue.push(() => assignIndexToDependencyBlock(b)); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			if(block.variables) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 				iterationBlockVariable(block.variables, iteratorDependency); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			if(block.dependencies) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 				iterationOfArrayCallback(block.dependencies, iteratorDependency); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			if(block.blocks) { | 
					
						
							| 
									
										
										
										
											2017-01-26 03:39:24 +08:00
										 |  |  | 				var blocks = block.blocks; | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 				var indexBlock = blocks.length; | 
					
						
							|  |  |  | 				while(indexBlock--) { | 
					
						
							|  |  |  | 					iteratorBlock(blocks[indexBlock]); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 			var indexAll = allDependencies.length; | 
					
						
							|  |  |  | 			while(indexAll--) { | 
					
						
							|  |  |  | 				iteratorAllDependencies(allDependencies[indexAll]); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		while(queue.length) { | 
					
						
							|  |  |  | 			queue.pop()(); | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	assignDepth(module) { | 
					
						
							|  |  |  | 		function assignDepthToModule(module, depth) { | 
					
						
							|  |  |  | 			// enter module
 | 
					
						
							|  |  |  | 			if(typeof module.depth === "number" && module.depth <= depth) return; | 
					
						
							|  |  |  | 			module.depth = depth; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// enter it as block
 | 
					
						
							|  |  |  | 			assignDepthToDependencyBlock(module, depth + 1); | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		function assignDepthToDependency(dependency, depth) { | 
					
						
							|  |  |  | 			if(dependency.module) { | 
					
						
							|  |  |  | 				queue.push(() => assignDepthToModule(dependency.module, depth)); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		function assignDepthToDependencyBlock(block, depth) { | 
					
						
							|  |  |  | 			function iteratorDependency(d) { | 
					
						
							|  |  |  | 				assignDepthToDependency(d, depth); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			function iteratorBlock(b) { | 
					
						
							|  |  |  | 				assignDepthToDependencyBlock(b, depth); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-12-14 19:03:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			if(block.variables) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 				iterationBlockVariable(block.variables, iteratorDependency); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			if(block.dependencies) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 				iterationOfArrayCallback(block.dependencies, iteratorDependency); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			if(block.blocks) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 				iterationOfArrayCallback(block.blocks, iteratorBlock); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-12-14 19:03:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		const queue = [() => { | 
					
						
							|  |  |  | 			assignDepthToModule(module, 0); | 
					
						
							|  |  |  | 		}]; | 
					
						
							|  |  |  | 		while(queue.length) { | 
					
						
							|  |  |  | 			queue.pop()(); | 
					
						
							| 
									
										
										
										
											2016-12-14 19:03:24 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	processDependenciesBlockForChunk(block, chunk) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 		const iteratorBlock = b => { | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			let c; | 
					
						
							|  |  |  | 			if(!b.chunks) { | 
					
						
							|  |  |  | 				c = this.addChunk(b.chunkName, b.module, b.loc); | 
					
						
							|  |  |  | 				b.chunks = [c]; | 
					
						
							|  |  |  | 				c.addBlock(b); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				c = b.chunks[0]; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			chunk.addChunk(c); | 
					
						
							|  |  |  | 			c.addParent(chunk); | 
					
						
							|  |  |  | 			queue.push([b, c]); | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2016-12-14 19:03:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 		const iteratorDependency = d => { | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			if(!d.module) { | 
					
						
							|  |  |  | 				return; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if(d.weak) { | 
					
						
							|  |  |  | 				return; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if(chunk.addModule(d.module)) { | 
					
						
							|  |  |  | 				d.module.addChunk(chunk); | 
					
						
							|  |  |  | 				queue.push([d.module, chunk]); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		const queue = [ | 
					
						
							|  |  |  | 			[block, chunk] | 
					
						
							|  |  |  | 		]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		while(queue.length) { | 
					
						
							|  |  |  | 			var queueItem = queue.pop(); | 
					
						
							|  |  |  | 			block = queueItem[0]; | 
					
						
							|  |  |  | 			chunk = queueItem[1]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if(block.variables) { | 
					
						
							|  |  |  | 				iterationBlockVariable(block.variables, iteratorDependency); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if(block.dependencies) { | 
					
						
							|  |  |  | 				iterationOfArrayCallback(block.dependencies, iteratorDependency); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if(block.blocks) { | 
					
						
							|  |  |  | 				iterationOfArrayCallback(block.blocks, iteratorBlock); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2016-12-14 19:03:24 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	removeChunkFromDependencies(block, chunk) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 		const iteratorDependency = d => { | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			if(!d.module) { | 
					
						
							|  |  |  | 				return; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if(!d.module.hasReasonForChunk(chunk)) { | 
					
						
							|  |  |  | 				if(d.module.removeChunk(chunk)) { | 
					
						
							|  |  |  | 					this.removeChunkFromDependencies(d.module, chunk); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		var blocks = block.blocks; | 
					
						
							| 
									
										
										
										
											2017-01-25 03:39:38 +08:00
										 |  |  | 		for(var indexBlock = 0; indexBlock < blocks.length; indexBlock++) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 			var chunks = blocks[indexBlock].chunks; | 
					
						
							| 
									
										
										
										
											2017-01-25 03:39:38 +08:00
										 |  |  | 			for(var indexChunk = 0; indexChunk < chunks.length; indexChunk++) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 				var blockChunk = chunks[indexChunk]; | 
					
						
							|  |  |  | 				chunk.removeChunk(blockChunk); | 
					
						
							|  |  |  | 				blockChunk.removeParent(chunk); | 
					
						
							|  |  |  | 				this.removeChunkFromDependencies(chunks, blockChunk); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if(block.dependencies) { | 
					
						
							|  |  |  | 			iterationOfArrayCallback(block.dependencies, iteratorDependency); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if(block.variables) { | 
					
						
							|  |  |  | 			iterationBlockVariable(block.variables, iteratorDependency); | 
					
						
							| 
									
										
										
										
											2016-12-05 06:47:19 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-11-02 19:17:05 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-07-08 20:15:21 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	applyModuleIds() { | 
					
						
							| 
									
										
										
										
											2017-01-26 03:39:24 +08:00
										 |  |  | 		var unusedIds = []; | 
					
						
							|  |  |  | 		var nextFreeModuleId = 0; | 
					
						
							|  |  |  | 		var usedIds = []; | 
					
						
							| 
									
										
										
										
											2017-01-26 03:47:11 +08:00
										 |  |  | 		// TODO consider Map when performance has improved https://gist.github.com/sokra/234c077e1299b7369461f1708519c392
 | 
					
						
							| 
									
										
										
										
											2017-01-26 03:39:24 +08:00
										 |  |  | 		var usedIdMap = Object.create(null); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		if(this.usedModuleIds) { | 
					
						
							|  |  |  | 			Object.keys(this.usedModuleIds).forEach(key => { | 
					
						
							|  |  |  | 				const id = this.usedModuleIds[key]; | 
					
						
							| 
									
										
										
										
											2017-01-26 03:39:24 +08:00
										 |  |  | 				if(!usedIdMap[id]) { | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 					usedIds.push(id); | 
					
						
							| 
									
										
										
										
											2017-01-26 03:39:24 +08:00
										 |  |  | 					usedIdMap[id] = true; | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2014-07-19 20:32:48 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		var modules1 = this.modules; | 
					
						
							| 
									
										
										
										
											2017-01-25 03:39:38 +08:00
										 |  |  | 		for(var indexModule1 = 0; indexModule1 < modules1.length; indexModule1++) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 			var module1 = modules1[indexModule1]; | 
					
						
							| 
									
										
										
										
											2017-01-26 03:39:24 +08:00
										 |  |  | 			if(module1.id && !usedIdMap[module1.id]) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 				usedIds.push(module1.id); | 
					
						
							| 
									
										
										
										
											2017-01-26 03:39:24 +08:00
										 |  |  | 				usedIdMap[module1.id] = true; | 
					
						
							| 
									
										
										
										
											2014-07-19 20:32:48 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		if(usedIds.length > 0) { | 
					
						
							| 
									
										
										
										
											2017-01-26 03:39:24 +08:00
										 |  |  | 			var usedIdMax = -1; | 
					
						
							|  |  |  | 			for(var index = 0; index < usedIds.length; index++) { | 
					
						
							|  |  |  | 				var usedIdKey = usedIds[index]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if(typeof usedIdKey !== "number") { | 
					
						
							|  |  |  | 					continue; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				usedIdMax = Math.max(usedIdMax, usedIdKey); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			var lengthFreeModules = nextFreeModuleId = usedIdMax + 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			while(lengthFreeModules--) { | 
					
						
							|  |  |  | 				if(!usedIdMap[lengthFreeModules]) { | 
					
						
							|  |  |  | 					unusedIds.push(lengthFreeModules); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2016-09-14 18:04:42 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		var modules2 = this.modules; | 
					
						
							| 
									
										
										
										
											2017-01-25 03:39:38 +08:00
										 |  |  | 		for(var indexModule2 = 0; indexModule2 < modules2.length; indexModule2++) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 			var module2 = modules2[indexModule2]; | 
					
						
							|  |  |  | 			if(module2.id === null) { | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 				if(unusedIds.length > 0) | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 					module2.id = unusedIds.pop(); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 				else | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 					module2.id = nextFreeModuleId++; | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-07-18 06:41:26 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	applyChunkIds() { | 
					
						
							|  |  |  | 		const unusedIds = []; | 
					
						
							|  |  |  | 		let nextFreeChunkId = 0; | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		function getNextFreeChunkId(usedChunkIds) { | 
					
						
							|  |  |  | 			var keyChunks = Object.keys(usedChunkIds); | 
					
						
							|  |  |  | 			var result = -1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-25 03:39:38 +08:00
										 |  |  | 			for(var index = 0; index < keyChunks.length; index++) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 				var usedIdKey = keyChunks[index]; | 
					
						
							|  |  |  | 				var usedIdValue = usedChunkIds[usedIdKey]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if(typeof usedIdValue !== "number") { | 
					
						
							|  |  |  | 					continue; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				result = Math.max(result, usedIdValue); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			return result; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		if(this.usedChunkIds) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 			nextFreeChunkId = getNextFreeChunkId(this.usedChunkIds) + 1; | 
					
						
							| 
									
										
										
										
											2017-01-26 03:39:24 +08:00
										 |  |  | 			var index = nextFreeChunkId; | 
					
						
							|  |  |  | 			while(index--) { | 
					
						
							|  |  |  | 				if(this.usedChunkIds[index] !== index) { | 
					
						
							|  |  |  | 					unusedIds.push(index); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-05-08 19:28:54 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		var chunks = this.chunks; | 
					
						
							| 
									
										
										
										
											2017-01-25 03:39:38 +08:00
										 |  |  | 		for(var indexChunk = 0; indexChunk < chunks.length; indexChunk++) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 			var chunk = chunks[indexChunk]; | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			if(chunk.id === null) { | 
					
						
							|  |  |  | 				if(unusedIds.length > 0) | 
					
						
							|  |  |  | 					chunk.id = unusedIds.pop(); | 
					
						
							|  |  |  | 				else | 
					
						
							|  |  |  | 					chunk.id = nextFreeChunkId++; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if(!chunk.ids) { | 
					
						
							|  |  |  | 				chunk.ids = [chunk.id]; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-07-18 06:41:26 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	sortItemsWithModuleIds() { | 
					
						
							|  |  |  | 		this.modules.sort(byId); | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		var modules = this.modules; | 
					
						
							| 
									
										
										
										
											2017-01-25 03:39:38 +08:00
										 |  |  | 		for(var indexModule = 0; indexModule < modules.length; indexModule++) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 			modules[indexModule].sortItems(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		var chunks = this.chunks; | 
					
						
							| 
									
										
										
										
											2017-01-25 03:39:38 +08:00
										 |  |  | 		for(var indexChunk = 0; indexChunk < chunks.length; indexChunk++) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 			chunks[indexChunk].sortItems(); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	sortItemsWithChunkIds() { | 
					
						
							|  |  |  | 		this.chunks.sort(byId); | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		var modules = this.modules; | 
					
						
							| 
									
										
										
										
											2017-01-25 03:39:38 +08:00
										 |  |  | 		for(var indexModule = 0; indexModule < modules.length; indexModule++) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 			modules[indexModule].sortItems(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		var chunks = this.chunks; | 
					
						
							| 
									
										
										
										
											2017-01-25 03:39:38 +08:00
										 |  |  | 		for(var indexChunk = 0; indexChunk < chunks.length; indexChunk++) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 			chunks[indexChunk].sortItems(); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	summarizeDependencies() { | 
					
						
							|  |  |  | 		function filterDups(array) { | 
					
						
							|  |  |  | 			const newArray = []; | 
					
						
							|  |  |  | 			for(let i = 0; i < array.length; i++) { | 
					
						
							|  |  |  | 				if(i === 0 || array[i - 1] !== array[i]) | 
					
						
							|  |  |  | 					newArray.push(array[i]); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			return newArray; | 
					
						
							| 
									
										
										
										
											2015-01-18 04:55:44 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		this.fileDependencies = (this.compilationDependencies || []).slice(); | 
					
						
							|  |  |  | 		this.contextDependencies = []; | 
					
						
							|  |  |  | 		this.missingDependencies = []; | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		var children = this.children; | 
					
						
							| 
									
										
										
										
											2017-01-25 03:39:38 +08:00
										 |  |  | 		for(var indexChildren = 0; indexChildren < children.length; indexChildren++) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 			var child = children[indexChildren]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			this.fileDependencies = this.fileDependencies.concat(child.fileDependencies); | 
					
						
							|  |  |  | 			this.contextDependencies = this.contextDependencies.concat(child.contextDependencies); | 
					
						
							|  |  |  | 			this.missingDependencies = this.missingDependencies.concat(child.missingDependencies); | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		var modules = this.modules; | 
					
						
							| 
									
										
										
										
											2017-01-25 03:39:38 +08:00
										 |  |  | 		for(var indexModule = 0; indexModule < modules.length; indexModule++) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 			var module = modules[indexModule]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			if(module.fileDependencies) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 				var fileDependencies = module.fileDependencies; | 
					
						
							| 
									
										
										
										
											2017-01-25 03:39:38 +08:00
										 |  |  | 				for(var indexFileDep = 0; indexFileDep < fileDependencies.length; indexFileDep++) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 					this.fileDependencies.push(fileDependencies[indexFileDep]); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			if(module.contextDependencies) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 				var contextDependencies = module.contextDependencies; | 
					
						
							| 
									
										
										
										
											2017-01-25 03:39:38 +08:00
										 |  |  | 				for(var indexContextDep = 0; indexContextDep < contextDependencies.length; indexContextDep++) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 					this.contextDependencies.push(contextDependencies[indexContextDep]); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		this.errors.forEach(error => { | 
					
						
							|  |  |  | 			if(Array.isArray(error.missing)) { | 
					
						
							|  |  |  | 				error.missing.forEach(item => this.missingDependencies.push(item)); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 		this.fileDependencies.sort(); | 
					
						
							|  |  |  | 		this.fileDependencies = filterDups(this.fileDependencies); | 
					
						
							|  |  |  | 		this.contextDependencies.sort(); | 
					
						
							|  |  |  | 		this.contextDependencies = filterDups(this.contextDependencies); | 
					
						
							|  |  |  | 		this.missingDependencies.sort(); | 
					
						
							|  |  |  | 		this.missingDependencies = filterDups(this.missingDependencies); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	createHash() { | 
					
						
							|  |  |  | 		const outputOptions = this.outputOptions; | 
					
						
							|  |  |  | 		const hashFunction = outputOptions.hashFunction; | 
					
						
							|  |  |  | 		const hashDigest = outputOptions.hashDigest; | 
					
						
							|  |  |  | 		const hashDigestLength = outputOptions.hashDigestLength; | 
					
						
							| 
									
										
										
										
											2017-01-09 21:55:44 +08:00
										 |  |  | 		const hash = crypto.createHash(hashFunction); | 
					
						
							| 
									
										
										
										
											2016-06-05 02:03:42 +08:00
										 |  |  | 		if(outputOptions.hashSalt) | 
					
						
							|  |  |  | 			hash.update(outputOptions.hashSalt); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		this.mainTemplate.updateHash(hash); | 
					
						
							|  |  |  | 		this.chunkTemplate.updateHash(hash); | 
					
						
							|  |  |  | 		this.moduleTemplate.updateHash(hash); | 
					
						
							| 
									
										
										
										
											2017-01-06 13:03:54 +08:00
										 |  |  | 		this.children.forEach(function(child) { | 
					
						
							|  |  |  | 			hash.update(child.hash); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-01-10 20:20:54 +08:00
										 |  |  | 		// clone needed as sort below is inplace mutation
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		const chunks = this.chunks.slice(); | 
					
						
							| 
									
										
										
										
											2017-01-10 20:20:54 +08:00
										 |  |  | 		/** | 
					
						
							|  |  |  | 		 * sort here will bring all "falsy" values to the beginning | 
					
						
							|  |  |  | 		 * this is needed as the "hasRuntime()" chunks are dependent on the | 
					
						
							|  |  |  | 		 * hashes of the non-runtime chunks. | 
					
						
							|  |  |  | 		 */ | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		chunks.sort((a, b) => { | 
					
						
							|  |  |  | 			const aEntry = a.hasRuntime(); | 
					
						
							|  |  |  | 			const bEntry = b.hasRuntime(); | 
					
						
							|  |  |  | 			if(aEntry && !bEntry) return 1; | 
					
						
							|  |  |  | 			if(!aEntry && bEntry) return -1; | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 		for(let i = 0; i < chunks.length; i++) { | 
					
						
							| 
									
										
										
										
											2017-02-05 08:18:40 +08:00
										 |  |  | 			const chunk = chunks[i]; | 
					
						
							| 
									
										
										
										
											2017-01-09 21:55:44 +08:00
										 |  |  | 			const chunkHash = crypto.createHash(hashFunction); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			if(outputOptions.hashSalt) | 
					
						
							| 
									
										
										
										
											2017-01-10 06:45:59 +08:00
										 |  |  | 				chunkHash.update(outputOptions.hashSalt); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			chunk.updateHash(chunkHash); | 
					
						
							|  |  |  | 			if(chunk.hasRuntime()) { | 
					
						
							|  |  |  | 				this.mainTemplate.updateHashForChunk(chunkHash, chunk); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				this.chunkTemplate.updateHashForChunk(chunkHash); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			this.applyPlugins2("chunk-hash", chunk, chunkHash); | 
					
						
							|  |  |  | 			chunk.hash = chunkHash.digest(hashDigest); | 
					
						
							|  |  |  | 			hash.update(chunk.hash); | 
					
						
							|  |  |  | 			chunk.renderedHash = chunk.hash.substr(0, hashDigestLength); | 
					
						
							| 
									
										
										
										
											2015-06-25 05:17:12 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		this.fullHash = hash.digest(hashDigest); | 
					
						
							|  |  |  | 		this.hash = this.fullHash.substr(0, hashDigestLength); | 
					
						
							| 
									
										
										
										
											2013-02-13 20:00:01 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	modifyHash(update) { | 
					
						
							|  |  |  | 		const outputOptions = this.outputOptions; | 
					
						
							|  |  |  | 		const hashFunction = outputOptions.hashFunction; | 
					
						
							|  |  |  | 		const hashDigest = outputOptions.hashDigest; | 
					
						
							|  |  |  | 		const hashDigestLength = outputOptions.hashDigestLength; | 
					
						
							| 
									
										
										
										
											2017-01-09 21:55:44 +08:00
										 |  |  | 		const hash = crypto.createHash(hashFunction); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 		hash.update(this.fullHash); | 
					
						
							|  |  |  | 		hash.update(update); | 
					
						
							|  |  |  | 		this.fullHash = hash.digest(hashDigest); | 
					
						
							|  |  |  | 		this.hash = this.fullHash.substr(0, hashDigestLength); | 
					
						
							| 
									
										
										
										
											2016-10-29 17:11:44 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	createModuleAssets() { | 
					
						
							|  |  |  | 		for(let i = 0; i < this.modules.length; i++) { | 
					
						
							| 
									
										
										
										
											2017-02-05 08:18:40 +08:00
										 |  |  | 			const module = this.modules[i]; | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			if(module.assets) { | 
					
						
							| 
									
										
										
										
											2017-02-05 10:28:15 +08:00
										 |  |  | 				Object.keys(module.assets).forEach((assetName) => { | 
					
						
							|  |  |  | 					const fileName = this.getPath(assetName); | 
					
						
							|  |  |  | 					this.assets[fileName] = module.assets[assetName]; | 
					
						
							|  |  |  | 					this.applyPlugins2("module-asset", module, fileName); | 
					
						
							|  |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	createChunkAssets() { | 
					
						
							|  |  |  | 		const outputOptions = this.outputOptions; | 
					
						
							|  |  |  | 		const filename = outputOptions.filename; | 
					
						
							|  |  |  | 		const chunkFilename = outputOptions.chunkFilename; | 
					
						
							|  |  |  | 		for(let i = 0; i < this.chunks.length; i++) { | 
					
						
							|  |  |  | 			const chunk = this.chunks[i]; | 
					
						
							|  |  |  | 			chunk.files = []; | 
					
						
							|  |  |  | 			const chunkHash = chunk.hash; | 
					
						
							|  |  |  | 			let source; | 
					
						
							|  |  |  | 			let file; | 
					
						
							|  |  |  | 			const filenameTemplate = chunk.filenameTemplate ? chunk.filenameTemplate : | 
					
						
							|  |  |  | 				chunk.isInitial() ? filename : | 
					
						
							|  |  |  | 				chunkFilename; | 
					
						
							|  |  |  | 			try { | 
					
						
							|  |  |  | 				const useChunkHash = !chunk.hasRuntime() || (this.mainTemplate.useChunkHash && this.mainTemplate.useChunkHash(chunk)); | 
					
						
							|  |  |  | 				const usedHash = useChunkHash ? chunkHash : this.fullHash; | 
					
						
							| 
									
										
										
										
											2017-01-26 03:39:24 +08:00
										 |  |  | 				const cacheName = "c" + chunk.id; | 
					
						
							|  |  |  | 				if(this.cache && this.cache[cacheName] && this.cache[cacheName].hash === usedHash) { | 
					
						
							|  |  |  | 					source = this.cache[cacheName].source; | 
					
						
							| 
									
										
										
										
											2015-06-27 17:34:17 +08:00
										 |  |  | 				} else { | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 					if(chunk.hasRuntime()) { | 
					
						
							|  |  |  | 						source = this.mainTemplate.render(this.hash, chunk, this.moduleTemplate, this.dependencyTemplates); | 
					
						
							|  |  |  | 					} else { | 
					
						
							|  |  |  | 						source = this.chunkTemplate.render(chunk, this.moduleTemplate, this.dependencyTemplates); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					if(this.cache) { | 
					
						
							| 
									
										
										
										
											2017-01-26 03:39:24 +08:00
										 |  |  | 						this.cache[cacheName] = { | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 							hash: usedHash, | 
					
						
							|  |  |  | 							source: source = (source instanceof CachedSource ? source : new CachedSource(source)) | 
					
						
							|  |  |  | 						}; | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2015-06-27 17:34:17 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 				file = this.getPath(filenameTemplate, { | 
					
						
							|  |  |  | 					noChunkHash: !useChunkHash, | 
					
						
							|  |  |  | 					chunk | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 				if(this.assets[file]) | 
					
						
							|  |  |  | 					throw new Error(`Conflict: Multiple assets emit to the same filename ${file}`); | 
					
						
							|  |  |  | 				this.assets[file] = source; | 
					
						
							|  |  |  | 				chunk.files.push(file); | 
					
						
							|  |  |  | 				this.applyPlugins2("chunk-asset", chunk, file); | 
					
						
							|  |  |  | 			} catch(err) { | 
					
						
							|  |  |  | 				this.errors.push(new ChunkRenderError(chunk, file || filenameTemplate, err)); | 
					
						
							| 
									
										
										
										
											2013-05-08 19:28:54 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-12-03 18:19:30 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	getPath(filename, data) { | 
					
						
							|  |  |  | 		data = data || {}; | 
					
						
							|  |  |  | 		data.hash = data.hash || this.hash; | 
					
						
							|  |  |  | 		return this.mainTemplate.applyPluginsWaterfall("asset-path", filename, data); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	getStats() { | 
					
						
							|  |  |  | 		return new Stats(this); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	createChildCompiler(name, outputOptions) { | 
					
						
							|  |  |  | 		return this.compiler.createChildCompiler(this, name, outputOptions); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	checkConstraints() { | 
					
						
							|  |  |  | 		const usedIds = {}; | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		var modules = this.modules; | 
					
						
							| 
									
										
										
										
											2017-01-25 03:39:38 +08:00
										 |  |  | 		for(var indexModule = 0; indexModule < modules.length; indexModule++) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 			var moduleId = modules[indexModule].id; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if(usedIds[moduleId]) | 
					
						
							|  |  |  | 				throw new Error(`checkConstraints: duplicate module id ${moduleId}`); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		var chunks = this.chunks; | 
					
						
							| 
									
										
										
										
											2017-01-25 03:39:38 +08:00
										 |  |  | 		for(var indexChunk = 0; indexChunk < chunks.length; indexChunk++) { | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 			var chunk = chunks[indexChunk]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if(chunks.indexOf(chunk) !== indexChunk) | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 				throw new Error(`checkConstraints: duplicate chunk in compilation ${chunk.debugId}`); | 
					
						
							|  |  |  | 			chunk.checkConstraints(); | 
					
						
							| 
									
										
										
										
											2017-01-24 02:52:20 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-01-06 01:00:36 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module.exports = Compilation; |