Skip to content

Commit 6aeb1a0

Browse files
committed
Docs update
1 parent 4aef537 commit 6aeb1a0

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

README.md

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,16 @@ A Rollup plugin that automatically declares NodeJS built-in modules as `external
33

44
Works in monorepos too!
55

6-
> ### Breaking changes in version 5
7-
> - In previous versions, the `devDeps` option (see below) defaulted to `true`.<br>This was practical, but often wrong: devDependencies are meant just for that: being used when developping. Therefore, the `devDeps` option now defaults to `false`, meaning Rollup will include them in your bundle.
8-
>- As anticipated since v4, the `builtinsPrefix` option now defaults to `'add'`.
9-
>- The deprecated `prefixedBuiltins` option has been removed.
10-
> - `rollup-plugin-node-externals` no longer depends on the Find-Up package (while this is not a breaking change per se, it can be in some edge situations).
11-
> - Now has a _peer dependency_ on `rollup ^2.60.0 || ^3.0.0`.
12-
13-
> ### Breaking changes in version 4
14-
> - In previous versions, the `deps` option (see below) defaulted to `false`.<br>This was practical, but often wrong: when bundling for distribution, you want your own dependencies to be installed by the package manager alongside your package, so they should not be bundled in the code. Therefore, the `deps` option now defaults to `true`.
15-
> - Now requires Node 14 (up from Node 12 for previous versions).
16-
> - Now has a _peer dependency_ on `rollup ^2.60.0`.
17-
186
## Why you need this
197
<details><summary>(click to expand)</summary>
208

21-
By default, Rollup doesn't know a thing about NodeJS, so trying to bundle simple things like `import path from 'path'` in your code generates an `Unresolved dependencies` warning.
9+
By default, Rollup doesn't know a thing about NodeJS, so trying to bundle simple things like `import path from 'node:path'` in your code generates an `Unresolved dependencies` warning.
2210

23-
The solution here is quite simple: you must tell Rollup that the `path` module is in fact `external`. This way, Rollup won't try to bundle it in and rather leave the `import` statement as is (or translate it to a `require()` call if bundling for CommonJS).
11+
The solution here is quite simple: you must tell Rollup that the `node:path` module is in fact _external_. This way, Rollup won't try to bundle it in and rather leave the `import` statement as is (or translate it to a `require()` call if bundling for CommonJS).
2412

25-
However, this must be done for each and every NodeJS built-in you happen to use in your program: `path`, `os`, `fs`, `url`, etc., which can quicky become cumbersome when done manually.
13+
However, this must be done for each and every NodeJS built-in you happen to use in your program: `node:path`, `node:os`, `node:fs`, `node:url`, etc., which can quicky become cumbersome when done manually.
2614

27-
So the primary goal of this plugin is simply to automatically declare all NodeJS built-in modules as `external`.
15+
So the primary goal of this plugin is simply to automatically declare all NodeJS built-in modules as external.
2816

2917
As an added bonus, this plugin will also allow you to declare your dependencies (as per your local or monorepo `package.json` file(s)) as external.
3018
</details>
@@ -38,7 +26,7 @@ npm install --save-dev rollup-plugin-node-externals
3826
## Usage
3927
When bundling an application or library, you want to have your **runtime dependencies** listed under `dependencies` in `package.json`, and **development dependencies** listed under `devDependencies`.
4028

41-
If you follow this simple rule, then the built-in defaults are just what you need:
29+
If you follow this simple rule, then the defaults are just what you need:
4230
```js
4331
export default {
4432
...
@@ -48,17 +36,7 @@ export default {
4836
}
4937
```
5038

51-
- Or, if you'd rather bundle dependencies in:
52-
```js
53-
export default {
54-
...
55-
plugins: [
56-
externals({
57-
deps: false, // Dependencies will be bundled in
58-
}),
59-
]
60-
}
61-
```
39+
This will bundle your `devDependencies` in while leaving your `dependencies`, `peerDependencies` and `optionalDependencies` external.
6240

6341
### Options
6442
All options are, well, optional.
@@ -122,15 +100,15 @@ Set the `deps`, `devDeps`, `peerDeps` and `optDeps` options to `false` to preven
122100

123101
#### include?: string | RegExp | (string | RegExp)[] = []
124102
#### exclude?: string | RegExp | (string | RegExp)[] = []
125-
Use the `include` option to force certain dependencies into the list of externals:
103+
Use the `include` option to force certain dependencies into the list of externals, regardless of other settings:
126104
```js
127105
externals({
128106
deps: false, // Deps will be bundled in
129107
include: /^fsevents/ // Except for fsevents
130108
})
131109
```
132110

133-
Conversely, use the `exclude` option to remove certain dependencies from the list of externals:
111+
Conversely, use the `exclude` option to remove certain dependencies from the list of externals, regardless of other settings:
134112
```js
135113
externals({
136114
deps: true, // Deps are external
@@ -144,11 +122,14 @@ Falsy values in `include` and `exclude` are silently ignored. This allows for co
144122

145123
### 2/ This plugin is not _that_ smart
146124
It uses an exact match against your imports, so if your are using some kind of path substitution in your code, eg.:
125+
147126
```js
148127
// In your code, say '@/' is mapped to some directory:
149128
import something from '@/mylib'
150129
```
130+
151131
and you don't want `mylib` bundled in, then write:
132+
152133
```js
153134
// In rollup.config.js:
154135
externals({
@@ -160,7 +141,8 @@ However, subpath imports are supported with regexes, meaning that `include: /^lo
160141

161142

162143
### 3/ Order matters
163-
If you're also using `@rollup/plugin-node-resolve`, make sure this plugin comes _before_ it in the `plugins` array:
144+
If you're also using [`@rollup/plugin-node-resolve`](https://github.com/rollup/plugins/tree/master/packages/node-resolve/#readme), make sure this plugin comes _before_ it in the `plugins` array:
145+
164146
```js
165147
import externals from 'rollup-plugin-node-externals'
166148
import resolve from '@rollup/plugin-node-resolve'
@@ -173,11 +155,29 @@ export default {
173155
]
174156
}
175157
```
158+
176159
As a general rule of thumb, you might want to always make this plugin the first one in the `plugins` array.
177160

178161
### 4/ Rollup rules
179162
Rollup's own `external` configuration option always takes precedence over this plugin. This is intentional.
180163

181164

165+
## Breaking changes
166+
<details><summary>(click to expand)</summary>
167+
168+
### Breaking changes in version 5
169+
- In previous versions, the `devDeps` option (see below) defaulted to `true`.<br>This was practical, but often wrong: devDependencies are meant just for that: being used when developping. Therefore, the `devDeps` option now defaults to `false`, meaning Rollup will include them in your bundle.
170+
- As anticipated since v4, the `builtinsPrefix` option now defaults to `'add'`.
171+
- The deprecated `prefixedBuiltins` option has been removed.
172+
- `rollup-plugin-node-externals` no longer depends on the Find-Up package (while this is not a breaking change per se, it can be in some edge situations).
173+
- Now has a _peer dependency_ on `rollup ^2.60.0 || ^3.0.0`.
174+
175+
### Breaking changes in version 4
176+
- In previous versions, the `deps` option (see below) defaulted to `false`.<br>This was practical, but often wrong: when bundling for distribution, you want your own dependencies to be installed by the package manager alongside your package, so they should not be bundled in the code. Therefore, the `deps` option now defaults to `true`.
177+
- Now requires Node 14 (up from Node 12 for previous versions).
178+
- Now has a _peer dependency_ on `rollup ^2.60.0`.
179+
</summary>
180+
181+
182182
## Licence
183183
MIT

0 commit comments

Comments
 (0)