Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(plugin-vue): hmr not working when updating script+template at the same time with a template preprocessor #106

Merged
merged 2 commits into from
Jul 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/plugin-vue/src/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type {
SFCTemplateCompileResults,
} from 'vue/compiler-sfc'
import type { PluginContext, TransformPluginContext } from 'rollup'
import { getResolvedScript } from './script'
import { getResolvedScript, resolveScript } from './script'
import { createRollupError } from './utils/error'
import type { ResolvedOptions } from '.'

Expand Down Expand Up @@ -68,6 +68,7 @@ export function compile(
ssr: boolean,
) {
const filename = descriptor.filename
resolveScript(descriptor, options, ssr)
const result = options.compiler.compileTemplate({
...resolveTemplateCompilerOptions(descriptor, options, ssr)!,
source: code,
Expand Down
2 changes: 2 additions & 0 deletions playground/vue/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
</div>
<Syntax />
<PreProcessors />
<PreProcessorsHmr />
<CssModules />
<Assets />
<CustomBlock />
Expand All @@ -33,6 +34,7 @@ import Hmr from './Hmr.vue'
import HmrTsx from './HmrTsx.vue'
import Syntax from './Syntax.vue'
import PreProcessors from './PreProcessors.vue'
import PreProcessorsHmr from './PreProcessorsHmr.vue'
import CssModules from './CssModules.vue'
import Assets from './Assets.vue'
import CustomBlock from './CustomBlock.vue'
Expand Down
8 changes: 8 additions & 0 deletions playground/vue/PreProcessorsHmr.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<template lang="pug">
h2.pre-processors-hmr Pre-Processors Hmr
p.pug-hmr {{ preHmr }}
</template>

<script setup>
const preHmr = 'pre-hmr'
</script>
10 changes: 10 additions & 0 deletions playground/vue/__tests__/vue.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,16 @@ describe('pre-processors', () => {
)
await untilUpdated(() => getColor('p.pug-stylus'), 'orange')
})

test('pug hmr', async () => {
expect(await page.textContent('p.pug-hmr')).toMatch('pre-hmr')
editFile('PreProcessorsHmr.vue', (code) =>
code
.replace('p.pug-hmr {{ preHmr }}', 'p.pug-hmr {{ postHmr }}')
.replace(`const preHmr = 'pre-hmr'`, `const postHmr = 'post-hmr'`),
)
await untilUpdated(() => page.textContent('p.pug-hmr'), 'post-hmr')
})
})

describe('css modules', () => {
Expand Down