diff --git a/packages/vite/misc/rolldown-runtime.js b/packages/vite/misc/rolldown-runtime.js index 1a2ce4e5cb1b3c..86b99004b9b7cd 100644 --- a/packages/vite/misc/rolldown-runtime.js +++ b/packages/vite/misc/rolldown-runtime.js @@ -126,6 +126,8 @@ var rolldown_runtime = (self.rolldown_runtime = { }) } }, + // TODO: import.meta.hot.on + on: () => {}, }, }) this.executeModuleStack.push(id) diff --git a/packages/vite/src/node/server/environments/rolldown.ts b/packages/vite/src/node/server/environments/rolldown.ts index 225d05ca716255..9205e4b4aef095 100644 --- a/packages/vite/src/node/server/environments/rolldown.ts +++ b/packages/vite/src/node/server/environments/rolldown.ts @@ -205,6 +205,7 @@ class RolldownEnvironment extends DevEnvironment { 'vite:css', 'vite:css-post', 'vite:asset', + 'vite:vue', ].includes(p.name) || [ 'AliasPlugin', @@ -230,6 +231,20 @@ class RolldownEnvironment extends DevEnvironment { patchRuntimePlugin(this), patchCssPlugin(), reactRefreshPlugin(), + { + // TODO: import.meta not supported by app format + name: 'patch-import-meta', + transform: { + filter: { + code: [/import\.meta\.hot/], + }, + handler(code) { + const output = new MagicString(code) + output.replaceAll('import.meta.hot', 'module.hot') + return { code: output.toString(), map: output.generateMap() } + }, + }, + }, ], moduleTypes: { '.css': 'js', diff --git a/playground/rolldown-dev-vue/__tests__/basic.spec.ts b/playground/rolldown-dev-vue/__tests__/basic.spec.ts new file mode 100644 index 00000000000000..7a47a7182ace0b --- /dev/null +++ b/playground/rolldown-dev-vue/__tests__/basic.spec.ts @@ -0,0 +1,18 @@ +import { test } from 'vitest' +import { editFile, isBuild, page, viteTestUrl } from '../../test-utils' + +test('basic', async () => { + await page.getByRole('button', { name: 'Count: 0' }).click() + await page.getByRole('button', { name: 'Count: 1' }).click() +}) + +test.runIf(!isBuild)('hmr js', async () => { + await page.goto(viteTestUrl) + await page.getByRole('button', { name: 'Count: 0' }).click() + + editFile('./src/App.vue', (s) => s.replace('Count:', 'Count-x:')) + await page.getByRole('button', { name: 'Count-x: 1' }).click() + + editFile('./src/app.tsx', (s) => s.replace('Count-x:', 'Count:')) + await page.getByRole('button', { name: 'Count: 2' }).click() +}) diff --git a/playground/rolldown-dev-vue/index.html b/playground/rolldown-dev-vue/index.html new file mode 100644 index 00000000000000..a1c813e07a7db0 --- /dev/null +++ b/playground/rolldown-dev-vue/index.html @@ -0,0 +1,10 @@ + + + + + + +
+ + + diff --git a/playground/rolldown-dev-vue/package.json b/playground/rolldown-dev-vue/package.json new file mode 100644 index 00000000000000..25009cbd56b515 --- /dev/null +++ b/playground/rolldown-dev-vue/package.json @@ -0,0 +1,16 @@ +{ + "name": "@vitejs/test-rolldown-dev-vue", + "private": true, + "type": "module", + "scripts": { + "dev": "vite", + "build": "vite build", + "preview": "vite preview" + }, + "dependencies": { + "vue": "^3.5.13" + }, + "devDependencies": { + "@vitejs/plugin-vue": "^5.2.1" + } +} diff --git a/playground/rolldown-dev-vue/src/App.vue b/playground/rolldown-dev-vue/src/App.vue new file mode 100644 index 00000000000000..5c470b8f87b816 --- /dev/null +++ b/playground/rolldown-dev-vue/src/App.vue @@ -0,0 +1,11 @@ + + + + + diff --git a/playground/rolldown-dev-vue/src/main.js b/playground/rolldown-dev-vue/src/main.js new file mode 100644 index 00000000000000..01433bca2ac765 --- /dev/null +++ b/playground/rolldown-dev-vue/src/main.js @@ -0,0 +1,4 @@ +import { createApp } from 'vue' +import App from './App.vue' + +createApp(App).mount('#app') diff --git a/playground/rolldown-dev-vue/vite.config.ts b/playground/rolldown-dev-vue/vite.config.ts new file mode 100644 index 00000000000000..33b063489fd06e --- /dev/null +++ b/playground/rolldown-dev-vue/vite.config.ts @@ -0,0 +1,20 @@ +import { defineConfig } from 'vite' +import vue from '@vitejs/plugin-vue' + +export default defineConfig({ + clearScreen: false, + experimental: { + rolldownDev: { + hmr: true, + }, + }, + plugins: [ + vue(), + { + name: 'debug', + buildEnd(err) { + console.log('[buildEnd]', err) + }, + }, + ], +}) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 310c0db645d215..306efee178a09f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1357,6 +1357,16 @@ importers: specifier: ^18.3.1 version: 18.3.1 + playground/rolldown-dev-vue: + dependencies: + vue: + specifier: ^3.5.13 + version: 3.5.13(typescript@5.6.3) + devDependencies: + '@vitejs/plugin-vue': + specifier: ^5.2.1 + version: 5.2.1(vite@packages+vite)(vue@3.5.13(typescript@5.6.3)) + playground/self-referencing: {} playground/ssr: @@ -3344,6 +3354,13 @@ packages: vite: workspace:* vue: ^3.2.25 + '@vitejs/plugin-vue@5.2.1': + resolution: {integrity: sha512-cxh314tzaWwOLqVes2gnnCtvBDcM1UMdn+iFR+UjAn411dPT3tOmqrJjbMd7koZpMAmBM/GqeV4n9ge7JSiJJQ==} + engines: {node: ^18.0.0 || >=20.0.0} + peerDependencies: + vite: workspace:* + vue: ^3.2.25 + '@vitejs/release-scripts@1.3.2': resolution: {integrity: sha512-g4jaMHxdjPiGlFV8qSq8EaE3SYtLHeEGGfmVASvJ+mn+W0kKH0nDXO3u9RR25zVbW9ooamQcpEAx2fTMhlwvkg==} @@ -9078,6 +9095,11 @@ snapshots: vite: link:packages/vite vue: 3.5.13(typescript@5.6.3) + '@vitejs/plugin-vue@5.2.1(vite@packages+vite)(vue@3.5.13(typescript@5.6.3))': + dependencies: + vite: link:packages/vite + vue: 3.5.13(typescript@5.6.3) + '@vitejs/release-scripts@1.3.2': dependencies: execa: 8.0.1