Skip to content

Commit 93c444c

Browse files
authored
fix(plugin-vue): hmr not working when updating script+template at the same time with a template preprocessor (#106)
Fixes #28 Fixes #76
1 parent 7466b4f commit 93c444c

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

packages/plugin-vue/src/template.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type {
77
SFCTemplateCompileResults,
88
} from 'vue/compiler-sfc'
99
import type { PluginContext, TransformPluginContext } from 'rollup'
10-
import { getResolvedScript } from './script'
10+
import { getResolvedScript, resolveScript } from './script'
1111
import { createRollupError } from './utils/error'
1212
import type { ResolvedOptions } from '.'
1313

@@ -70,6 +70,7 @@ export function compile(
7070
ssr: boolean,
7171
) {
7272
const filename = descriptor.filename
73+
resolveScript(descriptor, options, ssr)
7374
const result = options.compiler.compileTemplate({
7475
...resolveTemplateCompilerOptions(descriptor, options, ssr)!,
7576
source: code,

playground/vue/Main.vue

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<TypeProps msg="msg" bar="bar" :id="123" />
1212
<Syntax />
1313
<PreProcessors />
14+
<PreProcessorsHmr />
1415
<CssModules />
1516
<Assets />
1617
<CustomBlock />
@@ -36,6 +37,7 @@ import Hmr from './Hmr.vue'
3637
import HmrTsx from './HmrTsx.vue'
3738
import Syntax from './Syntax.vue'
3839
import PreProcessors from './PreProcessors.vue'
40+
import PreProcessorsHmr from './PreProcessorsHmr.vue'
3941
import CssModules from './CssModules.vue'
4042
import Assets from './Assets.vue'
4143
import CustomBlock from './CustomBlock.vue'

playground/vue/PreProcessorsHmr.vue

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<template lang="pug">
2+
h2.pre-processors-hmr Pre-Processors Hmr
3+
p.pug-hmr {{ preHmr }}
4+
</template>
5+
6+
<script setup>
7+
const preHmr = 'pre-hmr'
8+
</script>

playground/vue/__tests__/vue.spec.ts

+10
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,16 @@ describe('pre-processors', () => {
9595
)
9696
await untilUpdated(() => getColor('p.pug-stylus'), 'orange')
9797
})
98+
99+
test('pug hmr', async () => {
100+
expect(await page.textContent('p.pug-hmr')).toMatch('pre-hmr')
101+
editFile('PreProcessorsHmr.vue', (code) =>
102+
code
103+
.replace('p.pug-hmr {{ preHmr }}', 'p.pug-hmr {{ postHmr }}')
104+
.replace(`const preHmr = 'pre-hmr'`, `const postHmr = 'post-hmr'`),
105+
)
106+
await untilUpdated(() => page.textContent('p.pug-hmr'), 'post-hmr')
107+
})
98108
})
99109

100110
describe('css modules', () => {

0 commit comments

Comments
 (0)