mirror of https://github.com/webpack/webpack.git
				
				
				
			
		
			
				
	
	
		
			80 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
			
		
		
	
	
			80 lines
		
	
	
		
			2.5 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
/*
 | 
						|
	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
						|
	Author Tobias Koppers @sokra
 | 
						|
*/
 | 
						|
 | 
						|
"use strict";
 | 
						|
 | 
						|
const RuntimeGlobals = require("../RuntimeGlobals");
 | 
						|
const ImportScriptsChunkLoadingRuntimeModule = require("./ImportScriptsChunkLoadingRuntimeModule");
 | 
						|
const WebWorkerChunkTemplatePlugin = require("./WebWorkerChunkTemplatePlugin");
 | 
						|
 | 
						|
/** @typedef {import("../Compiler")} Compiler */
 | 
						|
 | 
						|
class WebWorkerTemplatePlugin {
 | 
						|
	/**
 | 
						|
	 * @param {Compiler} compiler the compiler instance
 | 
						|
	 * @returns {void}
 | 
						|
	 */
 | 
						|
	apply(compiler) {
 | 
						|
		compiler.hooks.thisCompilation.tap(
 | 
						|
			"WebWorkerTemplatePlugin",
 | 
						|
			compilation => {
 | 
						|
				new WebWorkerChunkTemplatePlugin(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 ImportScriptsChunkLoadingRuntimeModule(
 | 
						|
							chunk,
 | 
						|
							compilation.outputOptions,
 | 
						|
							set
 | 
						|
						)
 | 
						|
					);
 | 
						|
				};
 | 
						|
				compilation.hooks.runtimeRequirementInTree
 | 
						|
					.for(RuntimeGlobals.ensureChunkHandlers)
 | 
						|
					.tap("JsonpTemplatePlugin", handler);
 | 
						|
				compilation.hooks.runtimeRequirementInTree
 | 
						|
					.for(RuntimeGlobals.startup)
 | 
						|
					.tap("JsonpTemplatePlugin", handler);
 | 
						|
				compilation.hooks.runtimeRequirementInTree
 | 
						|
					.for(RuntimeGlobals.hmrDownloadUpdateHandlers)
 | 
						|
					.tap("JsonpTemplatePlugin", handler);
 | 
						|
				compilation.hooks.runtimeRequirementInTree
 | 
						|
					.for(RuntimeGlobals.hmrDownloadManifest)
 | 
						|
					.tap("JsonpTemplatePlugin", handler);
 | 
						|
 | 
						|
				compilation.hooks.runtimeRequirementInTree
 | 
						|
					.for(RuntimeGlobals.ensureChunkHandlers)
 | 
						|
					.tap("JsonpTemplatePlugin", (chunk, set) => {
 | 
						|
						set.add(RuntimeGlobals.publicPath);
 | 
						|
						set.add(RuntimeGlobals.getChunkScriptFilename);
 | 
						|
					});
 | 
						|
				compilation.hooks.runtimeRequirementInTree
 | 
						|
					.for(RuntimeGlobals.hmrDownloadUpdateHandlers)
 | 
						|
					.tap("JsonpTemplatePlugin", (chunk, set) => {
 | 
						|
						set.add(RuntimeGlobals.publicPath);
 | 
						|
						set.add(RuntimeGlobals.getChunkUpdateScriptFilename);
 | 
						|
						set.add(RuntimeGlobals.moduleCache);
 | 
						|
						set.add(RuntimeGlobals.hmrModuleData);
 | 
						|
						set.add(RuntimeGlobals.moduleFactories);
 | 
						|
					});
 | 
						|
				compilation.hooks.runtimeRequirementInTree
 | 
						|
					.for(RuntimeGlobals.hmrDownloadManifest)
 | 
						|
					.tap("JsonpTemplatePlugin", (chunk, set) => {
 | 
						|
						set.add(RuntimeGlobals.publicPath);
 | 
						|
						set.add(RuntimeGlobals.getUpdateManifestFilename);
 | 
						|
					});
 | 
						|
			}
 | 
						|
		);
 | 
						|
	}
 | 
						|
}
 | 
						|
module.exports = WebWorkerTemplatePlugin;
 |