Skip to content

Commit b23c1c2

Browse files
committed
Update tests and docs
1 parent 3058b81 commit b23c1c2

File tree

17 files changed

+259
-554
lines changed

17 files changed

+259
-554
lines changed

README.md

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

44
Works in monorepos too!
55

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.
1011
1112
## Why you need this
1213
<details><summary>(click to expand)</summary>
@@ -29,42 +30,30 @@ npm install --save-dev rollup-plugin-node-externals
2930
```
3031

3132
## Usage
32-
- To bundle a package that depends on other packages **at runtime**, the built-in defaults are just what you need:
33-
```js
34-
export default {
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`.
4134

42-
- To bundle _a standalone package_:
35+
If you follow this simple rule, then the built-in defaults are just what you need:
4336
```js
4437
export default {
4538
...
4639
plugins: [
47-
externals({
48-
deps: false, // Dependencies will be bundled in
49-
}),
40+
externals(),
5041
]
5142
}
5243
```
5344

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:
5546
```js
5647
export default {
5748
...
5849
plugins: [
5950
externals({
60-
deps: true, // Regular dependencies are external
61-
devDeps: false // devDependencies will be bundled in
51+
deps: false, // Dependencies will be bundled in
6252
}),
6353
]
6454
}
6555
```
6656

67-
6857
### Options
6958
All options are, well, optional.
7059

@@ -75,35 +64,30 @@ export default {
7564
...
7665
plugins: [
7766
externals({
78-
// Make node builtins external. Default: true.
79-
builtins?: boolean,
8067

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
8470

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'
8973

9074
// The path(s) to your package.json. See below for default.
91-
packagePath?: string | string[],
75+
packagePath?: string | string[]
9276

9377
// Make pkg.dependencies external. Default: true.
94-
deps?: boolean,
78+
deps?: boolean
9579

96-
// Make pkg.devDependencies external. Default: true.
97-
devDeps?: boolean,
80+
// Make pkg.devDependencies external. Default: false.
81+
devDeps?: boolean
9882

9983
// Make pkg.peerDependencies external. Default: true.
100-
peerDeps?: boolean,
84+
peerDeps?: boolean
10185

10286
// Make pkg.optionalDependencies external. Default: true.
103-
optDeps?: boolean,
87+
optDeps?: boolean
10488

10589
// Modules to force include in externals. Default: [].
106-
include?: string | RegExp | (string | RegExp)[],
90+
include?: string | RegExp | (string | RegExp)[]
10791

10892
// Modules to force exclude from externals. Default: [].
10993
exclude?: string | RegExp | (string | RegExp)[]
@@ -115,24 +99,17 @@ export default {
11599
#### builtins?: boolean = true
116100
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.
117101

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._
123-
124-
#### [DEPRECATED] prefixedBuiltins?: boolean | 'add' | 'strip' = 'strip'
125-
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.
126106
- 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>
130107

131108
#### packagePath?: string | string[] = []
132109
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.
133110

134111
#### deps?: boolean = true
135-
#### devDeps?: boolean = true
112+
#### devDeps?: boolean = false
136113
#### peerDeps?: boolean = true
137114
#### optDeps?: boolean = true
138115
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({
173150
})
174151
```
175152

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.
177154

178155

179156
### 3/ Order matters

0 commit comments

Comments
 (0)