| | |
| | | |
| | | const PLUGIN_NAME = "ImportScriptsChunkLoadingPlugin"; |
| | | |
| | | /** |
| | | * Enables worker-side chunk loading via `importScripts` and wires in the |
| | | * runtime helpers needed for startup, loading, and hot updates. |
| | | */ |
| | | class ImportScriptsChunkLoadingPlugin { |
| | | /** |
| | | * Apply the plugin |
| | | * Registers compilation hooks that attach the `importScripts` chunk-loading |
| | | * runtime and its supporting globals to chunks using that backend. |
| | | * @param {Compiler} compiler the compiler instance |
| | | * @returns {void} |
| | | */ |
| | |
| | | compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => { |
| | | const globalChunkLoading = compilation.outputOptions.chunkLoading; |
| | | /** |
| | | * Determines whether the chunk resolves additional chunks through the |
| | | * worker-side `importScripts` backend. |
| | | * @param {Chunk} chunk chunk |
| | | * @returns {boolean} true, if wasm loading is enabled for the chunk |
| | | */ |
| | |
| | | : globalChunkLoading; |
| | | return chunkLoading === "import-scripts"; |
| | | }; |
| | | /** @type {WeakSet<Chunk>} */ |
| | | const onceForChunkSet = new WeakSet(); |
| | | /** |
| | | * Adds the `importScripts` chunk-loading runtime module to a chunk once |
| | | * and records the globals it depends on. |
| | | * @param {Chunk} chunk chunk |
| | | * @param {RuntimeRequirements} set runtime requirements |
| | | */ |