Type 'apply' method of plugins
This commit is contained in:
parent
63e15dac11
commit
8a10ea3c92
|
@ -10,6 +10,8 @@ const NullFactory = require("./NullFactory");
|
||||||
const CachedConstDependency = require("./dependencies/CachedConstDependency");
|
const CachedConstDependency = require("./dependencies/CachedConstDependency");
|
||||||
const ConstDependency = require("./dependencies/ConstDependency");
|
const ConstDependency = require("./dependencies/ConstDependency");
|
||||||
|
|
||||||
|
/** @typedef {import("./Compiler")} Compiler */
|
||||||
|
|
||||||
const getQuery = request => {
|
const getQuery = request => {
|
||||||
const i = request.indexOf("?");
|
const i = request.indexOf("?");
|
||||||
return i !== -1 ? request.substr(i) : "";
|
return i !== -1 ? request.substr(i) : "";
|
||||||
|
@ -110,6 +112,10 @@ const getHoistedDeclarations = (branch, includeFunctionDeclarations) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
class ConstPlugin {
|
class ConstPlugin {
|
||||||
|
/**
|
||||||
|
* @param {Compiler} compiler the compiler instance
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
apply(compiler) {
|
apply(compiler) {
|
||||||
compiler.hooks.compilation.tap(
|
compiler.hooks.compilation.tap(
|
||||||
"ConstPlugin",
|
"ConstPlugin",
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
|
|
||||||
const EvalDevToolModuleTemplatePlugin = require("./EvalDevToolModuleTemplatePlugin");
|
const EvalDevToolModuleTemplatePlugin = require("./EvalDevToolModuleTemplatePlugin");
|
||||||
|
|
||||||
|
/** @typedef {import("./Compiler")} Compiler */
|
||||||
|
|
||||||
class EvalDevToolModulePlugin {
|
class EvalDevToolModulePlugin {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
this.sourceUrlComment = options.sourceUrlComment;
|
this.sourceUrlComment = options.sourceUrlComment;
|
||||||
|
@ -14,6 +16,10 @@ class EvalDevToolModulePlugin {
|
||||||
this.namespace = options.namespace;
|
this.namespace = options.namespace;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Compiler} compiler the compiler instance
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
apply(compiler) {
|
apply(compiler) {
|
||||||
compiler.hooks.compilation.tap("EvalDevToolModulePlugin", compilation => {
|
compiler.hooks.compilation.tap("EvalDevToolModulePlugin", compilation => {
|
||||||
new EvalDevToolModuleTemplatePlugin({
|
new EvalDevToolModuleTemplatePlugin({
|
||||||
|
|
|
@ -8,6 +8,10 @@
|
||||||
const { RawSource } = require("webpack-sources");
|
const { RawSource } = require("webpack-sources");
|
||||||
const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
|
const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
|
||||||
|
|
||||||
|
/** @typedef {import("webpack-sources").Source} Source */
|
||||||
|
/** @typedef {import("./ModuleTemplate")} ModuleTemplate */
|
||||||
|
|
||||||
|
/** @type {WeakMap<Source, Source>} */
|
||||||
const cache = new WeakMap();
|
const cache = new WeakMap();
|
||||||
|
|
||||||
class EvalDevToolModuleTemplatePlugin {
|
class EvalDevToolModuleTemplatePlugin {
|
||||||
|
@ -20,6 +24,10 @@ class EvalDevToolModuleTemplatePlugin {
|
||||||
this.namespace = options.namespace || "";
|
this.namespace = options.namespace || "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ModuleTemplate} moduleTemplate the module template
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
apply(moduleTemplate) {
|
apply(moduleTemplate) {
|
||||||
moduleTemplate.hooks.module.tap(
|
moduleTemplate.hooks.module.tap(
|
||||||
"EvalDevToolModuleTemplatePlugin",
|
"EvalDevToolModuleTemplatePlugin",
|
||||||
|
|
|
@ -8,6 +8,10 @@
|
||||||
const { RawSource } = require("webpack-sources");
|
const { RawSource } = require("webpack-sources");
|
||||||
const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
|
const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
|
||||||
|
|
||||||
|
/** @typedef {import("webpack-sources").Source} Source */
|
||||||
|
/** @typedef {import("./ModuleTemplate")} ModuleTemplate */
|
||||||
|
|
||||||
|
/** @type {WeakMap<Source, Source>} */
|
||||||
const cache = new WeakMap();
|
const cache = new WeakMap();
|
||||||
|
|
||||||
class EvalSourceMapDevToolModuleTemplatePlugin {
|
class EvalSourceMapDevToolModuleTemplatePlugin {
|
||||||
|
@ -22,6 +26,10 @@ class EvalSourceMapDevToolModuleTemplatePlugin {
|
||||||
this.options = options;
|
this.options = options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {ModuleTemplate} moduleTemplate the module template
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
apply(moduleTemplate) {
|
apply(moduleTemplate) {
|
||||||
const options = this.options;
|
const options = this.options;
|
||||||
const matchModule = ModuleFilenameHelpers.matchObject.bind(
|
const matchModule = ModuleFilenameHelpers.matchObject.bind(
|
||||||
|
|
|
@ -11,6 +11,7 @@ const validateOptions = require("schema-utils");
|
||||||
const schema = require("../schemas/plugins/LoaderOptionsPlugin.json");
|
const schema = require("../schemas/plugins/LoaderOptionsPlugin.json");
|
||||||
|
|
||||||
/** @typedef {import("../declarations/plugins/LoaderOptionsPlugin").LoaderOptionsPluginOptions} LoaderOptionsPluginOptions */
|
/** @typedef {import("../declarations/plugins/LoaderOptionsPlugin").LoaderOptionsPluginOptions} LoaderOptionsPluginOptions */
|
||||||
|
/** @typedef {import("./Compiler")} Compiler */
|
||||||
|
|
||||||
class LoaderOptionsPlugin {
|
class LoaderOptionsPlugin {
|
||||||
/**
|
/**
|
||||||
|
@ -28,6 +29,10 @@ class LoaderOptionsPlugin {
|
||||||
this.options = options;
|
this.options = options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Compiler} compiler the compiler instance
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
apply(compiler) {
|
apply(compiler) {
|
||||||
const options = this.options;
|
const options = this.options;
|
||||||
compiler.hooks.compilation.tap("LoaderOptionsPlugin", compilation => {
|
compiler.hooks.compilation.tap("LoaderOptionsPlugin", compilation => {
|
||||||
|
|
|
@ -5,11 +5,20 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
/** @typedef {import("./Compiler")} Compiler */
|
||||||
|
|
||||||
class LoaderTargetPlugin {
|
class LoaderTargetPlugin {
|
||||||
|
/**
|
||||||
|
* @param {string} target the target
|
||||||
|
*/
|
||||||
constructor(target) {
|
constructor(target) {
|
||||||
this.target = target;
|
this.target = target;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Compiler} compiler the compiler instance
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
apply(compiler) {
|
apply(compiler) {
|
||||||
compiler.hooks.compilation.tap("LoaderTargetPlugin", compilation => {
|
compiler.hooks.compilation.tap("LoaderTargetPlugin", compilation => {
|
||||||
compilation.hooks.normalModuleLoader.tap(
|
compilation.hooks.normalModuleLoader.tap(
|
||||||
|
|
|
@ -101,8 +101,13 @@ class Module extends DependenciesBlock {
|
||||||
/** @type {object} */
|
/** @type {object} */
|
||||||
this.buildInfo = undefined;
|
this.buildInfo = undefined;
|
||||||
|
|
||||||
/** @type {boolean} */
|
// TODO refactor this -> options object filled from Factory
|
||||||
this.useSourceMap = false;
|
this.useSourceMap = false;
|
||||||
|
this.lineToLine = false;
|
||||||
|
|
||||||
|
// TODO figure out if this should be defined here instead of `NormalModule`.
|
||||||
|
// Without this, type checking fails because the hooks use `Module`.
|
||||||
|
this.resource = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO remove in webpack 6
|
// TODO remove in webpack 6
|
||||||
|
|
|
@ -115,11 +115,6 @@ class NormalModule extends Module {
|
||||||
/** @private @type {Map<string, CachedSourceEntry>} */
|
/** @private @type {Map<string, CachedSourceEntry>} */
|
||||||
this._cachedSources = new Map();
|
this._cachedSources = new Map();
|
||||||
|
|
||||||
// Options for the NormalModule set by plugins
|
|
||||||
// TODO refactor this -> options object filled from Factory
|
|
||||||
this.useSourceMap = false;
|
|
||||||
this.lineToLine = false;
|
|
||||||
|
|
||||||
// Cache
|
// Cache
|
||||||
this._lastSuccessfulBuildMeta = {};
|
this._lastSuccessfulBuildMeta = {};
|
||||||
this._forceBuild = true;
|
this._forceBuild = true;
|
||||||
|
|
|
@ -10,11 +10,20 @@ const NullFactory = require("./NullFactory");
|
||||||
const ConstDependency = require("./dependencies/ConstDependency");
|
const ConstDependency = require("./dependencies/ConstDependency");
|
||||||
const ProvidedDependency = require("./dependencies/ProvidedDependency");
|
const ProvidedDependency = require("./dependencies/ProvidedDependency");
|
||||||
|
|
||||||
|
/** @typedef {import("./Compiler")} Compiler */
|
||||||
|
|
||||||
class ProvidePlugin {
|
class ProvidePlugin {
|
||||||
|
/**
|
||||||
|
* @param {Record<string, string | string[]>} definitions the provided identifiers
|
||||||
|
*/
|
||||||
constructor(definitions) {
|
constructor(definitions) {
|
||||||
this.definitions = definitions;
|
this.definitions = definitions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Compiler} compiler the compiler instance
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
apply(compiler) {
|
apply(compiler) {
|
||||||
const definitions = this.definitions;
|
const definitions = this.definitions;
|
||||||
compiler.hooks.compilation.tap(
|
compiler.hooks.compilation.tap(
|
||||||
|
|
|
@ -5,6 +5,10 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {number} size the size in bytes
|
||||||
|
* @returns {string} the formatted size
|
||||||
|
*/
|
||||||
exports.formatSize = size => {
|
exports.formatSize = size => {
|
||||||
if (typeof size !== "number" || Number.isNaN(size) === true) {
|
if (typeof size !== "number" || Number.isNaN(size) === true) {
|
||||||
return "unknown size";
|
return "unknown size";
|
||||||
|
|
|
@ -7,11 +7,17 @@
|
||||||
|
|
||||||
const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
|
const ModuleFilenameHelpers = require("./ModuleFilenameHelpers");
|
||||||
|
|
||||||
|
/** @typedef {import("./Compilation")} Compilation */
|
||||||
|
|
||||||
class SourceMapDevToolModuleOptionsPlugin {
|
class SourceMapDevToolModuleOptionsPlugin {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
this.options = options;
|
this.options = options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Compilation} compilation the compiler instance
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
apply(compilation) {
|
apply(compilation) {
|
||||||
const options = this.options;
|
const options = this.options;
|
||||||
if (options.module !== false) {
|
if (options.module !== false) {
|
||||||
|
|
|
@ -9,6 +9,7 @@ const validateOptions = require("schema-utils");
|
||||||
const schema = require("../schemas/plugins/WatchIgnorePlugin.json");
|
const schema = require("../schemas/plugins/WatchIgnorePlugin.json");
|
||||||
|
|
||||||
/** @typedef {import("../declarations/plugins/WatchIgnorePlugin").WatchIgnorePluginOptions} WatchIgnorePluginOptions */
|
/** @typedef {import("../declarations/plugins/WatchIgnorePlugin").WatchIgnorePluginOptions} WatchIgnorePluginOptions */
|
||||||
|
/** @typedef {import("./Compiler")} Compiler */
|
||||||
|
|
||||||
class IgnoringWatchFileSystem {
|
class IgnoringWatchFileSystem {
|
||||||
constructor(wfs, paths) {
|
constructor(wfs, paths) {
|
||||||
|
@ -94,6 +95,10 @@ class WatchIgnorePlugin {
|
||||||
this.paths = paths;
|
this.paths = paths;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Compiler} compiler the compiler instance
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
apply(compiler) {
|
apply(compiler) {
|
||||||
compiler.hooks.afterEnvironment.tap("WatchIgnorePlugin", () => {
|
compiler.hooks.afterEnvironment.tap("WatchIgnorePlugin", () => {
|
||||||
compiler.watchFileSystem = new IgnoringWatchFileSystem(
|
compiler.watchFileSystem = new IgnoringWatchFileSystem(
|
||||||
|
|
|
@ -5,7 +5,15 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
module.exports = (chunks, compilation) => {
|
/** @typedef {import("../Chunk")} Chunk */
|
||||||
|
/** @typedef {import("../Compilation")} Compilation */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Iterable<Chunk>} chunks the chunks
|
||||||
|
* @param {Compilation} compilation the compilation
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
const assignAscendingChunkIds = (chunks, compilation) => {
|
||||||
const usedIds = new Set();
|
const usedIds = new Set();
|
||||||
if (compilation.usedChunkIds) {
|
if (compilation.usedChunkIds) {
|
||||||
for (const id of compilation.usedChunkIds) {
|
for (const id of compilation.usedChunkIds) {
|
||||||
|
@ -40,3 +48,5 @@ module.exports = (chunks, compilation) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
module.exports = assignAscendingChunkIds;
|
||||||
|
|
|
@ -5,7 +5,15 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
module.exports = (modules, compilation) => {
|
/** @typedef {import("../Compilation")} Compilation */
|
||||||
|
/** @typedef {import("../Module")} Module */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Iterable<Module>} modules the modules
|
||||||
|
* @param {Compilation} compilation the compilation
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
const assignAscendingModuleIds = (modules, compilation) => {
|
||||||
const chunkGraph = compilation.chunkGraph;
|
const chunkGraph = compilation.chunkGraph;
|
||||||
|
|
||||||
const usedIds = new Set();
|
const usedIds = new Set();
|
||||||
|
@ -38,3 +46,5 @@ module.exports = (modules, compilation) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
module.exports = assignAscendingModuleIds;
|
||||||
|
|
|
@ -10,7 +10,13 @@ const NodeJsInputFileSystem = require("enhanced-resolve/lib/NodeJsInputFileSyste
|
||||||
const NodeOutputFileSystem = require("./NodeOutputFileSystem");
|
const NodeOutputFileSystem = require("./NodeOutputFileSystem");
|
||||||
const NodeWatchFileSystem = require("./NodeWatchFileSystem");
|
const NodeWatchFileSystem = require("./NodeWatchFileSystem");
|
||||||
|
|
||||||
|
/** @typedef {import("../Compiler")} Compiler */
|
||||||
|
|
||||||
class NodeEnvironmentPlugin {
|
class NodeEnvironmentPlugin {
|
||||||
|
/**
|
||||||
|
* @param {Compiler} compiler the compiler instance
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
apply(compiler) {
|
apply(compiler) {
|
||||||
compiler.inputFileSystem = new CachedInputFileSystem(
|
compiler.inputFileSystem = new CachedInputFileSystem(
|
||||||
new NodeJsInputFileSystem(),
|
new NodeJsInputFileSystem(),
|
||||||
|
@ -22,8 +28,11 @@ class NodeEnvironmentPlugin {
|
||||||
compiler.inputFileSystem
|
compiler.inputFileSystem
|
||||||
);
|
);
|
||||||
compiler.hooks.beforeRun.tap("NodeEnvironmentPlugin", compiler => {
|
compiler.hooks.beforeRun.tap("NodeEnvironmentPlugin", compiler => {
|
||||||
if (compiler.inputFileSystem === inputFileSystem) inputFileSystem.purge();
|
if (compiler.inputFileSystem === inputFileSystem) {
|
||||||
|
inputFileSystem.purge();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = NodeEnvironmentPlugin;
|
module.exports = NodeEnvironmentPlugin;
|
||||||
|
|
|
@ -10,10 +10,17 @@ const nodeLibsBrowser = require("node-libs-browser");
|
||||||
const { getModulePath } = require("../JavascriptParserHelpers");
|
const { getModulePath } = require("../JavascriptParserHelpers");
|
||||||
const ProvidedDependency = require("../dependencies/ProvidedDependency");
|
const ProvidedDependency = require("../dependencies/ProvidedDependency");
|
||||||
|
|
||||||
|
/** @typedef {import("../Compiler")} Compiler */
|
||||||
|
|
||||||
module.exports = class NodeSourcePlugin {
|
module.exports = class NodeSourcePlugin {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
this.options = options;
|
this.options = options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Compiler} compiler the compiler instance
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
apply(compiler) {
|
apply(compiler) {
|
||||||
const options = this.options;
|
const options = this.options;
|
||||||
if (options === false) {
|
if (options === false) {
|
||||||
|
|
|
@ -7,11 +7,17 @@
|
||||||
|
|
||||||
const ExternalsPlugin = require("../ExternalsPlugin");
|
const ExternalsPlugin = require("../ExternalsPlugin");
|
||||||
|
|
||||||
|
/** @typedef {import("../Compiler")} Compiler */
|
||||||
|
|
||||||
const builtins =
|
const builtins =
|
||||||
// eslint-disable-next-line node/no-unsupported-features/node-builtins,node/no-deprecated-api
|
// eslint-disable-next-line node/no-unsupported-features/node-builtins,node/no-deprecated-api
|
||||||
require("module").builtinModules || Object.keys(process.binding("natives"));
|
require("module").builtinModules || Object.keys(process.binding("natives"));
|
||||||
|
|
||||||
class NodeTargetPlugin {
|
class NodeTargetPlugin {
|
||||||
|
/**
|
||||||
|
* @param {Compiler} compiler the compiler instance
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
apply(compiler) {
|
apply(compiler) {
|
||||||
new ExternalsPlugin("commonjs", builtins).apply(compiler);
|
new ExternalsPlugin("commonjs", builtins).apply(compiler);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,12 +9,18 @@ const NodeChunkTemplatePlugin = require("./NodeChunkTemplatePlugin");
|
||||||
const NodeHotUpdateChunkTemplatePlugin = require("./NodeHotUpdateChunkTemplatePlugin");
|
const NodeHotUpdateChunkTemplatePlugin = require("./NodeHotUpdateChunkTemplatePlugin");
|
||||||
const NodeMainTemplatePlugin = require("./NodeMainTemplatePlugin");
|
const NodeMainTemplatePlugin = require("./NodeMainTemplatePlugin");
|
||||||
|
|
||||||
|
/** @typedef {import("../Compiler")} Compiler */
|
||||||
|
|
||||||
class NodeTemplatePlugin {
|
class NodeTemplatePlugin {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
options = options || {};
|
options = options || {};
|
||||||
this.asyncChunkLoading = options.asyncChunkLoading;
|
this.asyncChunkLoading = options.asyncChunkLoading;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Compiler} compiler the compiler instance
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
apply(compiler) {
|
apply(compiler) {
|
||||||
compiler.hooks.thisCompilation.tap("NodeTemplatePlugin", compilation => {
|
compiler.hooks.thisCompilation.tap("NodeTemplatePlugin", compilation => {
|
||||||
new NodeMainTemplatePlugin(this.asyncChunkLoading).apply(
|
new NodeMainTemplatePlugin(this.asyncChunkLoading).apply(
|
||||||
|
|
|
@ -8,11 +8,17 @@
|
||||||
const Template = require("../Template");
|
const Template = require("../Template");
|
||||||
const WasmMainTemplatePlugin = require("../wasm/WasmMainTemplatePlugin");
|
const WasmMainTemplatePlugin = require("../wasm/WasmMainTemplatePlugin");
|
||||||
|
|
||||||
|
/** @typedef {import("../Compiler")} Compiler */
|
||||||
|
|
||||||
class ReadFileCompileWasmTemplatePlugin {
|
class ReadFileCompileWasmTemplatePlugin {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
this.options = options || {};
|
this.options = options || {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Compiler} compiler the compiler instance
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
apply(compiler) {
|
apply(compiler) {
|
||||||
compiler.hooks.thisCompilation.tap(
|
compiler.hooks.thisCompilation.tap(
|
||||||
"ReadFileCompileWasmTemplatePlugin",
|
"ReadFileCompileWasmTemplatePlugin",
|
||||||
|
|
|
@ -7,7 +7,15 @@
|
||||||
|
|
||||||
const { STAGE_BASIC } = require("../OptimizationStages");
|
const { STAGE_BASIC } = require("../OptimizationStages");
|
||||||
|
|
||||||
|
/** @typedef {import("../Chunk")} Chunk */
|
||||||
|
/** @typedef {import("../ChunkGroup")} ChunkGroup */
|
||||||
|
/** @typedef {import("../Compiler")} Compiler */
|
||||||
|
|
||||||
class EnsureChunkConditionsPlugin {
|
class EnsureChunkConditionsPlugin {
|
||||||
|
/**
|
||||||
|
* @param {Compiler} compiler the compiler instance
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
apply(compiler) {
|
apply(compiler) {
|
||||||
compiler.hooks.compilation.tap(
|
compiler.hooks.compilation.tap(
|
||||||
"EnsureChunkConditionsPlugin",
|
"EnsureChunkConditionsPlugin",
|
||||||
|
@ -17,7 +25,9 @@ class EnsureChunkConditionsPlugin {
|
||||||
let changed = false;
|
let changed = false;
|
||||||
// These sets are hoisted here to save memory
|
// These sets are hoisted here to save memory
|
||||||
// They are cleared at the end of every loop
|
// They are cleared at the end of every loop
|
||||||
|
/** @type {Set<Chunk>} */
|
||||||
const sourceChunks = new Set();
|
const sourceChunks = new Set();
|
||||||
|
/** @type {Set<ChunkGroup>} */
|
||||||
const chunkGroups = new Set();
|
const chunkGroups = new Set();
|
||||||
for (const module of compilation.modules) {
|
for (const module of compilation.modules) {
|
||||||
for (const chunk of chunkGraph.getModuleChunksIterable(module)) {
|
for (const chunk of chunkGraph.getModuleChunksIterable(module)) {
|
||||||
|
@ -29,6 +39,7 @@ class EnsureChunkConditionsPlugin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sourceChunks.size === 0) continue;
|
if (sourceChunks.size === 0) continue;
|
||||||
|
/** @type {Set<Chunk>} */
|
||||||
const targetChunks = new Set();
|
const targetChunks = new Set();
|
||||||
chunkGroupLoop: for (const chunkGroup of chunkGroups) {
|
chunkGroupLoop: for (const chunkGroup of chunkGroups) {
|
||||||
// Can module be placed in a chunk of this group?
|
// Can module be placed in a chunk of this group?
|
||||||
|
|
|
@ -5,7 +5,15 @@
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
/** @typedef {import("../Chunk")} Chunk */
|
||||||
|
/** @typedef {import("../Compiler")} Compiler */
|
||||||
|
/** @typedef {import("../Module")} Module */
|
||||||
|
|
||||||
class FlagIncludedChunksPlugin {
|
class FlagIncludedChunksPlugin {
|
||||||
|
/**
|
||||||
|
* @param {Compiler} compiler the compiler instance
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
apply(compiler) {
|
apply(compiler) {
|
||||||
compiler.hooks.compilation.tap("FlagIncludedChunksPlugin", compilation => {
|
compiler.hooks.compilation.tap("FlagIncludedChunksPlugin", compilation => {
|
||||||
compilation.hooks.optimizeChunkIds.tap(
|
compilation.hooks.optimizeChunkIds.tap(
|
||||||
|
@ -24,6 +32,7 @@ class FlagIncludedChunksPlugin {
|
||||||
// so 1 / modulesCount == p^31
|
// so 1 / modulesCount == p^31
|
||||||
// <=> p = sqrt31(1 / modulesCount)
|
// <=> p = sqrt31(1 / modulesCount)
|
||||||
// so we use a modulo of 1 / sqrt31(1 / modulesCount)
|
// so we use a modulo of 1 / sqrt31(1 / modulesCount)
|
||||||
|
/** @type {WeakMap<Module, number>} */
|
||||||
const moduleBits = new WeakMap();
|
const moduleBits = new WeakMap();
|
||||||
const modulesCount = compilation.modules.size;
|
const modulesCount = compilation.modules.size;
|
||||||
|
|
||||||
|
@ -46,6 +55,7 @@ class FlagIncludedChunksPlugin {
|
||||||
}
|
}
|
||||||
|
|
||||||
// interate all chunks to generate bitmaps
|
// interate all chunks to generate bitmaps
|
||||||
|
/** @type {WeakMap<Chunk, number>} */
|
||||||
const chunkModulesHash = new WeakMap();
|
const chunkModulesHash = new WeakMap();
|
||||||
for (const chunk of chunks) {
|
for (const chunk of chunks) {
|
||||||
let hash = 0;
|
let hash = 0;
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
|
|
||||||
const { STAGE_ADVANCED } = require("../OptimizationStages");
|
const { STAGE_ADVANCED } = require("../OptimizationStages");
|
||||||
|
|
||||||
|
/** @typedef {import("../Compiler")} Compiler */
|
||||||
|
|
||||||
class RuntimeChunkPlugin {
|
class RuntimeChunkPlugin {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
this.options = Object.assign(
|
this.options = Object.assign(
|
||||||
|
@ -17,6 +19,10 @@ class RuntimeChunkPlugin {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Compiler} compiler the compiler instance
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
apply(compiler) {
|
apply(compiler) {
|
||||||
compiler.hooks.thisCompilation.tap("RuntimeChunkPlugin", compilation => {
|
compiler.hooks.thisCompilation.tap("RuntimeChunkPlugin", compilation => {
|
||||||
compilation.hooks.optimizeChunks.tap(
|
compilation.hooks.optimizeChunks.tap(
|
||||||
|
|
|
@ -8,11 +8,17 @@
|
||||||
const RuntimeGlobals = require("../RuntimeGlobals");
|
const RuntimeGlobals = require("../RuntimeGlobals");
|
||||||
const WasmMainTemplatePlugin = require("../wasm/WasmMainTemplatePlugin");
|
const WasmMainTemplatePlugin = require("../wasm/WasmMainTemplatePlugin");
|
||||||
|
|
||||||
|
/** @typedef {import("../Compiler")} Compiler */
|
||||||
|
|
||||||
class FetchCompileWasmTemplatePlugin {
|
class FetchCompileWasmTemplatePlugin {
|
||||||
constructor(options) {
|
constructor(options) {
|
||||||
this.options = options || {};
|
this.options = options || {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Compiler} compiler the compiler instance
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
apply(compiler) {
|
apply(compiler) {
|
||||||
compiler.hooks.thisCompilation.tap(
|
compiler.hooks.thisCompilation.tap(
|
||||||
"FetchCompileWasmTemplatePlugin",
|
"FetchCompileWasmTemplatePlugin",
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
|
|
||||||
const { ConcatSource } = require("webpack-sources");
|
const { ConcatSource } = require("webpack-sources");
|
||||||
|
|
||||||
|
/** @typedef {import("../Compilation")} Compilation */
|
||||||
|
|
||||||
class JsonpExportMainTemplatePlugin {
|
class JsonpExportMainTemplatePlugin {
|
||||||
/**
|
/**
|
||||||
* @param {string} name jsonp function name
|
* @param {string} name jsonp function name
|
||||||
|
@ -15,6 +17,10 @@ class JsonpExportMainTemplatePlugin {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Compilation} compilation the compilation instance
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
apply(compilation) {
|
apply(compilation) {
|
||||||
const { mainTemplate, chunkTemplate } = compilation;
|
const { mainTemplate, chunkTemplate } = compilation;
|
||||||
|
|
||||||
|
@ -26,12 +32,15 @@ class JsonpExportMainTemplatePlugin {
|
||||||
return new ConcatSource(`${name}(`, source, ");");
|
return new ConcatSource(`${name}(`, source, ");");
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const template of [mainTemplate, chunkTemplate]) {
|
mainTemplate.hooks.renderWithEntry.tap(
|
||||||
template.hooks.renderWithEntry.tap(
|
"JsonpExportMainTemplatePlugin",
|
||||||
"JsonpExportMainTemplatePlugin",
|
onRenderWithEntry
|
||||||
onRenderWithEntry
|
);
|
||||||
);
|
|
||||||
}
|
chunkTemplate.hooks.renderWithEntry.tap(
|
||||||
|
"JsonpExportMainTemplatePlugin",
|
||||||
|
onRenderWithEntry
|
||||||
|
);
|
||||||
|
|
||||||
mainTemplate.hooks.hash.tap("JsonpExportMainTemplatePlugin", hash => {
|
mainTemplate.hooks.hash.tap("JsonpExportMainTemplatePlugin", hash => {
|
||||||
hash.update("jsonp export");
|
hash.update("jsonp export");
|
||||||
|
|
|
@ -9,7 +9,13 @@ const JsonpChunkTemplatePlugin = require("./JsonpChunkTemplatePlugin");
|
||||||
const JsonpHotUpdateChunkTemplatePlugin = require("./JsonpHotUpdateChunkTemplatePlugin");
|
const JsonpHotUpdateChunkTemplatePlugin = require("./JsonpHotUpdateChunkTemplatePlugin");
|
||||||
const JsonpMainTemplatePlugin = require("./JsonpMainTemplatePlugin");
|
const JsonpMainTemplatePlugin = require("./JsonpMainTemplatePlugin");
|
||||||
|
|
||||||
|
/** @typedef {import("../Compiler")} Compiler */
|
||||||
|
|
||||||
class JsonpTemplatePlugin {
|
class JsonpTemplatePlugin {
|
||||||
|
/**
|
||||||
|
* @param {Compiler} compiler the compiler instance
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
apply(compiler) {
|
apply(compiler) {
|
||||||
compiler.hooks.thisCompilation.tap("JsonpTemplatePlugin", compilation => {
|
compiler.hooks.thisCompilation.tap("JsonpTemplatePlugin", compilation => {
|
||||||
new JsonpMainTemplatePlugin(compilation).apply(compilation.mainTemplate);
|
new JsonpMainTemplatePlugin(compilation).apply(compilation.mainTemplate);
|
||||||
|
|
|
@ -9,7 +9,13 @@ const WebWorkerChunkTemplatePlugin = require("./WebWorkerChunkTemplatePlugin");
|
||||||
const WebWorkerHotUpdateChunkTemplatePlugin = require("./WebWorkerHotUpdateChunkTemplatePlugin");
|
const WebWorkerHotUpdateChunkTemplatePlugin = require("./WebWorkerHotUpdateChunkTemplatePlugin");
|
||||||
const WebWorkerMainTemplatePlugin = require("./WebWorkerMainTemplatePlugin");
|
const WebWorkerMainTemplatePlugin = require("./WebWorkerMainTemplatePlugin");
|
||||||
|
|
||||||
|
/** @typedef {import("../Compiler")} Compiler */
|
||||||
|
|
||||||
class WebWorkerTemplatePlugin {
|
class WebWorkerTemplatePlugin {
|
||||||
|
/**
|
||||||
|
* @param {Compiler} compiler the compiler instance
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
apply(compiler) {
|
apply(compiler) {
|
||||||
compiler.hooks.thisCompilation.tap(
|
compiler.hooks.thisCompilation.tap(
|
||||||
"WebWorkerTemplatePlugin",
|
"WebWorkerTemplatePlugin",
|
||||||
|
|
Loading…
Reference in New Issue