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.md
+39-1
Original file line number
Diff line number
Diff line change
@@ -15,6 +15,7 @@ contributors:
15
15
- beejunk
16
16
- EugeneHlushko
17
17
- chenxsan
18
+
- pranshuchittora
18
19
---
19
20
20
21
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.
console.log(window._.head(['a', 'b'])); // logs a here
402
403
```
403
404
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]'`.
405
406
406
407
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/).
`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.
0 commit comments