From e3230000ff04deac6057ee0e59861d04da97fa8e Mon Sep 17 00:00:00 2001 From: Mr-ccyou <1787176370@qq.com> Date: Wed, 9 Nov 2022 15:03:11 +0800 Subject: [PATCH 1/4] fix(plugin-vue): trigger scss hmr on custom template languages(fix #10677) --- packages/plugin-vue/src/handleHotUpdate.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/plugin-vue/src/handleHotUpdate.ts b/packages/plugin-vue/src/handleHotUpdate.ts index 0db6b23f936280..b58c07449071ca 100644 --- a/packages/plugin-vue/src/handleHotUpdate.ts +++ b/packages/plugin-vue/src/handleHotUpdate.ts @@ -147,8 +147,10 @@ export async function handleHotUpdate( if (!templateModule) { affectedModules.add(mainModule) } else if (mainModule && !affectedModules.has(mainModule)) { + const cssLangs = `\\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)($|\\?)` + 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)) } From 1502f680f09761b2642243862a9ea3576bab1204 Mon Sep 17 00:00:00 2001 From: "[Jevon-cc]" <[1787176370@qq.com]> Date: Sat, 12 Nov 2022 09:23:30 +0800 Subject: [PATCH 2/4] chore: import cssLangs rather than duplicating it --- packages/plugin-vue/src/handleHotUpdate.ts | 2 +- packages/vite/src/node/plugins/css.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/plugin-vue/src/handleHotUpdate.ts b/packages/plugin-vue/src/handleHotUpdate.ts index b58c07449071ca..37f0c4edad87c3 100644 --- a/packages/plugin-vue/src/handleHotUpdate.ts +++ b/packages/plugin-vue/src/handleHotUpdate.ts @@ -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/src/node/plugins/css' import { createDescriptor, getDescriptor, @@ -147,7 +148,6 @@ export async function handleHotUpdate( if (!templateModule) { affectedModules.add(mainModule) } else if (mainModule && !affectedModules.has(mainModule)) { - const cssLangs = `\\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)($|\\?)` const cssLangRE = new RegExp(cssLangs) const styleImporters = [...mainModule.importers].filter((m) => cssLangRE.test(m.url) diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index c14269ccf99734..6704f22d52ce0d 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -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)($|\\?)` const cssLangRE = new RegExp(cssLangs) const cssModuleRE = new RegExp(`\\.module${cssLangs}`) const directRequestRE = /(\?|&)direct\b/ From 01a2381f6ce81017f8f8d469facbac84a7614cac Mon Sep 17 00:00:00 2001 From: "[Jevon-cc]" <[1787176370@qq.com]> Date: Sat, 12 Nov 2022 10:02:12 +0800 Subject: [PATCH 3/4] chore: export cssLangs from vite --- packages/plugin-vue/src/handleHotUpdate.ts | 2 +- packages/vite/src/node/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/plugin-vue/src/handleHotUpdate.ts b/packages/plugin-vue/src/handleHotUpdate.ts index 37f0c4edad87c3..9f96da945bf436 100644 --- a/packages/plugin-vue/src/handleHotUpdate.ts +++ b/packages/plugin-vue/src/handleHotUpdate.ts @@ -1,7 +1,7 @@ import _debug from 'debug' import type { SFCBlock, SFCDescriptor } from 'vue/compiler-sfc' import type { HmrContext, ModuleNode } from 'vite' -import { cssLangs } from 'vite/src/node/plugins/css' +import { cssLangs } from 'vite' import { createDescriptor, getDescriptor, diff --git a/packages/vite/src/node/index.ts b/packages/vite/src/node/index.ts index f0d1276ecbc604..16be22676bab37 100644 --- a/packages/vite/src/node/index.ts +++ b/packages/vite/src/node/index.ts @@ -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' From 3464b6e37b3776c2df03f14bb8ebcc8895348909 Mon Sep 17 00:00:00 2001 From: Mr-ccyou <1787176370@qq.com> Date: Mon, 14 Nov 2022 11:38:27 +0800 Subject: [PATCH 4/4] chore: import isCssRequest from vite --- packages/plugin-vue/src/handleHotUpdate.ts | 6 +++--- packages/vite/src/node/index.ts | 2 +- packages/vite/src/node/plugins/css.ts | 2 +- packages/vite/src/node/publicUtils.ts | 3 ++- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/plugin-vue/src/handleHotUpdate.ts b/packages/plugin-vue/src/handleHotUpdate.ts index 9f96da945bf436..11be308c8c3cbc 100644 --- a/packages/plugin-vue/src/handleHotUpdate.ts +++ b/packages/plugin-vue/src/handleHotUpdate.ts @@ -1,7 +1,8 @@ import _debug from 'debug' import type { SFCBlock, SFCDescriptor } from 'vue/compiler-sfc' import type { HmrContext, ModuleNode } from 'vite' -import { cssLangs } from 'vite' +import { isCSSRequest } from 'vite' + import { createDescriptor, getDescriptor, @@ -148,9 +149,8 @@ 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) => - cssLangRE.test(m.url) + isCSSRequest(m.url) ) styleImporters.forEach((m) => affectedModules.add(m)) } diff --git a/packages/vite/src/node/index.ts b/packages/vite/src/node/index.ts index 16be22676bab37..f0d1276ecbc604 100644 --- a/packages/vite/src/node/index.ts +++ b/packages/vite/src/node/index.ts @@ -3,7 +3,7 @@ export { createServer } from './server' export { preview } from './preview' export { build } from './build' export { optimizeDeps } from './optimizer' -export { formatPostcssSourceMap, preprocessCSS, cssLangs } from './plugins/css' +export { formatPostcssSourceMap, preprocessCSS } from './plugins/css' export { transformWithEsbuild } from './plugins/esbuild' export { resolvePackageEntry } from './plugins/resolve' export { resolvePackageData } from './packages' diff --git a/packages/vite/src/node/plugins/css.ts b/packages/vite/src/node/plugins/css.ts index 6704f22d52ce0d..c14269ccf99734 100644 --- a/packages/vite/src/node/plugins/css.ts +++ b/packages/vite/src/node/plugins/css.ts @@ -108,7 +108,7 @@ export interface CSSModulesOptions { | null } -export const cssLangs = `\\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)($|\\?)` +const cssLangs = `\\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)($|\\?)` const cssLangRE = new RegExp(cssLangs) const cssModuleRE = new RegExp(`\\.module${cssLangs}`) const directRequestRE = /(\?|&)direct\b/ diff --git a/packages/vite/src/node/publicUtils.ts b/packages/vite/src/node/publicUtils.ts index 5bf523a87f5799..f6cc21ca9243ff 100644 --- a/packages/vite/src/node/publicUtils.ts +++ b/packages/vite/src/node/publicUtils.ts @@ -8,7 +8,8 @@ export { version as esbuildVersion } from 'esbuild' export { VERSION as rollupVersion } from 'rollup' export { splitVendorChunkPlugin, - splitVendorChunk + splitVendorChunk, + isCSSRequest } from './plugins/splitVendorChunk' export { normalizePath, mergeConfig, mergeAlias, createFilter } from './utils' export { send } from './server/send'