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): trigger css hmr on custom template languages #6987

Merged
merged 3 commits into from
May 13, 2022
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
5 changes: 5 additions & 0 deletions packages/plugin-vue/src/handleHotUpdate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ export async function handleHotUpdate(
// template is inlined into main, add main module instead
if (!templateModule) {
affectedModules.add(mainModule)
} else if (mainModule && !affectedModules.has(mainModule)) {
const styleImporters = [...mainModule.importers].filter((m) =>
/\.css($|\?)/.test(m.url)
)
styleImporters.forEach((m) => affectedModules.add(m))
}
}
if (didUpdateStyle) {
Expand Down
21 changes: 21 additions & 0 deletions playground/tailwind/__test__/tailwind.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
editFile,
untilUpdated,
getColor,
getBgColor,
browserLogs,
page
} from '~utils'
Expand Down Expand Up @@ -64,4 +65,24 @@ if (!isBuild) {

browserLogs.length = 0
})

test('regenerate CSS and HMR (pug template)', async () => {
browserLogs.length = 0
const el = await page.$('.pug')

expect(await getBgColor(el)).toBe('rgb(248, 113, 113)')

editFile('src/components/PugTemplate.vue', (code) =>
code.replace('bg-red-400', 'bg-red-600')
)

await untilUpdated(() => getBgColor(el), 'rgb(220, 38, 38)')

expect(browserLogs).toMatchObject([
'[vite] css hot updated: /index.css',
'[vite] hot updated: /src/components/PugTemplate.vue?vue&type=template&lang.js'
])

browserLogs.length = 0
})
}
3 changes: 3 additions & 0 deletions playground/tailwind/src/components/PugTemplate.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template lang="pug">
.bg-red-400.pug Pug template
</template>
4 changes: 3 additions & 1 deletion playground/tailwind/src/views/Page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@
Tailwind style
</div>
<HelloWorld />
<PugTemplate />
</div>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue'
import HelloWorld from '../components/HelloWorld.vue'
import PugTemplate from '../components/PugTemplate.vue'

export default defineComponent({
components: { HelloWorld },
components: { HelloWorld, PugTemplate },
setup() {
const val = ref(0)

Expand Down