mirror of https://github.com/webpack/webpack.git
				
				
				
			
		
			
				
	
	
		
			77 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
			
		
		
	
	
			77 lines
		
	
	
		
			2.4 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
| /*
 | |
| 	MIT License http://www.opensource.org/licenses/mit-license.php
 | |
| 	Author Tobias Koppers @sokra
 | |
| */
 | |
| 
 | |
| "use strict";
 | |
| 
 | |
| const RuntimeGlobals = require("../RuntimeGlobals");
 | |
| const NodeChunkTemplatePlugin = require("./NodeChunkTemplatePlugin");
 | |
| const ReadFileChunkLoadingRuntimeModule = require("./ReadFileChunkLoadingRuntimeModule");
 | |
| const RequireChunkLoadingRuntimeModule = require("./RequireChunkLoadingRuntimeModule");
 | |
| 
 | |
| /** @typedef {import("../Compiler")} Compiler */
 | |
| 
 | |
| class NodeTemplatePlugin {
 | |
| 	constructor(options) {
 | |
| 		options = options || {};
 | |
| 		this.asyncChunkLoading = options.asyncChunkLoading;
 | |
| 	}
 | |
| 
 | |
| 	/**
 | |
| 	 * @param {Compiler} compiler the compiler instance
 | |
| 	 * @returns {void}
 | |
| 	 */
 | |
| 	apply(compiler) {
 | |
| 		const ChunkLoadingRuntimeModule = this.asyncChunkLoading
 | |
| 			? ReadFileChunkLoadingRuntimeModule
 | |
| 			: RequireChunkLoadingRuntimeModule;
 | |
| 
 | |
| 		compiler.hooks.thisCompilation.tap("NodeTemplatePlugin", compilation => {
 | |
| 			new NodeChunkTemplatePlugin(compilation).apply(compilation.chunkTemplate);
 | |
| 
 | |
| 			const onceForChunkSet = new WeakSet();
 | |
| 			const handler = (chunk, set) => {
 | |
| 				if (onceForChunkSet.has(chunk)) return;
 | |
| 				onceForChunkSet.add(chunk);
 | |
| 				set.add(RuntimeGlobals.moduleFactories);
 | |
| 				compilation.addRuntimeModule(
 | |
| 					chunk,
 | |
| 					new ChunkLoadingRuntimeModule(chunk, set)
 | |
| 				);
 | |
| 			};
 | |
| 
 | |
| 			compilation.hooks.runtimeRequirementInTree
 | |
| 				.for(RuntimeGlobals.ensureChunkHandlers)
 | |
| 				.tap("NodeTemplatePlugin", handler);
 | |
| 			compilation.hooks.runtimeRequirementInTree
 | |
| 				.for(RuntimeGlobals.hmrDownloadUpdateHandlers)
 | |
| 				.tap("NodeTemplatePlugin", handler);
 | |
| 			compilation.hooks.runtimeRequirementInTree
 | |
| 				.for(RuntimeGlobals.hmrDownloadManifest)
 | |
| 				.tap("NodeTemplatePlugin", handler);
 | |
| 
 | |
| 			compilation.hooks.runtimeRequirementInTree
 | |
| 				.for(RuntimeGlobals.ensureChunkHandlers)
 | |
| 				.tap("NodeTemplatePlugin", (chunk, set) => {
 | |
| 					set.add(RuntimeGlobals.getChunkScriptFilename);
 | |
| 				});
 | |
| 			compilation.hooks.runtimeRequirementInTree
 | |
| 				.for(RuntimeGlobals.hmrDownloadUpdateHandlers)
 | |
| 				.tap("NodeTemplatePlugin", (chunk, set) => {
 | |
| 					set.add(RuntimeGlobals.getChunkUpdateScriptFilename);
 | |
| 					set.add(RuntimeGlobals.moduleCache);
 | |
| 					set.add(RuntimeGlobals.hmrModuleData);
 | |
| 					set.add(RuntimeGlobals.moduleFactories);
 | |
| 				});
 | |
| 			compilation.hooks.runtimeRequirementInTree
 | |
| 				.for(RuntimeGlobals.hmrDownloadManifest)
 | |
| 				.tap("NodeTemplatePlugin", (chunk, set) => {
 | |
| 					set.add(RuntimeGlobals.getUpdateManifestFilename);
 | |
| 				});
 | |
| 		});
 | |
| 	}
 | |
| }
 | |
| 
 | |
| module.exports = NodeTemplatePlugin;
 |