Skip to content

Commit 6386fc4

Browse files
committed
docs(externals): document defer/source phase preservation in ESM externals
Webpack 5.107 preserves the defer and source import phase keywords on external dependencies the same way it preserves import attributes. Adds subsections under externalsType.module and externalsType.import showing the static and dynamic forms emitted in the output bundle. Refs: webpack/webpack#20934
1 parent f992f03 commit 6386fc4

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

src/content/configuration/externals.mdx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,24 @@ jq(".my-element").animate(/* ... */);
489489

490490
Note that there will be an `import` statement in the output bundle.
491491

492+
#### Preserving phase keywords
493+
494+
<Badge text="5.107.0+" />
495+
496+
The `defer` and `source` import phase keywords are preserved on `module` externals the same way [import attributes](/configuration/module/#ruleparserimportattributes) are. A static `import defer * as ns from "mod"` against a `module` external is emitted as a native `import defer * as ...` statement, and `import source v from "mod"` becomes `import source ... from "mod"`. The same external imported with two different phases produces distinct `ExternalModule` instances, so neither phase is silently dropped.
497+
498+
{/* eslint-skip */}
499+
500+
```js
501+
// input
502+
import defer * as ns from "external-mod";
503+
import source v from "external-mod";
504+
505+
// emitted output (with externalsType: "module")
506+
import defer * as ns from "external-mod";
507+
import source v from "external-mod";
508+
```
509+
492510
### externalsType.import
493511

494512
<Badge text="5.94.0+" />
@@ -536,6 +554,24 @@ async function foo() {
536554

537555
Note that the output bundle will have an `import()` statement.
538556

557+
#### Preserving phase keywords
558+
559+
<Badge text="5.107.0+" />
560+
561+
Dynamic `import.defer(...)` and `import.source(...)` are also preserved on `import` externals when the import function name is the default `"import"`. The phase keyword is emitted in the output instead of being stripped.
562+
563+
{/* eslint-skip */}
564+
565+
```js
566+
// input
567+
const ns = await import.defer("external-mod");
568+
const src = await import.source("external-mod");
569+
570+
// emitted output (with externalsType: "import")
571+
const ns = await import.defer("external-mod");
572+
const src = await import.source("external-mod");
573+
```
574+
539575
### externalsType.module-import
540576

541577
<Badge text="5.94.0+" />

0 commit comments

Comments
 (0)