Skip to content

Commit

Permalink
Fix #30
Browse files Browse the repository at this point in the history
  • Loading branch information
Septh committed Apr 25, 2024
1 parent e174cb9 commit 5a5a9b1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ dist/
out/
zz*
/.np-config.json
/*.tgz
9 changes: 5 additions & 4 deletions source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,22 +118,23 @@ const isString = (str: unknown): str is string =>
typeof str === 'string' && str.length > 0

/**
* A Rollup plugin that automatically declares NodeJS built-in modules,
* A Rollup/Vite plugin that automatically declares NodeJS built-in modules,
* and optionally npm dependencies, as 'external'.
*/
function nodeExternals(options: ExternalsOptions = {}): Plugin {

const config: Config = { ...defaults, ...options }

let include: RegExp[],
exclude: RegExp[]
let include: RegExp[] = [], // Initialized to empty arrays
exclude: RegExp[] = [] // as a workaround 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))

return {
name: name.replace(/^rollup-plugin-/, ''),
version,
enforce: 'pre', // For Vite

async buildStart() {

Expand Down Expand Up @@ -258,7 +259,7 @@ function nodeExternals(options: ExternalsOptions = {}): Plugin {
: null // normal handling
}
}
}
} as Plugin & { enforce: 'pre' | 'post' }
}

export default nodeExternals
Expand Down

0 comments on commit 5a5a9b1

Please sign in to comment.