Skip to content

Commit 04f6184

Browse files
committed
fix: include v3 bundle candidates in vite hmr
1 parent 0fe0882 commit 04f6184

3 files changed

Lines changed: 13 additions & 3 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"weapp-tailwindcss": patch
3+
---
4+
5+
修复 Tailwind CSS v3 在 Vite 增量构建中只使用 source scan 候选集时遗漏当前 bundle 新增类名的问题,避免 WXML 已转义但 WXSS 未生成对应样式。

packages/weapp-tailwindcss/src/bundlers/vite/generate-bundle.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ interface GenerateBundleContext {
4040
forceRefresh?: boolean,
4141
options?: {
4242
allowBaselineOnlyInitialSync?: boolean | undefined
43+
baseClassSet?: Set<string> | undefined
4344
},
4445
) => Promise<Set<string>>
4546
debug: (format: string, ...args: unknown[]) => void
@@ -168,7 +169,10 @@ export function createGenerateBundleHook(context: GenerateBundleContext) {
168169
&& !disableV3OxideSourceRuntime
169170
const runtimeStart = performance.now()
170171
const runtime = useV3OxideSourceRuntime
171-
? new Set<string>()
172+
? await ensureBundleRuntimeClassSet(snapshot, forceRuntimeRefreshByEnv, {
173+
allowBaselineOnlyInitialSync: true,
174+
baseClassSet: sourceCandidates,
175+
})
172176
: useBundleRuntimeClassSet
173177
? await ensureBundleRuntimeClassSet(snapshot, forceRuntimeRefreshByEnv, {
174178
allowBaselineOnlyInitialSync: buildCommand,

packages/weapp-tailwindcss/src/bundlers/vite/runtime-class-set.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ export function createViteRuntimeClassSet(options: CreateViteRuntimeClassSetOpti
113113
forceRefresh = false,
114114
options: {
115115
allowBaselineOnlyInitialSync?: boolean | undefined
116+
baseClassSet?: Set<string> | undefined
116117
} = {},
117118
) {
118119
const forceRuntimeRefresh = forceRefresh || process.env['WEAPP_TW_VITE_FORCE_RUNTIME_REFRESH'] === '1'
@@ -144,8 +145,8 @@ export function createViteRuntimeClassSet(options: CreateViteRuntimeClassSetOpti
144145

145146
if (runtimeState.twPatcher.majorVersion === 3 && !forceRuntimeRefresh) {
146147
try {
147-
let baseClassSet: Set<string> | undefined
148-
if (!runtimeSet || shouldRefreshPatcher) {
148+
let baseClassSet = options.baseClassSet
149+
if (!baseClassSet && (!runtimeSet || shouldRefreshPatcher)) {
149150
baseClassSet = await collectRuntimeClassSet(runtimeState.twPatcher, {
150151
force: true,
151152
skipRefresh: shouldRefreshPatcher,

0 commit comments

Comments
 (0)