Skip to content

Commit 564f0f5

Browse files
author
Stephan Septh Schreiber
committed
Update deps, move builtin-modules to peer
1 parent 2b15198 commit 564f0f5

File tree

5 files changed

+569
-512
lines changed

5 files changed

+569
-512
lines changed

.gitignore

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
1-
node_modules
2-
dist
3-
test-app
4-
out
5-
**/zz_*
1+
node_modules
2+
dist

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ A Rollup plugin that automatically declares NodeJS built-in modules as `external
44

55
## Why?
66

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).
810

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`.
1012

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

1315

1416
## Install
@@ -95,8 +97,8 @@ externals({
9597
- Use the `include` option to force certain dependencies into the list of externals, for example:
9698
```js
9799
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
100102
})
101103
```
102104
Just like `exclude`, the `include` option can be a string, a regex or an array of those.
@@ -127,7 +129,7 @@ externals({ deps: true })
127129
```
128130
if you want the same behavior.
129131
- 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`.
131133

132134

133135
## Licence

0 commit comments

Comments
 (0)