diff --git a/README.md b/README.md index 0fa2876..dd86fbe 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,7 @@ How to handle the `node:` scheme used in recent versions of Node (i.e., `import > _Note that scheme handling is always applied, regardless of the `builtins` options being enabled or not._ #### 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, the root of the monorepo is reached, or no other `package.json` can be found. #### deps?: boolean = true
devDeps?: boolean = false
peerDeps?: boolean = true
optDeps?: boolean = true 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. @@ -151,7 +151,7 @@ nodeExternals({ It uses an exact match against your imports _as written in your code_. No resolving of path aliases or substitutions is made: ```js -// In your code, say '@/lib' is an alias for node_modules/deep/path/to/some/lib: +// In your code, say '@/lib' is an alias for source/deep/path/to/some/lib: import something from '@/lib' ``` @@ -160,7 +160,7 @@ If you don't want `lib` bundled in, then write: ```js // In rollup.config.js: nodeExternals({ - include: '@/mylib' + include: '@/lib' }) ``` @@ -180,13 +180,13 @@ export default { } ``` -As a general rule of thumb, you will want to always make this plugin the first one in the `plugins` array. +Note that as of version 7, this plugin's `resolveId` hook has a `order: 'pre'` property that will make Rollup call it very early in the module resolution process. Nevertheless, it is best to always make this plugin the first one in the `plugins` array. ### 4/ Rollup rules Rollup's own `external` configuration option always takes precedence over this plugin. This is intentional. ### 5/ Using with Vite -While this plugin has always been compatible with Vite, it was previously necessary to use the following `vite.config.js` to make it work reliably in every situations: +While this plugin has always been compatible with Vite, it was previously necessary to use the following `vite.config.js` to make it work reliably in every situation: ```js import { defineConfig } from 'vite' diff --git a/source/index.ts b/source/index.ts index b74372b..c0e84ec 100644 --- a/source/index.ts +++ b/source/index.ts @@ -90,7 +90,7 @@ interface PackageJson { // Get our own name and version const { name, version } = createRequire(import.meta.url)('../package.json') as PackageJson -// Files that mark the root of a workspace +// Files that mark the root of a monorepo const workspaceRootFiles = new Set([ 'pnpm-workspace.yaml', // pnpm 'lerna.json', // Lerna @@ -125,8 +125,8 @@ function nodeExternals(options: ExternalsOptions = {}): Plugin { const config: Config = { ...defaults, ...options } - let include: RegExp[] = [], // Initialized to empty arrays - exclude: RegExp[] = [] // as a workaround to https://github.com/Septh/rollup-plugin-node-externals/issues/30 + let include: RegExp[] = [], // Initialized to empty arrays as a workaround + exclude: RegExp[] = [] // to https://github.com/Septh/rollup-plugin-node-externals/issues/30 const isIncluded = (id: string) => include.length > 0 && include.some(rx => rx.test(id)), isExcluded = (id: string) => exclude.length > 0 && exclude.some(rx => rx.test(id)) @@ -157,9 +157,9 @@ function nodeExternals(options: ExternalsOptions = {}): Plugin { // from cwd up to the root of the git repo, the root of the monorepo, // or the root of the volume, whichever comes first. const packagePaths = ([] as string[]) - .concat(config.packagePath) - .filter(isString) - .map(packagePath => path.resolve(packagePath)) + .concat(config.packagePath) + .filter(isString) + .map(packagePath => path.resolve(packagePath)) if (packagePaths.length === 0) { for ( let current = process.cwd(), previous: string | undefined = undefined;