Skip to content

Commit bf394d1

Browse files
committed
optimize rollup external checks ordering
1 parent bf926c8 commit bf394d1

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

.config/rollup.base.config.mjs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,26 @@ export default function baseConfig(extendConfig = {}) {
5656
return {
5757
treeshake: false,
5858
external(rawId) {
59+
// Order checks by likelihood for better performance.
60+
// Externalize Node.js built-ins (most common case).
61+
if (isBuiltin(rawId)) {
62+
return true
63+
}
5964
const id = normalizeId(rawId)
65+
// Externalize TypeScript declaration files.
66+
if (
67+
id.endsWith('.d.ts') ||
68+
id.endsWith('.d.mts') ||
69+
id.endsWith('.d.cts')
70+
) {
71+
return true
72+
}
73+
// Externalize specific external packages.
6074
const pkgName = getPackageName(
6175
id,
6276
path.isAbsolute(id) ? nmPath.length + 1 : 0,
6377
)
64-
return (
65-
id.endsWith('.d.cts') ||
66-
id.endsWith('.d.mts') ||
67-
id.endsWith('.d.ts') ||
68-
EXTERNAL_PACKAGES.has(pkgName) ||
69-
isBuiltin(rawId)
70-
)
78+
return EXTERNAL_PACKAGES.has(pkgName)
7179
},
7280
onwarn(warning, warn) {
7381
// Suppress warnings.

0 commit comments

Comments
 (0)