Skip to content

Commit b120a59

Browse files
committed
feat: allow using parseAst from rollup with VITE_USE_LEGACY_PARSE_AST
1 parent 608039f commit b120a59

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

packages/vite/rollup.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ const nodeConfig = defineConfig({
110110
external: [
111111
/^vite\//,
112112
'fsevents',
113+
'rollup/parseAst',
113114
'rolldown/parseAst',
114115
'rolldown/experimental',
115116
/^tsx\//,

packages/vite/src/node/server/pluginContainer.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ export function throwClosedServerError(): never {
119119
throw err
120120
}
121121

122+
// NOTE: add a env var to use parseAst from rollup for now
123+
const useLegacyParseAst = !!process.env.VITE_USE_LEGACY_PARSE_AST
124+
let legacyParseAst: typeof import('rollup/parseAst').parseAst
125+
122126
export interface PluginContainerOptions {
123127
cwd?: string
124128
output?: OutputOptions
@@ -141,6 +145,9 @@ export async function createEnvironmentPluginContainer(
141145
plugins,
142146
watcher,
143147
)
148+
if (useLegacyParseAst) {
149+
legacyParseAst = await import('rollup/parseAst').then((mod) => mod.parseAst)
150+
}
144151
await container.resolveRollupOptions()
145152
return container
146153
}
@@ -578,6 +585,9 @@ class PluginContext
578585
}
579586

580587
parse(code: string, opts: any) {
588+
if (useLegacyParseAst) {
589+
return legacyParseAst(code, opts)
590+
}
581591
return rolldownParseAst(code, opts)
582592
}
583593

0 commit comments

Comments
 (0)