Skip to content

Commit

Permalink
wip: test vue plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed Dec 5, 2024
1 parent 714079b commit 3b8e8b8
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/vite/misc/rolldown-runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ var rolldown_runtime = (self.rolldown_runtime = {
})
}
},
// TODO: import.meta.hot.on
on: () => {},
},
})
this.executeModuleStack.push(id)
Expand Down
15 changes: 15 additions & 0 deletions packages/vite/src/node/server/environments/rolldown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ class RolldownEnvironment extends DevEnvironment {
'vite:css',
'vite:css-post',
'vite:asset',
'vite:vue',
].includes(p.name) ||
[
'AliasPlugin',
Expand All @@ -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',
Expand Down
18 changes: 18 additions & 0 deletions playground/rolldown-dev-vue/__tests__/basic.spec.ts
Original file line number Diff line number Diff line change
@@ -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()
})
10 changes: 10 additions & 0 deletions playground/rolldown-dev-vue/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.js"></script>
</body>
</html>
16 changes: 16 additions & 0 deletions playground/rolldown-dev-vue/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
11 changes: 11 additions & 0 deletions playground/rolldown-dev-vue/src/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<script setup>
import { ref } from 'vue'
const count = ref(0)
</script>

<template>
<h1>Vite + Vue</h1>
<button type="button" @click="count++">Count: {{ count }}</button>
</template>

<!-- TODO: scoped css -->
4 changes: 4 additions & 0 deletions playground/rolldown-dev-vue/src/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { createApp } from 'vue'
import App from './App.vue'

createApp(App).mount('#app')
20 changes: 20 additions & 0 deletions playground/rolldown-dev-vue/vite.config.ts
Original file line number Diff line number Diff line change
@@ -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)
},
},
],
})
22 changes: 22 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3b8e8b8

Please sign in to comment.