123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- "use strict";
- const enabledTypes = new WeakMap();
- const getEnabledTypes = compiler => {
- let set = enabledTypes.get(compiler);
- if (set === undefined) {
- set = new Set();
- enabledTypes.set(compiler, set);
- }
- return set;
- };
- class EnableWasmLoadingPlugin {
-
- constructor(type) {
- this.type = type;
- }
-
- static setEnabled(compiler, type) {
- getEnabledTypes(compiler).add(type);
- }
-
- static checkEnabled(compiler, type) {
- if (!getEnabledTypes(compiler).has(type)) {
- throw new Error(
- `Library type "${type}" is not enabled. ` +
- "EnableWasmLoadingPlugin need to be used to enable this type of wasm loading. " +
- 'This usually happens through the "output.enabledWasmLoadingTypes" option. ' +
- 'If you are using a function as entry which sets "wasmLoading", you need to add all potential library types to "output.enabledWasmLoadingTypes". ' +
- `These types are enabled: ${Array.from(
- getEnabledTypes(compiler)
- ).join(", ")}`
- );
- }
- }
-
- apply(compiler) {
- const { type } = this;
-
- const enabled = getEnabledTypes(compiler);
- if (enabled.has(type)) return;
- enabled.add(type);
- if (typeof type === "string") {
- switch (type) {
- case "fetch": {
- if (compiler.options.experiments.syncWebAssembly) {
-
- const FetchCompileWasmPlugin = require("../web/FetchCompileWasmPlugin");
- new FetchCompileWasmPlugin({
- mangleImports: compiler.options.optimization.mangleWasmImports
- }).apply(compiler);
- }
- if (compiler.options.experiments.asyncWebAssembly) {
- const FetchCompileAsyncWasmPlugin = require("../web/FetchCompileAsyncWasmPlugin");
- new FetchCompileAsyncWasmPlugin().apply(compiler);
- }
- break;
- }
- case "async-node": {
- if (compiler.options.experiments.syncWebAssembly) {
-
- const ReadFileCompileWasmPlugin = require("../node/ReadFileCompileWasmPlugin");
- new ReadFileCompileWasmPlugin({
- mangleImports: compiler.options.optimization.mangleWasmImports,
- import:
- compiler.options.output.environment.module &&
- compiler.options.output.environment.dynamicImport
- }).apply(compiler);
- }
- if (compiler.options.experiments.asyncWebAssembly) {
- const ReadFileCompileAsyncWasmPlugin = require("../node/ReadFileCompileAsyncWasmPlugin");
- new ReadFileCompileAsyncWasmPlugin({
- import:
- compiler.options.output.environment.module &&
- compiler.options.output.environment.dynamicImport
- }).apply(compiler);
- }
- break;
- }
- case "universal": {
- const UniversalCompileAsyncWasmPlugin = require("../wasm-async/UniversalCompileAsyncWasmPlugin");
- new UniversalCompileAsyncWasmPlugin().apply(compiler);
- break;
- }
- default:
- throw new Error(`Unsupported wasm loading type ${type}.
- Plugins which provide custom wasm loading types must call EnableWasmLoadingPlugin.setEnabled(compiler, type) to disable this error.`);
- }
- } else {
-
-
- }
- }
- }
- module.exports = EnableWasmLoadingPlugin;
|