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 @@ + + + +