Skip to content

Commit 5a5a9b1

Browse files
committed
Fix #30
1 parent e174cb9 commit 5a5a9b1

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ dist/
33
out/
44
zz*
55
/.np-config.json
6+
/*.tgz

source/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,22 +118,23 @@ const isString = (str: unknown): str is string =>
118118
typeof str === 'string' && str.length > 0
119119

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

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

128-
let include: RegExp[],
129-
exclude: RegExp[]
128+
let include: RegExp[] = [], // Initialized to empty arrays
129+
exclude: RegExp[] = [] // as a workaround to https://github.com/Septh/rollup-plugin-node-externals/issues/30
130130

131131
const isIncluded = (id: string) => include.length > 0 && include.some(rx => rx.test(id)),
132132
isExcluded = (id: string) => exclude.length > 0 && exclude.some(rx => rx.test(id))
133133

134134
return {
135135
name: name.replace(/^rollup-plugin-/, ''),
136136
version,
137+
enforce: 'pre', // For Vite
137138

138139
async buildStart() {
139140

@@ -258,7 +259,7 @@ function nodeExternals(options: ExternalsOptions = {}): Plugin {
258259
: null // normal handling
259260
}
260261
}
261-
}
262+
} as Plugin & { enforce: 'pre' | 'post' }
262263
}
263264

264265
export default nodeExternals

0 commit comments

Comments
 (0)