fix: modules should not be externalized in iife format

This commit is contained in:
EGOIST 2021-09-26 20:42:05 +08:00
parent eceda2fbda
commit f29ec8fca8
2 changed files with 8 additions and 2 deletions

View File

@ -6,14 +6,18 @@ const NON_NODE_MODULE_RE = /^[^.\/]|^\.[^.\/]|^\.\.[^\/]/
export const externalPlugin = ({
patterns,
skipNodeModulesBundle,
disabled,
}: {
patterns?: (string | RegExp)[]
skipNodeModulesBundle?: boolean
disabled?: boolean
}): Plugin => {
return {
name: `external`,
setup(build) {
if (disabled) return
if (skipNodeModulesBundle) {
build.onResolve({ filter: NON_NODE_MODULE_RE }, (args) => ({
path: args.path,

View File

@ -184,6 +184,8 @@ export async function runEsbuild(
// esbuild's `external` option doesn't support RegExp
// So here we use a custom plugin to implement it
externalPlugin({
// everything should be bundled for iife format
disabled: format === 'iife',
patterns: external,
skipNodeModulesBundle: options.skipNodeModulesBundle,
}),
@ -360,8 +362,8 @@ const normalizeOptions = async (
log('CLI', 'info', `Building entry: ${options.entryPoints.join(', ')}`)
}
} else {
Object.keys(input).forEach(alias => {
const filename = input[alias]!;
Object.keys(input).forEach((alias) => {
const filename = input[alias]!
if (!fs.existsSync(filename)) {
throw new PrettyError(`Cannot find ${alias}: ${filename}`)
}