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): support scss/sass/less... hmr on custom template languages(fix #10677) #10844

Merged
merged 5 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/plugin-vue/src/handleHotUpdate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import _debug from 'debug'
import type { SFCBlock, SFCDescriptor } from 'vue/compiler-sfc'
import type { HmrContext, ModuleNode } from 'vite'
import { cssLangs } from 'vite'
import {
createDescriptor,
getDescriptor,
Expand Down Expand Up @@ -147,8 +148,9 @@ export async function handleHotUpdate(
if (!templateModule) {
affectedModules.add(mainModule)
} else if (mainModule && !affectedModules.has(mainModule)) {
const cssLangRE = new RegExp(cssLangs)
const styleImporters = [...mainModule.importers].filter((m) =>
/\.css($|\?)/.test(m.url)
cssLangRE.test(m.url)
)
styleImporters.forEach((m) => affectedModules.add(m))
}
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export { createServer } from './server'
export { preview } from './preview'
export { build } from './build'
export { optimizeDeps } from './optimizer'
export { formatPostcssSourceMap, preprocessCSS } from './plugins/css'
export { formatPostcssSourceMap, preprocessCSS, cssLangs } from './plugins/css'
export { transformWithEsbuild } from './plugins/esbuild'
export { resolvePackageEntry } from './plugins/resolve'
export { resolvePackageData } from './packages'
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export interface CSSModulesOptions {
| null
}

const cssLangs = `\\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)($|\\?)`
export const cssLangs = `\\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)($|\\?)`
benmccann marked this conversation as resolved.
Show resolved Hide resolved
const cssLangRE = new RegExp(cssLangs)
const cssModuleRE = new RegExp(`\\.module${cssLangs}`)
const directRequestRE = /(\?|&)direct\b/
Expand Down