| | |
| | | /** @typedef {import("../Module").RuntimeRequirements} RuntimeRequirements */ |
| | | |
| | | /** |
| | | * Defines the common js chunk loading plugin options type used by this module. |
| | | * @typedef {object} CommonJsChunkLoadingPluginOptions |
| | | * @property {boolean=} asyncChunkLoading enable async chunk loading |
| | | */ |
| | |
| | | |
| | | class CommonJsChunkLoadingPlugin { |
| | | /** |
| | | * Creates an instance of CommonJsChunkLoadingPlugin. |
| | | * @param {CommonJsChunkLoadingPluginOptions=} options options |
| | | */ |
| | | constructor(options = {}) { |
| | | this._asyncChunkLoading = options.asyncChunkLoading; |
| | | /** @type {CommonJsChunkLoadingPluginOptions} */ |
| | | this.options = options; |
| | | } |
| | | |
| | | /** |
| | | * Apply the plugin |
| | | * Applies the plugin by registering its hooks on the compiler. |
| | | * @param {Compiler} compiler the compiler instance |
| | | * @returns {void} |
| | | */ |
| | | apply(compiler) { |
| | | const ChunkLoadingRuntimeModule = this._asyncChunkLoading |
| | | const ChunkLoadingRuntimeModule = this.options.asyncChunkLoading |
| | | ? require("./ReadFileChunkLoadingRuntimeModule") |
| | | : require("./RequireChunkLoadingRuntimeModule"); |
| | | const chunkLoadingValue = this._asyncChunkLoading |
| | | const chunkLoadingValue = this.options.asyncChunkLoading |
| | | ? "async-node" |
| | | : "require"; |
| | | new StartupChunkDependenciesPlugin({ |
| | | chunkLoading: chunkLoadingValue, |
| | | asyncChunkLoading: this._asyncChunkLoading |
| | | asyncChunkLoading: this.options.asyncChunkLoading |
| | | }).apply(compiler); |
| | | compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => { |
| | | const globalChunkLoading = compilation.outputOptions.chunkLoading; |
| | | /** |
| | | * Checks whether this common js chunk loading plugin is enabled for chunk. |
| | | * @param {Chunk} chunk chunk |
| | | * @returns {boolean} true, if wasm loading is enabled for the chunk |
| | | */ |
| | |
| | | : globalChunkLoading; |
| | | return chunkLoading === chunkLoadingValue; |
| | | }; |
| | | /** @type {WeakSet<Chunk>} */ |
| | | const onceForChunkSet = new WeakSet(); |
| | | /** |
| | | * Handles the hook callback for this code path. |
| | | * @param {Chunk} chunk chunk |
| | | * @param {RuntimeRequirements} set runtime requirements |
| | | */ |