Skip to content

Commit 9a647a3

Browse files
committed
pre-3.1.1
1 parent 852e13a commit 9a647a3

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

README.md

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ By default, Rollup doesn't know a thing about NodeJS, so trying to bundle simple
66

77
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).
88

9-
However, this must be done for each and every NodeJS built-in that you happen to use in your program: `path`, `os`, `fs`, `url`, etc., which can quicky become cumbersome when done manually.
9+
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.
1010

1111
So the primary goal of this plugin is simply to automatically declare all NodeJS built-in modules as `external`.
1212

13-
As an added bonus, this plugin will also allow you to declare your dependencies (as declared in your local or monorepo `package.json` file) as external.
13+
As an added bonus, this plugin will also allow you to declare your dependencies (as per in your local or monorepo `package.json` file) as external.
1414

1515

1616
## Installation
17-
Use your favorite package manager. Mine is npm.
17+
Use your favorite package manager. Mine is [npm](https://www.npmjs.com).
1818
```sh
1919
npm install --save-dev rollup-plugin-node-externals
2020
```
@@ -59,6 +59,7 @@ export default {
5959
}
6060
```
6161

62+
### Options
6263
Most of the time, the built-in defaults are just what you need:
6364
```typescript
6465
import externals from 'rollup-plugin-node-externals'
@@ -71,40 +72,37 @@ export default {
7172
}
7273
```
7374

74-
### Options
75-
By default, this plugin will mark all Node built-in modules and _all_ your `dev-`, `peer-` and `optionalDependencies` as external. Normal `dependencies` are left unmarked so Rollup will still bundle them with your code as expected in most situations.
76-
7775
#### packagePath?: string | string[] = []
7876
If you're working with monorepos, the `packagePath` 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.
7977

8078
#### builtins?: boolean = true
81-
Set the `builtins` option to `false` if you'd like to use some shims for those.
79+
Set the `builtins` option to `false` if you'd like to use some shims for those. You'll most certainly need an other plugin for this.
8280

8381
#### prefixedBuiltins?: boolean | 'strip' = true
8482
How to handle the `node:` (or sometimes `nodejs:`) prefix some authors use in their code (i.e., `import path from 'node:path'`). If `true` (default), prefixed builtins are treated as their unprefixed equivalent. If `strip`, the prefix is removed from the name and other plugins will never know it was there.
8583

8684
#### deps?: boolean = false
8785
Set the `deps` option to `true` to externalize your normal dependencies, therefore preventing Rollup from bundling them with your code.
8886

89-
#### devDeps?: boolean = true,
87+
#### devDeps?: boolean = true
9088
#### peerDeps?: boolean = true
9189
#### optDeps?: boolean = true
92-
Set the `devDeps`, `peerDeps` and `optDeps` options to `false` to prevent the corresponding dependencies from being externalized, therefore letting Rollup bundle them with your code. Note that bundling these dependencies is quite meaningless but it might be useful as a transitional step before migrating them to `devDependencies`.
90+
Set the `devDeps`, `peerDeps` and `optDeps` options to `false` to prevent the corresponding dependencies from being externalized, therefore letting Rollup bundle them with your code. Note that bundling these dependencies is quite meaningless but it might be useful as a transitional step before migrating them to `dependencies`.
9391

9492
#### include?: string | RegExp | (string | RegExp)[] = []
9593
#### exclude?: string | RegExp | (string | RegExp)[] = []
9694
Use the `include` option to force certain dependencies into the list of externals:
9795
```typescript
9896
externals({
99-
deps: false, // Bundle dependencies in
97+
deps: false, // Deps will be bundled in
10098
include: /^fsevents/ // Except for fsevents
10199
})
102100
```
103101

104102
Conversely, use the `exclude` option to remove certain dependencies from the list of externals:
105103
```typescript
106104
externals({
107-
deps: true, // Don't bundle dependencies, we'll import/require them at runtime instead
105+
deps: true, // Deps are external
108106
exclude: [
109107
'electron-reload' // Yet we want `electron-reload` bundled in
110108
]
@@ -116,7 +114,7 @@ externals({
116114
Falsy values in `include` and `exclude` are silently ignored. This allows for conditional constructs like so: `exclude: process.env.NODE_ENV === 'production' && /my-prod-only-dep/`.
117115

118116
### 2/ This plugin is not _that_ smart
119-
It uses an exact match against your imports, so if your are using some path substitution in your code, eg.:
117+
It uses an exact match against your imports, so if your are using some kind of path substitution in your code, eg.:
120118
```typescript
121119
// In your code, say '@/' is mapped to some directory:
122120
import something from '@/mylib'
@@ -138,14 +136,15 @@ import resolve from '@rollup/plugin-node-resolve'
138136
...
139137

140138
export default {
141-
// ...
139+
...
142140
plugins: [
143141
externals(),
144142
resolve(),
145-
// other plugins
143+
...
146144
]
147145
}
148146
```
147+
As a general rule of thumb, you might want to always make this plugin the first one in the `plugins` array.
149148

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
"modules",
2323
"monorepo"
2424
],
25+
"homepage": "https://github.com/Septh/rollup-plugin-node-externals",
2526
"repository": {
2627
"type": "git",
2728
"url": "https://github.com/Septh/rollup-plugin-node-externals"
2829
},
29-
"homepage": "https://github.com/Septh/rollup-plugin-node-externals",
3030
"license": "MIT",
3131
"engines": {
3232
"node": ">=14.0.0"

0 commit comments

Comments
 (0)