UNPKG

webpack

Version:

Packs ECMAScript/CommonJs/AMD modules for the browser. Allows you to split your codebase into multiple bundles, which can be loaded on demand. Supports loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.

182 lines (175 loc) 6.11 kB
/* MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ "use strict"; const util = require("util"); const JavascriptModulesPlugin = require("./javascript/JavascriptModulesPlugin"); /** @import { Tap } from "tapable" */ /** @import { Source } from "webpack-sources" */ /** * @import { * OutputNormalizedWithDefaults as OutputOptions * } from "./config/defaults" */ /** @import Chunk from "./Chunk" */ /** @import Compilation, { ChunkHashContext } from "./Compilation" */ /** @import ModuleTemplate from "./ModuleTemplate" */ /** @import { RenderContext } from "./javascript/JavascriptModulesPlugin" */ /** @import { RenderManifestEntry, RenderManifestOptions } from "./Template" */ /** @import Hash from "./util/Hash" */ /** * Defines the if set type used by this module. * @template T * @typedef {import("tapable").IfSet<T>} IfSet */ // TODO webpack 6 remove this class class ChunkTemplate { /** * Creates an instance of ChunkTemplate. * @param {OutputOptions} outputOptions output options * @param {Compilation} compilation the compilation */ constructor(outputOptions, compilation) { this._outputOptions = outputOptions || {}; this.hooks = Object.freeze({ renderManifest: { tap: util.deprecate( /** * Handles the callback logic for this hook. * @template AdditionalOptions * @param {string | Tap & IfSet<AdditionalOptions>} options options * @param {(renderManifestEntries: RenderManifestEntry[], renderManifestOptions: RenderManifestOptions) => RenderManifestEntry[]} fn function */ (options, fn) => { compilation.hooks.renderManifest.tap( options, (entries, options) => { if (options.chunk.hasRuntime()) return entries; return fn(entries, options); } ); }, "ChunkTemplate.hooks.renderManifest is deprecated (use Compilation.hooks.renderManifest instead)", "DEP_WEBPACK_CHUNK_TEMPLATE_RENDER_MANIFEST" ) }, modules: { tap: util.deprecate( /** * Handles the callback logic for this hook. * @template AdditionalOptions * @param {string | Tap & IfSet<AdditionalOptions>} options options * @param {(source: Source, moduleTemplate: ModuleTemplate, renderContext: RenderContext) => Source} fn function */ (options, fn) => { JavascriptModulesPlugin.getCompilationHooks( compilation ).renderChunk.tap(options, (source, renderContext) => fn(source, compilation.moduleTemplates.javascript, renderContext) ); }, "ChunkTemplate.hooks.modules is deprecated (use JavascriptModulesPlugin.getCompilationHooks().renderChunk instead)", "DEP_WEBPACK_CHUNK_TEMPLATE_MODULES" ) }, render: { tap: util.deprecate( /** * Handles the callback logic for this hook. * @template AdditionalOptions * @param {string | Tap & IfSet<AdditionalOptions>} options options * @param {(source: Source, moduleTemplate: ModuleTemplate, renderContext: RenderContext) => Source} fn function */ (options, fn) => { JavascriptModulesPlugin.getCompilationHooks( compilation ).renderChunk.tap(options, (source, renderContext) => fn(source, compilation.moduleTemplates.javascript, renderContext) ); }, "ChunkTemplate.hooks.render is deprecated (use JavascriptModulesPlugin.getCompilationHooks().renderChunk instead)", "DEP_WEBPACK_CHUNK_TEMPLATE_RENDER" ) }, renderWithEntry: { tap: util.deprecate( /** * Handles the callback logic for this hook. * @template AdditionalOptions * @param {string | Tap & IfSet<AdditionalOptions>} options options * @param {(source: Source, chunk: Chunk) => Source} fn function */ (options, fn) => { JavascriptModulesPlugin.getCompilationHooks(compilation).render.tap( options, (source, renderContext) => { if ( renderContext.chunkGraph.getNumberOfEntryModules( renderContext.chunk ) === 0 || renderContext.chunk.hasRuntime() ) { return source; } return fn(source, renderContext.chunk); } ); }, "ChunkTemplate.hooks.renderWithEntry is deprecated (use JavascriptModulesPlugin.getCompilationHooks().render instead)", "DEP_WEBPACK_CHUNK_TEMPLATE_RENDER_WITH_ENTRY" ) }, hash: { tap: util.deprecate( /** * Handles the callback logic for this hook. * @template AdditionalOptions * @param {string | Tap & IfSet<AdditionalOptions>} options options * @param {(hash: Hash) => void} fn function */ (options, fn) => { compilation.hooks.fullHash.tap(options, fn); }, "ChunkTemplate.hooks.hash is deprecated (use Compilation.hooks.fullHash instead)", "DEP_WEBPACK_CHUNK_TEMPLATE_HASH" ) }, hashForChunk: { tap: util.deprecate( /** * Handles the callback logic for this hook. * @template AdditionalOptions * @param {string | Tap & IfSet<AdditionalOptions>} options options * @param {(hash: Hash, chunk: Chunk, chunkHashContext: ChunkHashContext) => void} fn function */ (options, fn) => { JavascriptModulesPlugin.getCompilationHooks( compilation ).chunkHash.tap(options, (chunk, hash, context) => { if (chunk.hasRuntime()) return; fn(hash, chunk, context); }); }, "ChunkTemplate.hooks.hashForChunk is deprecated (use JavascriptModulesPlugin.getCompilationHooks().chunkHash instead)", "DEP_WEBPACK_CHUNK_TEMPLATE_HASH_FOR_CHUNK" ) } }); } } Object.defineProperty(ChunkTemplate.prototype, "outputOptions", { get: util.deprecate( /** * Returns output options. * @this {ChunkTemplate} * @returns {OutputOptions} output options */ function outputOptions() { return this._outputOptions; }, "ChunkTemplate.outputOptions is deprecated (use Compilation.outputOptions instead)", "DEP_WEBPACK_CHUNK_TEMPLATE_OUTPUT_OPTIONS" ) }); module.exports = ChunkTemplate;