mirror of https://github.com/webpack/webpack.git
feat: allow to setup dynamic import in worker
This commit is contained in:
parent
dd94f64a0b
commit
615af4a47b
|
@ -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) { ... }').
|
||||
*/
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -13,6 +13,7 @@ module.exports = {
|
|||
"const": false,
|
||||
"destructuring": false,
|
||||
"dynamicImport": false,
|
||||
"dynamicImportInWorker": false,
|
||||
"forOf": false,
|
||||
"globalThis": false,
|
||||
"module": false,
|
||||
|
|
|
@ -13,6 +13,7 @@ module.exports = {
|
|||
"const": false,
|
||||
"destructuring": false,
|
||||
"dynamicImport": false,
|
||||
"dynamicImportInWorker": false,
|
||||
"forOf": false,
|
||||
"globalThis": false,
|
||||
"module": false,
|
||||
|
|
|
@ -11,6 +11,7 @@ module.exports = {
|
|||
"const": false,
|
||||
"destructuring": false,
|
||||
"dynamicImport": false,
|
||||
"dynamicImportInWorker": false,
|
||||
"forOf": false,
|
||||
"globalThis": false,
|
||||
"module": false,
|
||||
|
|
|
@ -11,6 +11,7 @@ module.exports = {
|
|||
"const": true,
|
||||
"destructuring": true,
|
||||
"dynamicImport": true,
|
||||
"dynamicImportInWorker": false,
|
||||
"forOf": true,
|
||||
"globalThis": true,
|
||||
"module": true,
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
/** @type {import("../../../../types").LoaderDefinition<{}>} */
|
||||
module.exports = function loader(content) {
|
||||
const target = this.target;
|
||||
const environment = this.environment;
|
||||
|
|
|
@ -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) { ... }').
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue