Skip to content

Commit 6dc8265

Browse files
authored
Update README.md
add `externalsPresets` for webpack 5
1 parent b298f10 commit 6dc8265

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ npm install webpack-node-externals --save-dev
1818

1919
In your `webpack.config.js`:
2020
```js
21-
var nodeExternals = require('webpack-node-externals');
21+
const nodeExternals = require('webpack-node-externals');
2222
...
2323
module.exports = {
2424
...
@@ -29,6 +29,20 @@ module.exports = {
2929
```
3030
And that's it. All node modules will no longer be bundled but will be left as `require('module')`.
3131

32+
**Note**: For Webpack 5, replace `target: 'node'` with the `externalsPreset` object:
33+
```js
34+
// Webpack 5
35+
36+
const nodeExternals = require('webpack-node-externals');
37+
...
38+
module.exports = {
39+
...
40+
externalsPresets: { node: true }, // in order to ignore built-in modules like path, fs, etc.
41+
externals: [nodeExternals()], // in order to ignore all modules in node_modules folder
42+
...
43+
};
44+
```
45+
3246
## Detailed overview
3347
### Description
3448
This library scans the `node_modules` folder for all node_modules names, and builds an *externals* function that tells Webpack not to bundle those modules, or any sub-modules of theirs.

0 commit comments

Comments
 (0)