Skip to content

Commit 960e9ef

Browse files
renovate[bot]h-a-n-ashulaodasapphi-red
authored
feat: update rolldown-related dependencies and use client-side HMR in bundled-dev (#22961)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Hana <shuyuan@voidzero.dev> Co-authored-by: shulaoda <165626830+shulaoda@users.noreply.github.com> Co-authored-by: andrew <andywangsy@gmail.com> Co-authored-by: 翠 <green@sapphi.red>
1 parent c60b4d7 commit 960e9ef

36 files changed

Lines changed: 1173 additions & 652 deletions

docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"@voidzero-dev/vitepress-theme": "^5.0.2",
1515
"feed": "^6.0.0",
1616
"markdown-it-image-size": "^15.0.1",
17-
"oxc-minify": "^0.139.0",
17+
"oxc-minify": "^0.140.0",
1818
"vitepress": "^2.0.0-alpha.18",
1919
"vitepress-plugin-graphviz": "^0.1.0",
2020
"vitepress-plugin-group-icons": "^1.7.5",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
"oxfmt": "^0.59.0",
6565
"picocolors": "^1.1.1",
6666
"playwright-chromium": "^1.61.1",
67-
"rolldown": "~1.1.5",
67+
"rolldown": "~1.2.0",
6868
"rollup": "^4.59.0",
6969
"simple-git-hooks": "^2.13.1",
7070
"tsx": "^4.23.1",

packages/create-vite/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"@vercel/detect-agent": "^1.2.3",
3939
"cross-spawn": "^7.0.6",
4040
"mri": "^1.2.0",
41-
"tsdown": "^0.22.5",
41+
"tsdown": "^0.22.8",
4242
"unrun": "^0.3.1"
4343
}
4444
}

packages/plugin-legacy/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"devDependencies": {
5555
"acorn": "^8.17.0",
5656
"picocolors": "^1.1.1",
57-
"tsdown": "^0.22.5",
57+
"tsdown": "^0.22.8",
5858
"unrun": "^0.3.1",
5959
"vite": "workspace:*"
6060
},

packages/vite/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"lightningcss": "^1.33.0",
7373
"picomatch": "^4.0.5",
7474
"postcss": "^8.5.20",
75-
"rolldown": "~1.1.5",
75+
"rolldown": "~1.2.0",
7676
"tinyglobby": "^0.2.17"
7777
},
7878
"devDependencies": {
@@ -122,7 +122,7 @@
122122
"postcss-modules": "^9.0.1",
123123
"premove": "^4.0.0",
124124
"resolve.exports": "^2.0.3",
125-
"rolldown-plugin-dts": "^0.27.6",
125+
"rolldown-plugin-dts": "^0.27.9",
126126
"rollup": "^4.59.0",
127127
"rollup-plugin-license": "^3.7.1",
128128
"sass": "^1.101.0",

packages/vite/rolldown.config.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const envConfig = defineConfig({
2626
})
2727

2828
const clientConfig = defineConfig({
29-
input: path.resolve(dirname, 'src/client/client.ts'),
29+
input: path.resolve(dirname, 'src/client/clientEntry.ts'),
3030
platform: 'browser',
3131
transform: {
3232
target: 'es2020',
@@ -38,6 +38,20 @@ const clientConfig = defineConfig({
3838
},
3939
})
4040

41+
// separate entry so the full-bundle-mode HMR code is never bundled into `client.mjs`
42+
const bundledDevClientConfig = defineConfig({
43+
input: path.resolve(dirname, 'src/client/bundledDevClient.ts'),
44+
platform: 'browser',
45+
transform: {
46+
target: 'es2020',
47+
},
48+
external: ['@vite/env'],
49+
output: {
50+
dir: path.resolve(dirname, 'dist'),
51+
entryFileNames: 'client/bundledDevClient.mjs',
52+
},
53+
})
54+
4155
const sharedNodeOptions = defineConfig({
4256
platform: 'node',
4357
treeshake: {
@@ -155,6 +169,7 @@ const moduleRunnerConfig = defineConfig({
155169
export default defineConfig([
156170
envConfig,
157171
clientConfig,
172+
bundledDevClientConfig,
158173
nodeConfig,
159174
moduleRunnerConfig,
160175
])
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { nanoid } from 'nanoid/non-secure'
2+
import type { DevRuntime as DevRuntimeType } from 'rolldown/experimental/runtime-types'
3+
import {
4+
BundledDevHMRClient,
5+
BundledDevHMRContext,
6+
} from './bundledDevHmrClient'
7+
import {
8+
base,
9+
clearOverlayOrReloadOnFirstUpdate,
10+
pageReload,
11+
registerBundledDevClient,
12+
removeStyle,
13+
transport,
14+
updateStyle,
15+
} from './client'
16+
17+
// keep the same public exports as `client.ts`, which this entry replaces when inlined
18+
export {
19+
createHotContext,
20+
injectQuery,
21+
removeStyle,
22+
updateStyle,
23+
ErrorOverlay,
24+
} from './client'
25+
26+
// injected by rolldown's hmr plugin into the bundle prelude, ahead of this client
27+
declare const DevRuntime: typeof DevRuntimeType
28+
29+
if (typeof DevRuntime !== 'undefined') {
30+
class ViteDevRuntime extends DevRuntime {
31+
override createModuleHotContext(moduleId: string) {
32+
const ctx = new BundledDevHMRContext(bundledDevHmrClient, moduleId)
33+
// @ts-expect-error TODO: support CSS properly
34+
ctx._internal = { updateStyle, removeStyle }
35+
return ctx
36+
}
37+
}
38+
39+
const clientId = nanoid()
40+
41+
transport.send({
42+
type: 'custom',
43+
event: 'vite:client-connected',
44+
data: { clientId },
45+
})
46+
47+
const runtime = ((globalThis as any).__rolldown_runtime__ ??=
48+
new ViteDevRuntime(clientId))
49+
50+
const bundledDevHmrClient = new BundledDevHMRClient(
51+
{
52+
error: (err) => console.error('[vite]', err),
53+
debug: (...msg) => console.debug('[vite]', ...msg),
54+
},
55+
transport,
56+
runtime,
57+
{
58+
base,
59+
beforeApply: clearOverlayOrReloadOnFirstUpdate,
60+
pageReload,
61+
},
62+
)
63+
registerBundledDevClient(bundledDevHmrClient)
64+
65+
runtime.hooks = {
66+
createModuleHotContext: (id: string) => runtime.createModuleHotContext(id),
67+
onModuleCacheRemoval: (id: string) =>
68+
bundledDevHmrClient.handleModuleCacheRemoval(id),
69+
}
70+
}

0 commit comments

Comments
 (0)