You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/configuration/externals.mdx
+11-1Lines changed: 11 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -354,6 +354,8 @@ Supported types:
354
354
-`'import'` - uses `import()` to load a native EcmaScript module (async module)
355
355
-`'jsonp'`
356
356
-[`'module'`](#externalstypemodule)
357
+
-[`'import'`](#externalstypeimport)
358
+
-[`'module-import'`](#externalstypemodule-import)
357
359
-[`'node-commonjs'`](#externalstypenode-commonjs)
358
360
-[`'promise'`](#externalstypepromise) - same as `'var'` but awaits the result (async module)
359
361
-[`'self'`](#externalstypeself)
@@ -520,7 +522,7 @@ async function foo() {
520
522
521
523
Note that there will be an `import()` statement in the output bundle.
522
524
523
-
### externalsType['module-import']
525
+
### externalsType.module-import
524
526
525
527
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.
526
528
@@ -572,6 +574,14 @@ async function foo() {
572
574
573
575
Note that there will be an `import` or `import()` statement in the output bundle.
574
576
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
+
575
585
### externalsType.node-commonjs
576
586
577
587
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