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: README.md
+31-31Lines changed: 31 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,28 +3,16 @@ A Rollup plugin that automatically declares NodeJS built-in modules as `external
3
3
4
4
Works in monorepos too!
5
5
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
-
18
6
## Why you need this
19
7
<details><summary>(click to expand)</summary>
20
8
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.
22
10
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).
24
12
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.
26
14
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.
28
16
29
17
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.
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`.
40
28
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:
42
30
```js
43
31
exportdefault {
44
32
...
@@ -48,17 +36,7 @@ export default {
48
36
}
49
37
```
50
38
51
-
- Or, if you'd rather bundle dependencies in:
52
-
```js
53
-
exportdefault {
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.
62
40
63
41
### Options
64
42
All options are, well, optional.
@@ -122,15 +100,15 @@ Set the `deps`, `devDeps`, `peerDeps` and `optDeps` options to `false` to preven
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:
126
104
```js
127
105
externals({
128
106
deps:false, // Deps will be bundled in
129
107
include:/^fsevents/// Except for fsevents
130
108
})
131
109
```
132
110
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:
134
112
```js
135
113
externals({
136
114
deps:true, // Deps are external
@@ -144,11 +122,14 @@ Falsy values in `include` and `exclude` are silently ignored. This allows for co
144
122
145
123
### 2/ This plugin is not _that_ smart
146
124
It uses an exact match against your imports, so if your are using some kind of path substitution in your code, eg.:
125
+
147
126
```js
148
127
// In your code, say '@/' is mapped to some directory:
149
128
importsomethingfrom'@/mylib'
150
129
```
130
+
151
131
and you don't want `mylib` bundled in, then write:
132
+
152
133
```js
153
134
// In rollup.config.js:
154
135
externals({
@@ -160,7 +141,8 @@ However, subpath imports are supported with regexes, meaning that `include: /^lo
160
141
161
142
162
143
### 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
+
164
146
```js
165
147
importexternalsfrom'rollup-plugin-node-externals'
166
148
importresolvefrom'@rollup/plugin-node-resolve'
@@ -173,11 +155,29 @@ export default {
173
155
]
174
156
}
175
157
```
158
+
176
159
As a general rule of thumb, you might want to always make this plugin the first one in the `plugins` array.
177
160
178
161
### 4/ Rollup rules
179
162
Rollup's own `external` configuration option always takes precedence over this plugin. This is intentional.
180
163
181
164
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`.
0 commit comments