Skip to content

Commit

Permalink
feat: add noExternal option
Browse files Browse the repository at this point in the history
skip-release
  • Loading branch information
egoist committed Nov 25, 2021
1 parent 8cadbb1 commit f7ed948
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 15 deletions.
22 changes: 9 additions & 13 deletions src/esbuild/external.ts
Expand Up @@ -5,11 +5,13 @@ import { tsconfigPathsToRegExp, match } from 'bundle-require'
const NON_NODE_MODULE_RE = /^[^.\/]|^\.[^.\/]|^\.\.[^\/]/

export const externalPlugin = ({
patterns,
external,
noExternal,
skipNodeModulesBundle,
tsconfigResolvePaths,
}: {
patterns?: (string | RegExp)[]
external?: (string | RegExp)[]
noExternal?: (string | RegExp)[]
skipNodeModulesBundle?: boolean
tsconfigResolvePaths?: Record<string, any>
}): Plugin => {
Expand All @@ -35,18 +37,12 @@ export const externalPlugin = ({
})
}

if (!patterns || patterns.length === 0) return

build.onResolve({ filter: /.*/ }, (args) => {
const external = patterns.some((p) => {
if (p instanceof RegExp) {
return p.test(args.path)
}
return args.path === p
})

if (external) {
return { path: args.path, external }
if (match(args.path, noExternal)) {
return
}
if (match(args.path, external)) {
return { external: true }
}
})
},
Expand Down
2 changes: 1 addition & 1 deletion src/esbuild/index.ts
Expand Up @@ -102,7 +102,7 @@ export async function runEsbuild(
// So here we use a custom plugin to implement it
format !== 'iife' &&
externalPlugin({
patterns: external,
external,
skipNodeModulesBundle: options.skipNodeModulesBundle,
tsconfigResolvePaths: options.tsconfigResolvePaths,
}),
Expand Down
4 changes: 3 additions & 1 deletion src/options.ts
Expand Up @@ -50,7 +50,9 @@ export type Options = {
}
dts?: boolean | string | DtsConfig
sourcemap?: BuildOptions['sourcemap']
/** Don't bundle these packages */
/** Always bundle modules matching given patterns */
noExternal?: (string | RegExp)[]
/** Don't bundle these modules */
external?: (string | RegExp)[]
/** Transform the result with `@babel/core` */
babel?: boolean
Expand Down

1 comment on commit f7ed948

@vercel
Copy link

@vercel vercel bot commented on f7ed948 Nov 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.