Skip to content

Commit 213bd5a

Browse files
docs: externalsPresets option (webpack#3974)
1 parent 8c8f0f9 commit 213bd5a

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

src/content/configuration/externals.md

+39-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ contributors:
1515
- beejunk
1616
- EugeneHlushko
1717
- chenxsan
18+
- pranshuchittora
1819
---
1920

2021
The `externals` configuration option provides a way of excluding dependencies from the output bundles. Instead, the created bundle relies on that dependency to be present in the consumer's (any end-user application) environment. This feature is typically most useful to __library developers__, however there are a variety of applications for it.
@@ -401,6 +402,43 @@ console.log(head([1, 2, 3])); // logs 1 here
401402
console.log(window._.head(['a', 'b'])); // logs a here
402403
```
403404

404-
T> When loading code with HTML `<script>` tags, the webpack runtime will try to find an existing `<script>` tag that matches the `src` attribute or has a specific `data-webpack` attribute. For chunk loading `data-webpack` attribute would have value of `'[output.uniqueName]:chunk-[chunkId]'` while external script has value of `'[output.uniqueName]:[global]'`.
405+
T> When loading code with HTML `<script>` tags, the webpack runtime will try to find an existing `<script>` tag that matches the `src` attribute or has a specific `data-webpack` attribute. For chunk loading `data-webpack` attribute would have value of `'[output.uniqueName]:chunk-[chunkId]'` while external script has value of `'[output.uniqueName]:[global]'`.
405406

406407
T> Options like `output.chunkLoadTimeout`, `output.crossOriginLoading` and `output.scriptType` will also have effect on the external scripts loaded this way.
408+
409+
## `externalsPresets`
410+
411+
`object`
412+
413+
Enable presets of externals for specific targets.
414+
415+
W> In earlier webpack versions, the following functionality was achieved by using [`target`](/configuration/target/).
416+
417+
418+
419+
Option | Description | Input Type
420+
----------- | ------------------------------------------------ | ----------
421+
`electron` | Treat common electron built-in modules in main and preload context like `electron`, `ipc` or `shell` as external and load them via `require()` when used. | boolean
422+
`electronMain` | Treat electron built-in modules in the main context like `app`, `ipc-main` or `shell` as external and load them via `require()` when used. | boolean
423+
`electronPreload` | Treat electron built-in modules in the preload context like `web-frame`, `ipc-renderer` or `shell` as external and load them via require() when used. | boolean
424+
`electronRenderer` | Treat electron built-in modules in the renderer context like `web-frame`, `ipc-renderer` or `shell` as external and load them via `require()` when used. | boolean
425+
`node` | Treat node.js built-in modules like `fs`, `path` or `vm` as external and load them via `require()` when used.| boolean
426+
`nwjs` | Treat `NW.js` legacy `nw.gui` module as external and load it via `require()` when used.| boolean
427+
`web` | Treat references to `http(s)://...` and `std:...` as external and load them via `import` when used. __(Note that this changes execution order as externals are executed before any other code in the chunk)__.| boolean
428+
`webAsync` | Treat references to 'http(s)://...' and 'std:...' as external and load them via `async import()` when used __(Note that this external type is an `async` module, which has various effects on the execution)__.| boolean
429+
430+
431+
__Example__
432+
433+
Using `node` preset will not bundle built-in modules and treats them as external and loads them via `require()` when used.
434+
435+
__webpack.config.js__
436+
437+
```js
438+
module.exports = {
439+
// ...
440+
externalsPresets:{
441+
node: true
442+
}
443+
};
444+
```

0 commit comments

Comments
 (0)