weapp-tailwindcss 4.11.0-alpha.1 → 4.11.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-35EI5JMK.mjs → chunk-23K4XDKF.mjs} +3 -1
- package/dist/chunk-4AFQP74Z.js +24 -0
- package/dist/{chunk-4LPOQMFS.js → chunk-5KSBT6GU.js} +396 -219
- package/dist/{chunk-RRHPTTCP.mjs → chunk-76S2EME4.mjs} +2 -0
- package/dist/{chunk-G3G437UE.js → chunk-7LKMJZD2.js} +2 -2
- package/dist/{chunk-GWDHNCL2.js → chunk-APTYSWEQ.js} +123 -42
- package/dist/{chunk-SQG2MOFQ.js → chunk-CBZ7BRNV.js} +12 -8
- package/dist/{chunk-OV7FX6XR.js → chunk-CRDOWYG4.js} +1 -1
- package/dist/{chunk-JBM3HGHP.mjs → chunk-DFHWHTMB.mjs} +4 -6
- package/dist/{chunk-DOH7FULQ.mjs → chunk-EFBQ4SQR.mjs} +1 -1
- package/dist/{chunk-IEZ5RBMG.mjs → chunk-EW2K6CO5.mjs} +365 -188
- package/dist/{chunk-W2EMGF7H.js → chunk-JS74G7LK.js} +10 -12
- package/dist/{chunk-CZLXTEHN.js → chunk-KIEB7M3C.js} +132 -91
- package/dist/{chunk-ACTJYB33.js → chunk-LL3QUKJI.js} +3 -1
- package/dist/{chunk-FZNYV7VH.mjs → chunk-NAW56TSQ.mjs} +212 -258
- package/dist/{chunk-KKT2DKMW.mjs → chunk-NYDCSSXH.mjs} +91 -10
- package/dist/{chunk-LTJQUORK.js → chunk-OF6MFURR.js} +2 -0
- package/dist/{chunk-R6KEYO3F.mjs → chunk-QO7CF2RF.mjs} +5 -1
- package/dist/{chunk-LD7LZ4IK.mjs → chunk-SRMDDOZQ.mjs} +91 -50
- package/dist/{chunk-G5NLM3AL.js → chunk-V3CX3X6I.js} +278 -324
- package/dist/cli.js +1006 -147
- package/dist/cli.mjs +942 -107
- package/dist/core.d.mts +2 -2
- package/dist/core.d.ts +2 -2
- package/dist/core.js +9 -11
- package/dist/core.mjs +6 -8
- package/dist/css-macro/postcss.js +1 -1
- package/dist/css-macro/postcss.mjs +1 -1
- package/dist/css-macro.js +3 -3
- package/dist/css-macro.mjs +4 -4
- package/dist/defaults.d.mts +2 -2
- package/dist/defaults.d.ts +2 -2
- package/dist/defaults.js +3 -3
- package/dist/defaults.mjs +2 -2
- package/dist/gulp.d.mts +2 -2
- package/dist/gulp.d.ts +2 -2
- package/dist/gulp.js +7 -8
- package/dist/gulp.mjs +6 -7
- package/dist/{index-t_VBjwYm.d.ts → index-BMwzhITq.d.mts} +6 -6
- package/dist/{index-t_VBjwYm.d.mts → index-BMwzhITq.d.ts} +6 -6
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +11 -12
- package/dist/index.mjs +9 -10
- package/dist/postcss-html-transform.js +1 -1
- package/dist/postcss-html-transform.mjs +1 -1
- package/dist/presets.d.mts +2 -2
- package/dist/presets.d.ts +2 -2
- package/dist/presets.js +5 -5
- package/dist/presets.mjs +2 -2
- package/dist/reset.js +1 -1
- package/dist/reset.mjs +1 -1
- package/dist/types.d.mts +4 -4
- package/dist/types.d.ts +4 -4
- package/dist/types.js +1 -1
- package/dist/types.mjs +1 -1
- package/dist/vite.d.mts +2 -2
- package/dist/vite.d.ts +2 -2
- package/dist/vite.js +8 -9
- package/dist/vite.mjs +6 -7
- package/dist/weapp-tw-css-import-rewrite-loader.js +3 -1
- package/dist/weapp-tw-runtime-classset-loader.js +29 -2
- package/dist/webpack.d.mts +2 -2
- package/dist/webpack.d.ts +2 -2
- package/dist/webpack.js +9 -10
- package/dist/webpack.mjs +7 -8
- package/dist/webpack4.d.mts +2 -2
- package/dist/webpack4.d.ts +2 -2
- package/dist/webpack4.js +41 -41
- package/dist/webpack4.mjs +12 -12
- package/package.json +8 -8
- package/dist/chunk-NOKJXG3W.js +0 -29
- package/dist/chunk-QYZCRG7F.mjs +0 -29
|
@@ -5,12 +5,13 @@ import {
|
|
|
5
5
|
ensureMpxTailwindcssAliases,
|
|
6
6
|
getCacheKey,
|
|
7
7
|
hasLoaderEntry,
|
|
8
|
+
hasWatchChanges,
|
|
8
9
|
injectMpxCssRewritePreRules,
|
|
9
10
|
isCssLikeModuleResource,
|
|
10
11
|
isMpx,
|
|
11
12
|
patchMpxLoaderResolve,
|
|
12
13
|
setupMpxTailwindcssRedirect
|
|
13
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-QO7CF2RF.mjs";
|
|
14
15
|
import {
|
|
15
16
|
pushConcurrentTaskFactories,
|
|
16
17
|
resolveDisabledOptions,
|
|
@@ -20,23 +21,24 @@ import {
|
|
|
20
21
|
} from "./chunk-F2CKKG6Q.mjs";
|
|
21
22
|
import {
|
|
22
23
|
processCachedTask
|
|
23
|
-
} from "./chunk-
|
|
24
|
-
import {
|
|
25
|
-
setupPatchRecorder
|
|
26
|
-
} from "./chunk-QYZCRG7F.mjs";
|
|
24
|
+
} from "./chunk-76S2EME4.mjs";
|
|
27
25
|
import {
|
|
28
26
|
createDebug,
|
|
29
27
|
ensureRuntimeClassSet,
|
|
30
28
|
getCompilerContext,
|
|
29
|
+
pluginName,
|
|
30
|
+
setupPatchRecorder
|
|
31
|
+
} from "./chunk-NAW56TSQ.mjs";
|
|
32
|
+
import {
|
|
31
33
|
getRuntimeClassSetSignature,
|
|
32
|
-
|
|
33
|
-
} from "./chunk-
|
|
34
|
+
resolveTailwindcssOptions
|
|
35
|
+
} from "./chunk-EW2K6CO5.mjs";
|
|
34
36
|
import {
|
|
35
37
|
getGroupedEntries
|
|
36
38
|
} from "./chunk-OOHJLO5M.mjs";
|
|
37
39
|
import {
|
|
38
40
|
__dirname
|
|
39
|
-
} from "./chunk-
|
|
41
|
+
} from "./chunk-EFBQ4SQR.mjs";
|
|
40
42
|
|
|
41
43
|
// src/bundlers/webpack/BaseUnifiedPlugin/v5.ts
|
|
42
44
|
import process3 from "process";
|
|
@@ -56,6 +58,9 @@ function setupWebpackV5ProcessAssetsHook(options) {
|
|
|
56
58
|
options: compilerOptions,
|
|
57
59
|
appType,
|
|
58
60
|
runtimeState,
|
|
61
|
+
getRuntimeRefreshRequirement,
|
|
62
|
+
refreshRuntimeMetadata,
|
|
63
|
+
consumeRuntimeRefreshRequirement,
|
|
59
64
|
debug: debug2
|
|
60
65
|
} = options;
|
|
61
66
|
const { Compilation, sources } = compiler.webpack;
|
|
@@ -153,12 +158,18 @@ function setupWebpackV5ProcessAssetsHook(options) {
|
|
|
153
158
|
return created;
|
|
154
159
|
};
|
|
155
160
|
const staleClassNameFallback = resolveWebpackStaleClassNameFallback(compilerOptions.staleClassNameFallback, compiler);
|
|
161
|
+
const forceRuntimeRefresh = getRuntimeRefreshRequirement();
|
|
162
|
+
debug2("processAssets ensure runtime set forceRefresh=%s major=%s", forceRuntimeRefresh, runtimeState.twPatcher.majorVersion ?? "unknown");
|
|
156
163
|
const runtimeSet = await ensureRuntimeClassSet(runtimeState, {
|
|
164
|
+
forceRefresh: forceRuntimeRefresh,
|
|
157
165
|
// webpack 的 script-only 热更新可能不会触发 runtime classset loader,
|
|
158
166
|
// 这里强制收集可避免沿用上轮 class set,保证 JS 仅按最新集合精确命中。
|
|
159
167
|
forceCollect: true,
|
|
168
|
+
clearCache: forceRuntimeRefresh,
|
|
160
169
|
allowEmpty: false
|
|
161
170
|
});
|
|
171
|
+
await refreshRuntimeMetadata(forceRuntimeRefresh);
|
|
172
|
+
consumeRuntimeRefreshRequirement();
|
|
162
173
|
const defaultTemplateHandlerOptions = {
|
|
163
174
|
runtimeSet
|
|
164
175
|
};
|
|
@@ -302,6 +313,7 @@ function setupWebpackV5Loaders(options) {
|
|
|
302
313
|
runtimeLoaderPath,
|
|
303
314
|
runtimeCssImportRewriteLoaderPath,
|
|
304
315
|
getClassSetInLoader,
|
|
316
|
+
getRuntimeWatchDependencies,
|
|
305
317
|
debug: debug2
|
|
306
318
|
} = options;
|
|
307
319
|
const isMpxApp = isMpx(appType);
|
|
@@ -317,7 +329,8 @@ function setupWebpackV5Loaders(options) {
|
|
|
317
329
|
appType
|
|
318
330
|
} : void 0;
|
|
319
331
|
const classSetLoaderOptions = {
|
|
320
|
-
getClassSet: getClassSetInLoader
|
|
332
|
+
getClassSet: getClassSetInLoader,
|
|
333
|
+
getWatchDependencies: getRuntimeWatchDependencies
|
|
321
334
|
};
|
|
322
335
|
const { findRewriteAnchor, findClassSetAnchor } = createLoaderAnchorFinders(appType);
|
|
323
336
|
const cssImportRewriteLoaderOptions = runtimeLoaderRewriteOptions ? {
|
|
@@ -445,9 +458,63 @@ var UnifiedWebpackPluginV5 = class {
|
|
|
445
458
|
};
|
|
446
459
|
let runtimeSetPrepared = false;
|
|
447
460
|
let runtimeSetSignature;
|
|
461
|
+
let runtimeRefreshRequiredForCompilation = false;
|
|
462
|
+
const runtimeWatchDependencyFiles = /* @__PURE__ */ new Set();
|
|
463
|
+
const runtimeWatchDependencyContexts = /* @__PURE__ */ new Set();
|
|
464
|
+
let runtimeMetadataPrepared = false;
|
|
465
|
+
const updateRuntimeWatchDependencies = async () => {
|
|
466
|
+
runtimeWatchDependencyFiles.clear();
|
|
467
|
+
runtimeWatchDependencyContexts.clear();
|
|
468
|
+
const tailwindOptions = resolveTailwindcssOptions(runtimeState.twPatcher.options);
|
|
469
|
+
if (tailwindOptions?.config) {
|
|
470
|
+
runtimeWatchDependencyFiles.add(tailwindOptions.config);
|
|
471
|
+
}
|
|
472
|
+
for (const entry of tailwindOptions?.v4?.cssEntries ?? []) {
|
|
473
|
+
runtimeWatchDependencyFiles.add(entry);
|
|
474
|
+
}
|
|
475
|
+
for (const source of tailwindOptions?.v4?.sources ?? []) {
|
|
476
|
+
if (source?.base) {
|
|
477
|
+
runtimeWatchDependencyContexts.add(source.base);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
if (typeof runtimeState.twPatcher.collectContentTokens !== "function") {
|
|
481
|
+
return;
|
|
482
|
+
}
|
|
483
|
+
try {
|
|
484
|
+
const report = await runtimeState.twPatcher.collectContentTokens();
|
|
485
|
+
for (const entry of report.entries ?? []) {
|
|
486
|
+
if (entry.file) {
|
|
487
|
+
runtimeWatchDependencyFiles.add(entry.file);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
for (const source of report.sources ?? []) {
|
|
491
|
+
if (source?.base) {
|
|
492
|
+
runtimeWatchDependencyContexts.add(source.base);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
} catch (error) {
|
|
496
|
+
debug("collect runtime watch dependencies failed: %O", error);
|
|
497
|
+
}
|
|
498
|
+
};
|
|
499
|
+
const ensureRuntimeMetadata = async (force = false) => {
|
|
500
|
+
if (runtimeMetadataPrepared && !force) {
|
|
501
|
+
return;
|
|
502
|
+
}
|
|
503
|
+
await updateRuntimeWatchDependencies();
|
|
504
|
+
runtimeMetadataPrepared = true;
|
|
505
|
+
};
|
|
506
|
+
const syncRuntimeRefreshRequirement = () => {
|
|
507
|
+
runtimeRefreshRequiredForCompilation = runtimeRefreshRequiredForCompilation || hasWatchChanges(compiler);
|
|
508
|
+
};
|
|
448
509
|
const resetRuntimePreparation = () => {
|
|
449
510
|
runtimeSetPrepared = false;
|
|
511
|
+
runtimeMetadataPrepared = false;
|
|
512
|
+
syncRuntimeRefreshRequirement();
|
|
450
513
|
};
|
|
514
|
+
compiler.hooks.invalid?.tap?.(pluginName, () => {
|
|
515
|
+
runtimeRefreshRequiredForCompilation = true;
|
|
516
|
+
});
|
|
517
|
+
compiler.hooks.watchRun?.tap?.(pluginName, syncRuntimeRefreshRequirement);
|
|
451
518
|
if (compiler.hooks.thisCompilation?.tap) {
|
|
452
519
|
compiler.hooks.thisCompilation.tap(pluginName, resetRuntimePreparation);
|
|
453
520
|
} else if (compiler.hooks.compilation?.tap) {
|
|
@@ -458,7 +525,8 @@ var UnifiedWebpackPluginV5 = class {
|
|
|
458
525
|
return;
|
|
459
526
|
}
|
|
460
527
|
const signature = getRuntimeClassSetSignature(runtimeState.twPatcher);
|
|
461
|
-
const forceRefresh = signature !== runtimeSetSignature;
|
|
528
|
+
const forceRefresh = runtimeRefreshRequiredForCompilation || signature !== runtimeSetSignature;
|
|
529
|
+
debug("runtime loader ensure class set forceRefresh=%s watchDirty=%s signatureChanged=%s", forceRefresh, runtimeRefreshRequiredForCompilation, signature !== runtimeSetSignature);
|
|
462
530
|
runtimeSetPrepared = true;
|
|
463
531
|
await ensureRuntimeClassSet(runtimeState, {
|
|
464
532
|
forceRefresh,
|
|
@@ -466,7 +534,9 @@ var UnifiedWebpackPluginV5 = class {
|
|
|
466
534
|
clearCache: forceRefresh,
|
|
467
535
|
allowEmpty: true
|
|
468
536
|
});
|
|
537
|
+
await ensureRuntimeMetadata(forceRefresh);
|
|
469
538
|
runtimeSetSignature = signature;
|
|
539
|
+
runtimeRefreshRequiredForCompilation = false;
|
|
470
540
|
}
|
|
471
541
|
onLoad();
|
|
472
542
|
setupWebpackV5Loaders({
|
|
@@ -478,6 +548,12 @@ var UnifiedWebpackPluginV5 = class {
|
|
|
478
548
|
runtimeLoaderPath,
|
|
479
549
|
runtimeCssImportRewriteLoaderPath,
|
|
480
550
|
getClassSetInLoader,
|
|
551
|
+
getRuntimeWatchDependencies() {
|
|
552
|
+
return {
|
|
553
|
+
files: runtimeWatchDependencyFiles,
|
|
554
|
+
contexts: runtimeWatchDependencyContexts
|
|
555
|
+
};
|
|
556
|
+
},
|
|
481
557
|
debug
|
|
482
558
|
});
|
|
483
559
|
setupWebpackV5ProcessAssetsHook({
|
|
@@ -485,6 +561,11 @@ var UnifiedWebpackPluginV5 = class {
|
|
|
485
561
|
options: this.options,
|
|
486
562
|
appType: this.appType,
|
|
487
563
|
runtimeState,
|
|
564
|
+
getRuntimeRefreshRequirement: () => runtimeRefreshRequiredForCompilation,
|
|
565
|
+
refreshRuntimeMetadata: ensureRuntimeMetadata,
|
|
566
|
+
consumeRuntimeRefreshRequirement() {
|
|
567
|
+
runtimeRefreshRequiredForCompilation = false;
|
|
568
|
+
},
|
|
488
569
|
debug
|
|
489
570
|
});
|
|
490
571
|
}
|
|
@@ -4,6 +4,7 @@ async function processCachedTask({
|
|
|
4
4
|
cacheKey,
|
|
5
5
|
hashKey = cacheKey,
|
|
6
6
|
rawSource,
|
|
7
|
+
hash,
|
|
7
8
|
readCache,
|
|
8
9
|
applyResult,
|
|
9
10
|
transform,
|
|
@@ -14,6 +15,7 @@ async function processCachedTask({
|
|
|
14
15
|
key: cacheKey,
|
|
15
16
|
hashKey,
|
|
16
17
|
rawSource,
|
|
18
|
+
hash,
|
|
17
19
|
resolveCache: readCache,
|
|
18
20
|
async onCacheHit(value) {
|
|
19
21
|
cacheHit = true;
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "./chunk-F2CKKG6Q.mjs";
|
|
4
4
|
import {
|
|
5
5
|
pluginName
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-NAW56TSQ.mjs";
|
|
7
7
|
|
|
8
8
|
// src/shared/mpx.ts
|
|
9
9
|
import path2 from "path";
|
|
@@ -235,6 +235,9 @@ function createAssetHashByChunkMap(chunks) {
|
|
|
235
235
|
}
|
|
236
236
|
return hashByFile;
|
|
237
237
|
}
|
|
238
|
+
function hasWatchChanges(compiler) {
|
|
239
|
+
return (compiler.modifiedFiles?.size ?? 0) > 0 || (compiler.removedFiles?.size ?? 0) > 0;
|
|
240
|
+
}
|
|
238
241
|
|
|
239
242
|
// src/bundlers/webpack/shared/loader-anchors.ts
|
|
240
243
|
var MPX_STRIP_CONDITIONAL_LOADER = "@mpxjs/webpack-plugin/lib/style-compiler/strip-conditional-loader";
|
|
@@ -284,5 +287,6 @@ export {
|
|
|
284
287
|
isCssLikeModuleResource,
|
|
285
288
|
hasLoaderEntry,
|
|
286
289
|
createAssetHashByChunkMap,
|
|
290
|
+
hasWatchChanges,
|
|
287
291
|
createLoaderAnchorFinders
|
|
288
292
|
};
|
|
@@ -9,10 +9,7 @@ import {
|
|
|
9
9
|
} from "./chunk-F2CKKG6Q.mjs";
|
|
10
10
|
import {
|
|
11
11
|
processCachedTask
|
|
12
|
-
} from "./chunk-
|
|
13
|
-
import {
|
|
14
|
-
setupPatchRecorder
|
|
15
|
-
} from "./chunk-QYZCRG7F.mjs";
|
|
12
|
+
} from "./chunk-76S2EME4.mjs";
|
|
16
13
|
import {
|
|
17
14
|
babelParse,
|
|
18
15
|
collectRuntimeClassSet,
|
|
@@ -20,17 +17,19 @@ import {
|
|
|
20
17
|
createDebug,
|
|
21
18
|
generateCode,
|
|
22
19
|
getCompilerContext,
|
|
23
|
-
getRuntimeClassSetSignature,
|
|
24
20
|
refreshTailwindRuntimeState,
|
|
25
21
|
replaceWxml,
|
|
22
|
+
setupPatchRecorder,
|
|
26
23
|
toCustomAttributesEntities,
|
|
27
24
|
traverse,
|
|
28
25
|
vitePluginName
|
|
29
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-NAW56TSQ.mjs";
|
|
30
27
|
import {
|
|
31
28
|
findNearestPackageRoot,
|
|
32
|
-
findTailwindConfig
|
|
33
|
-
|
|
29
|
+
findTailwindConfig,
|
|
30
|
+
getRuntimeClassSetSignature,
|
|
31
|
+
resolveTailwindcssOptions
|
|
32
|
+
} from "./chunk-EW2K6CO5.mjs";
|
|
34
33
|
import {
|
|
35
34
|
resolveUniUtsPlatform
|
|
36
35
|
} from "./chunk-OOHJLO5M.mjs";
|
|
@@ -420,6 +419,8 @@ function createUniAppXAssetTask(file, originalSource, outDir, options) {
|
|
|
420
419
|
// src/bundlers/vite/generate-bundle.ts
|
|
421
420
|
import path2 from "path";
|
|
422
421
|
import process2 from "process";
|
|
422
|
+
import { logger } from "@weapp-tailwindcss/logger";
|
|
423
|
+
import { splitCode } from "@weapp-tailwindcss/shared/extractors";
|
|
423
424
|
|
|
424
425
|
// src/bundlers/vite/bundle-entries.ts
|
|
425
426
|
import { Buffer } from "buffer";
|
|
@@ -707,34 +708,6 @@ function buildBundleSnapshot(bundle, opts, outDir, state, forceAll = false) {
|
|
|
707
708
|
linkedImpactsByEntry
|
|
708
709
|
};
|
|
709
710
|
}
|
|
710
|
-
function buildBundleSnapshotForBuild(bundle, opts, outDir) {
|
|
711
|
-
const processFiles = createProcessFiles();
|
|
712
|
-
const jsEntries = /* @__PURE__ */ new Map();
|
|
713
|
-
const entries = [];
|
|
714
|
-
for (const [file, output] of Object.entries(bundle)) {
|
|
715
|
-
const type = classifyBundleEntry(file, opts);
|
|
716
|
-
const source = readEntrySource(output);
|
|
717
|
-
markProcessFile(type, file, processFiles);
|
|
718
|
-
collectJsEntries(file, output, outDir, jsEntries);
|
|
719
|
-
entries.push({
|
|
720
|
-
file,
|
|
721
|
-
output,
|
|
722
|
-
source,
|
|
723
|
-
type
|
|
724
|
-
});
|
|
725
|
-
}
|
|
726
|
-
return {
|
|
727
|
-
entries,
|
|
728
|
-
jsEntries,
|
|
729
|
-
sourceHashByFile: /* @__PURE__ */ new Map(),
|
|
730
|
-
runtimeAffectingSignatureByFile: /* @__PURE__ */ new Map(),
|
|
731
|
-
runtimeAffectingHashByFile: /* @__PURE__ */ new Map(),
|
|
732
|
-
changedByType: createChangedByType(),
|
|
733
|
-
runtimeAffectingChangedByType: createChangedByType(),
|
|
734
|
-
processFiles,
|
|
735
|
-
linkedImpactsByEntry: /* @__PURE__ */ new Map()
|
|
736
|
-
};
|
|
737
|
-
}
|
|
738
711
|
function invertLinkedByEntry(linkedByEntry) {
|
|
739
712
|
const dependentsByLinkedFile = /* @__PURE__ */ new Map();
|
|
740
713
|
for (const [entryFile, linkedFiles] of linkedByEntry.entries()) {
|
|
@@ -749,12 +722,22 @@ function invertLinkedByEntry(linkedByEntry) {
|
|
|
749
722
|
}
|
|
750
723
|
return dependentsByLinkedFile;
|
|
751
724
|
}
|
|
752
|
-
function updateBundleBuildState(state, snapshot, linkedByEntry) {
|
|
725
|
+
function updateBundleBuildState(state, snapshot, linkedByEntry, options = {}) {
|
|
726
|
+
const incremental = options.incremental === true;
|
|
753
727
|
state.iteration += 1;
|
|
754
|
-
state.sourceHashByFile =
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
728
|
+
state.sourceHashByFile = incremental ? new Map([
|
|
729
|
+
...state.sourceHashByFile,
|
|
730
|
+
...snapshot.sourceHashByFile
|
|
731
|
+
]) : snapshot.sourceHashByFile;
|
|
732
|
+
state.runtimeAffectingHashByFile = incremental ? new Map([
|
|
733
|
+
...state.runtimeAffectingHashByFile,
|
|
734
|
+
...snapshot.runtimeAffectingHashByFile
|
|
735
|
+
]) : snapshot.runtimeAffectingHashByFile;
|
|
736
|
+
state.linkedByEntry = incremental ? new Map([
|
|
737
|
+
...state.linkedByEntry,
|
|
738
|
+
...linkedByEntry
|
|
739
|
+
]) : linkedByEntry;
|
|
740
|
+
state.dependentsByLinkedFile = invertLinkedByEntry(state.linkedByEntry);
|
|
758
741
|
}
|
|
759
742
|
|
|
760
743
|
// src/bundlers/vite/js-precheck.ts
|
|
@@ -862,6 +845,39 @@ function hasRuntimeAffectingSourceChanges(changedByType) {
|
|
|
862
845
|
function canShareCssTransformResult(rawSource) {
|
|
863
846
|
return !rawSource.includes("@import") && !rawSource.includes("url(");
|
|
864
847
|
}
|
|
848
|
+
function hasOmittedKnownBundleFiles(currentBundleFiles, previousBundleFiles) {
|
|
849
|
+
const currentFileSet = new Set(currentBundleFiles);
|
|
850
|
+
for (const file of previousBundleFiles) {
|
|
851
|
+
if (!currentFileSet.has(file)) {
|
|
852
|
+
return true;
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
return false;
|
|
856
|
+
}
|
|
857
|
+
var MUSTACHE_EXPRESSION_RE = /\{\{[\s\S]*?\}\}/g;
|
|
858
|
+
var QUOTED_LITERAL_RE = /'([^']*)'|"([^"]*)"|`([^`]*)`/g;
|
|
859
|
+
function isArbitraryValueCandidate(candidate) {
|
|
860
|
+
return candidate.includes("[") && candidate.includes("]");
|
|
861
|
+
}
|
|
862
|
+
function collectUnescapedDynamicCandidates(source) {
|
|
863
|
+
const matches = /* @__PURE__ */ new Set();
|
|
864
|
+
for (const expression of source.match(MUSTACHE_EXPRESSION_RE) ?? []) {
|
|
865
|
+
QUOTED_LITERAL_RE.lastIndex = 0;
|
|
866
|
+
let quoted = QUOTED_LITERAL_RE.exec(expression);
|
|
867
|
+
while (quoted !== null) {
|
|
868
|
+
const literal = quoted[1] ?? quoted[2] ?? quoted[3] ?? "";
|
|
869
|
+
for (const candidate of splitCode(literal, true)) {
|
|
870
|
+
const normalized = candidate.trim();
|
|
871
|
+
if (!normalized || !isArbitraryValueCandidate(normalized)) {
|
|
872
|
+
continue;
|
|
873
|
+
}
|
|
874
|
+
matches.add(normalized);
|
|
875
|
+
}
|
|
876
|
+
quoted = QUOTED_LITERAL_RE.exec(expression);
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
return [...matches];
|
|
880
|
+
}
|
|
865
881
|
function createGenerateBundleHook(context) {
|
|
866
882
|
const state = createBundleBuildState();
|
|
867
883
|
const cssHandlerOptionsCache = /* @__PURE__ */ new Map();
|
|
@@ -914,10 +930,12 @@ function createGenerateBundleHook(context) {
|
|
|
914
930
|
const disableJsPrecheck = process2.env.WEAPP_TW_VITE_DISABLE_JS_PRECHECK === "1";
|
|
915
931
|
const debugCssDiff = process2.env.WEAPP_TW_VITE_DEBUG_CSS_DIFF === "1";
|
|
916
932
|
const resolvedConfig = getResolvedConfig();
|
|
917
|
-
const
|
|
933
|
+
const bundleFiles = Object.keys(bundle);
|
|
934
|
+
const buildCommand = resolvedConfig?.command === "build";
|
|
935
|
+
const useIncrementalMode = !buildCommand || hasOmittedKnownBundleFiles(bundleFiles, state.sourceHashByFile.keys());
|
|
918
936
|
const rootDir = resolvedConfig?.root ? path2.resolve(resolvedConfig.root) : process2.cwd();
|
|
919
937
|
const outDir = resolvedConfig?.build?.outDir ? path2.resolve(rootDir, resolvedConfig.build.outDir) : rootDir;
|
|
920
|
-
const snapshot =
|
|
938
|
+
const snapshot = buildBundleSnapshot(bundle, opts, outDir, state, disableDirtyOptimization || !useIncrementalMode);
|
|
921
939
|
const useBundleRuntimeClassSet = useIncrementalMode || runtimeState.twPatcher.majorVersion === 4;
|
|
922
940
|
const forceRuntimeRefreshBySource = useIncrementalMode && hasRuntimeAffectingSourceChanges(snapshot.runtimeAffectingChangedByType);
|
|
923
941
|
const processFiles = snapshot.processFiles;
|
|
@@ -1026,7 +1044,27 @@ function createGenerateBundleHook(context) {
|
|
|
1026
1044
|
},
|
|
1027
1045
|
async transform() {
|
|
1028
1046
|
const start = performance.now();
|
|
1029
|
-
|
|
1047
|
+
let transformed = await templateHandler(rawSource, defaultTemplateHandlerOptions);
|
|
1048
|
+
let unresolvedDynamicCandidates = collectUnescapedDynamicCandidates(transformed);
|
|
1049
|
+
if (unresolvedDynamicCandidates.length > 0) {
|
|
1050
|
+
logger.warn(
|
|
1051
|
+
"\u68C0\u6D4B\u5230 WXML \u52A8\u6001\u7C7B\u540D\u672A\u5B8C\u6210\u8F6C\u8BD1\uFF0C\u5DF2\u56DE\u9000\u5230\u5B8C\u6574 runtimeSet \u91CD\u8BD5: %s -> %O",
|
|
1052
|
+
file,
|
|
1053
|
+
unresolvedDynamicCandidates
|
|
1054
|
+
);
|
|
1055
|
+
const fullRuntimeSet = await context.ensureRuntimeClassSet(true);
|
|
1056
|
+
transformed = await templateHandler(rawSource, {
|
|
1057
|
+
runtimeSet: fullRuntimeSet
|
|
1058
|
+
});
|
|
1059
|
+
unresolvedDynamicCandidates = collectUnescapedDynamicCandidates(transformed);
|
|
1060
|
+
if (unresolvedDynamicCandidates.length > 0) {
|
|
1061
|
+
logger.warn(
|
|
1062
|
+
"WXML \u52A8\u6001\u7C7B\u540D\u5728\u5B8C\u6574 runtimeSet \u91CD\u8BD5\u540E\u4ECD\u672A\u5B8C\u6210\u8F6C\u8BD1: %s -> %O",
|
|
1063
|
+
file,
|
|
1064
|
+
unresolvedDynamicCandidates
|
|
1065
|
+
);
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1030
1068
|
metrics.html.elapsed += measureElapsed(start);
|
|
1031
1069
|
metrics.html.transformed++;
|
|
1032
1070
|
onUpdate(file, rawSource, transformed);
|
|
@@ -1241,9 +1279,12 @@ function createGenerateBundleHook(context) {
|
|
|
1241
1279
|
for (const apply of pendingLinkedUpdates) {
|
|
1242
1280
|
apply();
|
|
1243
1281
|
}
|
|
1244
|
-
|
|
1245
|
-
|
|
1246
|
-
|
|
1282
|
+
updateBundleBuildState(
|
|
1283
|
+
state,
|
|
1284
|
+
snapshot,
|
|
1285
|
+
useIncrementalMode ? linkedByEntry ?? /* @__PURE__ */ new Map() : /* @__PURE__ */ new Map(),
|
|
1286
|
+
{ incremental: useIncrementalMode }
|
|
1287
|
+
);
|
|
1247
1288
|
debug3(
|
|
1248
1289
|
"metrics iteration=%d runtime=%sms html(total=%d transform=%d hit=%d rate=%s elapsed=%sms) js(total=%d transform=%d hit=%d rate=%s elapsed=%sms) css(total=%d transform=%d hit=%d rate=%s elapsed=%sms)",
|
|
1249
1290
|
useIncrementalMode ? state.iteration : 0,
|
|
@@ -1293,7 +1334,7 @@ function isPostcssPluginImportTarget(value) {
|
|
|
1293
1334
|
return value === "@tailwindcss/postcss" || value === "@tailwindcss/postcss7-compat" || value.includes("/postcss");
|
|
1294
1335
|
}
|
|
1295
1336
|
function resolveTailwindCssImportTarget(patcher) {
|
|
1296
|
-
const tailwindOptions = patcher.options
|
|
1337
|
+
const tailwindOptions = resolveTailwindcssOptions(patcher.options);
|
|
1297
1338
|
const cssEntries = tailwindOptions?.v4?.cssEntries?.filter((item) => typeof item === "string" && item.length > 0);
|
|
1298
1339
|
if (cssEntries && cssEntries.length > 0) {
|
|
1299
1340
|
return createCssImportSource(cssEntries);
|
|
@@ -1336,7 +1377,7 @@ function resolveMaybeAbsolute(base, value) {
|
|
|
1336
1377
|
}
|
|
1337
1378
|
async function resolveTailwindCssSource(patcher) {
|
|
1338
1379
|
const projectRoot = getProjectRoot(patcher);
|
|
1339
|
-
const tailwindOptions = patcher.options
|
|
1380
|
+
const tailwindOptions = resolveTailwindcssOptions(patcher.options);
|
|
1340
1381
|
const configuredBase = resolveMaybeAbsolute(projectRoot, tailwindOptions?.v4?.base);
|
|
1341
1382
|
const configDir = tailwindOptions?.config ? path3.dirname(tailwindOptions.config) : void 0;
|
|
1342
1383
|
const sharedFallbacks = [
|
|
@@ -1763,7 +1804,7 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
|
|
|
1763
1804
|
let runtimeRefreshOptionsKey;
|
|
1764
1805
|
const bundleRuntimeClassSetManager = createBundleRuntimeClassSetManager();
|
|
1765
1806
|
function resolveRuntimeRefreshOptions() {
|
|
1766
|
-
const configPath = runtimeState.twPatcher.options?.
|
|
1807
|
+
const configPath = resolveTailwindcssOptions(runtimeState.twPatcher.options)?.config;
|
|
1767
1808
|
const signature = getRuntimeClassSetSignature(runtimeState.twPatcher);
|
|
1768
1809
|
const optionsKey = JSON.stringify({
|
|
1769
1810
|
appType,
|