rollup-plugin-node-externals
Advanced tools
Comparing version 6.0.1 to 6.1.0
@@ -68,5 +68,6 @@ import type { Plugin } from 'rollup'; | ||
*/ | ||
declare function externals(options?: ExternalsOptions): Plugin; | ||
export default externals; | ||
export { externals }; | ||
declare function nodeExternals(options?: ExternalsOptions): Plugin; | ||
export default nodeExternals; | ||
export { nodeExternals, // Named export since 6.1 | ||
nodeExternals as externals }; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -11,2 +11,6 @@ import path from 'node:path'; | ||
}; | ||
// node:test is currently not part of builtinModules... and may well never be | ||
// (see https://github.com/nodejs/node/issues/42785) | ||
builtins.all.add('node:test'); | ||
builtins.alwaysPrefixed.add('node:test'); | ||
const workspaceRootFiles = new Set([ | ||
@@ -36,3 +40,3 @@ 'pnpm-workspace.yaml', | ||
*/ | ||
function externals(options = {}) { | ||
function nodeExternals(options = {}) { | ||
const config = { ...defaults, ...options }; | ||
@@ -60,7 +64,5 @@ let include, exclude; | ||
// or the root of the volume, whichever comes first. | ||
const packagePaths = Array.isArray(config.packagePath) | ||
? config.packagePath.filter(isString) | ||
: isString(config.packagePath) | ||
? [config.packagePath] | ||
: []; | ||
const packagePaths = [] | ||
.concat(config['packagePath']) | ||
.filter(isString); | ||
if (packagePaths.length === 0) { | ||
@@ -112,3 +114,3 @@ for (let current = process.cwd(), previous; previous !== current; previous = current, current = path.dirname(current)) { | ||
async resolveId(id) { | ||
// Let Rollup handle already resolved ids, relative imports and virtual modules. | ||
// Ignore already resolved ids, relative imports and virtual modules. | ||
if (path.isAbsolute(id) || /^(?:\0|\.{1,2}[\\/])/.test(id)) | ||
@@ -125,3 +127,3 @@ return null; | ||
: stripped, | ||
external: config.builtins && !isExcluded(id), | ||
external: (config.builtins || isIncluded(id)) && !isExcluded(id), | ||
moduleSideEffects: false | ||
@@ -137,4 +139,6 @@ }; | ||
} | ||
export default externals; | ||
export { externals }; | ||
export default nodeExternals; | ||
export { nodeExternals, // Named export since 6.1 | ||
nodeExternals as externals // For backwards compatibility | ||
}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "rollup-plugin-node-externals", | ||
"version": "6.0.1", | ||
"version": "6.1.0", | ||
"description": "Automatically declare NodeJS built-in modules and npm dependencies as 'external' in Rollup config", | ||
@@ -39,4 +39,3 @@ "author": "Stephan Schreiber <septh@sfr.fr>", | ||
"type": "module", | ||
"main": "./dist/index.js", | ||
"types": "./dist/index.d.ts", | ||
"exports": "./dist/index.js", | ||
"scripts": { | ||
@@ -43,0 +42,0 @@ "build": "tsc", |
@@ -6,2 +6,3 @@ # rollup-plugin-node-externals | ||
## Why you need this | ||
@@ -14,3 +15,3 @@ <details><summary>(click to expand)</summary> | ||
However, this must be done for each and every NodeJS built-in you happen to use in your program: `node:path`, `node:os`, `node:fs`, `node:url`, etc., which can quicky become cumbersome when done manually. | ||
However, this must be done for each and every NodeJS built-in you happen to use in your program: `node:path`, `node:os`, `node:fs`, `node:url`, etc., which can quickly become cumbersome when done manually. | ||
@@ -22,4 +23,6 @@ So the primary goal of this plugin is simply to automatically declare all NodeJS built-in modules as external. | ||
## Installation | ||
Use your favorite package manager. Mine is [npm](https://www.npmjs.com). | ||
```sh | ||
@@ -29,11 +32,34 @@ npm install --save-dev rollup-plugin-node-externals | ||
## Usage | ||
You generally want to have your **runtime dependencies** listed under `dependencies` in `package.json`, and your **development dependencies** listed under `devDependencies`. | ||
If you follow this simple rule, then the defaults are just what you need: | ||
### Import | ||
The plugin is available both as the default export and as a named export: | ||
```js | ||
import nodeExternals from 'rollup-plugin-node-externals' | ||
``` | ||
and | ||
```js | ||
import { nodeExternals } from 'rollup-plugin-node-externals' | ||
``` | ||
will both work. | ||
> Note: an undocumented named export `externals` also exists that is kept in v6.1 for backwards compatibility only and will be removed in the next major version. | ||
### Options | ||
You generally want to have your **runtime dependencies** (those that will be imported/required at runtime) listed under `dependencies` in `package.json`, and your **development dependencies** (those that should be bundled in by Rollup) listed under `devDependencies`. | ||
If you follow this simple rule, then the defaults settings are just what you need: | ||
```js | ||
// rollup.config.js | ||
export default { | ||
... | ||
plugins: [ | ||
externals(), | ||
nodeExternals(), | ||
] | ||
@@ -45,7 +71,6 @@ } | ||
### Options | ||
All options are, well, optional. | ||
Should the defaults not suit your case, here is the full list of options. | ||
```typescript | ||
import externals from 'rollup-plugin-node-externals' | ||
import nodeExternals from 'rollup-plugin-node-externals' | ||
@@ -55,3 +80,3 @@ export default { | ||
plugins: [ | ||
externals({ | ||
nodeExternals({ | ||
@@ -94,9 +119,9 @@ // Make node builtins external. Default: true. | ||
How to handle the `node:` scheme used in recent versions of Node (i.e., `import path from 'node:path'`).<br> | ||
- If `add` (the default), the `node:` prefix is always added. In effect, this homogenizes all your imports of node builtins to their prefixed version. | ||
- If `strip` (the default), the import is always resolved unprefixed. In effect, this homogenizes all your imports of node builtins to their unprefixed version. | ||
- `ignore` will simply leave all prefixes as written in your code. | ||
> _Note that prefix handling is independant of the `builtins` options being enabled or disabled._ | ||
- If `add` (the default, recommended), the `node:` prefix is always added. In effect, this homogenizes all your imports of Node builtins to their prefixed version. | ||
- If `strip` (the default), the import is always resolved unprefixed. In effect, this homogenizes all your imports of Node builtins to their unprefixed version. | ||
- `ignore` will simply leave all builtins imports as written in your code. | ||
> _Note that prefix handling is always applied, regardless of the `builtins` options being enabled or disabled._ | ||
#### packagePath?: string | string[] = [] | ||
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. | ||
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. | ||
@@ -111,4 +136,5 @@ #### deps?: boolean = true | ||
Use the `include` option to force certain dependencies into the list of externals, regardless of other settings: | ||
```js | ||
externals({ | ||
nodeExternals({ | ||
deps: false, // Deps will be bundled in | ||
@@ -121,4 +147,5 @@ include: /^fsevents/ // Except for fsevents | ||
Conversely, use the `exclude` option to remove certain dependencies from the list of externals, regardless of other settings: | ||
```js | ||
externals({ | ||
nodeExternals({ | ||
deps: true, // Deps are external | ||
@@ -129,3 +156,5 @@ exclude: 'electron-reload' // Yet we want `electron-reload` bundled in | ||
## Notes | ||
### 1/ This plugin is smart | ||
@@ -147,3 +176,3 @@ - Falsy values in `include` and `exclude` are silently ignored. This allows for conditional constructs like `exclude: process.env.NODE_ENV === 'production' && 'my-prod-only-dep'`. | ||
// In rollup.config.js: | ||
externals({ | ||
nodeExternals({ | ||
include: '@/mylib' | ||
@@ -157,4 +186,4 @@ }) | ||
```js | ||
import externals from 'rollup-plugin-node-externals' | ||
import resolve from '@rollup/plugin-node-resolve' | ||
import nodeExternals from 'rollup-plugin-node-externals' | ||
import nodeResolve from '@rollup/plugin-node-resolve' | ||
@@ -164,4 +193,4 @@ export default { | ||
plugins: [ | ||
externals(), | ||
resolve(), | ||
nodeExternals(), | ||
nodeResolve(), | ||
] | ||
@@ -168,0 +197,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19240
208
217