| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | var async = require("async"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | var Tapable = require("tapable"); | 
					
						
							|  |  |  | var Parser = require("./Parser"); | 
					
						
							|  |  |  | var Dependency = require("./Dependency"); | 
					
						
							|  |  |  | var EntryModuleNotFoundError = require("./EntryModuleNotFoundError"); | 
					
						
							|  |  |  | var ModuleNotFoundError = require("./ModuleNotFoundError"); | 
					
						
							| 
									
										
										
										
											2013-02-13 21:42:34 +08:00
										 |  |  | var CriticalDependenciesWarning = require("./CriticalDependenciesWarning"); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | var Module = require("./Module"); | 
					
						
							|  |  |  | var ArrayMap = require("./ArrayMap"); | 
					
						
							|  |  |  | var Chunk = require("./Chunk"); | 
					
						
							|  |  |  | var Stats = require("./Stats"); | 
					
						
							| 
									
										
										
										
											2013-03-26 23:54:41 +08:00
										 |  |  | var Template = require("./Template"); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | function Compilation(compiler) { | 
					
						
							|  |  |  | 	Tapable.call(this); | 
					
						
							|  |  |  | 	this.compiler = compiler; | 
					
						
							|  |  |  | 	this.mainTemplate = compiler.mainTemplate; | 
					
						
							|  |  |  | 	this.chunkTemplate = compiler.chunkTemplate; | 
					
						
							| 
									
										
										
										
											2013-06-19 19:49:57 +08:00
										 |  |  | 	this.hotUpdateChunkTemplate = compiler.hotUpdateChunkTemplate; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	this.moduleTemplate = compiler.moduleTemplate; | 
					
						
							|  |  |  | 	this.resolvers = compiler.resolvers; | 
					
						
							|  |  |  | 	this.inputFileSystem = compiler.inputFileSystem; | 
					
						
							| 
									
										
										
										
											2013-02-13 21:42:34 +08:00
										 |  |  | 	var options = this.options = compiler.options; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	this.outputOptions = options && options.output; | 
					
						
							|  |  |  | 	this.bail = options && options.bail; | 
					
						
							| 
									
										
										
										
											2013-05-08 20:47:13 +08:00
										 |  |  | 	this.profile = options && options.profile; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	this.entries = []; | 
					
						
							| 
									
										
										
										
											2013-05-22 16:12:53 +08:00
										 |  |  | 	this.preparedChunks = []; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	this.chunks = []; | 
					
						
							|  |  |  | 	this.namedChunks = {}; | 
					
						
							|  |  |  | 	this.modules = []; | 
					
						
							|  |  |  | 	this._modules = {}; | 
					
						
							|  |  |  | 	this.cache = null; | 
					
						
							| 
									
										
										
										
											2013-05-31 18:22:40 +08:00
										 |  |  | 	this.records = null; | 
					
						
							|  |  |  | 	this.nextFreeModuleId = 1; | 
					
						
							|  |  |  | 	this.nextFreeChunkId = 1; | 
					
						
							| 
									
										
										
										
											2013-07-01 19:59:02 +08:00
										 |  |  | 	this.additionalChunkAssets = []; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	this.assets = {}; | 
					
						
							|  |  |  | 	this.errors = []; | 
					
						
							|  |  |  | 	this.warnings = []; | 
					
						
							|  |  |  | 	this.children = []; | 
					
						
							|  |  |  | 	this.dependencyFactories = new ArrayMap(); | 
					
						
							|  |  |  | 	this.dependencyTemplates = new ArrayMap(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | module.exports = Compilation; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Compilation.prototype = Object.create(Tapable.prototype); | 
					
						
							| 
									
										
										
										
											2013-10-28 23:21:29 +08:00
										 |  |  | Compilation.prototype.addModule = function(module, cacheGroup) { | 
					
						
							|  |  |  | 	cacheGroup = cacheGroup || "m"; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	var identifier = module.identifier(); | 
					
						
							|  |  |  | 	if(this._modules[identifier]) return false; | 
					
						
							| 
									
										
										
										
											2013-10-28 23:21:29 +08:00
										 |  |  | 	if(this.cache && this.cache[cacheGroup + identifier]) { | 
					
						
							|  |  |  | 		var cacheModule = this.cache[cacheGroup + identifier]; | 
					
						
							| 
									
										
										
										
											2013-05-08 19:28:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		var rebuild = true; | 
					
						
							|  |  |  | 		if(!cacheModule.error && cacheModule.cacheable && this.fileTimestamps && this.contextTimestamps) { | 
					
						
							|  |  |  | 			rebuild = cacheModule.needRebuild(this.fileTimestamps, this.contextTimestamps); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-02-01 01:00:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		if(!rebuild) { | 
					
						
							|  |  |  | 			cacheModule.disconnect(); | 
					
						
							|  |  |  | 			this._modules[identifier] = cacheModule; | 
					
						
							|  |  |  | 			this.modules.push(cacheModule); | 
					
						
							| 
									
										
										
										
											2013-03-05 18:05:13 +08:00
										 |  |  | 			cacheModule.errors.forEach(function(err) { | 
					
						
							|  |  |  | 				this.errors.push(err); | 
					
						
							|  |  |  | 			}, this); | 
					
						
							|  |  |  | 			cacheModule.warnings.forEach(function(err) { | 
					
						
							|  |  |  | 				this.warnings.push(err); | 
					
						
							|  |  |  | 			}, this); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 			return cacheModule; | 
					
						
							| 
									
										
										
										
											2013-05-08 19:28:54 +08:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			module.lastId = cacheModule.id; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	this._modules[identifier] = module; | 
					
						
							| 
									
										
										
										
											2013-10-28 23:21:29 +08:00
										 |  |  | 	if(this.cache) this.cache[cacheGroup + identifier] = module; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	this.modules.push(module); | 
					
						
							|  |  |  | 	return true; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Compilation.prototype.getModule = function(module) { | 
					
						
							|  |  |  | 	var identifier = module.identifier(); | 
					
						
							|  |  |  | 	return this._modules[identifier]; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-26 23:54:41 +08:00
										 |  |  | Compilation.prototype.findModule = function(identifier) { | 
					
						
							|  |  |  | 	return this._modules[identifier]; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-29 21:14:16 +08:00
										 |  |  | Compilation.prototype.buildModule = function(module, thisCallback) { | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	this.applyPlugins("build-module", module); | 
					
						
							| 
									
										
										
										
											2013-10-29 21:14:16 +08:00
										 |  |  | 	var building = module.building = [thisCallback]; | 
					
						
							|  |  |  | 	function callback(err) { | 
					
						
							|  |  |  | 		module.building = undefined; | 
					
						
							|  |  |  | 		building.forEach(function(cb) { | 
					
						
							|  |  |  | 			cb(err); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	module.build(this.options, this, this.resolvers.normal, this.inputFileSystem, function(err) { | 
					
						
							| 
									
										
										
										
											2013-02-19 19:48:17 +08:00
										 |  |  | 		module.errors.forEach(function(err) { | 
					
						
							|  |  |  | 			this.errors.push(err); | 
					
						
							|  |  |  | 		}, this); | 
					
						
							|  |  |  | 		module.warnings.forEach(function(err) { | 
					
						
							|  |  |  | 			this.warnings.push(err); | 
					
						
							|  |  |  | 		}, this); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		if(err) { | 
					
						
							| 
									
										
										
										
											2013-05-18 20:42:11 +08:00
										 |  |  | 			module.error = err; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 			this.applyPlugins("failed-module", module); | 
					
						
							|  |  |  | 			return callback(err); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		this.applyPlugins("succeed-module", module); | 
					
						
							|  |  |  | 		return callback(); | 
					
						
							|  |  |  | 	}.bind(this)); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Compilation.prototype.processModuleDependencies = function(module, callback) { | 
					
						
							|  |  |  | 	var dependencies = []; | 
					
						
							|  |  |  | 	function addDependency(dep) { | 
					
						
							|  |  |  | 		for(var i = 0; i < dependencies.length; i++) { | 
					
						
							|  |  |  | 			if(dep.isEqualResource(dependencies[i][0])) | 
					
						
							|  |  |  | 				return dependencies[i].push(dep); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		dependencies.push([dep]); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	function addDependenciesBlock(block) { | 
					
						
							| 
									
										
										
										
											2013-10-28 23:21:29 +08:00
										 |  |  | 		if(block.dependencies) block.dependencies.forEach(addDependency); | 
					
						
							|  |  |  | 		if(block.blocks) block.blocks.forEach(addDependenciesBlock); | 
					
						
							|  |  |  | 		if(block.variables) block.variables.forEach(function(v) { | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 			v.dependencies.forEach(addDependency); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	addDependenciesBlock(module); | 
					
						
							| 
									
										
										
										
											2013-10-28 23:21:29 +08:00
										 |  |  | 	this.addModuleDependencies(module, dependencies, this.bail, null, true, callback); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Compilation.prototype.addModuleDependencies = function(module, dependencies, bail, cacheGroup, recursive, callback) { | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	var factories = []; | 
					
						
							|  |  |  | 	for(var i = 0; i < dependencies.length; i++) { | 
					
						
							|  |  |  | 		var factory = this.dependencyFactories.get(dependencies[i][0].Class); | 
					
						
							|  |  |  | 		if(!factory) | 
					
						
							|  |  |  | 			return callback(new Error("No module factory availible for dependency type: " + dependencies[i][0].Class.name)); | 
					
						
							|  |  |  | 		factories[i] = [factory, dependencies[i]]; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	async.forEach(factories, function(item, callback) { | 
					
						
							|  |  |  | 		var dependencies = item[1]; | 
					
						
							| 
									
										
										
										
											2013-02-13 21:42:34 +08:00
										 |  |  | 		var criticalDependencies = dependencies.filter(function(d) { return !!d.critical }); | 
					
						
							|  |  |  | 		if(criticalDependencies.length > 0) { | 
					
						
							|  |  |  | 			this.warnings.push(new CriticalDependenciesWarning(module, criticalDependencies)); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		var errorAndCallback = function errorAndCallback(err) { | 
					
						
							|  |  |  | 			err.dependencies = dependencies; | 
					
						
							|  |  |  | 			err.origin = module; | 
					
						
							| 
									
										
										
										
											2013-05-18 20:42:11 +08:00
										 |  |  | 			module.dependenciesErrors.push(err); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 			this.errors.push(err); | 
					
						
							| 
									
										
										
										
											2013-10-28 23:21:29 +08:00
										 |  |  | 			if(bail) | 
					
						
							|  |  |  | 				callback(err); | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 				callback(); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		}.bind(this); | 
					
						
							|  |  |  | 		var warningAndCallback = function warningAndCallback(err) { | 
					
						
							|  |  |  | 			err.dependencies = dependencies; | 
					
						
							|  |  |  | 			err.origin = module; | 
					
						
							| 
									
										
										
										
											2013-05-18 20:42:11 +08:00
										 |  |  | 			module.dependenciesWarnings.push(err); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 			this.warnings.push(err); | 
					
						
							|  |  |  | 			callback(); | 
					
						
							|  |  |  | 		}.bind(this); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		var factory = item[0]; | 
					
						
							| 
									
										
										
										
											2013-05-08 20:47:13 +08:00
										 |  |  | 		if(this.profile) var start = +new Date(); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		factory.create(module.context, dependencies[0], function(err, dependantModule) { | 
					
						
							|  |  |  | 			function isOptional() { | 
					
						
							| 
									
										
										
										
											2013-02-13 21:42:34 +08:00
										 |  |  | 				return dependencies.filter(function(d) { return !d.optional }).length == 0; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			function errorOrWarningAndCallback(err) { | 
					
						
							|  |  |  | 				if(isOptional()) | 
					
						
							|  |  |  | 					return warningAndCallback(err); | 
					
						
							| 
									
										
										
										
											2013-02-13 21:42:34 +08:00
										 |  |  | 				else | 
					
						
							|  |  |  | 					return errorAndCallback(err); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			if(err) return errorOrWarningAndCallback(new ModuleNotFoundError(module, err)); | 
					
						
							|  |  |  | 			if(!dependantModule) return callback(); | 
					
						
							| 
									
										
										
										
											2013-05-08 20:47:13 +08:00
										 |  |  | 			if(this.profile) { | 
					
						
							|  |  |  | 				if(!dependantModule.profile) dependantModule.profile = {}; | 
					
						
							|  |  |  | 				var afterFactory = +new Date(); | 
					
						
							|  |  |  | 				dependantModule.profile.factory = afterFactory - start; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-05-08 19:28:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-08 20:47:13 +08:00
										 |  |  | 			dependantModule.issuer = module.identifier(); | 
					
						
							| 
									
										
										
										
											2013-10-28 23:21:29 +08:00
										 |  |  | 			var newModule = this.addModule(dependantModule, cacheGroup); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-04 01:12:19 +08:00
										 |  |  | 			if(!newModule) { // from cache
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 				dependantModule = this.getModule(dependantModule); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-04 01:12:19 +08:00
										 |  |  | 				if(dependantModule.id === 0) return errorOrWarningAndCallback( | 
					
						
							|  |  |  | 					new ModuleNotFoundError(module, new Error("a dependency to an entry point is not allowed")) | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 				dependencies.forEach(function(dep) { | 
					
						
							|  |  |  | 					dep.module = dependantModule; | 
					
						
							|  |  |  | 					dependantModule.addReason(module, dep); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-08 20:47:13 +08:00
										 |  |  | 				if(this.profile) { | 
					
						
							|  |  |  | 					if(!module.profile) module.profile = {}; | 
					
						
							|  |  |  | 					var time = +new Date() - start; | 
					
						
							|  |  |  | 					if(!module.profile.dependencies || time > module.profile.dependencies) | 
					
						
							|  |  |  | 						module.profile.dependencies = time; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 				return callback(); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-04 01:12:19 +08:00
										 |  |  | 			if(newModule instanceof Module) { | 
					
						
							| 
									
										
										
										
											2013-05-08 20:47:13 +08:00
										 |  |  | 				if(this.profile) | 
					
						
							|  |  |  | 					newModule.profile = dependantModule.profile; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				newModule.issuer = dependantModule.issuer; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 				dependantModule = newModule; | 
					
						
							| 
									
										
										
										
											2013-05-08 19:28:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 				dependencies.forEach(function(dep) { | 
					
						
							|  |  |  | 					dep.module = dependantModule; | 
					
						
							|  |  |  | 					dependantModule.addReason(module, dep); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-28 23:21:29 +08:00
										 |  |  | 				if(recursive) | 
					
						
							|  |  |  | 					return this.processModuleDependencies(dependantModule, callback); | 
					
						
							|  |  |  | 				else | 
					
						
							|  |  |  | 					return callback(); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-05-08 19:28:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-18 20:42:11 +08:00
										 |  |  | 			dependencies.forEach(function(dep) { | 
					
						
							|  |  |  | 				dep.module = dependantModule; | 
					
						
							|  |  |  | 				dependantModule.addReason(module, dep); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 			this.buildModule(dependantModule, function(err) { | 
					
						
							|  |  |  | 				if(err) return errorOrWarningAndCallback(err); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-08 20:47:13 +08:00
										 |  |  | 				if(this.profile) { | 
					
						
							|  |  |  | 					var afterBuilding = +new Date(); | 
					
						
							|  |  |  | 					dependantModule.profile.building = afterBuilding - afterFactory; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-28 23:21:29 +08:00
										 |  |  | 				if(recursive) | 
					
						
							|  |  |  | 					this.processModuleDependencies(dependantModule, callback); | 
					
						
							|  |  |  | 				else | 
					
						
							|  |  |  | 					return callback(); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 			}.bind(this)); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		}.bind(this)); | 
					
						
							|  |  |  | 	}.bind(this), function(err) { | 
					
						
							|  |  |  | 		if(err) callback(err); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return callback(); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | Compilation.prototype._addModuleChain = function process(context, dependency, onModule, callback) { | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	var errorAndCallback = this.bail ? function errorAndCallback(err) { | 
					
						
							|  |  |  | 		callback(err); | 
					
						
							|  |  |  | 	} : function errorAndCallback(err) { | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 		err.dependencies = [dependency]; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		this.errors.push(err); | 
					
						
							|  |  |  | 		callback(); | 
					
						
							|  |  |  | 	}.bind(this); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 	if(!(typeof dependency == "object" && dependency != null && dependency.Class)) | 
					
						
							|  |  |  | 		throw new Error("Parameter 'dependency' must be a Dependency"); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 	var moduleFactory = this.dependencyFactories.get(dependency.Class); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	if(!moduleFactory) | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 		throw new Error("No dependency factory availible for this dependency type: " + dependency.Class.name); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 	if(this.profile) var start = +new Date(); | 
					
						
							|  |  |  | 	moduleFactory.create(context, dependency, function(err, module) { | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		if(err) return errorAndCallback(new EntryModuleNotFoundError(err)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 		if(this.profile) { | 
					
						
							|  |  |  | 			if(!module.profile) module.profile = {}; | 
					
						
							|  |  |  | 			var afterFactory = +new Date(); | 
					
						
							|  |  |  | 			module.profile.factory = afterFactory - start; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		var result = this.addModule(module); | 
					
						
							|  |  |  | 		if(!result) { | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 			module = this.getModule(module); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			onModule(module); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			return callback(null, module); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-05-08 19:28:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		if(result instanceof Module) { | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 			if(this.profile) { | 
					
						
							|  |  |  | 				result.profile = module.profile; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 			module = result; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 		onModule(module); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if(result instanceof Module) { | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 			moduleReady.call(this); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			this.buildModule(module, function(err) { | 
					
						
							|  |  |  | 				if(err) return errorAndCallback(err); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 				if(this.profile) { | 
					
						
							|  |  |  | 					var afterBuilding = +new Date(); | 
					
						
							|  |  |  | 					module.profile.building = afterBuilding - afterFactory; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				moduleReady.call(this); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 			}.bind(this)); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-05-08 19:28:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 		function moduleReady() { | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 			this.processModuleDependencies(module, function(err) { | 
					
						
							|  |  |  | 				if(err) return callback(err); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 				return callback(null, module); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 			}.bind(this)); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}.bind(this)); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | Compilation.prototype.addEntry = function process(context, entry, name, callback) { | 
					
						
							|  |  |  | 	this._addModuleChain(context, entry, function(module) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		this.entries.push(module); | 
					
						
							|  |  |  | 		module.id = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	}.bind(this), function(err, module) { | 
					
						
							|  |  |  | 		if(err) return callback(err); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if(module) { | 
					
						
							| 
									
										
										
										
											2014-02-04 01:12:19 +08:00
										 |  |  | 			if(module.reasons.length > 0) return callback(new Error("module cannot be added as entry point, because its already in the bundle")); | 
					
						
							| 
									
										
										
										
											2013-05-22 16:12:53 +08:00
										 |  |  | 			this.preparedChunks.push({ | 
					
						
							|  |  |  | 				name: name, | 
					
						
							|  |  |  | 				module: module | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2013-05-13 19:34:00 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		return callback(); | 
					
						
							|  |  |  | 	}.bind(this)); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Compilation.prototype.prefetch = function process(context, dependency, callback) { | 
					
						
							|  |  |  | 	this._addModuleChain(context, dependency, function(module) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		module.prefetched = true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	}, callback); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | Compilation.prototype.seal = function seal(callback) { | 
					
						
							|  |  |  | 	this.applyPlugins("seal"); | 
					
						
							| 
									
										
										
										
											2013-05-22 16:12:53 +08:00
										 |  |  | 	this.preparedChunks.forEach(function(preparedChunk) { | 
					
						
							|  |  |  | 		var module = preparedChunk.module; | 
					
						
							| 
									
										
										
										
											2014-01-23 22:31:40 +08:00
										 |  |  | 		var chunk = this.addChunk(preparedChunk.name, module); | 
					
						
							| 
									
										
										
										
											2013-05-22 16:12:53 +08:00
										 |  |  | 		chunk.id = 0; | 
					
						
							| 
									
										
										
										
											2013-12-04 06:11:14 +08:00
										 |  |  | 		chunk.initial = chunk.entry = true; | 
					
						
							| 
									
										
										
										
											2013-05-22 16:12:53 +08:00
										 |  |  | 		chunk.addModule(module); | 
					
						
							|  |  |  | 		module.addChunk(chunk); | 
					
						
							|  |  |  | 		this.processDependenciesBlockForChunk(module, chunk); | 
					
						
							|  |  |  | 	}, this); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	this.applyPlugins("optimize"); | 
					
						
							| 
									
										
										
										
											2013-05-31 18:22:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	this.applyPlugins("optimize-modules", this.modules); | 
					
						
							|  |  |  | 	this.applyPlugins("after-optimize-modules", this.modules); | 
					
						
							| 
									
										
										
										
											2013-05-31 18:22:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	this.applyPlugins("optimize-chunks", this.chunks); | 
					
						
							|  |  |  | 	this.applyPlugins("after-optimize-chunks", this.chunks); | 
					
						
							| 
									
										
										
										
											2013-05-31 18:22:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-29 17:13:28 +08:00
										 |  |  | 	this.applyPluginsAsyncSeries("optimize-tree", this.chunks, this.modules, function(err) { | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		if(err) return callback(err); | 
					
						
							| 
									
										
										
										
											2014-01-29 17:13:28 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		this.applyPlugins("revive-modules", this.modules, this.records); | 
					
						
							|  |  |  | 		this.applyPlugins("optimize-module-order", this.modules); | 
					
						
							|  |  |  | 		this.applyModuleIds(); | 
					
						
							|  |  |  | 		this.applyPlugins("optimize-module-ids", this.modules); | 
					
						
							|  |  |  | 		this.applyPlugins("after-optimize-module-ids", this.modules); | 
					
						
							|  |  |  | 		this.applyPlugins("record-modules", this.modules, this.records); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		this.applyPlugins("revive-chunks", this.chunks, this.records); | 
					
						
							|  |  |  | 		this.applyPlugins("optimize-chunk-order", this.chunks); | 
					
						
							|  |  |  | 		this.applyChunkIds(); | 
					
						
							|  |  |  | 		this.applyPlugins("optimize-chunk-ids", this.chunks); | 
					
						
							|  |  |  | 		this.applyPlugins("after-optimize-chunk-ids", this.chunks); | 
					
						
							|  |  |  | 		this.applyPlugins("record-chunks", this.chunks, this.records); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		this.sortItems(); | 
					
						
							|  |  |  | 		this.applyPlugins("before-hash"); | 
					
						
							|  |  |  | 		this.createHash(); | 
					
						
							|  |  |  | 		this.applyPlugins("after-hash"); | 
					
						
							|  |  |  | 		this.applyPlugins("before-chunk-assets"); | 
					
						
							|  |  |  | 		this.createChunkAssets(); | 
					
						
							|  |  |  | 		this.applyPlugins("additional-chunk-assets", this.chunks); | 
					
						
							|  |  |  | 		this.summarizeDependencies(); | 
					
						
							|  |  |  | 		this.applyPlugins("record", this, this.records); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		this.applyPluginsAsync("optimize-chunk-assets", this.chunks, function(err) { | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 			if(err) return callback(err); | 
					
						
							| 
									
										
										
										
											2014-01-29 17:13:28 +08:00
										 |  |  | 			this.applyPlugins("after-optimize-chunk-assets", this.chunks); | 
					
						
							|  |  |  | 			this.applyPluginsAsync("optimize-assets", this.assets, function(err) { | 
					
						
							|  |  |  | 				if(err) return callback(err); | 
					
						
							|  |  |  | 				this.applyPlugins("after-optimize-assets", this.assets); | 
					
						
							|  |  |  | 				return callback(); | 
					
						
							|  |  |  | 			}.bind(this)); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		}.bind(this)); | 
					
						
							|  |  |  | 	}.bind(this)); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-01-23 22:31:40 +08:00
										 |  |  | Compilation.prototype.addChunk = function addChunk(name, module, loc) { | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	if(name) { | 
					
						
							| 
									
										
										
										
											2014-01-24 20:32:58 +08:00
										 |  |  | 		if(Object.prototype.hasOwnProperty.call(this.namedChunks, name)) { | 
					
						
							|  |  |  | 			var chunk = this.namedChunks[name]; | 
					
						
							|  |  |  | 			if(module) chunk.addOrigin(module, loc); | 
					
						
							|  |  |  | 			return chunk; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-01-23 22:31:40 +08:00
										 |  |  | 	var chunk = new Chunk(name, module, loc); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	this.chunks.push(chunk); | 
					
						
							|  |  |  | 	if(name) { | 
					
						
							|  |  |  | 		this.namedChunks[name] = chunk; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return chunk; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Compilation.prototype.processDependenciesBlockForChunk = function processDependenciesBlockForChunk(block, chunk) { | 
					
						
							|  |  |  | 	block.blocks.forEach(function(b) { | 
					
						
							|  |  |  | 		var c; | 
					
						
							|  |  |  | 		if(!b.chunk) { | 
					
						
							| 
									
										
										
										
											2014-01-23 22:31:40 +08:00
										 |  |  | 			c = this.addChunk(b.chunkName, b.module, b.loc); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 			b.chunk = c; | 
					
						
							|  |  |  | 			c.addBlock(b); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			c = b.chunk; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		chunk.addChunk(c); | 
					
						
							|  |  |  | 		c.addParent(chunk); | 
					
						
							|  |  |  | 		this.processDependenciesBlockForChunk(b, c); | 
					
						
							|  |  |  | 	}, this); | 
					
						
							|  |  |  | 	function iteratorDependency(d) { | 
					
						
							|  |  |  | 		if(!d.module) return; | 
					
						
							|  |  |  | 		if(d.module.error) { | 
					
						
							|  |  |  | 			d.module = null; | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if(chunk.addModule(d.module)) { | 
					
						
							|  |  |  | 			d.module.addChunk(chunk); | 
					
						
							|  |  |  | 			this.processDependenciesBlockForChunk(d.module, chunk); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	block.dependencies.forEach(iteratorDependency, this); | 
					
						
							|  |  |  | 	block.variables.forEach(function(v) { | 
					
						
							|  |  |  | 		v.dependencies.forEach(iteratorDependency, this); | 
					
						
							|  |  |  | 	}, this); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Compilation.prototype.applyModuleIds = function applyModuleIds() { | 
					
						
							|  |  |  | 	this.modules.forEach(function(module) { | 
					
						
							| 
									
										
										
										
											2013-05-08 19:28:54 +08:00
										 |  |  | 		if(module.id === null) { | 
					
						
							| 
									
										
										
										
											2013-05-31 18:22:40 +08:00
										 |  |  | 			module.id = this.nextFreeModuleId++; | 
					
						
							| 
									
										
										
										
											2013-05-08 19:28:54 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-05-31 18:22:40 +08:00
										 |  |  | 	}, this); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Compilation.prototype.applyChunkIds = function applyChunkIds() { | 
					
						
							|  |  |  | 	this.chunks.forEach(function(chunk) { | 
					
						
							| 
									
										
										
										
											2013-05-09 05:01:25 +08:00
										 |  |  | 		if(chunk.id === null) { | 
					
						
							|  |  |  | 			if(chunk.id === null) | 
					
						
							| 
									
										
										
										
											2013-05-31 18:22:40 +08:00
										 |  |  | 				chunk.id = this.nextFreeChunkId++; | 
					
						
							| 
									
										
										
										
											2013-05-09 05:01:25 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2013-02-24 09:05:55 +08:00
										 |  |  | 		if(!chunk.ids) | 
					
						
							|  |  |  | 			chunk.ids = [chunk.id]; | 
					
						
							| 
									
										
										
										
											2013-05-09 05:01:25 +08:00
										 |  |  | 	}, this); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Compilation.prototype.sortItems = function sortItems() { | 
					
						
							|  |  |  | 	function byId(a, b) { | 
					
						
							|  |  |  | 		return a.id - b.id; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	this.chunks.sort(byId); | 
					
						
							|  |  |  | 	this.modules.sort(byId); | 
					
						
							|  |  |  | 	this.modules.forEach(function(module) { | 
					
						
							|  |  |  | 		module.chunks.sort(byId); | 
					
						
							| 
									
										
										
										
											2014-02-04 01:12:19 +08:00
										 |  |  | 		module.reasons.sort(function(a, b) { | 
					
						
							|  |  |  | 			return byId(a.module, b.module) | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	}); | 
					
						
							|  |  |  | 	this.chunks.forEach(function(chunk) { | 
					
						
							|  |  |  | 		chunk.modules.sort(byId); | 
					
						
							|  |  |  | 	}); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Compilation.prototype.summarizeDependencies = function summarizeDependencies() { | 
					
						
							|  |  |  | 	function filterDups(array) { | 
					
						
							|  |  |  | 		var newArray = []; | 
					
						
							|  |  |  | 		for(var i = 0; i < array.length; i++) { | 
					
						
							|  |  |  | 			if(i == 0 || array[i-1] != array[i]) | 
					
						
							|  |  |  | 				newArray.push(array[i]); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return newArray; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	this.fileDependencies = []; | 
					
						
							|  |  |  | 	this.contextDependencies = []; | 
					
						
							|  |  |  | 	this.children.forEach(function(child) { | 
					
						
							|  |  |  | 		this.fileDependencies = this.fileDependencies.concat(child.fileDependencies); | 
					
						
							|  |  |  | 		this.contextDependencies = this.contextDependencies.concat(child.contextDependencies); | 
					
						
							|  |  |  | 	}.bind(this)); | 
					
						
							|  |  |  | 	this.modules.forEach(function(module) { | 
					
						
							|  |  |  | 		if(module.fileDependencies) { | 
					
						
							|  |  |  | 			module.fileDependencies.forEach(function(item) { | 
					
						
							|  |  |  | 				this.fileDependencies.push(item); | 
					
						
							|  |  |  | 			}, this); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if(module.contextDependencies) { | 
					
						
							|  |  |  | 			module.contextDependencies.forEach(function(item) { | 
					
						
							|  |  |  | 				this.contextDependencies.push(item); | 
					
						
							|  |  |  | 			}, this); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	}, this); | 
					
						
							|  |  |  | 	this.fileDependencies.sort(); | 
					
						
							|  |  |  | 	this.fileDependencies = filterDups(this.fileDependencies); | 
					
						
							|  |  |  | 	this.contextDependencies.sort(); | 
					
						
							|  |  |  | 	this.contextDependencies = filterDups(this.contextDependencies); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-01 19:59:02 +08:00
										 |  |  | Compilation.prototype.createHash = function createHash() { | 
					
						
							|  |  |  | 	var outputOptions = this.outputOptions; | 
					
						
							| 
									
										
										
										
											2013-05-21 17:08:08 +08:00
										 |  |  | 	var hashFunction = outputOptions.hashFunction; | 
					
						
							|  |  |  | 	var hashDigest = outputOptions.hashDigest; | 
					
						
							|  |  |  | 	var hashDigestLength = outputOptions.hashDigestLength; | 
					
						
							| 
									
										
										
										
											2013-07-11 05:20:07 +08:00
										 |  |  | 	var hash = require("crypto").createHash(hashFunction); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	this.mainTemplate.updateHash(hash); | 
					
						
							|  |  |  | 	this.chunkTemplate.updateHash(hash); | 
					
						
							|  |  |  | 	this.moduleTemplate.updateHash(hash); | 
					
						
							|  |  |  | 	var i, chunk; | 
					
						
							| 
									
										
										
										
											2013-02-13 20:00:01 +08:00
										 |  |  | 	for(i = 0; i < this.chunks.length; i++) { | 
					
						
							|  |  |  | 		var chunk = this.chunks[i]; | 
					
						
							| 
									
										
										
										
											2013-07-11 05:20:07 +08:00
										 |  |  | 		var chunkHash = require("crypto").createHash(hashFunction); | 
					
						
							| 
									
										
										
										
											2013-05-21 07:46:14 +08:00
										 |  |  | 		chunk.updateHash(chunkHash); | 
					
						
							|  |  |  | 		this.chunkTemplate.updateHash(chunkHash); | 
					
						
							| 
									
										
										
										
											2013-05-21 17:08:08 +08:00
										 |  |  | 		chunk.hash = chunkHash.digest(hashDigest); | 
					
						
							| 
									
										
										
										
											2013-05-21 07:46:14 +08:00
										 |  |  | 		hash.update(chunk.hash); | 
					
						
							| 
									
										
										
										
											2013-05-21 17:08:08 +08:00
										 |  |  | 		chunk.renderedHash = chunk.hash.substr(0, hashDigestLength); | 
					
						
							| 
									
										
										
										
											2013-02-13 20:00:01 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-07-01 19:59:02 +08:00
										 |  |  | 	this.fullHash = hash.digest(hashDigest); | 
					
						
							|  |  |  | 	this.hash = this.fullHash.substr(0, hashDigestLength); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Compilation.prototype.modifyHash = function modifyHash(update) { | 
					
						
							|  |  |  | 	var outputOptions = this.outputOptions; | 
					
						
							|  |  |  | 	var hashFunction = outputOptions.hashFunction; | 
					
						
							|  |  |  | 	var hashDigest = outputOptions.hashDigest; | 
					
						
							|  |  |  | 	var hashDigestLength = outputOptions.hashDigestLength; | 
					
						
							| 
									
										
										
										
											2013-07-11 05:20:07 +08:00
										 |  |  | 	var hash = require("crypto").createHash(hashFunction); | 
					
						
							| 
									
										
										
										
											2013-07-01 19:59:02 +08:00
										 |  |  | 	hash.update(this.fullHash); | 
					
						
							|  |  |  | 	hash.update(update); | 
					
						
							|  |  |  | 	this.fullHash = hash.digest(hashDigest); | 
					
						
							|  |  |  | 	this.hash = this.fullHash.substr(0, hashDigestLength); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Compilation.prototype.createChunkAssets = function createChunkAssets() { | 
					
						
							|  |  |  | 	var outputOptions = this.outputOptions; | 
					
						
							|  |  |  | 	var filename = outputOptions.filename || "bundle.js"; | 
					
						
							|  |  |  | 	var chunkFilename = outputOptions.chunkFilename || "[id]." + filename.replace(Template.REGEXP_NAME, ""); | 
					
						
							|  |  |  | 	var namedChunkFilename = outputOptions.namedChunkFilename || null; | 
					
						
							| 
									
										
										
										
											2013-07-04 18:11:17 +08:00
										 |  |  | 	for(var i = 0; i < this.modules.length; i++) { | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		var module = this.modules[i]; | 
					
						
							|  |  |  | 		if(module.assets) { | 
					
						
							|  |  |  | 			Object.keys(module.assets).forEach(function(name) { | 
					
						
							| 
									
										
										
										
											2013-05-21 17:08:08 +08:00
										 |  |  | 				var file = name.replace(Template.REGEXP_HASH, this.hash); | 
					
						
							| 
									
										
										
										
											2013-03-26 23:54:41 +08:00
										 |  |  | 				this.assets[file] = module.assets[name]; | 
					
						
							|  |  |  | 				this.applyPlugins("module-asset", module, file); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 			}, this); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-07-04 18:11:17 +08:00
										 |  |  | 	for(var i = 0; i < this.chunks.length; i++) { | 
					
						
							|  |  |  | 		var chunk = this.chunks[i]; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		chunk.files = []; | 
					
						
							| 
									
										
										
										
											2013-05-21 07:46:14 +08:00
										 |  |  | 		var chunkHash = chunk.hash; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		var source; | 
					
						
							|  |  |  | 		var file; | 
					
						
							| 
									
										
										
										
											2013-12-03 18:19:30 +08:00
										 |  |  | 		var filenameTemplate = chunk.filenameTemplate ?	chunk.filenameTemplate : | 
					
						
							| 
									
										
										
										
											2013-12-04 06:11:14 +08:00
										 |  |  | 			chunk.initial ? filename : | 
					
						
							| 
									
										
										
										
											2013-12-03 18:19:30 +08:00
										 |  |  | 			chunkFilename; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		if(chunk.entry) { | 
					
						
							| 
									
										
										
										
											2013-07-01 19:59:02 +08:00
										 |  |  | 			if(this.cache && this.cache["c" + chunk.id + chunk.name] && this.cache["c" + chunk.id + chunk.name].hash == this.fullHash) { | 
					
						
							| 
									
										
										
										
											2013-05-08 19:28:54 +08:00
										 |  |  | 				source = this.cache["c" + chunk.id + chunk.name].source; | 
					
						
							|  |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2013-06-19 17:53:03 +08:00
										 |  |  | 				source = this.mainTemplate.render(this.hash, chunk, this.moduleTemplate, this.dependencyTemplates); | 
					
						
							| 
									
										
										
										
											2013-05-08 19:28:54 +08:00
										 |  |  | 				if(this.cache) { | 
					
						
							|  |  |  | 					this.cache["c" + chunk.id + chunk.name] = { | 
					
						
							| 
									
										
										
										
											2013-07-01 19:59:02 +08:00
										 |  |  | 						hash: this.fullHash, | 
					
						
							| 
									
										
										
										
											2013-05-08 19:28:54 +08:00
										 |  |  | 						source: source | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2013-05-08 19:28:54 +08:00
										 |  |  | 			if(this.cache && this.cache["c" + chunk.id] && this.cache["c" + chunk.id].hash == chunkHash) { | 
					
						
							|  |  |  | 				source = this.cache["c" + chunk.id].source; | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				source = this.chunkTemplate.render(chunk, this.moduleTemplate, this.dependencyTemplates); | 
					
						
							|  |  |  | 				if(this.cache) { | 
					
						
							|  |  |  | 					this.cache["c" + chunk.id] = { | 
					
						
							|  |  |  | 						hash: chunkHash, | 
					
						
							|  |  |  | 						source: source | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2013-12-03 18:19:30 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		this.assets[ | 
					
						
							|  |  |  | 			file = filenameTemplate | 
					
						
							|  |  |  | 				.replace(Template.REGEXP_HASH, this.hash) | 
					
						
							|  |  |  | 				.replace(Template.REGEXP_CHUNKHASH, chunk.renderedHash) | 
					
						
							|  |  |  | 				.replace(Template.REGEXP_ID, chunk.id) | 
					
						
							|  |  |  | 				.replace(Template.REGEXP_NAME, chunk.name || "") | 
					
						
							|  |  |  | 		] = source; | 
					
						
							|  |  |  | 		chunk.files.push(file); | 
					
						
							|  |  |  | 		this.applyPlugins("chunk-asset", chunk, file); | 
					
						
							|  |  |  | 		if(chunk.id !== 0 && namedChunkFilename && chunk.name) { | 
					
						
							|  |  |  | 			this.assets[ | 
					
						
							|  |  |  | 				file = namedChunkFilename | 
					
						
							|  |  |  | 					.replace(Template.REGEXP_CHUNKHASH, chunk.renderedHash) | 
					
						
							|  |  |  | 					.replace(Template.REGEXP_HASH, this.hash) | 
					
						
							|  |  |  | 					.replace(Template.REGEXP_ID, chunk.id) | 
					
						
							|  |  |  | 					.replace(Template.REGEXP_NAME, chunk.name || "") | 
					
						
							|  |  |  | 			] = source; | 
					
						
							|  |  |  | 			chunk.files.push(file); | 
					
						
							|  |  |  | 			this.applyPlugins("chunk-asset", chunk, file); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Compilation.prototype.getStats = function() { | 
					
						
							|  |  |  | 	return new Stats(this); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Compilation.prototype.createChildCompiler = function(name, outputOptions) { | 
					
						
							|  |  |  | 	return this.compiler.createChildCompiler(this, name, outputOptions); | 
					
						
							|  |  |  | }; |