Skip to content

Commit 7f1c1dd

Browse files
authored
fix: use correct self-reference import (#180)
1 parent cfc8de8 commit 7f1c1dd

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

packages/vite/rollup.config.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ const nodeConfig = defineConfig({
115115
constants: path.resolve(__dirname, 'src/node/constants.ts'),
116116
},
117117
external: [
118-
/^vite\//,
119118
'fsevents',
120119
/^rolldown\//,
121120
/^tsx\//,
@@ -124,6 +123,14 @@ const nodeConfig = defineConfig({
124123
...Object.keys(pkg.peerDependencies),
125124
],
126125
plugins: [
126+
{
127+
name: 'externalize-vite',
128+
resolveId(id) {
129+
if (id.startsWith('vite/')) {
130+
return { id: id.replace(/^vite\//, 'rolldown-vite/'), external: true }
131+
}
132+
},
133+
},
127134
// Some deps have try...catch require of optional deps, but rollup will
128135
// generate code that force require them upfront for side effects.
129136
// Shim them with eval() so rollup can skip these calls.

packages/vite/rollup.dts.config.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ const pkg = JSON.parse(
1515

1616
const external = [
1717
/^node:*/,
18-
/^vite\//,
1918
/^rolldown\//,
2019
...Object.keys(pkg.dependencies),
2120
...Object.keys(pkg.peerDependencies),
@@ -32,7 +31,18 @@ export default defineConfig({
3231
format: 'esm',
3332
},
3433
external,
35-
plugins: [patchTypes(), dts({ respectExternal: true })],
34+
plugins: [
35+
{
36+
name: 'externalize-vite',
37+
resolveId(id) {
38+
if (id.startsWith('vite/')) {
39+
return { id: id.replace(/^vite\//, 'rolldown-vite/'), external: true }
40+
}
41+
},
42+
},
43+
patchTypes(),
44+
dts({ respectExternal: true }),
45+
],
3646
})
3747

3848
// Taken from https://stackoverflow.com/a/36328890
@@ -140,7 +150,7 @@ function validateChunkImports(this: PluginContext, chunk: RenderedChunk) {
140150
!id.startsWith('../') &&
141151
!id.startsWith('node:') &&
142152
!id.startsWith('types.d') &&
143-
!id.startsWith('vite/') &&
153+
!id.startsWith('rolldown-vite/') &&
144154
// index and moduleRunner have a common chunk "moduleRunnerTransport"
145155
!id.startsWith('moduleRunnerTransport.d') &&
146156
!deps.includes(id) &&

0 commit comments

Comments
 (0)