| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const path = require("path"); | 
					
						
							| 
									
										
										
										
											2017-11-06 23:41:26 +08:00
										 |  |  | const util = require("util"); | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | const Tapable = require("tapable").Tapable; | 
					
						
							|  |  |  | const SyncHook = require("tapable").SyncHook; | 
					
						
							|  |  |  | const SyncBailHook = require("tapable").SyncBailHook; | 
					
						
							|  |  |  | const AsyncParallelHook = require("tapable").AsyncParallelHook; | 
					
						
							|  |  |  | const AsyncSeriesHook = require("tapable").AsyncSeriesHook; | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | const Compilation = require("./Compilation"); | 
					
						
							|  |  |  | const Stats = require("./Stats"); | 
					
						
							|  |  |  | const NormalModuleFactory = require("./NormalModuleFactory"); | 
					
						
							|  |  |  | const ContextModuleFactory = require("./ContextModuleFactory"); | 
					
						
							| 
									
										
										
										
											2017-11-17 21:26:23 +08:00
										 |  |  | const ResolverFactory = require("./ResolverFactory"); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-01 17:44:22 +08:00
										 |  |  | const RequestShortener = require("./RequestShortener"); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | const makePathsRelative = require("./util/identifier").makePathsRelative; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class Watching { | 
					
						
							|  |  |  | 	constructor(compiler, watchOptions, handler) { | 
					
						
							|  |  |  | 		this.startTime = null; | 
					
						
							|  |  |  | 		this.invalid = false; | 
					
						
							|  |  |  | 		this.handler = handler; | 
					
						
							| 
									
										
										
										
											2017-07-12 14:03:22 +08:00
										 |  |  | 		this.callbacks = []; | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		this.closed = false; | 
					
						
							|  |  |  | 		if(typeof watchOptions === "number") { | 
					
						
							|  |  |  | 			this.watchOptions = { | 
					
						
							|  |  |  | 				aggregateTimeout: watchOptions | 
					
						
							|  |  |  | 			}; | 
					
						
							|  |  |  | 		} else if(watchOptions && typeof watchOptions === "object") { | 
					
						
							|  |  |  | 			this.watchOptions = Object.assign({}, watchOptions); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			this.watchOptions = {}; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		this.watchOptions.aggregateTimeout = this.watchOptions.aggregateTimeout || 200; | 
					
						
							|  |  |  | 		this.compiler = compiler; | 
					
						
							|  |  |  | 		this.running = true; | 
					
						
							|  |  |  | 		this.compiler.readRecords(err => { | 
					
						
							|  |  |  | 			if(err) return this._done(err); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			this._go(); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2015-05-10 19:50:15 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	_go() { | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 		this.startTime = Date.now(); | 
					
						
							|  |  |  | 		this.running = true; | 
					
						
							|  |  |  | 		this.invalid = false; | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 		this.compiler.hooks.watchRun.callAsync(this.compiler, err => { | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 			if(err) return this._done(err); | 
					
						
							|  |  |  | 			const onCompiled = (err, compilation) => { | 
					
						
							|  |  |  | 				if(err) return this._done(err); | 
					
						
							|  |  |  | 				if(this.invalid) return this._done(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 				if(this.compiler.hooks.shouldEmit.call(compilation) === false) { | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 					return this._done(null, compilation); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2014-09-03 20:16:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 				this.compiler.emitAssets(compilation, err => { | 
					
						
							|  |  |  | 					if(err) return this._done(err); | 
					
						
							|  |  |  | 					if(this.invalid) return this._done(); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 					this.compiler.emitRecords(err => { | 
					
						
							|  |  |  | 						if(err) return this._done(err); | 
					
						
							| 
									
										
										
										
											2013-05-31 18:22:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:30 +08:00
										 |  |  | 						if(compilation.hooks.needAdditionalPass.call()) { | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 							compilation.needAdditionalPass = true; | 
					
						
							| 
									
										
										
										
											2015-01-30 07:46:52 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 							const stats = new Stats(compilation); | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 							stats.startTime = this.startTime; | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 							stats.endTime = Date.now(); | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 							this.compiler.hooks.done.call(stats); | 
					
						
							| 
									
										
										
										
											2015-01-30 07:46:52 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 							this.compiler.hooks.additionalPass.callAsync(err => { | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 								if(err) return this._done(err); | 
					
						
							| 
									
										
										
										
											2017-07-12 15:22:02 +08:00
										 |  |  | 								this.compiler.compile(onCompiled); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 							}); | 
					
						
							|  |  |  | 							return; | 
					
						
							|  |  |  | 						} | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 						return this._done(null, compilation); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2016-10-18 02:26:22 +08:00
										 |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 			}; | 
					
						
							|  |  |  | 			this.compiler.compile(onCompiled); | 
					
						
							| 
									
										
										
										
											2016-10-18 02:26:22 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-01-12 19:33:03 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	_getStats(compilation) { | 
					
						
							|  |  |  | 		const stats = new Stats(compilation); | 
					
						
							|  |  |  | 		stats.startTime = this.startTime; | 
					
						
							|  |  |  | 		stats.endTime = Date.now(); | 
					
						
							|  |  |  | 		return stats; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	_done(err, compilation) { | 
					
						
							|  |  |  | 		this.running = false; | 
					
						
							|  |  |  | 		if(this.invalid) return this._go(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		const stats = compilation ? this._getStats(compilation) : null; | 
					
						
							|  |  |  | 		if(err) { | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			this.compiler.hooks.failed.call(err); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 			this.handler(err, stats); | 
					
						
							|  |  |  | 			return; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 		this.compiler.hooks.done.call(stats); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		this.handler(null, stats); | 
					
						
							|  |  |  | 		if(!this.closed) { | 
					
						
							| 
									
										
										
										
											2017-11-06 23:41:26 +08:00
										 |  |  | 			this.watch(Array.from(compilation.fileDependencies), Array.from(compilation.contextDependencies), Array.from(compilation.missingDependencies)); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-07-12 14:03:22 +08:00
										 |  |  | 		this.callbacks.forEach(cb => cb()); | 
					
						
							|  |  |  | 		this.callbacks.length = 0; | 
					
						
							| 
									
										
										
										
											2014-05-08 15:08:01 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-04-24 05:55:50 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	watch(files, dirs, missing) { | 
					
						
							| 
									
										
										
										
											2017-02-22 17:45:49 +08:00
										 |  |  | 		this.pausedWatcher = null; | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		this.watcher = this.compiler.watchFileSystem.watch(files, dirs, missing, this.startTime, this.watchOptions, (err, filesModified, contextModified, missingModified, fileTimestamps, contextTimestamps) => { | 
					
						
							|  |  |  | 			this.pausedWatcher = this.watcher; | 
					
						
							|  |  |  | 			this.watcher = null; | 
					
						
							|  |  |  | 			if(err) return this.handler(err); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			this.compiler.fileTimestamps = fileTimestamps; | 
					
						
							|  |  |  | 			this.compiler.contextTimestamps = contextTimestamps; | 
					
						
							|  |  |  | 			this.invalidate(); | 
					
						
							|  |  |  | 		}, (fileName, changeTime) => { | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			this.compiler.hooks.invalid.call(fileName, changeTime); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-02-22 17:45:49 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-12 13:57:53 +08:00
										 |  |  | 	invalidate(callback) { | 
					
						
							| 
									
										
										
										
											2017-07-12 14:03:22 +08:00
										 |  |  | 		if(callback) { | 
					
						
							|  |  |  | 			this.callbacks.push(callback); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		if(this.watcher) { | 
					
						
							|  |  |  | 			this.pausedWatcher = this.watcher; | 
					
						
							|  |  |  | 			this.watcher.pause(); | 
					
						
							|  |  |  | 			this.watcher = null; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if(this.running) { | 
					
						
							|  |  |  | 			this.invalid = true; | 
					
						
							|  |  |  | 			return false; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			this._go(); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-02-22 17:45:49 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	close(callback) { | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 		if(callback === undefined) callback = () => {}; | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		this.closed = true; | 
					
						
							|  |  |  | 		if(this.watcher) { | 
					
						
							|  |  |  | 			this.watcher.close(); | 
					
						
							|  |  |  | 			this.watcher = null; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if(this.pausedWatcher) { | 
					
						
							|  |  |  | 			this.pausedWatcher.close(); | 
					
						
							|  |  |  | 			this.pausedWatcher = null; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if(this.running) { | 
					
						
							|  |  |  | 			this.invalid = true; | 
					
						
							|  |  |  | 			this._done = () => { | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 				this.compiler.hooks.watchClose.call(); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 				callback(); | 
					
						
							|  |  |  | 			}; | 
					
						
							|  |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			this.compiler.hooks.watchClose.call(); | 
					
						
							| 
									
										
										
										
											2014-05-08 15:08:01 +08:00
										 |  |  | 			callback(); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2014-05-08 15:08:01 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-01 23:59:43 +08:00
										 |  |  | class Compiler extends Tapable { | 
					
						
							| 
									
										
										
										
											2017-12-01 17:44:22 +08:00
										 |  |  | 	constructor(context) { | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		super(); | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 		this.hooks = { | 
					
						
							|  |  |  | 			shouldEmit: new SyncBailHook(["compilation"]), | 
					
						
							|  |  |  | 			done: new SyncHook(["stats"]), | 
					
						
							|  |  |  | 			additionalPass: new AsyncSeriesHook([]), | 
					
						
							|  |  |  | 			beforeRun: new AsyncSeriesHook(["compilation"]), | 
					
						
							|  |  |  | 			run: new AsyncSeriesHook(["compilation"]), | 
					
						
							|  |  |  | 			emit: new AsyncSeriesHook(["compilation"]), | 
					
						
							|  |  |  | 			afterEmit: new AsyncSeriesHook(["compilation"]), | 
					
						
							|  |  |  | 			thisCompilation: new SyncHook(["compilation", "params"]), | 
					
						
							|  |  |  | 			compilation: new SyncHook(["compilation", "params"]), | 
					
						
							|  |  |  | 			normalModuleFactory: new SyncHook(["normalModuleFactory"]), | 
					
						
							|  |  |  | 			contextModuleFactory: new SyncHook(["contextModulefactory"]), | 
					
						
							|  |  |  | 			beforeCompile: new AsyncSeriesHook(["params"]), | 
					
						
							|  |  |  | 			compile: new SyncHook(["params"]), | 
					
						
							|  |  |  | 			make: new AsyncParallelHook(["compilation"]), | 
					
						
							|  |  |  | 			afterCompile: new AsyncSeriesHook(["compilation"]), | 
					
						
							|  |  |  | 			watchRun: new AsyncSeriesHook(["compiler"]), | 
					
						
							|  |  |  | 			failed: new SyncHook(["error"]), | 
					
						
							|  |  |  | 			invalid: new SyncHook(["filename", "changeTime"]), | 
					
						
							|  |  |  | 			watchClose: new SyncHook([]), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			// TODO the following hooks are weirdly located here
 | 
					
						
							|  |  |  | 			// TODO move them for webpack 5
 | 
					
						
							|  |  |  | 			environment: new SyncHook([]), | 
					
						
							|  |  |  | 			afterEnvironment: new SyncHook([]), | 
					
						
							|  |  |  | 			afterPlugins: new SyncHook(["compiler"]), | 
					
						
							|  |  |  | 			afterResolvers: new SyncHook(["compiler"]), | 
					
						
							|  |  |  | 			entryOption: new SyncBailHook(["context", "entry"]), | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 		this._pluginCompat.tap("Compiler", options => { | 
					
						
							|  |  |  | 			switch(options.name) { | 
					
						
							|  |  |  | 				case "additional-pass": | 
					
						
							|  |  |  | 				case "before-run": | 
					
						
							|  |  |  | 				case "run": | 
					
						
							|  |  |  | 				case "emit": | 
					
						
							|  |  |  | 				case "after-emit": | 
					
						
							|  |  |  | 				case "before-compile": | 
					
						
							|  |  |  | 				case "make": | 
					
						
							|  |  |  | 				case "after-compile": | 
					
						
							|  |  |  | 				case "watch-run": | 
					
						
							|  |  |  | 					options.async = true; | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		this.outputPath = ""; | 
					
						
							|  |  |  | 		this.outputFileSystem = null; | 
					
						
							|  |  |  | 		this.inputFileSystem = null; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		this.recordsInputPath = null; | 
					
						
							|  |  |  | 		this.recordsOutputPath = null; | 
					
						
							|  |  |  | 		this.records = {}; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		this.fileTimestamps = {}; | 
					
						
							|  |  |  | 		this.contextTimestamps = {}; | 
					
						
							| 
									
										
										
										
											2016-10-18 02:26:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-17 21:26:23 +08:00
										 |  |  | 		this.resolverFactory = new ResolverFactory(); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		this.resolvers = { | 
					
						
							| 
									
										
										
										
											2017-11-17 21:26:23 +08:00
										 |  |  | 			normal: { | 
					
						
							|  |  |  | 				plugins: util.deprecate( | 
					
						
							|  |  |  | 					(hook, fn) => { | 
					
						
							|  |  |  | 						this.resolverFactory.plugin("resolver normal", resolver => { | 
					
						
							|  |  |  | 							resolver.plugin(hook, fn); | 
					
						
							|  |  |  | 						}); | 
					
						
							|  |  |  | 					}, | 
					
						
							|  |  |  | 					"webpack: Using compiler.resolvers.normal is deprecated.\n" + | 
					
						
							|  |  |  | 					"Use compiler.resolverFactory.plugin(\"resolver normal\", resolver => {\n  resolver.plugin(/* ... */);\n}); instead." | 
					
						
							|  |  |  | 				), | 
					
						
							|  |  |  | 				apply: util.deprecate( | 
					
						
							|  |  |  | 					(...args) => { | 
					
						
							|  |  |  | 						this.resolverFactory.plugin("resolver normal", resolver => { | 
					
						
							|  |  |  | 							resolver.apply(...args); | 
					
						
							|  |  |  | 						}); | 
					
						
							|  |  |  | 					}, | 
					
						
							|  |  |  | 					"webpack: Using compiler.resolvers.normal is deprecated.\n" + | 
					
						
							|  |  |  | 					"Use compiler.resolverFactory.plugin(\"resolver normal\", resolver => {\n  resolver.apply(/* ... */);\n}); instead." | 
					
						
							|  |  |  | 				) | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			loader: { | 
					
						
							|  |  |  | 				plugins: util.deprecate( | 
					
						
							|  |  |  | 					(hook, fn) => { | 
					
						
							|  |  |  | 						this.resolverFactory.plugin("resolver loader", resolver => { | 
					
						
							|  |  |  | 							resolver.plugin(hook, fn); | 
					
						
							|  |  |  | 						}); | 
					
						
							|  |  |  | 					}, | 
					
						
							|  |  |  | 					"webpack: Using compiler.resolvers.loader is deprecated.\n" + | 
					
						
							|  |  |  | 					"Use compiler.resolverFactory.plugin(\"resolver loader\", resolver => {\n  resolver.plugin(/* ... */);\n}); instead." | 
					
						
							|  |  |  | 				), | 
					
						
							|  |  |  | 				apply: util.deprecate( | 
					
						
							|  |  |  | 					(...args) => { | 
					
						
							|  |  |  | 						this.resolverFactory.plugin("resolver loader", resolver => { | 
					
						
							|  |  |  | 							resolver.apply(...args); | 
					
						
							|  |  |  | 						}); | 
					
						
							|  |  |  | 					}, | 
					
						
							|  |  |  | 					"webpack: Using compiler.resolvers.loader is deprecated.\n" + | 
					
						
							|  |  |  | 					"Use compiler.resolverFactory.plugin(\"resolver loader\", resolver => {\n  resolver.apply(/* ... */);\n}); instead." | 
					
						
							|  |  |  | 				) | 
					
						
							|  |  |  | 			}, | 
					
						
							|  |  |  | 			context: { | 
					
						
							|  |  |  | 				plugins: util.deprecate( | 
					
						
							|  |  |  | 					(hook, fn) => { | 
					
						
							|  |  |  | 						this.resolverFactory.plugin("resolver context", resolver => { | 
					
						
							|  |  |  | 							resolver.plugin(hook, fn); | 
					
						
							|  |  |  | 						}); | 
					
						
							|  |  |  | 					}, | 
					
						
							|  |  |  | 					"webpack: Using compiler.resolvers.context is deprecated.\n" + | 
					
						
							|  |  |  | 					"Use compiler.resolverFactory.plugin(\"resolver context\", resolver => {\n  resolver.plugin(/* ... */);\n}); instead." | 
					
						
							|  |  |  | 				), | 
					
						
							|  |  |  | 				apply: util.deprecate( | 
					
						
							|  |  |  | 					(...args) => { | 
					
						
							|  |  |  | 						this.resolverFactory.plugin("resolver context", resolver => { | 
					
						
							|  |  |  | 							resolver.apply(...args); | 
					
						
							|  |  |  | 						}); | 
					
						
							|  |  |  | 					}, | 
					
						
							|  |  |  | 					"webpack: Using compiler.resolvers.context is deprecated.\n" + | 
					
						
							|  |  |  | 					"Use compiler.resolverFactory.plugin(\"resolver context\", resolver => {\n  resolver.apply(/* ... */);\n}); instead." | 
					
						
							|  |  |  | 				) | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		}; | 
					
						
							|  |  |  | 		this.parser = { | 
					
						
							| 
									
										
										
										
											2017-11-08 12:58:48 +08:00
										 |  |  | 			plugin: util.deprecate( | 
					
						
							|  |  |  | 				(hook, fn) => { | 
					
						
							|  |  |  | 					this.plugin("compilation", (compilation, data) => { | 
					
						
							|  |  |  | 						data.normalModuleFactory.plugin("parser", parser => { | 
					
						
							|  |  |  | 							parser.plugin(hook, fn); | 
					
						
							|  |  |  | 						}); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2017-11-08 12:58:48 +08:00
										 |  |  | 				}, | 
					
						
							|  |  |  | 				"webpack: Using compiler.parser is deprecated.\n" + | 
					
						
							| 
									
										
										
										
											2017-11-06 23:41:26 +08:00
										 |  |  | 				"Use compiler.plugin(\"compilation\", function(compilation, data) {\n  data.normalModuleFactory.plugin(\"parser\", function(parser, options) { parser.plugin(/* ... */); });\n}); instead. " | 
					
						
							|  |  |  | 			), | 
					
						
							| 
									
										
										
										
											2017-11-08 12:58:48 +08:00
										 |  |  | 			apply: util.deprecate( | 
					
						
							|  |  |  | 				(...args) => { | 
					
						
							|  |  |  | 					this.plugin("compilation", (compilation, data) => { | 
					
						
							|  |  |  | 						data.normalModuleFactory.plugin("parser", parser => { | 
					
						
							|  |  |  | 							parser.apply(...args); | 
					
						
							|  |  |  | 						}); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2017-11-08 12:58:48 +08:00
										 |  |  | 				}, | 
					
						
							|  |  |  | 				"webpack: Using compiler.parser is deprecated.\n" + | 
					
						
							| 
									
										
										
										
											2017-11-06 23:41:26 +08:00
										 |  |  | 				"Use compiler.plugin(\"compilation\", function(compilation, data) {\n  data.normalModuleFactory.plugin(\"parser\", function(parser, options) { parser.apply(/* ... */); });\n}); instead. " | 
					
						
							|  |  |  | 			) | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		this.options = {}; | 
					
						
							| 
									
										
										
										
											2017-12-01 17:44:22 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		this.context = context; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		this.requestShortener = new RequestShortener(context); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	watch(watchOptions, handler) { | 
					
						
							|  |  |  | 		this.fileTimestamps = {}; | 
					
						
							|  |  |  | 		this.contextTimestamps = {}; | 
					
						
							|  |  |  | 		const watching = new Watching(this, watchOptions, handler); | 
					
						
							|  |  |  | 		return watching; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-10-18 02:26:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	run(callback) { | 
					
						
							|  |  |  | 		const startTime = Date.now(); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 		const onCompiled = (err, compilation) => { | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 			if(err) return callback(err); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			if(this.hooks.shouldEmit.call(compilation) === false) { | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 				const stats = new Stats(compilation); | 
					
						
							|  |  |  | 				stats.startTime = startTime; | 
					
						
							|  |  |  | 				stats.endTime = Date.now(); | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 				this.hooks.done.call(stats); | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 				return callback(null, stats); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			this.emitAssets(compilation, err => { | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 				if(err) return callback(err); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:30 +08:00
										 |  |  | 				if(compilation.hooks.needAdditionalPass.call()) { | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 					compilation.needAdditionalPass = true; | 
					
						
							| 
									
										
										
										
											2013-05-31 18:22:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 					const stats = new Stats(compilation); | 
					
						
							|  |  |  | 					stats.startTime = startTime; | 
					
						
							|  |  |  | 					stats.endTime = Date.now(); | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 					this.hooks.done.call(stats); | 
					
						
							| 
									
										
										
										
											2015-01-30 07:46:52 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 					this.hooks.additionalPass.callAsync(err => { | 
					
						
							| 
									
										
										
										
											2013-05-31 18:22:40 +08:00
										 |  |  | 						if(err) return callback(err); | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 						this.compile(onCompiled); | 
					
						
							|  |  |  | 					}); | 
					
						
							|  |  |  | 					return; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2013-05-31 18:22:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 				this.emitRecords(err => { | 
					
						
							|  |  |  | 					if(err) return callback(err); | 
					
						
							| 
									
										
										
										
											2016-05-07 04:45:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 					const stats = new Stats(compilation); | 
					
						
							|  |  |  | 					stats.startTime = startTime; | 
					
						
							|  |  |  | 					stats.endTime = Date.now(); | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 					this.hooks.done.call(stats); | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 					return callback(null, stats); | 
					
						
							|  |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2016-05-07 04:45:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 		this.hooks.beforeRun.callAsync(this, err => { | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 			if(err) return callback(err); | 
					
						
							| 
									
										
										
										
											2016-05-07 04:45:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			this.hooks.run.callAsync(this, err => { | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 				if(err) return callback(err); | 
					
						
							| 
									
										
										
										
											2016-05-07 04:45:44 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 				this.readRecords(err => { | 
					
						
							|  |  |  | 					if(err) return callback(err); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 					this.compile(onCompiled); | 
					
						
							| 
									
										
										
										
											2016-10-18 02:26:22 +08:00
										 |  |  | 				}); | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	runAsChild(callback) { | 
					
						
							|  |  |  | 		this.compile((err, compilation) => { | 
					
						
							|  |  |  | 			if(err) return callback(err); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 			this.parentCompilation.children.push(compilation); | 
					
						
							|  |  |  | 			Object.keys(compilation.assets).forEach(name => { | 
					
						
							|  |  |  | 				this.parentCompilation.assets[name] = compilation.assets[name]; | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2015-01-05 21:30:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 			const entries = Object.keys(compilation.entrypoints).map(name => { | 
					
						
							|  |  |  | 				return compilation.entrypoints[name].chunks; | 
					
						
							|  |  |  | 			}).reduce((array, chunks) => { | 
					
						
							|  |  |  | 				return array.concat(chunks); | 
					
						
							|  |  |  | 			}, []); | 
					
						
							| 
									
										
										
										
											2015-07-13 06:20:09 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 			return callback(null, entries, compilation); | 
					
						
							|  |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	purgeInputFileSystem() { | 
					
						
							|  |  |  | 		if(this.inputFileSystem && this.inputFileSystem.purge) | 
					
						
							|  |  |  | 			this.inputFileSystem.purge(); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-06-12 04:52:02 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	emitAssets(compilation, callback) { | 
					
						
							|  |  |  | 		let outputPath; | 
					
						
							| 
									
										
										
										
											2014-03-12 01:42:51 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-11 13:52:25 +08:00
										 |  |  | 		const emitFiles = (err) => { | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 			if(err) return callback(err); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 			require("async").forEach(Object.keys(compilation.assets), (file, callback) => { | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 				let targetFile = file; | 
					
						
							|  |  |  | 				const queryStringIdx = targetFile.indexOf("?"); | 
					
						
							|  |  |  | 				if(queryStringIdx >= 0) { | 
					
						
							|  |  |  | 					targetFile = targetFile.substr(0, queryStringIdx); | 
					
						
							| 
									
										
										
										
											2013-05-08 19:28:54 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2017-01-17 13:57:27 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-11 13:52:25 +08:00
										 |  |  | 				const writeOut = (err) => { | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 					if(err) return callback(err); | 
					
						
							|  |  |  | 					const targetPath = this.outputFileSystem.join(outputPath, targetFile); | 
					
						
							|  |  |  | 					const source = compilation.assets[file]; | 
					
						
							|  |  |  | 					if(source.existsAt === targetPath) { | 
					
						
							|  |  |  | 						source.emitted = false; | 
					
						
							|  |  |  | 						return callback(); | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					let content = source.source(); | 
					
						
							| 
									
										
										
										
											2017-01-17 13:57:27 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 					if(!Buffer.isBuffer(content)) { | 
					
						
							|  |  |  | 						content = new Buffer(content, "utf8"); // eslint-disable-line
 | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					source.existsAt = targetPath; | 
					
						
							|  |  |  | 					source.emitted = true; | 
					
						
							|  |  |  | 					this.outputFileSystem.writeFile(targetPath, content, callback); | 
					
						
							| 
									
										
										
										
											2017-08-11 13:52:25 +08:00
										 |  |  | 				}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				if(targetFile.match(/\/|\\/)) { | 
					
						
							|  |  |  | 					const dir = path.dirname(targetFile); | 
					
						
							|  |  |  | 					this.outputFileSystem.mkdirp(this.outputFileSystem.join(outputPath, dir), writeOut); | 
					
						
							|  |  |  | 				} else writeOut(); | 
					
						
							| 
									
										
										
										
											2017-01-17 13:57:27 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 			}, err => { | 
					
						
							|  |  |  | 				if(err) return callback(err); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 				this.hooks.afterEmit.callAsync(compilation, err => { | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 					if(err) return callback(err); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 					return callback(); | 
					
						
							|  |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2017-08-11 13:52:25 +08:00
										 |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 		this.hooks.emit.callAsync(compilation, err => { | 
					
						
							| 
									
										
										
										
											2017-08-11 13:52:25 +08:00
										 |  |  | 			if(err) return callback(err); | 
					
						
							|  |  |  | 			outputPath = compilation.getPath(this.outputPath); | 
					
						
							|  |  |  | 			this.outputFileSystem.mkdirp(outputPath, emitFiles); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	emitRecords(callback) { | 
					
						
							|  |  |  | 		if(!this.recordsOutputPath) return callback(); | 
					
						
							|  |  |  | 		const idx1 = this.recordsOutputPath.lastIndexOf("/"); | 
					
						
							|  |  |  | 		const idx2 = this.recordsOutputPath.lastIndexOf("\\"); | 
					
						
							|  |  |  | 		let recordsOutputPathDirectory = null; | 
					
						
							|  |  |  | 		if(idx1 > idx2) recordsOutputPathDirectory = this.recordsOutputPath.substr(0, idx1); | 
					
						
							|  |  |  | 		if(idx1 < idx2) recordsOutputPathDirectory = this.recordsOutputPath.substr(0, idx2); | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		const writeFile = () => { | 
					
						
							|  |  |  | 			this.outputFileSystem.writeFile(this.recordsOutputPath, JSON.stringify(this.records, undefined, 2), callback); | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if(!recordsOutputPathDirectory) | 
					
						
							|  |  |  | 			return writeFile(); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		this.outputFileSystem.mkdirp(recordsOutputPathDirectory, err => { | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 			if(err) return callback(err); | 
					
						
							| 
									
										
										
										
											2017-11-08 18:32:05 +08:00
										 |  |  | 			writeFile(); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2013-06-10 20:25:54 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	readRecords(callback) { | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 		if(!this.recordsInputPath) { | 
					
						
							|  |  |  | 			this.records = {}; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 			return callback(); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 		this.inputFileSystem.stat(this.recordsInputPath, err => { | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 			// It doesn't exist
 | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 			// We can ignore this.
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 			if(err) return callback(); | 
					
						
							| 
									
										
										
										
											2013-06-10 20:25:54 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 			this.inputFileSystem.readFile(this.recordsInputPath, (err, content) => { | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 				if(err) return callback(err); | 
					
						
							| 
									
										
										
										
											2013-05-31 18:22:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 				try { | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 					this.records = JSON.parse(content.toString("utf-8")); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 				} catch(e) { | 
					
						
							|  |  |  | 					e.message = "Cannot parse records: " + e.message; | 
					
						
							|  |  |  | 					return callback(e); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2013-05-31 18:22:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 				return callback(); | 
					
						
							|  |  |  | 			}); | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 		}); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	createChildCompiler(compilation, compilerName, compilerIndex, outputOptions, plugins) { | 
					
						
							| 
									
										
										
										
											2017-12-01 17:44:22 +08:00
										 |  |  | 		const childCompiler = new Compiler(this.context); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		if(Array.isArray(plugins)) { | 
					
						
							|  |  |  | 			plugins.forEach(plugin => childCompiler.apply(plugin)); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 		for(const name in this.hooks) { | 
					
						
							|  |  |  | 			if(["make", "compile", "emit", "afterEmit", "invalid", "done", "thisCompilation"].indexOf(name) < 0) { | 
					
						
							|  |  |  | 				if(childCompiler.hooks[name]) | 
					
						
							|  |  |  | 					childCompiler.hooks[name].taps = this.hooks[name].taps.slice(); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		childCompiler.name = compilerName; | 
					
						
							|  |  |  | 		childCompiler.outputPath = this.outputPath; | 
					
						
							|  |  |  | 		childCompiler.inputFileSystem = this.inputFileSystem; | 
					
						
							|  |  |  | 		childCompiler.outputFileSystem = null; | 
					
						
							| 
									
										
										
										
											2017-11-17 21:26:23 +08:00
										 |  |  | 		childCompiler.resolverFactory = this.resolverFactory; | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		childCompiler.fileTimestamps = this.fileTimestamps; | 
					
						
							|  |  |  | 		childCompiler.contextTimestamps = this.contextTimestamps; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		const relativeCompilerName = makePathsRelative(this.context, compilerName); | 
					
						
							|  |  |  | 		if(!this.records[relativeCompilerName]) this.records[relativeCompilerName] = []; | 
					
						
							|  |  |  | 		if(this.records[relativeCompilerName][compilerIndex]) | 
					
						
							|  |  |  | 			childCompiler.records = this.records[relativeCompilerName][compilerIndex]; | 
					
						
							| 
									
										
										
										
											2017-04-13 19:43:51 +08:00
										 |  |  | 		else | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 			this.records[relativeCompilerName].push(childCompiler.records = {}); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		childCompiler.options = Object.create(this.options); | 
					
						
							|  |  |  | 		childCompiler.options.output = Object.create(childCompiler.options.output); | 
					
						
							|  |  |  | 		for(const name in outputOptions) { | 
					
						
							|  |  |  | 			childCompiler.options.output[name] = outputOptions[name]; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		childCompiler.parentCompilation = compilation; | 
					
						
							| 
									
										
										
										
											2017-09-13 22:29:37 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:30 +08:00
										 |  |  | 		compilation.hooks.childCompiler.call(childCompiler, compilerName, compilerIndex); | 
					
						
							| 
									
										
										
										
											2017-09-13 22:29:37 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		return childCompiler; | 
					
						
							| 
									
										
										
										
											2013-06-10 20:25:54 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-05-31 18:22:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	isChild() { | 
					
						
							|  |  |  | 		return !!this.parentCompilation; | 
					
						
							| 
									
										
										
										
											2013-05-31 18:22:40 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	createCompilation() { | 
					
						
							|  |  |  | 		return new Compilation(this); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-05-31 18:22:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	newCompilation(params) { | 
					
						
							|  |  |  | 		const compilation = this.createCompilation(); | 
					
						
							|  |  |  | 		compilation.fileTimestamps = this.fileTimestamps; | 
					
						
							|  |  |  | 		compilation.contextTimestamps = this.contextTimestamps; | 
					
						
							|  |  |  | 		compilation.name = this.name; | 
					
						
							|  |  |  | 		compilation.records = this.records; | 
					
						
							|  |  |  | 		compilation.compilationDependencies = params.compilationDependencies; | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 		this.hooks.thisCompilation.call(compilation, params); | 
					
						
							|  |  |  | 		this.hooks.compilation.call(compilation, params); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		return compilation; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-05-31 18:22:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	createNormalModuleFactory() { | 
					
						
							| 
									
										
										
										
											2017-11-17 21:26:23 +08:00
										 |  |  | 		const normalModuleFactory = new NormalModuleFactory(this.options.context, this.resolverFactory, this.options.module || {}); | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 		this.hooks.normalModuleFactory.call(normalModuleFactory); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		return normalModuleFactory; | 
					
						
							| 
									
										
										
										
											2017-01-18 05:26:38 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2013-02-04 21:44:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	createContextModuleFactory() { | 
					
						
							| 
									
										
										
										
											2017-11-17 21:26:23 +08:00
										 |  |  | 		const contextModuleFactory = new ContextModuleFactory(this.resolverFactory, this.inputFileSystem); | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 		this.hooks.contextModuleFactory.call(contextModuleFactory); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		return contextModuleFactory; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-09-14 18:04:42 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	newCompilationParams() { | 
					
						
							|  |  |  | 		const params = { | 
					
						
							|  |  |  | 			normalModuleFactory: this.createNormalModuleFactory(), | 
					
						
							|  |  |  | 			contextModuleFactory: this.createContextModuleFactory(), | 
					
						
							| 
									
										
										
										
											2017-11-06 23:41:26 +08:00
										 |  |  | 			compilationDependencies: new Set() | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 		}; | 
					
						
							|  |  |  | 		return params; | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2016-07-13 17:03:14 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	compile(callback) { | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 		const params = this.newCompilationParams(); | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 		this.hooks.beforeCompile.callAsync(params, err => { | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 			if(err) return callback(err); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			this.hooks.compile.call(params); | 
					
						
							| 
									
										
										
										
											2016-09-14 18:04:42 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-01 23:47:36 +08:00
										 |  |  | 			const compilation = this.newCompilation(params); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 			this.hooks.make.callAsync(compilation, err => { | 
					
						
							| 
									
										
										
										
											2013-01-31 01:49:25 +08:00
										 |  |  | 				if(err) return callback(err); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 				compilation.finish(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				compilation.seal(err => { | 
					
						
							| 
									
										
										
										
											2016-09-14 18:04:42 +08:00
										 |  |  | 					if(err) return callback(err); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-27 22:27:37 +08:00
										 |  |  | 					this.hooks.afterCompile.callAsync(compilation, err => { | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 						if(err) return callback(err); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 						return callback(null, compilation); | 
					
						
							|  |  |  | 					}); | 
					
						
							| 
									
										
										
										
											2016-09-14 18:04:42 +08:00
										 |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2016-10-18 02:26:22 +08:00
										 |  |  | 			}); | 
					
						
							|  |  |  | 		}); | 
					
						
							| 
									
										
										
										
											2017-06-21 10:44:55 +08:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-07-01 23:59:43 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Compiler.Watching = Watching; | 
					
						
							|  |  |  | module.exports = Compiler; |