Skip to content

Commit d9a6d9b

Browse files
authored
Update externals.mdx
1 parent b3bd506 commit d9a6d9b

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/content/configuration/externals.mdx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,8 @@ Supported types:
354354
- `'import'` - uses `import()` to load a native EcmaScript module (async module)
355355
- `'jsonp'`
356356
- [`'module'`](#externalstypemodule)
357+
- [`'import'`](#externalstypeimport)
358+
- [`'module-import'`](#externalstypemodule-import)
357359
- [`'node-commonjs'`](#externalstypenode-commonjs)
358360
- [`'promise'`](#externalstypepromise) - same as `'var'` but awaits the result (async module)
359361
- [`'self'`](#externalstypeself)
@@ -520,7 +522,7 @@ async function foo() {
520522

521523
Note that there will be an `import()` statement in the output bundle.
522524

523-
### externalsType['module-import']
525+
### externalsType.module-import
524526

525527
Specify the default type of externals as `'module-import'`. This combines [`'module'`](#externalstypemodule) and [`'import'`](#externalstypeimport). Webpack will automatically detect the type of import syntax, setting it to `'module'` for static imports and `'import'` for dynamic imports.
526528

@@ -572,6 +574,14 @@ async function foo() {
572574

573575
Note that there will be an `import` or `import()` statement in the output bundle.
574576

577+
When a module is not imported via `import` or `import()`, webpack will determine which type of external to use as fallback based on the configuration of [`externalsPresets`](#externalspresets). When one of the previous `externalsPresets` type is enabled, the following `externalsPresets` type will no longer apply. The order is listed below.
578+
579+
- When `externalsPresets.web` is `true`, use `module`.
580+
- When `externalsPresets.webAsync` is `true`, use `import`.
581+
- When node.js related (`electron`, `electronMain`, `electronPreload`, `electronRenderer`, `node`, `nwjs`) externalsPresets is true, use `node-commonjs`.
582+
583+
When none of the above `externalsPresets` type is enabled or can be derived, webpack will use `commonjs` as the default type.
584+
575585
### externalsType.node-commonjs
576586

577587
Specify the default type of externals as `'node-commonjs'`. Webpack will import [`createRequire`](https://nodejs.org/api/module.html#module_module_createrequire_filename) from `'module'` to construct a require function for loading externals used in a module.

0 commit comments

Comments
 (0)