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
+27-50Lines changed: 27 additions & 50 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,10 +3,11 @@ 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 4
7
-
> - 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`.
8
-
> - Now requires Node 14 (up from Node 12 for previous versions).
9
-
> - Now has a _peer dependency_ on Rollup ^2.60.0.
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 ment 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.
- To bundle a package that depends on other packages **at runtime**, the built-in defaults are just what you need:
33
-
```js
34
-
exportdefault {
35
-
...
36
-
plugins: [
37
-
externals(), // Make all Node builtins and all dependencies external
38
-
]
39
-
}
40
-
```
33
+
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`.
41
34
42
-
- To bundle _a standalone package_:
35
+
If you follow this simple rule, then the built-in defaults are just what you need:
43
36
```js
44
37
exportdefault {
45
38
...
46
39
plugins: [
47
-
externals({
48
-
deps:false, // Dependencies will be bundled in
49
-
}),
40
+
externals(),
50
41
]
51
42
}
52
43
```
53
44
54
-
-You may also want to bundle some libraries with your code but still `import`/`require` others at runtime. In that case, you could use something like:
45
+
-Or, if you'd rather bundle dependencies in:
55
46
```js
56
47
exportdefault {
57
48
...
58
49
plugins: [
59
50
externals({
60
-
deps:true, // Regular dependencies are external
61
-
devDeps:false// devDependencies will be bundled in
51
+
deps:false, // Dependencies will be bundled in
62
52
}),
63
53
]
64
54
}
65
55
```
66
56
67
-
68
57
### Options
69
58
All options are, well, optional.
70
59
@@ -75,35 +64,30 @@ export default {
75
64
...
76
65
plugins: [
77
66
externals({
78
-
// Make node builtins external. Default: true.
79
-
builtins?: boolean,
80
67
81
-
// node: prefix handing for importing Node builtins.
82
-
// Default: 'strip' (will be 'add' in next major).
83
-
builtinsPrefix?: 'add'|'strip',
68
+
// Make node builtins external. Default: true.
69
+
builtins?: boolean
84
70
85
-
// DEPRECATED. Will be removed in next major.
86
-
// Please use builtinsPrefix instead (see above).
87
-
// Default: 'strip'
88
-
prefixedBuiltins?: boolean|'strip'|'add',
71
+
// node: prefix handing for importing Node builtins. Default: 'add'.
72
+
builtinsPrefix?:'add'|'strip'
89
73
90
74
// The path(s) to your package.json. See below for default.
91
-
packagePath?: string|string[],
75
+
packagePath?:string|string[]
92
76
93
77
// Make pkg.dependencies external. Default: true.
94
-
deps?: boolean,
78
+
deps?:boolean
95
79
96
-
// Make pkg.devDependencies external. Default: true.
97
-
devDeps?: boolean,
80
+
// Make pkg.devDependencies external. Default: false.
81
+
devDeps?:boolean
98
82
99
83
// Make pkg.peerDependencies external. Default: true.
100
-
peerDeps?: boolean,
84
+
peerDeps?:boolean
101
85
102
86
// Make pkg.optionalDependencies external. Default: true.
103
-
optDeps?: boolean,
87
+
optDeps?:boolean
104
88
105
89
// Modules to force include in externals. Default: [].
106
-
include?: string|RegExp| (string|RegExp)[],
90
+
include?:string|RegExp| (string|RegExp)[]
107
91
108
92
// Modules to force exclude from externals. Default: [].
109
93
exclude?:string|RegExp| (string|RegExp)[]
@@ -115,24 +99,17 @@ export default {
115
99
#### builtins?: boolean = true
116
100
Set the `builtins` option to `false` if you'd like to use some shims/polyfills for those. You'll most certainly need [an other plugin](https://github.com/ionic-team/rollup-plugin-node-polyfills) for this.
117
101
118
-
#### builtinsPrefix?: 'add' | 'strip' = 'strip'
119
-
How to handle the `node:` scheme used in recent versions of Node (i.e., `import path from 'node:path'`).
120
-
- If `strip` (the default), the import is always resolved unprefixed. In effect, this homogenizes all your imports of node builtins to their unprefixed version.
121
-
- If `add`, the `node:` prefix is always added. In effect, this homogenizes all your imports of node builtins to their prefixed version.<br>
122
-
_Note: `'add'` will be the default for this option in the next major release of this plugin._
How to handle the `node:` scheme used in recent versions of Node (i.e., `import path from 'node:path'`).
102
+
#### builtinsPrefix?: 'add' | 'strip' = 'add'
103
+
How to handle the `node:` scheme used in recent versions of Node (i.e., `import path from 'node:path'`).<br>
104
+
_Note that prefix handling is independant of the `builtins` options being enabled or disabled._
105
+
- If `add` (the default), the `node:` prefix is always added. In effect, this homogenizes all your imports of node builtins to their prefixed version.
126
106
- If `strip` (the default), the import is always resolved unprefixed. In effect, this homogenizes all your imports of node builtins to their unprefixed version.
127
-
- If `add`, the `node:` prefix is always added. In effect, this homogenizes all your imports of node builtins to their prefixed version.<br>
128
-
- If `false`, the import is used as-is, meaning that `'node:path'` and `'path'` are considered two distincts imports. **This may cause redundant imports in your final code if you (or your dependencies) are mixing prefixed and unprefixed imports.**<br>
129
-
-`true` is the same as `add`.<br>
130
107
131
108
#### packagePath?: string | string[] = []
132
109
If you're working with monorepos, the `packagePath` option is made for you. It can take a path, or an array of paths, to your package.json file(s). If not specified, the default is to start with the current directory's package.json then go up scan for all package.json files in parent directories recursively until either the root git directory is reached or until no other package.json can be found.
133
110
134
111
#### deps?: boolean = true
135
-
#### devDeps?: boolean = true
112
+
#### devDeps?: boolean = false
136
113
#### peerDeps?: boolean = true
137
114
#### optDeps?: boolean = true
138
115
Set the `deps`, `devDeps`, `peerDeps` and `optDeps` options to `false` to prevent the corresponding dependencies from being externalized, therefore letting Rollup bundle them with your code.
@@ -173,7 +150,7 @@ externals({
173
150
})
174
151
```
175
152
176
-
However, subpath imports are supported with regexes, meaning that `include: /^lodash/` will also externalize `loadash/map`, `lodash/merge`, etc.
153
+
However, subpath imports are supported with regexes, meaning that `include: /^lodash/` will externalize `lodash` and also `lodash/map`, `lodash/merge`, etc.
0 commit comments