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
+8-6Lines changed: 8 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,11 +4,13 @@ A Rollup plugin that automatically declares NodeJS built-in modules as `external
4
4
5
5
## Why?
6
6
7
-
By default, Rollup doesn't know a thing about NodeJS, so using simple things like `require('path')` or `import * as path from 'path'` in your code generates an `Unresolved dependencies` error. The solution here is to tell Rollup that the `path` module is in fact `external`: this way, Rollup won't try to bundle the `path` module in but simply leave the `require()` or `import` statement as is.
7
+
By default, Rollup doesn't know a thing about NodeJS, so using simple things like `import * as path from 'path'` in your code generates an `Unresolved dependencies` error. The solution here is twofold, depending on what you're building:
8
+
* If building a *standalone app*, e.g. for the browser, you'll need to use some kind of shim like those provided by [rollup-plugin-node-builtins](https://github.com/calvinmetcalf/rollup-plugin-node-builtins).
9
+
* If building *an npm module or lib*, you'll need to tell Rollup that the `path` module is in fact `external`: this way, Rollup won't try to bundle the module in, but simply leave the `import` statement as is (or translate it to a `require()` call if bundling for CommonJS).
8
10
9
-
However, this must be done for each and every NodeJS built-in modules: `path`, `os`, `fs`, etc., which can quicky become cumbersome when done manually. So the primary goal of this plugin is simply to automatically declare all NodeJS built-in modules as `external`.
11
+
However, this must be done for each and every NodeJS built-in: `path`, `os`, `fs`, etc., which can quicky become cumbersome when done manually. So the primary goal of this plugin is simply to automatically declare all NodeJS built-in modules as `external`.
10
12
11
-
This plugin will also allow you, should you need it, to declare your dependencies (as declared in your `package.json` file) as `external` so they are not bundled in but will be required or imported at runtime.
13
+
This plugin will also allow you, should you need it, to declare your dependencies (as declared in your `package.json` file) as `external`. This may come in handy when building an [Electron](https://electronjs.org/) app, for example.
12
14
13
15
14
16
## Install
@@ -95,8 +97,8 @@ externals({
95
97
- Use the `include` option to force certain dependencies into the list of externals, for example:
96
98
```js
97
99
externals({
98
-
peerDeps:false, // Bundle peerDependencies in
99
-
include:/^lodash(\/.+)?/// Except for Lodash (this regex accounts for the namespaced version of lodash, ie. loadash/map)
100
+
peerDeps:false, // Bundle peerDependencies in
101
+
include:/^lodash/// Except for Lodash
100
102
})
101
103
```
102
104
Just like `exclude`, the `include` option can be a string, a regex or an array of those.
@@ -127,7 +129,7 @@ externals({ deps: true })
127
129
```
128
130
if you want the same behavior.
129
131
- For consistency with all other Rollup plugins out there, the `except` option from 1.x is now deprecated in favor of the Rollup-friendly `exclude` option.
130
-
`except` is still accepted for backward compatibility and works exactly the same as `exclude` but it will issue a warning if used. To suppress this warning, just replace `except` with `include`.
132
+
`except` is still accepted for backward compatibility and works exactly the same as `exclude` but it will issue a warning if used. To suppress this warning, just replace `except` with `exclude`.
0 commit comments