diff --git a/declarations/WebpackOptions.d.ts b/declarations/WebpackOptions.d.ts index fc4172be1..1ee08a179 100644 --- a/declarations/WebpackOptions.d.ts +++ b/declarations/WebpackOptions.d.ts @@ -2246,6 +2246,10 @@ export interface Environment { * The environment supports an async import() function to import EcmaScript modules. */ dynamicImport?: boolean; + /** + * The environment supports an async import() is available when creating a worker. + */ + dynamicImportInWorker?: boolean; /** * The environment supports 'for of' iteration ('for (const x of array) { ... }'). */ diff --git a/lib/config/defaults.js b/lib/config/defaults.js index a8aa4b1d3..63245a051 100644 --- a/lib/config/defaults.js +++ b/lib/config/defaults.js @@ -1087,6 +1087,12 @@ const applyOutputDefaults = ( output.module ) ); + F(environment, "dynamicImportInWorker", () => + conditionallyOptimistic( + /** @type {boolean | undefined} */ (tp && tp.dynamicImportInWorker), + output.module + ) + ); F(environment, "module", () => conditionallyOptimistic( /** @type {boolean | undefined} */ (tp && tp.module), diff --git a/schemas/WebpackOptions.json b/schemas/WebpackOptions.json index c2457017c..cd39cfbef 100644 --- a/schemas/WebpackOptions.json +++ b/schemas/WebpackOptions.json @@ -744,6 +744,10 @@ "description": "The environment supports an async import() function to import EcmaScript modules.", "type": "boolean" }, + "dynamicImportInWorker": { + "description": "The environment supports an async import() is available when creating a worker.", + "type": "boolean" + }, "forOf": { "description": "The environment supports 'for of' iteration ('for (const x of array) { ... }').", "type": "boolean" diff --git a/test/Defaults.unittest.js b/test/Defaults.unittest.js index b5516a5e1..8d0c125c1 100644 --- a/test/Defaults.unittest.js +++ b/test/Defaults.unittest.js @@ -123,6 +123,7 @@ describe("snapshots", () => { "const": true, "destructuring": true, "dynamicImport": undefined, + "dynamicImportInWorker": undefined, "forOf": true, "globalThis": undefined, "module": undefined, @@ -343,6 +344,7 @@ describe("snapshots", () => { "const": true, "destructuring": true, "dynamicImport": undefined, + "dynamicImportInWorker": undefined, "forOf": true, "globalThis": undefined, "module": undefined, @@ -901,7 +903,9 @@ describe("snapshots", () => { + "externalsType": "module", @@ ... @@ - "dynamicImport": undefined, + - "dynamicImportInWorker": undefined, + "dynamicImport": true, + + "dynamicImportInWorker": true, @@ ... @@ - "module": undefined, + "module": true, @@ -910,7 +914,9 @@ describe("snapshots", () => { + "chunkFilename": "[name].mjs", @@ ... @@ - "dynamicImport": undefined, + - "dynamicImportInWorker": undefined, + "dynamicImport": true, + + "dynamicImportInWorker": true, @@ ... @@ - "module": undefined, + "module": true, @@ -2017,6 +2023,7 @@ describe("snapshots", () => { - "const": true, - "destructuring": true, - "dynamicImport": undefined, + - "dynamicImportInWorker": undefined, - "forOf": true, - "globalThis": undefined, - "module": undefined, @@ -2027,6 +2034,7 @@ describe("snapshots", () => { + "const": false, + "destructuring": false, + "dynamicImport": false, + + "dynamicImportInWorker": false, + "forOf": false, + "globalThis": false, + "module": false, @@ -2044,6 +2052,7 @@ describe("snapshots", () => { - "const": true, - "destructuring": true, - "dynamicImport": undefined, + - "dynamicImportInWorker": undefined, - "forOf": true, - "globalThis": undefined, - "module": undefined, @@ -2054,6 +2063,7 @@ describe("snapshots", () => { + "const": false, + "destructuring": false, + "dynamicImport": false, + + "dynamicImportInWorker": false, + "forOf": false, + "globalThis": false, + "module": false, diff --git a/test/__snapshots__/Cli.basictest.js.snap b/test/__snapshots__/Cli.basictest.js.snap index be6e755dd..4fe7a79bf 100644 --- a/test/__snapshots__/Cli.basictest.js.snap +++ b/test/__snapshots__/Cli.basictest.js.snap @@ -5946,6 +5946,19 @@ Object { "multiple": false, "simpleType": "boolean", }, + "output-environment-dynamic-import-in-worker": Object { + "configs": Array [ + Object { + "description": "The environment supports an async import() is available when creating a worker.", + "multiple": false, + "path": "output.environment.dynamicImportInWorker", + "type": "boolean", + }, + ], + "description": "The environment supports an async import() is available when creating a worker.", + "multiple": false, + "simpleType": "boolean", + }, "output-environment-for-of": Object { "configs": Array [ Object { diff --git a/test/configCases/ecmaVersion/browserslist-config-env/webpack.config.js b/test/configCases/ecmaVersion/browserslist-config-env/webpack.config.js index 65acc8d11..9f8e4ec3d 100644 --- a/test/configCases/ecmaVersion/browserslist-config-env/webpack.config.js +++ b/test/configCases/ecmaVersion/browserslist-config-env/webpack.config.js @@ -13,6 +13,7 @@ module.exports = { "const": false, "destructuring": false, "dynamicImport": false, + "dynamicImportInWorker": false, "forOf": false, "globalThis": false, "module": false, diff --git a/test/configCases/ecmaVersion/browserslist-config/webpack.config.js b/test/configCases/ecmaVersion/browserslist-config/webpack.config.js index a21ad76fd..f92c521ef 100644 --- a/test/configCases/ecmaVersion/browserslist-config/webpack.config.js +++ b/test/configCases/ecmaVersion/browserslist-config/webpack.config.js @@ -13,6 +13,7 @@ module.exports = { "const": false, "destructuring": false, "dynamicImport": false, + "dynamicImportInWorker": false, "forOf": false, "globalThis": false, "module": false, diff --git a/test/configCases/ecmaVersion/browserslist-query/webpack.config.js b/test/configCases/ecmaVersion/browserslist-query/webpack.config.js index 691367562..f0db5d3e8 100644 --- a/test/configCases/ecmaVersion/browserslist-query/webpack.config.js +++ b/test/configCases/ecmaVersion/browserslist-query/webpack.config.js @@ -11,6 +11,7 @@ module.exports = { "const": false, "destructuring": false, "dynamicImport": false, + "dynamicImportInWorker": false, "forOf": false, "globalThis": false, "module": false, diff --git a/test/configCases/ecmaVersion/browserslist/webpack.config.js b/test/configCases/ecmaVersion/browserslist/webpack.config.js index dd589bc48..801640dd2 100644 --- a/test/configCases/ecmaVersion/browserslist/webpack.config.js +++ b/test/configCases/ecmaVersion/browserslist/webpack.config.js @@ -11,6 +11,7 @@ module.exports = { "const": true, "destructuring": true, "dynamicImport": true, + "dynamicImportInWorker": false, "forOf": true, "globalThis": true, "module": true, diff --git a/test/configCases/ecmaVersion/loader-context/index.js b/test/configCases/ecmaVersion/loader-context/index.js index f5ec512fd..71b94e507 100644 --- a/test/configCases/ecmaVersion/loader-context/index.js +++ b/test/configCases/ecmaVersion/loader-context/index.js @@ -5,4 +5,5 @@ it("should compile and export target and environment", function() { expect(mod.environment.globalThis).toBe(false); expect(mod.environment.optionalChaining).toBe(true); expect(mod.environment.templateLiteral).toBe(true); + expect(mod.environment.dynamicImportInWorker).toBe(true); }); diff --git a/test/configCases/ecmaVersion/loader-context/loader.js b/test/configCases/ecmaVersion/loader-context/loader.js index 164066f23..1a1f276bb 100644 --- a/test/configCases/ecmaVersion/loader-context/loader.js +++ b/test/configCases/ecmaVersion/loader-context/loader.js @@ -1,3 +1,4 @@ +/** @type {import("../../../../types").LoaderDefinition<{}>} */ module.exports = function loader(content) { const target = this.target; const environment = this.environment; diff --git a/types.d.ts b/types.d.ts index 8f72dd52a..6ac53db35 100644 --- a/types.d.ts +++ b/types.d.ts @@ -3501,6 +3501,11 @@ declare interface Environment { */ dynamicImport?: boolean; + /** + * The environment supports an async import() is available when creating a worker. + */ + dynamicImportInWorker?: boolean; + /** * The environment supports 'for of' iteration ('for (const x of array) { ... }'). */