Skip to content
This repository has been archived by the owner on Feb 17, 2023. It is now read-only.

Commit

Permalink
fix: fixed HMR of styles on template change (#153) (#170)
Browse files Browse the repository at this point in the history
  • Loading branch information
mihalikv authored Jan 25, 2022
1 parent df64cc8 commit 38b6d4f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/hmr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
setPrevDescriptor,
} from './utils/descriptorCache'
import { ModuleNode, HmrContext } from 'vite'
import { isCSSRequest } from './utils/css'
import { ResolvedOptions } from './index'
import { SFCBlock } from '@vue/component-compiler-utils'

Expand Down Expand Up @@ -114,6 +115,12 @@ export async function handleHotUpdate(
// template is inlined into main, add main module instead
if (!templateModule) {
affectedModules.add(mainModule)
} else if (mainModule) {
for (const importer of mainModule.importers) {
if (isCSSRequest(importer.url)) {
affectedModules.add(importer)
}
}
}
}
if (didUpdateStyle) {
Expand Down
5 changes: 5 additions & 0 deletions src/utils/css.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const cssLangs = `\\.(css|less|sass|scss|styl|stylus|pcss|postcss)($|\\?)`
const cssLangRE = new RegExp(cssLangs)

export const isCSSRequest = (request: string): boolean =>
cssLangRE.test(request)

0 comments on commit 38b6d4f

Please sign in to comment.