weapp-tailwindcss 5.1.14 → 5.1.15
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/auto-2dg_uhEJ.mjs +13 -0
- package/dist/bundlers/gulp/frameworks/native/index.d.ts +2 -0
- package/dist/bundlers/gulp/index.d.ts +2 -0
- package/dist/bundlers/gulp/shared/create-native-framework-plugins.d.ts +2 -0
- package/dist/bundlers/shared/generated-css-marker.d.ts +2 -2
- package/dist/bundlers/shared/generator-css/local-imports.d.ts +1 -1
- package/dist/bundlers/shared/generator-css/source-resolver/postcss-source.d.ts +2 -0
- package/dist/bundlers/shared/generator-css/types.d.ts +5 -0
- package/dist/bundlers/shared/style-requests.d.ts +1 -0
- package/dist/bundlers/vite/bundle-state.d.ts +1 -0
- package/dist/bundlers/vite/generate-bundle/bundle-markup-candidates.d.ts +20 -0
- package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +1 -0
- package/dist/bundlers/vite/generate-bundle/remembered-css-replay.d.ts +1 -0
- package/dist/bundlers/vite/generate-bundle/sfc-style-source.d.ts +2 -1
- package/dist/bundlers/vite/generate-bundle/source-candidate-source.d.ts +1 -0
- package/dist/bundlers/vite/generate-bundle/types.d.ts +5 -0
- package/dist/bundlers/vite/serve-css-generation.d.ts +3 -2
- package/dist/bundlers/vite/shared/create-framework-plugins.d.ts +1 -0
- package/dist/bundlers/vite/watch-css-post.d.ts +10 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +6 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/css-source-resolvers.d.ts +1 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers.d.ts +2 -0
- package/dist/bundlers/webpack/loaders/runtime-registry.d.ts +1 -0
- package/dist/bundlers/webpack/loaders/weapp-tw-css-generation-loader.d.ts +4 -0
- package/dist/bundlers/webpack/loaders/weapp-tw-css-import-rewrite-loader.d.ts +3 -0
- package/dist/{context-BL8Gy71H.mjs → context-BgGWVAmN.mjs} +2 -2
- package/dist/core.mjs +1 -1
- package/dist/css-macro.mjs +1 -1
- package/dist/{generator-B59OA64h.mjs → generator-CEo920So.mjs} +1 -1
- package/dist/generator.mjs +1 -1
- package/dist/{gulp-C1Q3LRzg.js → gulp-3m1dAiig.js} +84 -50
- package/dist/{gulp-DUYWxmZC.mjs → gulp-DP71z1jG.mjs} +87 -53
- package/dist/gulp.js +1 -1
- package/dist/gulp.mjs +1 -1
- package/dist/{hmr-timing-C3ed5vCx.mjs → hmr-timing-1aS6--U7.mjs} +170 -44
- package/dist/{hmr-timing-BZ5sWIqO.js → hmr-timing-B8p4f0ca.js} +219 -39
- package/dist/index.js +3 -3
- package/dist/index.mjs +4 -4
- package/dist/postcss.mjs +1 -1
- package/dist/presets.mjs +1 -1
- package/dist/rspack.js +1 -1
- package/dist/rspack.mjs +1 -1
- package/dist/shared/mpx.d.ts +4 -1
- package/dist/{source-candidate-scan-signature-R3dzamcm.js → source-candidate-scan-signature-BAahhiwb.js} +4 -96
- package/dist/{source-candidate-scan-signature-D7RWjWsY.mjs → source-candidate-scan-signature-Cf7259PR.mjs} +6 -62
- package/dist/{tailwindcss-DPcKMLxL.mjs → tailwindcss-xs704TRw.mjs} +1 -1
- package/dist/{transform-D5JUgMpE.mjs → transform-B_KM9sLX.mjs} +47 -5
- package/dist/{transform-COFRlmDF.js → transform-CcYptivi.js} +47 -5
- package/dist/uni-app-x/component-local-style.d.ts +1 -0
- package/dist/uni-app-x/style-asset/style-value.d.ts +1 -1
- package/dist/{vite-BNlPdsGM.js → vite-DUVjMduj.js} +550 -273
- package/dist/{vite-CBU5NXTX.mjs → vite-nXZEiwG0.mjs} +501 -224
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/weapp-tw-css-generation-loader.js +12 -0
- package/dist/weapp-tw-css-import-rewrite-loader-DNk0IxAt.js +10198 -0
- package/dist/weapp-tw-css-import-rewrite-loader.js +6 -10255
- package/dist/{webpack-CZ38fMGC.mjs → webpack-C_UUFRgj.mjs} +223 -57
- package/dist/{webpack-Jpe048pQ.js → webpack-nppysF4B.js} +232 -66
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +11 -3
- package/dist/auto-CrJJc5rK.mjs +0 -13
|
@@ -6,8 +6,8 @@ const require_tailwindcss = require("./tailwindcss-KBYPJ2DW.js");
|
|
|
6
6
|
require("./utils-CuKLf1Zv.js");
|
|
7
7
|
const require_wxml = require("./wxml-Ce10eREX.js");
|
|
8
8
|
const require_context = require("./context-VeFq_8vW.js");
|
|
9
|
-
const require_hmr_timing = require("./hmr-timing-
|
|
10
|
-
const require_source_candidate_scan_signature = require("./source-candidate-scan-signature-
|
|
9
|
+
const require_hmr_timing = require("./hmr-timing-B8p4f0ca.js");
|
|
10
|
+
const require_source_candidate_scan_signature = require("./source-candidate-scan-signature-BAahhiwb.js");
|
|
11
11
|
require("./logger-TlKT3xmR.js");
|
|
12
12
|
let node_fs = require("node:fs");
|
|
13
13
|
node_fs = require_rolldown_runtime.__toESM(node_fs);
|
|
@@ -196,8 +196,28 @@ function createStyleValueFromApplySources(sources, utilityStyles) {
|
|
|
196
196
|
}
|
|
197
197
|
return Object.keys(result).length > 0 ? result : void 0;
|
|
198
198
|
}
|
|
199
|
-
function
|
|
200
|
-
|
|
199
|
+
function resolveReferencePaths(styleSource, sourceId) {
|
|
200
|
+
if (!sourceId || !styleSource.includes("@reference")) return styleSource;
|
|
201
|
+
let root;
|
|
202
|
+
try {
|
|
203
|
+
root = _weapp_tailwindcss_postcss.postcss.parse(styleSource);
|
|
204
|
+
} catch {
|
|
205
|
+
return styleSource;
|
|
206
|
+
}
|
|
207
|
+
const cleanSourceId = sourceId.replace(/\?.*$/, "");
|
|
208
|
+
root.walkAtRules("reference", (rule) => {
|
|
209
|
+
const quote = rule.params[0];
|
|
210
|
+
if (quote !== "\"" && quote !== "'") return;
|
|
211
|
+
const closingQuoteIndex = rule.params.indexOf(quote, 1);
|
|
212
|
+
if (closingQuoteIndex <= 1) return;
|
|
213
|
+
const referencePath = rule.params.slice(1, closingQuoteIndex);
|
|
214
|
+
if (!referencePath.startsWith(".")) return;
|
|
215
|
+
rule.params = `${quote}${node_path.default.resolve(node_path.default.dirname(cleanSourceId), referencePath)}${quote}${rule.params.slice(closingQuoteIndex + 1)}`;
|
|
216
|
+
});
|
|
217
|
+
return root.toString();
|
|
218
|
+
}
|
|
219
|
+
function collectUniAppXHarmonyApplyStyleSourcesFromSource(source, sourceId) {
|
|
220
|
+
return (source.includes("<style") ? [...source.matchAll(SFC_STYLE_BLOCK_RE$2)].map((styleBlock) => styleBlock[1] ?? "") : [source]).map((styleSource) => resolveReferencePaths(styleSource.trim(), sourceId)).filter((styleSource) => styleSource.length > 0 && styleSource.includes("@apply"));
|
|
201
221
|
}
|
|
202
222
|
function collectUniAppXHarmonyApplyUtilitiesFromSources(sources) {
|
|
203
223
|
const utilities = /* @__PURE__ */ new Set();
|
|
@@ -242,7 +262,18 @@ const STYLE_DECL_RE = /const\s+(_style_\d+)\s*=\s*\{/g;
|
|
|
242
262
|
const EXPORT_SFC_RE = /_export_sfc\(_sfc_main\s*,\s*\[/;
|
|
243
263
|
const UNI_APP_X_STYLE_PLACEHOLDER_VERSION = "uni-app-x-style-placeholder-v2";
|
|
244
264
|
function createUniAppXHarmonyApplyGeneratorSource(applyStyleSources, _applyUtilities) {
|
|
245
|
-
return applyStyleSources.
|
|
265
|
+
return applyStyleSources.map((source) => {
|
|
266
|
+
let root;
|
|
267
|
+
try {
|
|
268
|
+
root = _weapp_tailwindcss_postcss.postcss.parse(source);
|
|
269
|
+
} catch {
|
|
270
|
+
return source;
|
|
271
|
+
}
|
|
272
|
+
root.walkAtRules("reference", (rule) => {
|
|
273
|
+
if (rule.params.match(/^(['"])(.+?)\1/)?.[2]?.startsWith(".")) rule.remove();
|
|
274
|
+
});
|
|
275
|
+
return root.toString();
|
|
276
|
+
}).join("\n");
|
|
246
277
|
}
|
|
247
278
|
function collectUniAppXHarmonyApplyUtilities(bundle) {
|
|
248
279
|
const utilities = /* @__PURE__ */ new Set();
|
|
@@ -471,6 +502,127 @@ function createUniAppXBundleAssetSourceGetter(bundle) {
|
|
|
471
502
|
};
|
|
472
503
|
}
|
|
473
504
|
//#endregion
|
|
505
|
+
//#region src/bundlers/vite/generate-bundle/transform-filter.ts
|
|
506
|
+
function toArray(value) {
|
|
507
|
+
return Array.isArray(value) ? value : value === void 0 ? [] : [value];
|
|
508
|
+
}
|
|
509
|
+
function normalizeSourceId(id) {
|
|
510
|
+
const file = (0, _weapp_tailwindcss_shared.cleanUrl)(id);
|
|
511
|
+
return node_path.default.isAbsolute(file) ? node_path.default.resolve(file) : void 0;
|
|
512
|
+
}
|
|
513
|
+
function collectChunkModuleIds$2(chunk) {
|
|
514
|
+
const ids = /* @__PURE__ */ new Set();
|
|
515
|
+
for (const id of chunk.moduleIds ?? []) {
|
|
516
|
+
const normalized = normalizeSourceId(id);
|
|
517
|
+
if (normalized) ids.add(normalized);
|
|
518
|
+
}
|
|
519
|
+
for (const id of Object.keys(chunk.modules ?? {})) {
|
|
520
|
+
const normalized = normalizeSourceId(id);
|
|
521
|
+
if (normalized) ids.add(normalized);
|
|
522
|
+
}
|
|
523
|
+
return ids;
|
|
524
|
+
}
|
|
525
|
+
function collectAssetSourceIds(asset, fallbackFile, rootDir) {
|
|
526
|
+
const ids = /* @__PURE__ */ new Set();
|
|
527
|
+
const sourceCandidates = [asset.originalFileName, ...asset.originalFileNames ?? []].filter((candidate) => typeof candidate === "string" && candidate.length > 0);
|
|
528
|
+
const candidates = sourceCandidates.length > 0 ? sourceCandidates : [fallbackFile];
|
|
529
|
+
for (const candidate of candidates) {
|
|
530
|
+
if (typeof candidate !== "string" || candidate.length === 0) continue;
|
|
531
|
+
const cleanCandidate = (0, _weapp_tailwindcss_shared.cleanUrl)(candidate);
|
|
532
|
+
const resolved = node_path.default.isAbsolute(cleanCandidate) ? node_path.default.resolve(cleanCandidate) : node_path.default.resolve(rootDir, cleanCandidate);
|
|
533
|
+
ids.add(resolved);
|
|
534
|
+
}
|
|
535
|
+
return ids;
|
|
536
|
+
}
|
|
537
|
+
function isStringRuleMatched(rule, id, rootDir) {
|
|
538
|
+
const normalizedId = require_source_candidate_scan_signature.slash(id);
|
|
539
|
+
const normalizedRule = require_source_candidate_scan_signature.slash(rule);
|
|
540
|
+
if (node_path.default.isAbsolute(rule)) return micromatch.default.isMatch(normalizedId, normalizedRule);
|
|
541
|
+
const relative = require_source_candidate_scan_signature.slash(node_path.default.relative(rootDir, id));
|
|
542
|
+
return relative.length > 0 && !relative.startsWith("../") && !node_path.default.isAbsolute(relative) && micromatch.default.isMatch(relative, normalizedRule);
|
|
543
|
+
}
|
|
544
|
+
function isRuleMatched(rule, id, rootDir) {
|
|
545
|
+
if (typeof rule === "string") return isStringRuleMatched(rule, id, rootDir);
|
|
546
|
+
if (rule instanceof RegExp) {
|
|
547
|
+
rule.lastIndex = 0;
|
|
548
|
+
return rule.test(require_source_candidate_scan_signature.slash(id));
|
|
549
|
+
}
|
|
550
|
+
return rule(id) === true;
|
|
551
|
+
}
|
|
552
|
+
function createTransformMatcher(rules, rootDir) {
|
|
553
|
+
const normalizedRules = toArray(rules);
|
|
554
|
+
if (normalizedRules.length === 0) return;
|
|
555
|
+
return (id) => normalizedRules.some((rule) => isRuleMatched(rule, id, rootDir));
|
|
556
|
+
}
|
|
557
|
+
function shouldSkipSourceIds(sourceIds, filter) {
|
|
558
|
+
if (sourceIds.size === 0) return false;
|
|
559
|
+
if (filter.exclude) {
|
|
560
|
+
let excluded = true;
|
|
561
|
+
for (const id of sourceIds) if (!filter.exclude(id)) {
|
|
562
|
+
excluded = false;
|
|
563
|
+
break;
|
|
564
|
+
}
|
|
565
|
+
if (excluded) return true;
|
|
566
|
+
}
|
|
567
|
+
if (filter.include) {
|
|
568
|
+
for (const id of sourceIds) if (filter.include(id)) return false;
|
|
569
|
+
return true;
|
|
570
|
+
}
|
|
571
|
+
return false;
|
|
572
|
+
}
|
|
573
|
+
function createTransformFilter(options, rootDir) {
|
|
574
|
+
const include = createTransformMatcher(options?.include, rootDir);
|
|
575
|
+
const exclude = createTransformMatcher(options?.exclude, rootDir);
|
|
576
|
+
if (!include && !exclude) return;
|
|
577
|
+
return {
|
|
578
|
+
include,
|
|
579
|
+
exclude
|
|
580
|
+
};
|
|
581
|
+
}
|
|
582
|
+
function shouldSkipViteJsChunkTransform(chunk, filter) {
|
|
583
|
+
if (!filter) return false;
|
|
584
|
+
return shouldSkipSourceIds(collectChunkModuleIds$2(chunk), filter);
|
|
585
|
+
}
|
|
586
|
+
function shouldSkipViteAssetTransform(asset, file, rootDir, filter) {
|
|
587
|
+
if (!filter) return false;
|
|
588
|
+
return shouldSkipSourceIds(collectAssetSourceIds(asset, file, rootDir), filter);
|
|
589
|
+
}
|
|
590
|
+
function createRuleSignature(rules) {
|
|
591
|
+
return toArray(rules).map((rule) => {
|
|
592
|
+
if (typeof rule === "string") return `s:${rule}`;
|
|
593
|
+
if (rule instanceof RegExp) return `r:${rule.source}/${rule.flags}`;
|
|
594
|
+
return "f";
|
|
595
|
+
}).join("|") || "none";
|
|
596
|
+
}
|
|
597
|
+
function createTransformFilterSignature(options) {
|
|
598
|
+
return [`include:${createRuleSignature(options?.include)}`, `exclude:${createRuleSignature(options?.exclude)}`].join(";");
|
|
599
|
+
}
|
|
600
|
+
//#endregion
|
|
601
|
+
//#region src/bundlers/vite/generate-bundle/bundle-markup-candidates.ts
|
|
602
|
+
async function collectBundleMarkupCandidates(options) {
|
|
603
|
+
const { extractSourceCandidates, previousCandidatesByFile, preserveMissingFiles, resolveSourceCandidateFile, rootDir, snapshot, transformFilter } = options;
|
|
604
|
+
const candidatesByFile = preserveMissingFiles ? new Map([...previousCandidatesByFile ?? []].map(([file, candidates]) => [file, new Set(candidates)])) : /* @__PURE__ */ new Map();
|
|
605
|
+
await Promise.all(snapshot.entries.map(async (entry) => {
|
|
606
|
+
if (!extractSourceCandidates || entry.type !== "html" || entry.output.type !== "asset" || shouldSkipViteAssetTransform(entry.output, entry.file, rootDir, transformFilter)) return;
|
|
607
|
+
const sourceFile = resolveSourceCandidateFile(entry.file) ?? node_path.default.resolve(rootDir, entry.file);
|
|
608
|
+
candidatesByFile.set(sourceFile, await extractSourceCandidates(sourceFile, entry.source));
|
|
609
|
+
}));
|
|
610
|
+
const valuesForEntries = (entries, filterOptions = {}) => {
|
|
611
|
+
const values = /* @__PURE__ */ new Set();
|
|
612
|
+
for (const [file, candidates] of candidatesByFile) {
|
|
613
|
+
if (entries !== void 0 && !require_generator.isFileMatchedByTailwindSourceEntries(file, entries)) continue;
|
|
614
|
+
if (filterOptions.excludeEntries?.length && require_generator.isFileMatchedByTailwindSourceEntries(file, filterOptions.excludeEntries)) continue;
|
|
615
|
+
for (const candidate of candidates) values.add(candidate);
|
|
616
|
+
}
|
|
617
|
+
return values;
|
|
618
|
+
};
|
|
619
|
+
return {
|
|
620
|
+
candidatesByFile,
|
|
621
|
+
values: valuesForEntries(void 0),
|
|
622
|
+
valuesForEntries
|
|
623
|
+
};
|
|
624
|
+
}
|
|
625
|
+
//#endregion
|
|
474
626
|
//#region src/bundlers/vite/generate-bundle/configured-css-sources.ts
|
|
475
627
|
function collectConfiguredTailwindV4CssSources(opts) {
|
|
476
628
|
const runtimeCssSources = opts.tailwindcssRuntimeOptions?.tailwindcss?.v4?.cssSources ?? [];
|
|
@@ -554,7 +706,8 @@ function registerGeneratorDependencies$1(ctx, dependencies) {
|
|
|
554
706
|
//#region src/bundlers/vite/generate-bundle/css-assets.ts
|
|
555
707
|
function createCssAssetEmitter(context, bundle) {
|
|
556
708
|
return (fileName, source) => {
|
|
557
|
-
const
|
|
709
|
+
const fileNameKey = require_source_candidate_scan_signature.normalizeOutputPathKey(fileName);
|
|
710
|
+
const existing = bundle?.[fileName] ?? Object.entries(bundle ?? {}).find(([bundleFile, output]) => output != null && typeof output === "object" && "type" in output && output.type === "asset" && require_source_candidate_scan_signature.normalizeOutputPathKey("fileName" in output && typeof output.fileName === "string" ? output.fileName : bundleFile) === fileNameKey)?.[1];
|
|
558
711
|
if (existing && typeof existing === "object" && "type" in existing && existing.type === "asset") {
|
|
559
712
|
existing.source = source;
|
|
560
713
|
return existing;
|
|
@@ -651,8 +804,9 @@ function resolveMiniProgramStyleOutputExtension(options = {}) {
|
|
|
651
804
|
return resolveStyleOutputExtensionFromFiles(options.files, options.cssMatcher, options.stem) ?? resolveStyleOutputExtensionFromFiles(options.files, options.cssMatcher) ?? resolveStyleOutputExtensionFromMatcher(options.cssMatcher, options.stem) ?? normalizeStyleOutputExtension(options.fallback) ?? FALLBACK_STYLE_OUTPUT_EXTENSION;
|
|
652
805
|
}
|
|
653
806
|
function resolveReplayCssOutputFile(rootDir, file) {
|
|
654
|
-
const
|
|
655
|
-
|
|
807
|
+
const cleanFile = file.replace(/[?#].*$/, "");
|
|
808
|
+
const normalizedFile = require_source_candidate_scan_signature.normalizeOutputPathKey(node_path.default.isAbsolute(cleanFile) ? node_path.default.relative(resolveCssOutputRealPath(rootDir), resolveCssOutputRealPath(cleanFile)) : cleanFile);
|
|
809
|
+
if (normalizedFile.length === 0 || normalizedFile === "." || normalizedFile === ".." || normalizedFile.startsWith("../")) return require_source_candidate_scan_signature.normalizeOutputPathKey(node_path.default.basename(cleanFile));
|
|
656
810
|
return normalizedFile;
|
|
657
811
|
}
|
|
658
812
|
function normalizeViteSourceRoot(rootDir, sourceRoot) {
|
|
@@ -668,9 +822,10 @@ function resolveReplayCssOutputFileFromSourceRoot(rootDir, file, sourceRoot) {
|
|
|
668
822
|
return outputFile;
|
|
669
823
|
}
|
|
670
824
|
function resolveViteCssOutputFile(file, opts, isWebGeneratorTarget, preserveCssExtension = false, styleOutputExtension, styleOutputFiles) {
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
825
|
+
const cleanFile = file.replace(/[?#].*$/, "");
|
|
826
|
+
if (isWebGeneratorTarget || preserveCssExtension || opts.cssMatcher(cleanFile) || !CSS_SOURCE_OUTPUT_EXT_RE.test(cleanFile) || !require_source_candidate_scan_signature.isCSSRequest(file)) return cleanFile;
|
|
827
|
+
const stem = cleanFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, "");
|
|
828
|
+
return cleanFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, resolveMiniProgramStyleOutputExtension({
|
|
674
829
|
cssMatcher: opts.cssMatcher,
|
|
675
830
|
fallback: styleOutputExtension,
|
|
676
831
|
files: styleOutputFiles,
|
|
@@ -678,20 +833,40 @@ function resolveViteCssOutputFile(file, opts, isWebGeneratorTarget, preserveCssE
|
|
|
678
833
|
}));
|
|
679
834
|
}
|
|
680
835
|
function resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget = false, preserveCssExtension = false, sourceRoot, styleOutputExtension, styleOutputFiles) {
|
|
681
|
-
const
|
|
682
|
-
const cleanFile =
|
|
836
|
+
const sourceStyleRequest = require_source_candidate_scan_signature.isCSSRequest(file);
|
|
837
|
+
const cleanFile = resolveReplayCssOutputFileFromSourceRoot(rootDir, file, sourceRoot).replace(/[?#].*$/, "");
|
|
838
|
+
const sourceExtension = node_path.default.extname(cleanFile);
|
|
839
|
+
if (sourceStyleRequest && !isWebGeneratorTarget && !preserveCssExtension && sourceExtension.length > 0 && !CSS_SOURCE_OUTPUT_EXT_RE.test(cleanFile)) {
|
|
840
|
+
const stem = cleanFile.slice(0, -sourceExtension.length);
|
|
841
|
+
return `${stem}${resolveMiniProgramStyleOutputExtension({
|
|
842
|
+
cssMatcher: opts.cssMatcher,
|
|
843
|
+
fallback: styleOutputExtension,
|
|
844
|
+
files: styleOutputFiles,
|
|
845
|
+
stem
|
|
846
|
+
})}`;
|
|
847
|
+
}
|
|
683
848
|
const stem = cleanFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, "");
|
|
684
849
|
const matchedStyleExtension = !isWebGeneratorTarget && !preserveCssExtension ? resolveStyleOutputExtensionFromFiles(styleOutputFiles, opts.cssMatcher, stem) : void 0;
|
|
685
|
-
if (matchedStyleExtension && CSS_SOURCE_OUTPUT_EXT_RE.test(cleanFile) &&
|
|
686
|
-
if (isWebGeneratorTarget || preserveCssExtension || opts.cssMatcher(
|
|
850
|
+
if (matchedStyleExtension && CSS_SOURCE_OUTPUT_EXT_RE.test(cleanFile) && sourceStyleRequest) return cleanFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, matchedStyleExtension);
|
|
851
|
+
if (isWebGeneratorTarget || preserveCssExtension || opts.cssMatcher(cleanFile) || !CSS_SOURCE_OUTPUT_EXT_RE.test(cleanFile) || !sourceStyleRequest) return cleanFile;
|
|
687
852
|
const fallbackExtension = normalizeStyleOutputExtension(styleOutputExtension);
|
|
688
|
-
if (!fallbackExtension && !SOURCE_STYLE_OUTPUT_EXT_RE.test(
|
|
689
|
-
return
|
|
853
|
+
if (!fallbackExtension && !SOURCE_STYLE_OUTPUT_EXT_RE.test(cleanFile)) return cleanFile;
|
|
854
|
+
return cleanFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, fallbackExtension ?? FALLBACK_STYLE_OUTPUT_EXTENSION);
|
|
690
855
|
}
|
|
691
856
|
function resolveViteCssPipelineOutputFileFromSourceFile(sourceFile, opts, rootDir, isWebGeneratorTarget = false, preserveCssExtension = false, sourceRoot, styleOutputExtension, styleOutputFiles) {
|
|
692
|
-
const
|
|
693
|
-
const cleanFile =
|
|
694
|
-
|
|
857
|
+
const sourceStyleRequest = require_source_candidate_scan_signature.isCSSRequest(sourceFile);
|
|
858
|
+
const cleanFile = resolveReplayCssOutputFileFromSourceRoot(rootDir, sourceFile, sourceRoot).replace(/[?#].*$/, "");
|
|
859
|
+
const sourceExtension = node_path.default.extname(cleanFile);
|
|
860
|
+
if (sourceStyleRequest && !isWebGeneratorTarget && !preserveCssExtension && sourceExtension.length > 0 && !CSS_SOURCE_OUTPUT_EXT_RE.test(cleanFile)) {
|
|
861
|
+
const stem = cleanFile.slice(0, -sourceExtension.length);
|
|
862
|
+
return resolveStyleOutputFileFromFiles(styleOutputFiles, opts.cssMatcher, stem) ?? `${stem}${resolveMiniProgramStyleOutputExtension({
|
|
863
|
+
cssMatcher: opts.cssMatcher,
|
|
864
|
+
fallback: styleOutputExtension,
|
|
865
|
+
files: styleOutputFiles,
|
|
866
|
+
stem
|
|
867
|
+
})}`;
|
|
868
|
+
}
|
|
869
|
+
if (isWebGeneratorTarget || preserveCssExtension || !CSS_SOURCE_OUTPUT_EXT_RE.test(cleanFile) || !sourceStyleRequest) return cleanFile;
|
|
695
870
|
const stem = cleanFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, "");
|
|
696
871
|
const matchedStyleFile = resolveStyleOutputFileFromFiles(styleOutputFiles, opts.cssMatcher, stem);
|
|
697
872
|
if (matchedStyleFile) return matchedStyleFile;
|
|
@@ -701,7 +876,7 @@ function resolveViteCssPipelineOutputFileFromSourceFile(sourceFile, opts, rootDi
|
|
|
701
876
|
files: styleOutputFiles,
|
|
702
877
|
stem
|
|
703
878
|
}) ?? normalizeStyleOutputExtension(styleOutputExtension);
|
|
704
|
-
return
|
|
879
|
+
return cleanFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, styleExtension);
|
|
705
880
|
}
|
|
706
881
|
function canProcessViteSourceStyleAsCss(source, file) {
|
|
707
882
|
if (SOURCE_STYLE_NON_CSS_SYNTAX_RE.test(source)) return false;
|
|
@@ -853,7 +1028,8 @@ function createCssHandlerOptionsCache(options) {
|
|
|
853
1028
|
const appType = options.getAppType();
|
|
854
1029
|
const isMainChunk = options.mainCssChunkMatcher(file, appType);
|
|
855
1030
|
const outputRoot = options.getOutputRoot?.();
|
|
856
|
-
const
|
|
1031
|
+
const sourceFile = require_hmr_timing.stripRequestQuery(file);
|
|
1032
|
+
const from = node_path.default.isAbsolute(sourceFile) ? sourceFile : outputRoot ? node_path.default.resolve(outputRoot, sourceFile) : sourceFile;
|
|
857
1033
|
const extraOptions = options.getExtraOptions?.(file) ?? {};
|
|
858
1034
|
const dynamicCssOptions = options.getDynamicCssOptions?.() ?? {};
|
|
859
1035
|
const cacheKey = `${majorVersion ?? "unknown"}:${appType ?? "unknown"}:${isMainChunk ? "1" : "0"}:${outputRoot ?? ""}:${file}:${JSON.stringify(extraOptions)}:${JSON.stringify(dynamicCssOptions)}`;
|
|
@@ -865,7 +1041,10 @@ function createCssHandlerOptionsCache(options) {
|
|
|
865
1041
|
...dynamicCssOptions,
|
|
866
1042
|
postcssOptions: { options: { from } },
|
|
867
1043
|
majorVersion: require_context.normalizeStyleHandlerMajorVersion(majorVersion),
|
|
868
|
-
sourceOptions: {
|
|
1044
|
+
sourceOptions: {
|
|
1045
|
+
outputRoot,
|
|
1046
|
+
...sourceFile === file ? {} : { requestFile: file }
|
|
1047
|
+
}
|
|
869
1048
|
};
|
|
870
1049
|
cssHandlerOptionsCache.set(cacheKey, created);
|
|
871
1050
|
return created;
|
|
@@ -968,7 +1147,8 @@ function shouldSkipRawSourceStyleAsset(outputFile, file, rawSource, assetSourceF
|
|
|
968
1147
|
const source = rawSource.trim();
|
|
969
1148
|
if (source.length === 0) return false;
|
|
970
1149
|
if (canProcessViteSourceStyleAsCss(source, file)) return false;
|
|
971
|
-
|
|
1150
|
+
if (SOURCE_STYLE_OUTPUT_EXT_RE.test(assetSourceFile.replace(/[?#].*$/, ""))) return true;
|
|
1151
|
+
const isKnownStyleSource = require_hmr_timing.isSourceStyleRequest(assetSourceFile) || cssMatcher?.(assetSourceFile) === true;
|
|
972
1152
|
return outputFile !== file || !isKnownStyleSource;
|
|
973
1153
|
}
|
|
974
1154
|
function resolveOutputFileFromMatchedCssSource(options) {
|
|
@@ -1536,6 +1716,10 @@ const SFC_STYLE_SOURCE_EXTENSIONS = [
|
|
|
1536
1716
|
const SFC_STYLE_BLOCK_RE$1 = /<style\b([^>]*)>([\s\S]*?)<\/style>/gi;
|
|
1537
1717
|
const SFC_SCOPED_STYLE_ATTR_RE = /(?:^|\s)scoped(?:\s|=|$)/i;
|
|
1538
1718
|
const SFC_LANG_STYLE_ATTR_RE = /(?:^|\s)lang(?:=(?:"([^"]+)"|'([^']+)'|([^\s"'=<>`]+)))?/i;
|
|
1719
|
+
function isSfcStyleSourceFile(file) {
|
|
1720
|
+
const normalizedFile = file.replace(/[?#].*$/, "");
|
|
1721
|
+
return SFC_STYLE_SOURCE_EXTENSIONS.some((extension) => normalizedFile.endsWith(extension));
|
|
1722
|
+
}
|
|
1539
1723
|
function extractSfcStyleBlocks(source) {
|
|
1540
1724
|
const styleSources = [];
|
|
1541
1725
|
SFC_STYLE_BLOCK_RE$1.lastIndex = 0;
|
|
@@ -1581,7 +1765,7 @@ function createSfcStyleRequest(sourceFile, styleBlock) {
|
|
|
1581
1765
|
if (lang) params.set("lang", lang);
|
|
1582
1766
|
return `${sourceFile}?${params.toString()}`;
|
|
1583
1767
|
}
|
|
1584
|
-
function resolveSfcStyleRequestFromKnownSource(sourceFile, sfcSource, styleSource) {
|
|
1768
|
+
function resolveSfcStyleRequestFromKnownSource(sourceFile, sfcSource, styleSource, currentRequest) {
|
|
1585
1769
|
if (!sfcSource) return sourceFile;
|
|
1586
1770
|
const styleBlocks = extractSfcStyleBlocks(sfcSource);
|
|
1587
1771
|
if (styleBlocks.length === 0) return sourceFile;
|
|
@@ -1590,7 +1774,8 @@ function resolveSfcStyleRequestFromKnownSource(sourceFile, sfcSource, styleSourc
|
|
|
1590
1774
|
const normalizedBlockSource = normalizeSfcStyleSourceForCompare(styleBlock.source);
|
|
1591
1775
|
return normalizedBlockSource === normalizedStyleSource || normalizedBlockSource.includes(normalizedStyleSource) || normalizedStyleSource.includes(normalizedBlockSource);
|
|
1592
1776
|
});
|
|
1593
|
-
const
|
|
1777
|
+
const requestIndex = currentRequest ? Number.parseInt(new URLSearchParams(currentRequest.split("?", 2)[1] ?? "").get("index") ?? "", 10) : NaN;
|
|
1778
|
+
const styleBlock = (Number.isInteger(requestIndex) ? styleBlocks.find((styleBlock) => styleBlock.index === requestIndex) : void 0) ?? (matchedBlocks.length === 1 ? matchedBlocks[0] : styleBlocks.length === 1 ? styleBlocks[0] : void 0);
|
|
1594
1779
|
return styleBlock ? createSfcStyleRequest(sourceFile, styleBlock) : sourceFile;
|
|
1595
1780
|
}
|
|
1596
1781
|
function hasTailwindGenerationSource(source, options = {}) {
|
|
@@ -1628,7 +1813,7 @@ async function resolveSfcStyleSourceFromOutputFile(outputFile, snapshot, outputR
|
|
|
1628
1813
|
function normalizeSfcSourceFileForCompare(file) {
|
|
1629
1814
|
return require_source_candidate_scan_signature.normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
1630
1815
|
}
|
|
1631
|
-
function collectChunkModuleIds$
|
|
1816
|
+
function collectChunkModuleIds$1(output) {
|
|
1632
1817
|
const moduleIds = Array.isArray(output.moduleIds) ? output.moduleIds : [];
|
|
1633
1818
|
return [
|
|
1634
1819
|
output.facadeModuleId,
|
|
@@ -1652,7 +1837,7 @@ function resolveSiblingJsChunkFile(outputFile, cssMatcher) {
|
|
|
1652
1837
|
}
|
|
1653
1838
|
function normalizeSfcModuleId(id) {
|
|
1654
1839
|
const file = id.replace(/[?#].*$/, "");
|
|
1655
|
-
if (!
|
|
1840
|
+
if (!isSfcStyleSourceFile(file)) return;
|
|
1656
1841
|
if (!node_path.default.isAbsolute(file)) return;
|
|
1657
1842
|
return node_path.default.resolve(file);
|
|
1658
1843
|
}
|
|
@@ -1668,7 +1853,7 @@ function resolveSfcStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot, s
|
|
|
1668
1853
|
debug("sfc style sibling chunk skipped: missing chunk for %s -> %s", outputFile, siblingJsFile);
|
|
1669
1854
|
return;
|
|
1670
1855
|
}
|
|
1671
|
-
const sourceFiles = collectChunkModuleIds$
|
|
1856
|
+
const sourceFiles = collectChunkModuleIds$1(siblingChunk.output).map(normalizeSfcModuleId).filter((file, index, files) => Boolean(file) && files.indexOf(file) === index);
|
|
1672
1857
|
if (sourceFiles.length === 0) {
|
|
1673
1858
|
debug("sfc style sibling chunk skipped: no sfc modules for %s -> %s", outputFile, siblingJsFile);
|
|
1674
1859
|
return;
|
|
@@ -1699,7 +1884,7 @@ function resolveSourceStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot
|
|
|
1699
1884
|
debug("source style sibling chunk skipped: missing chunk for %s -> %s", outputFile, siblingJsFile);
|
|
1700
1885
|
return;
|
|
1701
1886
|
}
|
|
1702
|
-
const sourceFiles = collectChunkModuleIds$
|
|
1887
|
+
const sourceFiles = collectChunkModuleIds$1(siblingChunk.output).map(normalizeSourceStyleModuleId).filter((file, index, files) => Boolean(file) && files.indexOf(file) === index);
|
|
1703
1888
|
if (sourceFiles.length === 0) {
|
|
1704
1889
|
debug("source style sibling chunk skipped: no source style modules for %s -> %s", outputFile, siblingJsFile);
|
|
1705
1890
|
return;
|
|
@@ -1818,7 +2003,7 @@ function collectMiniProgramSubpackageSourceEntries(snapshot, subpackageRoots, so
|
|
|
1818
2003
|
if (entry.output.type !== "chunk" || !isSubpackageOutputFile(entry.file, subpackageRoots)) continue;
|
|
1819
2004
|
const matchedSubpackageRoot = [...subpackageRoots].find((root) => isSubpackageOutputFile(entry.file, /* @__PURE__ */ new Set([root])));
|
|
1820
2005
|
if (!matchedSubpackageRoot) continue;
|
|
1821
|
-
for (const moduleId of collectChunkModuleIds$
|
|
2006
|
+
for (const moduleId of collectChunkModuleIds$1(entry.output)) {
|
|
1822
2007
|
if (!node_path.default.isAbsolute(moduleId.replace(/[?#].*$/, ""))) continue;
|
|
1823
2008
|
const sourceRoot = resolveSubpackageSourceRootFromModuleId(moduleId, matchedSubpackageRoot);
|
|
1824
2009
|
if (sourceRoot) sourceRoots.add(sourceRoot);
|
|
@@ -1982,13 +2167,13 @@ function isMatchingGeneratedCssMarkerFile(targetFile, markerFile, resolveVitePro
|
|
|
1982
2167
|
return require_source_candidate_scan_signature.normalizeOutputPathKey(stripStyleExtension(targetFile)) === require_source_candidate_scan_signature.normalizeOutputPathKey(stripStyleExtension(normalizeMarkerOutputFile(markerFile, resolveViteProcessedCssOutputFile)));
|
|
1983
2168
|
}
|
|
1984
2169
|
function resolveViteProcessedCssAssetSource(file, rawSource, resolveViteProcessedCssOutputFile) {
|
|
1985
|
-
const blocks =
|
|
1986
|
-
if (blocks.length <= 1) return
|
|
2170
|
+
const blocks = require_hmr_timing.parseBundlerGeneratedCssMarkerBlocks(rawSource).filter((block) => block.bundler === "vite");
|
|
2171
|
+
if (blocks.length <= 1) return require_hmr_timing.stripBundlerGeneratedCssMarkers(rawSource);
|
|
1987
2172
|
const matchedCss = blocks.filter((block) => isMatchingGeneratedCssMarkerFile(file, block.file, resolveViteProcessedCssOutputFile)).map((block) => block.css);
|
|
1988
|
-
return matchedCss.length > 0 ? matchedCss.join("\n") :
|
|
2173
|
+
return matchedCss.length > 0 ? matchedCss.join("\n") : require_hmr_timing.stripBundlerGeneratedCssMarkers(rawSource);
|
|
1989
2174
|
}
|
|
1990
2175
|
function collectMatchingGeneratedCssMarkerFiles(file, rawSource, resolveViteProcessedCssOutputFile) {
|
|
1991
|
-
return
|
|
2176
|
+
return require_hmr_timing.parseBundlerGeneratedCssMarkerBlocks(rawSource).filter((block) => block.bundler === "vite").filter((block) => isMatchingGeneratedCssMarkerFile(file, block.file, resolveViteProcessedCssOutputFile)).map((block) => block.file).filter((markerFile) => typeof markerFile === "string" && markerFile.length > 0);
|
|
1992
2177
|
}
|
|
1993
2178
|
function collectRootStyleBundleCssSources(bundle, excludedFile) {
|
|
1994
2179
|
const sources = [];
|
|
@@ -1997,7 +2182,7 @@ function collectRootStyleBundleCssSources(bundle, excludedFile) {
|
|
|
1997
2182
|
if (output.type !== "asset") continue;
|
|
1998
2183
|
const file = require_source_candidate_scan_signature.normalizeOutputPathKey(getAssetFile$1(bundleFile, output));
|
|
1999
2184
|
if (file === excludedFileKey || !isRootStyleOutputFile(file)) continue;
|
|
2000
|
-
const source =
|
|
2185
|
+
const source = require_hmr_timing.stripBundlerGeneratedCssMarkers(readAssetSource$2(output)).trim();
|
|
2001
2186
|
if (source.length > 0) sources.push(source);
|
|
2002
2187
|
}
|
|
2003
2188
|
return sources;
|
|
@@ -2050,7 +2235,7 @@ function removeDuplicateUnlinkedRootCssAssetsReferencedByHtml(bundle, options =
|
|
|
2050
2235
|
if (output.type !== "asset") continue;
|
|
2051
2236
|
const file = getAssetFile$1(bundleFile, output);
|
|
2052
2237
|
if (!isCssOutputFile(file) || isMiniProgramStyleOutputFile(file) || !isLinkedStyleFile(file, linked)) continue;
|
|
2053
|
-
const source =
|
|
2238
|
+
const source = require_hmr_timing.stripBundlerGeneratedCssMarkers(readAssetSource$2(output)).trim();
|
|
2054
2239
|
if (source.length > 0) linkedSources.add(source);
|
|
2055
2240
|
}
|
|
2056
2241
|
if (linkedSources.size === 0) return 0;
|
|
@@ -2059,7 +2244,7 @@ function removeDuplicateUnlinkedRootCssAssetsReferencedByHtml(bundle, options =
|
|
|
2059
2244
|
if (output.type !== "asset") continue;
|
|
2060
2245
|
const file = getAssetFile$1(bundleFile, output);
|
|
2061
2246
|
if (!isRootStyleOutputFile(file) || isMiniProgramStyleOutputFile(file) || isLinkedStyleFile(file, linked)) continue;
|
|
2062
|
-
const source =
|
|
2247
|
+
const source = require_hmr_timing.stripBundlerGeneratedCssMarkers(readAssetSource$2(output)).trim();
|
|
2063
2248
|
if (!linkedSources.has(source)) continue;
|
|
2064
2249
|
delete bundle[bundleFile];
|
|
2065
2250
|
options.debug?.("remove duplicate unlinked root css asset referenced by html: %s", file);
|
|
@@ -2224,7 +2409,7 @@ function removeScopedTailwindPreflightCss(css) {
|
|
|
2224
2409
|
return removeScopedCssCoveredByRootStyleSources(css, []);
|
|
2225
2410
|
}
|
|
2226
2411
|
function collectSingleViteGeneratedCssMarkerFile(rawSource) {
|
|
2227
|
-
const blocks =
|
|
2412
|
+
const blocks = require_hmr_timing.parseBundlerGeneratedCssMarkerBlocks(rawSource).filter((block) => block.bundler === "vite");
|
|
2228
2413
|
if (blocks.length !== 1) return;
|
|
2229
2414
|
const file = blocks[0]?.file;
|
|
2230
2415
|
return typeof file === "string" && file.length > 0 ? file : void 0;
|
|
@@ -2409,7 +2594,7 @@ function removeCoveredInjectedSourceAssets(bundle, targetFile, targetCss, record
|
|
|
2409
2594
|
}
|
|
2410
2595
|
function removeCssCoveredByImportedViteResults(css, importedCssSources) {
|
|
2411
2596
|
if (importedCssSources.length === 0) return css;
|
|
2412
|
-
const importedCss = importedCssSources.map((source) =>
|
|
2597
|
+
const importedCss = importedCssSources.map((source) => require_hmr_timing.stripBundlerGeneratedCssMarkers(source).trim()).filter(Boolean).join("\n");
|
|
2413
2598
|
if (importedCss.length === 0) return css;
|
|
2414
2599
|
return restoreCssImportAtRules(css, removeCssRulesCoveredBySources(css, [importedCss], { exactOnly: true }));
|
|
2415
2600
|
}
|
|
@@ -2721,7 +2906,7 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
2721
2906
|
if (!shouldInjectViteProcessedCssResult(options.opts, mainFileKey, record.file, record)) continue;
|
|
2722
2907
|
if (isViteProcessedCssResultImported(record, importedStyleFiles)) continue;
|
|
2723
2908
|
targetViteCssResults.push(record);
|
|
2724
|
-
let css = normalizeInjectableCssForTarget(
|
|
2909
|
+
let css = normalizeInjectableCssForTarget(require_hmr_timing.stripBundlerGeneratedCssMarkers(record.css).trim(), file).trim();
|
|
2725
2910
|
css = removeCssCoveredByImportedViteResults(css, importedCssSources).trim();
|
|
2726
2911
|
if (css.length === 0) continue;
|
|
2727
2912
|
const mergedLayerCss = require_hmr_timing.mergeMarkedUserLayerComponentsCss(nextCss, css);
|
|
@@ -3349,11 +3534,12 @@ function collectUnescapedDynamicCandidates(source, allowedCandidates) {
|
|
|
3349
3534
|
//#region src/bundlers/vite/generate-bundle/html-processing.ts
|
|
3350
3535
|
function processHtmlBundleEntry(options) {
|
|
3351
3536
|
const { cache, context, debug, dynamicRetryCandidates, file, metrics, onUpdate, originalEntrySource, originalSource, rememberProcessCacheKey, resolveCurrentSourceCandidateSource, tasks, templateHandler, timeTask, transformRuntime, transformRuntimeSignature } = options;
|
|
3352
|
-
const
|
|
3353
|
-
const
|
|
3354
|
-
const
|
|
3537
|
+
const currentBundleSource = originalEntrySource;
|
|
3538
|
+
const candidateSource = resolveCurrentSourceCandidateSource(file) ?? currentBundleSource;
|
|
3539
|
+
const currentRawDynamicCandidates = /* @__PURE__ */ new Set([...collectUnescapedDynamicCandidates(candidateSource), ...collectUnescapedDynamicCandidates(currentBundleSource)]);
|
|
3540
|
+
const templateRuntime = currentRawDynamicCandidates.size > 0 ? /* @__PURE__ */ new Set([...transformRuntime, ...currentRawDynamicCandidates]) : transformRuntime;
|
|
3355
3541
|
const templateRuntimeSignature = templateRuntime === transformRuntime ? transformRuntimeSignature : require_source_candidate_scan_signature.createCandidateSignature(templateRuntime);
|
|
3356
|
-
const htmlProcessHash = `${cache.computeHash(
|
|
3542
|
+
const htmlProcessHash = `${cache.computeHash(currentBundleSource)}:${cache.computeHash(require_source_candidate_scan_signature.createRuntimeAffectingSourceSignature(currentBundleSource, "html"))}:${templateRuntimeSignature}`;
|
|
3357
3543
|
const cacheKey = `${file}:html:${htmlProcessHash}`;
|
|
3358
3544
|
const hashKey = cacheKey;
|
|
3359
3545
|
rememberProcessCacheKey(cacheKey, hashKey);
|
|
@@ -3371,7 +3557,7 @@ function processHtmlBundleEntry(options) {
|
|
|
3371
3557
|
},
|
|
3372
3558
|
async transform() {
|
|
3373
3559
|
const start = performance.now();
|
|
3374
|
-
let transformed = await templateHandler(
|
|
3560
|
+
let transformed = await templateHandler(currentBundleSource, { runtimeSet: templateRuntime });
|
|
3375
3561
|
let unresolvedDynamicCandidates = collectUnescapedDynamicCandidates(transformed);
|
|
3376
3562
|
let retryRuntimeSet;
|
|
3377
3563
|
if (unresolvedDynamicCandidates.length > 0) {
|
|
@@ -3382,13 +3568,13 @@ function processHtmlBundleEntry(options) {
|
|
|
3382
3568
|
}
|
|
3383
3569
|
if (retryRuntimeSet && unresolvedDynamicCandidates.length > 0) {
|
|
3384
3570
|
_weapp_tailwindcss_logger.logger.warn("检测到已提取 WXML 动态类名未完成转译,已回退到完整 runtimeSet 重试: %s -> %O", file, unresolvedDynamicCandidates);
|
|
3385
|
-
transformed = await templateHandler(
|
|
3571
|
+
transformed = await templateHandler(currentBundleSource, { runtimeSet: retryRuntimeSet });
|
|
3386
3572
|
unresolvedDynamicCandidates = collectUnescapedDynamicCandidates(transformed, retryRuntimeSet);
|
|
3387
3573
|
if (unresolvedDynamicCandidates.length > 0) _weapp_tailwindcss_logger.logger.warn("已提取 WXML 动态类名在完整 runtimeSet 重试后仍未完成转译: %s -> %O", file, unresolvedDynamicCandidates);
|
|
3388
3574
|
}
|
|
3389
3575
|
metrics.html.elapsed += measureElapsed(start);
|
|
3390
3576
|
metrics.html.transformed++;
|
|
3391
|
-
onUpdate(file,
|
|
3577
|
+
onUpdate(file, currentBundleSource, transformed);
|
|
3392
3578
|
debug("html handle: %s", file);
|
|
3393
3579
|
return { result: transformed };
|
|
3394
3580
|
}
|
|
@@ -3494,7 +3680,7 @@ function resolveUniAppXStyleIsolationEnabled(root) {
|
|
|
3494
3680
|
//#region src/uni-app-x/vite.ts
|
|
3495
3681
|
let transformUVuePromise;
|
|
3496
3682
|
function loadTransformUVue() {
|
|
3497
|
-
transformUVuePromise ?? (transformUVuePromise = Promise.resolve().then(() => require("./transform-
|
|
3683
|
+
transformUVuePromise ?? (transformUVuePromise = Promise.resolve().then(() => require("./transform-CcYptivi.js")).then((mod) => mod.transformUVue));
|
|
3498
3684
|
return transformUVuePromise;
|
|
3499
3685
|
}
|
|
3500
3686
|
const preprocessorLangs = /* @__PURE__ */ new Set([
|
|
@@ -3535,8 +3721,8 @@ function createUniAppXPlugins(options) {
|
|
|
3535
3721
|
let componentLocalStyleEnabled;
|
|
3536
3722
|
const harmonyApplyStyleSources = /* @__PURE__ */ new Set();
|
|
3537
3723
|
const harmonyApplyUtilities = /* @__PURE__ */ new Set();
|
|
3538
|
-
function rememberHarmonyApplySource(code) {
|
|
3539
|
-
const styleSources = collectUniAppXHarmonyApplyStyleSourcesFromSource(code);
|
|
3724
|
+
function rememberHarmonyApplySource(code, id) {
|
|
3725
|
+
const styleSources = collectUniAppXHarmonyApplyStyleSourcesFromSource(code, id);
|
|
3540
3726
|
if (styleSources.length === 0) return;
|
|
3541
3727
|
for (const styleSource of styleSources) {
|
|
3542
3728
|
harmonyApplyStyleSources.add(styleSource);
|
|
@@ -3569,7 +3755,7 @@ function createUniAppXPlugins(options) {
|
|
|
3569
3755
|
if (require_source_candidate_scan_signature.isCSSRequest(id) || parsed.vue && parsed.type === "style") {
|
|
3570
3756
|
if (isCssModuleExport(code)) return;
|
|
3571
3757
|
const shouldGenerateCss = require_generator.hasTailwindSourceDirectives(code, { importFallback: true }) || require_generator.hasTailwindApplyDirective(code);
|
|
3572
|
-
rememberHarmonyApplySource(code);
|
|
3758
|
+
rememberHarmonyApplySource(code, id);
|
|
3573
3759
|
const generatedCss = shouldGenerateCss ? await generateCss?.(id, code, hookContext) : void 0;
|
|
3574
3760
|
const styleCode = typeof generatedCss === "string" && generatedCss.trim().length > 0 ? generatedCss : code;
|
|
3575
3761
|
const cacheKey = `${mainCssChunkMatcher(id, appType) ? "1" : "0"}:${id}`;
|
|
@@ -3629,7 +3815,7 @@ function createUniAppXPlugins(options) {
|
|
|
3629
3815
|
async transform(code, id) {
|
|
3630
3816
|
if (!isEnabled()) return;
|
|
3631
3817
|
if (!UVUE_NVUE_QUERY_RE.test(id)) return;
|
|
3632
|
-
rememberHarmonyApplySource(code);
|
|
3818
|
+
rememberHarmonyApplySource(code, id);
|
|
3633
3819
|
const resolvedConfig = getResolvedConfig();
|
|
3634
3820
|
const isServeCommand = resolvedConfig?.command === "serve";
|
|
3635
3821
|
const isWatchBuild = resolvedConfig?.command === "build" && !!resolvedConfig.build?.watch;
|
|
@@ -3638,13 +3824,19 @@ function createUniAppXPlugins(options) {
|
|
|
3638
3824
|
const transformUVue = await loadTransformUVue();
|
|
3639
3825
|
const enableComponentLocalStyle = shouldEnableComponentLocalStyle();
|
|
3640
3826
|
const enablePageLocalStyle = shouldEnableHarmonyPageLocalStyle();
|
|
3641
|
-
if (customAttributesEntities.length > 0 || disabledDefaultTemplateHandler || enableComponentLocalStyle || enablePageLocalStyle)
|
|
3642
|
-
|
|
3643
|
-
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
|
|
3827
|
+
if (customAttributesEntities.length > 0 || disabledDefaultTemplateHandler || enableComponentLocalStyle || enablePageLocalStyle) {
|
|
3828
|
+
const result = transformUVue(code, id, jsHandler, currentRuntimeSet, require_object.omitUndefined({
|
|
3829
|
+
...customAttributesEntities.length > 0 ? { customAttributesEntities } : {},
|
|
3830
|
+
...disabledDefaultTemplateHandler ? { disabledDefaultTemplateHandler } : {},
|
|
3831
|
+
...enableComponentLocalStyle ? { enableComponentLocalStyle } : {},
|
|
3832
|
+
...enablePageLocalStyle ? { enablePageLocalStyle } : {}
|
|
3833
|
+
}));
|
|
3834
|
+
if (result?.code) rememberHarmonyApplySource(result.code, id);
|
|
3835
|
+
return result;
|
|
3836
|
+
}
|
|
3837
|
+
const result = transformUVue(code, id, jsHandler, currentRuntimeSet);
|
|
3838
|
+
if (result?.code) rememberHarmonyApplySource(result.code, id);
|
|
3839
|
+
return result;
|
|
3648
3840
|
},
|
|
3649
3841
|
async handleHotUpdate(ctx) {
|
|
3650
3842
|
if (!isEnabled()) return;
|
|
@@ -3674,7 +3866,7 @@ function createUniAppXPlugins(options) {
|
|
|
3674
3866
|
const getAssetSource = createUniAppXBundleAssetSourceGetter(bundle);
|
|
3675
3867
|
if (isHarmonyTarget) {
|
|
3676
3868
|
const cssSources = [];
|
|
3677
|
-
const applyStyleSources = [...harmonyApplyStyleSources
|
|
3869
|
+
const applyStyleSources = harmonyApplyStyleSources.size > 0 ? [...harmonyApplyStyleSources] : collectUniAppXHarmonyApplyStyleSources(bundle);
|
|
3678
3870
|
const applyUtilities = /* @__PURE__ */ new Set([...harmonyApplyUtilities, ...collectUniAppXHarmonyApplyUtilities(bundle)]);
|
|
3679
3871
|
if (applyStyleSources.length > 0 && applyUtilities.size > 0) {
|
|
3680
3872
|
const harmonyApplyCssFile = node_path.default.resolve(getResolvedConfig()?.root ?? node_process.default.cwd(), "uni-app-x-harmony-apply.css");
|
|
@@ -3895,7 +4087,7 @@ function findRememberedCssSources(sources, outputFile, file, originalSource, out
|
|
|
3895
4087
|
if (!sources) return [];
|
|
3896
4088
|
const rememberedSources = [...sources].map(([, remembered]) => remembered);
|
|
3897
4089
|
const source = typeof originalSource.source === "string" ? originalSource.source : originalSource.source.toString();
|
|
3898
|
-
const markerFiles = new Set(
|
|
4090
|
+
const markerFiles = new Set(require_hmr_timing.parseBundlerGeneratedCssMarkerBlocks(source).filter((block) => block.bundler === "vite" && typeof block.file === "string" && block.file.length > 0).map((block) => require_source_candidate_scan_signature.normalizeOutputPathKey(block.file)));
|
|
3899
4091
|
if (markerFiles.size > 0) {
|
|
3900
4092
|
const markerMatched = rememberedSources.filter((remembered) => markerFiles.has(normalizeRememberedSourceIdentity(remembered.sourceFile)));
|
|
3901
4093
|
if (markerMatched.length > 0) return selectBestRememberedCssSourceMatches(markerMatched, outputFile, outputRoot, sourceRoot);
|
|
@@ -3912,7 +4104,7 @@ function findRememberedCssSources(sources, outputFile, file, originalSource, out
|
|
|
3912
4104
|
}
|
|
3913
4105
|
const outputMatched = rememberedSources.filter((remembered) => require_source_candidate_scan_signature.normalizeOutputPathKey(remembered.outputFile) === require_source_candidate_scan_signature.normalizeOutputPathKey(outputFile));
|
|
3914
4106
|
if (outputMatched.length > 0) return outputMatched;
|
|
3915
|
-
if (!
|
|
4107
|
+
if (!require_hmr_timing.hasBundlerGeneratedCssMarker(source) && !hasTailwindGenerationSource(source)) return [];
|
|
3916
4108
|
const scoredMatches = selectBestRememberedCssSourceMatches(rememberedSources, outputFile, outputRoot, sourceRoot);
|
|
3917
4109
|
const strongScoredMatches = selectBestRememberedCssSourceMatches(rememberedSources, outputFile, outputRoot, sourceRoot, { minimumScore: 1e5 });
|
|
3918
4110
|
if (strongScoredMatches.length > 0 && strongScoredMatches.length < rememberedSources.length) return strongScoredMatches;
|
|
@@ -3952,17 +4144,25 @@ function collectRememberedCssReplayGroups(sources, opts, rootDir, isWebGenerator
|
|
|
3952
4144
|
}
|
|
3953
4145
|
//#endregion
|
|
3954
4146
|
//#region src/bundlers/vite/generate-bundle/remembered-css-replay.ts
|
|
4147
|
+
function shouldSkipRawRememberedCssSource(rawSource, sourceFile) {
|
|
4148
|
+
const cleanSourceFile = sourceFile.replace(/[?#].*$/, "");
|
|
4149
|
+
return SOURCE_STYLE_OUTPUT_EXT_RE.test(cleanSourceFile) && !canProcessViteSourceStyleAsCss(rawSource, sourceFile);
|
|
4150
|
+
}
|
|
3955
4151
|
async function processRememberedCssReplay(options) {
|
|
3956
4152
|
const { addWatchFile, activeViteCssCacheFiles, bundleFiles, cache, changedCssFiles = /* @__PURE__ */ new Set(), createScopedGeneratorRuntime, createScopedSourceCandidateGetter, createScopedSourceCandidateSourceGetter, cssTaskFactories, cssPipelineContext, cssPipelineStrategy, debug, defaultStyleOutputExtension, emitOrReplayCssAsset, generatorRuntime, generatorPlatform, getCssHandlerOptions, getCssUserHandlerOptions, getRememberedCssSignature, getRememberedCssSources, isNativeAppStyleTarget, isWebGeneratorTarget, lastCssRawSourceHashByFile = /* @__PURE__ */ new Map(), lastCssResultByFile, lastCssSourceHashByFile, markCssAssetProcessed, metrics, normalizeViteCssCacheKey, onUpdate, opts, recordCssAssetResult, recordViteProcessedCssAssetResult, refreshRememberedCssSource, rootDir, runtimeState, setRememberedCssSignature, shouldInjectCssIntoMainFromOutput, shouldPreserveAppCssExtension, sourceRoot, styleHandler, timeTask, useIncrementalMode } = options;
|
|
3957
4153
|
const rememberedReplayGroups = collectRememberedCssReplayGroups(getRememberedCssSources?.(), opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension, sourceRoot, defaultStyleOutputExtension, bundleFiles);
|
|
3958
4154
|
for (const [outputFile, rememberedGroup] of rememberedReplayGroups) {
|
|
3959
4155
|
if (require_source_candidate_scan_signature.isHTMLRequest(outputFile) || options.opts.htmlMatcher(outputFile)) continue;
|
|
3960
|
-
const
|
|
4156
|
+
const replayableRememberedGroup = (await Promise.all(rememberedGroup.map(async (item) => ({
|
|
3961
4157
|
key: item.key,
|
|
3962
4158
|
remembered: await refreshRememberedCssSource?.(item.remembered) ?? item.remembered
|
|
3963
|
-
})))
|
|
3964
|
-
|
|
3965
|
-
|
|
4159
|
+
})))).filter(({ remembered }) => {
|
|
4160
|
+
const shouldSkip = shouldSkipRawRememberedCssSource(remembered.rawSource, remembered.sourceFile);
|
|
4161
|
+
if (shouldSkip) debug("css replay skip raw source style: %s -> %s", remembered.sourceFile, outputFile);
|
|
4162
|
+
return !shouldSkip;
|
|
4163
|
+
});
|
|
4164
|
+
const rememberedKeys = replayableRememberedGroup.map((item) => item.key);
|
|
4165
|
+
const rememberedCssSource = mergeRememberedCssSources(replayableRememberedGroup.map((item) => item.remembered), outputFile);
|
|
3966
4166
|
if (!rememberedCssSource) continue;
|
|
3967
4167
|
const { rawSource, sourceFile } = rememberedCssSource;
|
|
3968
4168
|
const generatorRawSource = isWebGeneratorTarget ? rawSource : require_hmr_timing.normalizeMiniProgramGeneratorCssSource(rawSource, outputFile);
|
|
@@ -4267,13 +4467,12 @@ function createSubpackageSourceCandidateScope(options) {
|
|
|
4267
4467
|
function normalizeSourceCandidatePathKey(file) {
|
|
4268
4468
|
return require_source_candidate_scan_signature.normalizeOutputPathKey(node_path.default.resolve(file));
|
|
4269
4469
|
}
|
|
4270
|
-
function
|
|
4271
|
-
const { file,
|
|
4470
|
+
function createSourceCandidateFiles(options) {
|
|
4471
|
+
const { file, outDir, rootDir, sourceRoot } = options;
|
|
4272
4472
|
const cleanedFile = file.replace(/[?#].*$/, "");
|
|
4273
|
-
const normalizedFile = require_source_candidate_scan_signature.normalizeOutputPathKey(cleanedFile);
|
|
4274
4473
|
const absoluteFile = node_path.default.isAbsolute(cleanedFile) ? cleanedFile : node_path.default.resolve(rootDir, cleanedFile);
|
|
4275
4474
|
const relativeFromOutDir = require_source_candidate_scan_signature.normalizeOutputPathKey(node_path.default.relative(outDir, absoluteFile));
|
|
4276
|
-
|
|
4475
|
+
return [
|
|
4277
4476
|
sourceRoot ? node_path.default.resolve(sourceRoot, file) : void 0,
|
|
4278
4477
|
node_path.default.resolve(rootDir, file),
|
|
4279
4478
|
node_path.default.resolve(node_path.default.dirname(outDir), file),
|
|
@@ -4282,6 +4481,33 @@ function resolveCurrentSourceCandidateSource(options) {
|
|
|
4282
4481
|
!node_path.default.isAbsolute(relativeFromOutDir) && !relativeFromOutDir.startsWith("../") ? node_path.default.resolve(node_path.default.dirname(outDir), relativeFromOutDir) : void 0,
|
|
4283
4482
|
file
|
|
4284
4483
|
];
|
|
4484
|
+
}
|
|
4485
|
+
function resolveCurrentSourceCandidateFile(options) {
|
|
4486
|
+
const sourceCandidates = createSourceCandidateFiles(options);
|
|
4487
|
+
for (const candidate of sourceCandidates) if (candidate && options.getSourceCandidateSource?.(candidate) !== void 0) return candidate;
|
|
4488
|
+
const normalizedFile = require_source_candidate_scan_signature.normalizeOutputPathKey(options.file.replace(/[?#].*$/, ""));
|
|
4489
|
+
let bestMatch;
|
|
4490
|
+
const normalizedSourceCandidates = sourceCandidates.filter((candidate) => Boolean(candidate)).map((candidate) => ({
|
|
4491
|
+
absolute: node_path.default.isAbsolute(candidate),
|
|
4492
|
+
key: normalizeSourceCandidatePathKey(candidate)
|
|
4493
|
+
}));
|
|
4494
|
+
for (const [sourceFile] of options.getSourceCandidateSources?.() ?? []) {
|
|
4495
|
+
const normalizedSourceFile = normalizeSourceCandidatePathKey(sourceFile);
|
|
4496
|
+
let score = normalizedSourceCandidates.reduce((current, candidate) => {
|
|
4497
|
+
return normalizedSourceFile === candidate.key ? Math.max(current, candidate.absolute ? 100 : 80) : current;
|
|
4498
|
+
}, 0);
|
|
4499
|
+
if (normalizedSourceFile.endsWith(`/${normalizedFile}`)) score = Math.max(score, 20);
|
|
4500
|
+
if (score > (bestMatch?.score ?? 0)) bestMatch = {
|
|
4501
|
+
file: sourceFile,
|
|
4502
|
+
score
|
|
4503
|
+
};
|
|
4504
|
+
}
|
|
4505
|
+
return bestMatch?.file;
|
|
4506
|
+
}
|
|
4507
|
+
function resolveCurrentSourceCandidateSource(options) {
|
|
4508
|
+
const { file, getSourceCandidateSource, getSourceCandidateSources } = options;
|
|
4509
|
+
const normalizedFile = require_source_candidate_scan_signature.normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
4510
|
+
const sourceCandidates = createSourceCandidateFiles(options);
|
|
4285
4511
|
const explicitSource = sourceCandidates.reduce((source, candidate) => {
|
|
4286
4512
|
if (source || !candidate) return source;
|
|
4287
4513
|
return getSourceCandidateSource?.(candidate);
|
|
@@ -4540,102 +4766,6 @@ function createBundleTaskTimer(recordTimingDetail) {
|
|
|
4540
4766
|
};
|
|
4541
4767
|
}
|
|
4542
4768
|
//#endregion
|
|
4543
|
-
//#region src/bundlers/vite/generate-bundle/transform-filter.ts
|
|
4544
|
-
function toArray(value) {
|
|
4545
|
-
return Array.isArray(value) ? value : value === void 0 ? [] : [value];
|
|
4546
|
-
}
|
|
4547
|
-
function normalizeSourceId(id) {
|
|
4548
|
-
const file = (0, _weapp_tailwindcss_shared.cleanUrl)(id);
|
|
4549
|
-
return node_path.default.isAbsolute(file) ? node_path.default.resolve(file) : void 0;
|
|
4550
|
-
}
|
|
4551
|
-
function collectChunkModuleIds$1(chunk) {
|
|
4552
|
-
const ids = /* @__PURE__ */ new Set();
|
|
4553
|
-
for (const id of chunk.moduleIds ?? []) {
|
|
4554
|
-
const normalized = normalizeSourceId(id);
|
|
4555
|
-
if (normalized) ids.add(normalized);
|
|
4556
|
-
}
|
|
4557
|
-
for (const id of Object.keys(chunk.modules ?? {})) {
|
|
4558
|
-
const normalized = normalizeSourceId(id);
|
|
4559
|
-
if (normalized) ids.add(normalized);
|
|
4560
|
-
}
|
|
4561
|
-
return ids;
|
|
4562
|
-
}
|
|
4563
|
-
function collectAssetSourceIds(asset, fallbackFile, rootDir) {
|
|
4564
|
-
const ids = /* @__PURE__ */ new Set();
|
|
4565
|
-
const sourceCandidates = [asset.originalFileName, ...asset.originalFileNames ?? []].filter((candidate) => typeof candidate === "string" && candidate.length > 0);
|
|
4566
|
-
const candidates = sourceCandidates.length > 0 ? sourceCandidates : [fallbackFile];
|
|
4567
|
-
for (const candidate of candidates) {
|
|
4568
|
-
if (typeof candidate !== "string" || candidate.length === 0) continue;
|
|
4569
|
-
const cleanCandidate = (0, _weapp_tailwindcss_shared.cleanUrl)(candidate);
|
|
4570
|
-
const resolved = node_path.default.isAbsolute(cleanCandidate) ? node_path.default.resolve(cleanCandidate) : node_path.default.resolve(rootDir, cleanCandidate);
|
|
4571
|
-
ids.add(resolved);
|
|
4572
|
-
}
|
|
4573
|
-
return ids;
|
|
4574
|
-
}
|
|
4575
|
-
function isStringRuleMatched(rule, id, rootDir) {
|
|
4576
|
-
const normalizedId = require_source_candidate_scan_signature.slash(id);
|
|
4577
|
-
const normalizedRule = require_source_candidate_scan_signature.slash(rule);
|
|
4578
|
-
if (node_path.default.isAbsolute(rule)) return micromatch.default.isMatch(normalizedId, normalizedRule);
|
|
4579
|
-
const relative = require_source_candidate_scan_signature.slash(node_path.default.relative(rootDir, id));
|
|
4580
|
-
return relative.length > 0 && !relative.startsWith("../") && !node_path.default.isAbsolute(relative) && micromatch.default.isMatch(relative, normalizedRule);
|
|
4581
|
-
}
|
|
4582
|
-
function isRuleMatched(rule, id, rootDir) {
|
|
4583
|
-
if (typeof rule === "string") return isStringRuleMatched(rule, id, rootDir);
|
|
4584
|
-
if (rule instanceof RegExp) {
|
|
4585
|
-
rule.lastIndex = 0;
|
|
4586
|
-
return rule.test(require_source_candidate_scan_signature.slash(id));
|
|
4587
|
-
}
|
|
4588
|
-
return rule(id) === true;
|
|
4589
|
-
}
|
|
4590
|
-
function createTransformMatcher(rules, rootDir) {
|
|
4591
|
-
const normalizedRules = toArray(rules);
|
|
4592
|
-
if (normalizedRules.length === 0) return;
|
|
4593
|
-
return (id) => normalizedRules.some((rule) => isRuleMatched(rule, id, rootDir));
|
|
4594
|
-
}
|
|
4595
|
-
function shouldSkipSourceIds(sourceIds, filter) {
|
|
4596
|
-
if (sourceIds.size === 0) return false;
|
|
4597
|
-
if (filter.exclude) {
|
|
4598
|
-
let excluded = true;
|
|
4599
|
-
for (const id of sourceIds) if (!filter.exclude(id)) {
|
|
4600
|
-
excluded = false;
|
|
4601
|
-
break;
|
|
4602
|
-
}
|
|
4603
|
-
if (excluded) return true;
|
|
4604
|
-
}
|
|
4605
|
-
if (filter.include) {
|
|
4606
|
-
for (const id of sourceIds) if (filter.include(id)) return false;
|
|
4607
|
-
return true;
|
|
4608
|
-
}
|
|
4609
|
-
return false;
|
|
4610
|
-
}
|
|
4611
|
-
function createTransformFilter(options, rootDir) {
|
|
4612
|
-
const include = createTransformMatcher(options?.include, rootDir);
|
|
4613
|
-
const exclude = createTransformMatcher(options?.exclude, rootDir);
|
|
4614
|
-
if (!include && !exclude) return;
|
|
4615
|
-
return {
|
|
4616
|
-
include,
|
|
4617
|
-
exclude
|
|
4618
|
-
};
|
|
4619
|
-
}
|
|
4620
|
-
function shouldSkipViteJsChunkTransform(chunk, filter) {
|
|
4621
|
-
if (!filter) return false;
|
|
4622
|
-
return shouldSkipSourceIds(collectChunkModuleIds$1(chunk), filter);
|
|
4623
|
-
}
|
|
4624
|
-
function shouldSkipViteAssetTransform(asset, file, rootDir, filter) {
|
|
4625
|
-
if (!filter) return false;
|
|
4626
|
-
return shouldSkipSourceIds(collectAssetSourceIds(asset, file, rootDir), filter);
|
|
4627
|
-
}
|
|
4628
|
-
function createRuleSignature(rules) {
|
|
4629
|
-
return toArray(rules).map((rule) => {
|
|
4630
|
-
if (typeof rule === "string") return `s:${rule}`;
|
|
4631
|
-
if (rule instanceof RegExp) return `r:${rule.source}/${rule.flags}`;
|
|
4632
|
-
return "f";
|
|
4633
|
-
}).join("|") || "none";
|
|
4634
|
-
}
|
|
4635
|
-
function createTransformFilterSignature(options) {
|
|
4636
|
-
return [`include:${createRuleSignature(options?.include)}`, `exclude:${createRuleSignature(options?.exclude)}`].join(";");
|
|
4637
|
-
}
|
|
4638
|
-
//#endregion
|
|
4639
4769
|
//#region src/bundlers/vite/weapp-vite-config.ts
|
|
4640
4770
|
function resolveSourceRootCandidate(root, value) {
|
|
4641
4771
|
if (typeof value !== "string" || value.trim().length === 0) return;
|
|
@@ -4756,8 +4886,11 @@ function createGenerateBundleHook(context) {
|
|
|
4756
4886
|
})
|
|
4757
4887
|
});
|
|
4758
4888
|
return async function generateBundle(_opt, bundle) {
|
|
4889
|
+
if (context.shouldProcessBundle?.() === false) return;
|
|
4890
|
+
const processMarkupAndScripts = context.processMarkupAndScripts !== false;
|
|
4891
|
+
const processStyles = context.shouldProcessStyles?.() ?? context.processStyles !== false;
|
|
4759
4892
|
const addWatchFile = (id) => this.addWatchFile?.(id);
|
|
4760
|
-
const { opts, runtimeState, ensureBundleRuntimeClassSet, debug, getResolvedConfig, markCssAssetProcessed, isCssAssetProcessed, isViteProcessedCssAsset, recordCssAssetResult, recordViteProcessedCssAssetResult, getViteProcessedCssAssetResults, getViteProcessedCssAssetResult, getSourceCandidates, getSourceCandidateSource, getSourceCandidateSources, getSourceCandidatesForEntries, getSourceCandidateSourcesForEntries, waitForSourceCandidateSyncs, rememberCssSource, refreshRememberedCssSource, getRememberedCssSources, getRememberedCssSignature, setRememberedCssSignature, getKnownCssSource, getKnownSfcSource, getOriginalCssLayerSource, recordGeneratorCandidates, pruneViteCssCaches, getViteCssCacheStats, hmrTimingRecorder } = context;
|
|
4893
|
+
const { opts, runtimeState, ensureBundleRuntimeClassSet, debug, getResolvedConfig, markCssAssetProcessed, isCssAssetProcessed, isViteProcessedCssAsset, recordCssAssetResult, recordViteProcessedCssAssetResult, getViteProcessedCssAssetResults, getViteProcessedCssAssetResult, getSourceCandidates, getSourceCandidateSource, getSourceCandidateSources, extractSourceCandidates, getSourceCandidatesForEntries, getSourceCandidateSourcesForEntries, waitForSourceCandidateSyncs, rememberCssSource, refreshRememberedCssSource, getRememberedCssSources, getRememberedCssSignature, setRememberedCssSignature, getKnownCssSource, getKnownSfcSource, getOriginalCssLayerSource, recordGeneratorCandidates, pruneViteCssCaches, getViteCssCacheStats, hmrTimingRecorder } = context;
|
|
4761
4894
|
const getBundlerSfcSource = (sourceFile) => {
|
|
4762
4895
|
const code = this.getModuleInfo?.(sourceFile)?.code;
|
|
4763
4896
|
return typeof code === "string" && hasSfcStyleSources(code) ? code : void 0;
|
|
@@ -4815,7 +4948,7 @@ function createGenerateBundleHook(context) {
|
|
|
4815
4948
|
await runtimeState.readyPromise;
|
|
4816
4949
|
debug("start");
|
|
4817
4950
|
onStart();
|
|
4818
|
-
const collectedBundlerGeneratedCssFiles = new Set(Object.entries(bundle).filter(([, output]) => output.type === "asset" &&
|
|
4951
|
+
const collectedBundlerGeneratedCssFiles = new Set(Object.entries(bundle).filter(([, output]) => output.type === "asset" && require_hmr_timing.hasBundlerGeneratedCssMarker(output.source)).map(([file]) => file));
|
|
4819
4952
|
const subpackageRoots = collectMiniProgramSubpackageRoots(bundle);
|
|
4820
4953
|
if (subpackageRoots) currentSubpackageRoots = subpackageRoots;
|
|
4821
4954
|
collectViteProcessedCssAssetResults(bundle, {
|
|
@@ -4975,18 +5108,6 @@ function createGenerateBundleHook(context) {
|
|
|
4975
5108
|
return !require_source_candidate_scan_signature.normalizeOutputPathKey(entryOutputFile.replace(/[?#].*$/, "")).includes("/") || currentSubpackageRoots != null && !isSubpackageOutputFile(entryOutputFile, currentSubpackageRoots);
|
|
4976
5109
|
});
|
|
4977
5110
|
};
|
|
4978
|
-
const { createScopedSourceCandidateGetter, createScopedSourceCandidateSourceGetter, shouldExcludeSubpackageSourceCandidates, shouldInjectCssIntoMainFromOutput } = createSubpackageSourceCandidateScope({
|
|
4979
|
-
cssSourceFiles: configuredTailwindV4CssSourceEntriesForScope.map((entry) => entry.file),
|
|
4980
|
-
getSourceCandidateSourcesForEntries,
|
|
4981
|
-
getSourceCandidatesForEntries,
|
|
4982
|
-
projectRoot: opts.tailwindcssRuntimeOptions?.projectRoot,
|
|
4983
|
-
rootDir,
|
|
4984
|
-
snapshot,
|
|
4985
|
-
sourceRoot,
|
|
4986
|
-
subpackageRoots: currentSubpackageRoots,
|
|
4987
|
-
tailwindcssBasedir: opts.tailwindcssBasedir,
|
|
4988
|
-
useIncrementalMode
|
|
4989
|
-
});
|
|
4990
5111
|
recordTimingDetail("snapshot", snapshotStart);
|
|
4991
5112
|
const useBundleRuntimeClassSet = !isWebGeneratorTarget;
|
|
4992
5113
|
const forceRuntimeRefreshBySource = useIncrementalMode && require_source_candidate_scan_signature.hasRuntimeAffectingSourceChanges(snapshot.runtimeAffectingChangedByType);
|
|
@@ -5000,11 +5121,41 @@ function createGenerateBundleHook(context) {
|
|
|
5000
5121
|
const sourceCandidateWaitStart = performance.now();
|
|
5001
5122
|
await waitForSourceCandidateSyncs?.();
|
|
5002
5123
|
recordTimingDetail("sourceCandidates.wait", sourceCandidateWaitStart);
|
|
5003
|
-
const
|
|
5124
|
+
const transformFilter = createTransformFilter(opts.transform, rootDir);
|
|
5125
|
+
const bundleMarkupCandidates = await collectBundleMarkupCandidates({
|
|
5126
|
+
extractSourceCandidates: processMarkupAndScripts && !isWebGeneratorTarget ? extractSourceCandidates : void 0,
|
|
5127
|
+
previousCandidatesByFile: useIncrementalMode ? state.bundleMarkupCandidatesByFile : void 0,
|
|
5128
|
+
preserveMissingFiles: useIncrementalMode && snapshot.hasOmittedKnownFiles,
|
|
5129
|
+
resolveSourceCandidateFile: (file) => resolveCurrentSourceCandidateFile({
|
|
5130
|
+
file,
|
|
5131
|
+
getSourceCandidateSource,
|
|
5132
|
+
getSourceCandidateSources,
|
|
5133
|
+
outDir,
|
|
5134
|
+
rootDir,
|
|
5135
|
+
sourceRoot
|
|
5136
|
+
}),
|
|
5137
|
+
rootDir,
|
|
5138
|
+
snapshot,
|
|
5139
|
+
transformFilter
|
|
5140
|
+
});
|
|
5141
|
+
const getCombinedSourceCandidatesForEntries = getSourceCandidatesForEntries || bundleMarkupCandidates.values.size > 0 ? (entries, options) => /* @__PURE__ */ new Set([...getSourceCandidatesForEntries?.(entries, options) ?? [], ...bundleMarkupCandidates.valuesForEntries(entries, options)]) : void 0;
|
|
5142
|
+
const sourceCandidates = /* @__PURE__ */ new Set([...getSourceCandidates?.() ?? [], ...bundleMarkupCandidates.values]);
|
|
5143
|
+
const { createScopedSourceCandidateGetter, createScopedSourceCandidateSourceGetter, shouldExcludeSubpackageSourceCandidates, shouldInjectCssIntoMainFromOutput } = createSubpackageSourceCandidateScope({
|
|
5144
|
+
cssSourceFiles: configuredTailwindV4CssSourceEntriesForScope.map((entry) => entry.file),
|
|
5145
|
+
getSourceCandidateSourcesForEntries,
|
|
5146
|
+
getSourceCandidatesForEntries: getCombinedSourceCandidatesForEntries,
|
|
5147
|
+
projectRoot: opts.tailwindcssRuntimeOptions?.projectRoot,
|
|
5148
|
+
rootDir,
|
|
5149
|
+
snapshot,
|
|
5150
|
+
sourceRoot,
|
|
5151
|
+
subpackageRoots: currentSubpackageRoots,
|
|
5152
|
+
tailwindcssBasedir: opts.tailwindcssBasedir,
|
|
5153
|
+
useIncrementalMode
|
|
5154
|
+
});
|
|
5004
5155
|
const createScopedGeneratorRuntime$1 = (outputFile, cssHandlerOptions, runtime, rawSource, sourceFile) => require_source_candidate_scan_signature.createScopedGeneratorRuntime({
|
|
5005
5156
|
cssHandlerOptions,
|
|
5006
5157
|
fallbackRuntime: runtime,
|
|
5007
|
-
getSourceCandidatesForEntries,
|
|
5158
|
+
getSourceCandidatesForEntries: getCombinedSourceCandidatesForEntries,
|
|
5008
5159
|
majorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
5009
5160
|
outputFile,
|
|
5010
5161
|
rawSource,
|
|
@@ -5014,7 +5165,6 @@ function createGenerateBundleHook(context) {
|
|
|
5014
5165
|
});
|
|
5015
5166
|
const jsEntries = snapshot.jsEntries;
|
|
5016
5167
|
const getJsEntry = createJsEntryResolver(jsEntries);
|
|
5017
|
-
const transformFilter = createTransformFilter(opts.transform, rootDir);
|
|
5018
5168
|
const transformFilterSignature = createTransformFilterSignature(opts.transform);
|
|
5019
5169
|
const moduleGraphOptions = require_source_candidate_scan_signature.createBundleModuleGraphOptions(outDir, jsEntries);
|
|
5020
5170
|
const hasRuntimeAffectingChanges = require_source_candidate_scan_signature.hasRuntimeAffectingSourceChanges(snapshot.runtimeAffectingChangedByType);
|
|
@@ -5164,7 +5314,7 @@ function createGenerateBundleHook(context) {
|
|
|
5164
5314
|
const jsTaskFactories = [];
|
|
5165
5315
|
for (const entry of snapshot.entries) {
|
|
5166
5316
|
const { file, output: originalSource, source: originalEntrySource, type } = entry;
|
|
5167
|
-
if (type === "html" && originalSource.type === "asset") {
|
|
5317
|
+
if (processMarkupAndScripts && type === "html" && originalSource.type === "asset") {
|
|
5168
5318
|
metrics.html.total++;
|
|
5169
5319
|
if (isWebGeneratorTarget) {
|
|
5170
5320
|
debug("html skip web target: %s", file);
|
|
@@ -5203,7 +5353,7 @@ function createGenerateBundleHook(context) {
|
|
|
5203
5353
|
});
|
|
5204
5354
|
continue;
|
|
5205
5355
|
}
|
|
5206
|
-
if (type === "css" && originalSource.type === "asset") {
|
|
5356
|
+
if (processStyles && type === "css" && originalSource.type === "asset") {
|
|
5207
5357
|
metrics.css.total++;
|
|
5208
5358
|
const assetSourceFile = resolveAssetSourceFile(originalSource, file);
|
|
5209
5359
|
const rawSource = normalizeRelativeCssConfigDirectives(originalEntrySource, assetSourceFile, outDir, opts);
|
|
@@ -5468,6 +5618,11 @@ function createGenerateBundleHook(context) {
|
|
|
5468
5618
|
}
|
|
5469
5619
|
}
|
|
5470
5620
|
if (currentRawSourceHasExplicitScanContext) rememberedCssSources = rememberedCssSources.filter((remembered) => remembered.rawSource.includes("@source") || remembered.rawSource.includes("@config"));
|
|
5621
|
+
rememberedCssSources = rememberedCssSources.filter((remembered) => {
|
|
5622
|
+
const shouldSkip = shouldSkipRawRememberedCssSource(remembered.rawSource, remembered.sourceFile);
|
|
5623
|
+
if (shouldSkip) debug("css skip raw remembered source style: %s -> %s", remembered.sourceFile, outputFile);
|
|
5624
|
+
return !shouldSkip;
|
|
5625
|
+
});
|
|
5471
5626
|
let rememberedCssSource = mergeRememberedCssSources(rememberedCssSources, outputFile);
|
|
5472
5627
|
if (rememberedCssSource && viteProcessedCssAsset && outputCssHandlerOptions.isMainChunk !== true && configuredTailwindV4CssSourceFileKeysForScope.has(normalizeConfiguredTailwindV4CssEntryFileKey(rememberedCssSource.sourceFile))) {
|
|
5473
5628
|
const matchedOutputFile = resolveMatchedOutputFileForCurrentAsset(rememberedCssSource.sourceFile);
|
|
@@ -5555,14 +5710,14 @@ function createGenerateBundleHook(context) {
|
|
|
5555
5710
|
const cssRuntimeAffectingSignature = vitePipelineCssAsset ? require_source_candidate_scan_signature.createRuntimeAffectingSourceSignature(generatorRawSource, "css") : snapshot.runtimeAffectingSignatureByFile.get(file) ?? require_source_candidate_scan_signature.createRuntimeAffectingSourceSignature(generatorRawSource, "css");
|
|
5556
5711
|
const cssRuntimeAffectingHash = vitePipelineCssAsset ? cache.computeHash(cssRuntimeAffectingSignature) : snapshot.runtimeAffectingHashByFile.get(file) ?? cache.computeHash(cssRuntimeAffectingSignature);
|
|
5557
5712
|
const cssShareScope = createCssTransformShareScopeKey(opts, outputFile, generatorRawSource);
|
|
5558
|
-
const shouldRegenerateCollectedViteCss = viteProcessedCssAsset && useIncrementalMode && state.generatorCandidateSignature !== void 0 && generatorCandidatesChanged && (hasTailwindGenerationSource(generatorRawSource) ||
|
|
5713
|
+
const shouldRegenerateCollectedViteCss = viteProcessedCssAsset && useIncrementalMode && state.generatorCandidateSignature !== void 0 && generatorCandidatesChanged && (hasTailwindGenerationSource(generatorRawSource) || require_hmr_timing.hasBundlerGeneratedCssMarker(rawSource) || rememberedCssSource != null && hasTailwindGenerationSource(rememberedCssSource.rawSource));
|
|
5559
5714
|
const shouldRefreshViteProcessedCssByCandidates = viteProcessedCssAsset && useIncrementalMode && state.generatorCandidateSignature !== void 0 && generatorCandidatesChanged;
|
|
5560
5715
|
const vitePipelineCssInjectionOutputFile = webviewRootCssInjectionTarget ?? outputFile;
|
|
5561
5716
|
const shouldRecordVitePipelineCssByOutput = require_source_candidate_scan_signature.normalizeOutputPathKey(vitePipelineCssInjectionOutputFile) === require_source_candidate_scan_signature.normalizeOutputPathKey(outputFile);
|
|
5562
5717
|
const shouldInjectVitePipelineCssIntoMain = vitePipelineCssAsset && !resolvedFromConfiguredOriginalCssEntry && outputCssHandlerOptions.isMainChunk !== true && (webviewRootCssInjectionTarget != null || shouldInjectCssIntoMainFromOutput(outputFile, generatorSourceFile, outputCssHandlerOptions));
|
|
5563
5718
|
const shouldTrackGeneratorRuntime = hasStaleViteProcessedCssSource || shouldRegenerateMainPackageCssWithScopedCandidates || hasCurrentTailwindGenerationDirective || hasSameOutputRememberedTailwindGenerationSource || shouldProcessTailwindGeneration && (!useIncrementalMode || cssHandlerOptions.isMainChunk || processFiles.css.has(file) || runtimeLinkedCssFiles.has(file) || runtimeLinkedCssFiles.has(outputFile) || shouldRegenerateCollectedViteCss || hasRuntimeAffectingChanges && (alreadyProcessedCssAsset || vitePipelineCssAsset));
|
|
5564
|
-
const shouldPreserveCollectedViteCssAsset = !shouldRegenerateCollectedViteCss && (state.generatorCandidateSignature === void 0 || !generatorCandidatesChanged) && (collectedBundlerGeneratedCssFiles.has(file) ||
|
|
5565
|
-
const strippedViteProcessedCss =
|
|
5719
|
+
const shouldPreserveCollectedViteCssAsset = !shouldRegenerateCollectedViteCss && (state.generatorCandidateSignature === void 0 || !generatorCandidatesChanged) && (collectedBundlerGeneratedCssFiles.has(file) || require_hmr_timing.hasBundlerGeneratedCssMarker(rawSource));
|
|
5720
|
+
const strippedViteProcessedCss = require_hmr_timing.stripBundlerGeneratedCssMarkers(rawSource);
|
|
5566
5721
|
const shouldPreserveStaleGeneratedCssAsset = hasStaleViteProcessedCssSource && shouldPreserveCollectedViteCssAsset && strippedViteProcessedCss.trim().length > 0 && !strippedViteProcessedCss.includes("weapp-tailwindcss generator-placeholder") && !strippedViteProcessedCss.includes("vite-placeholder") && !hasTailwindGenerationSource(strippedViteProcessedCss) && !require_generator.hasTailwindApplyDirective(strippedViteProcessedCss);
|
|
5567
5722
|
if (alreadyProcessedCssAsset && !shouldRefreshViteProcessedCssByCandidates && (!hasStaleViteProcessedCssSource || shouldPreserveStaleGeneratedCssAsset) && !hasRememberedApplySource && !shouldRegenerateMainPackageCssWithScopedCandidates && (!shouldTrackGeneratorRuntime || shouldPreserveCollectedViteCssAsset)) {
|
|
5568
5723
|
const nextCss = removeRootCoveredCssFromScopedAsset(strippedViteProcessedCss);
|
|
@@ -5644,8 +5799,8 @@ function createGenerateBundleHook(context) {
|
|
|
5644
5799
|
const previousCss = !vitePipelineCssAsset && useIncrementalMode && !generatorCandidatesChanged && !hasRuntimeAffectingChanges && !snapshot.changedByType.css.has(file) ? getLastCssResult(lastCssResultByFile, outputFile, file) : void 0;
|
|
5645
5800
|
const generatorTransformRawSource = generatorRawSource;
|
|
5646
5801
|
const previousGeneratorCss = previousCss && !isWebGeneratorTarget ? normalizeMiniProgramGeneratorRawSource(previousCss, outputFile) : previousCss;
|
|
5647
|
-
const shouldGenerateCssWithCore = hasTailwindGenerationSource(generatorTransformRawSource) ||
|
|
5648
|
-
const bundleUserRawSource = vitePipelineCssAsset && !
|
|
5802
|
+
const shouldGenerateCssWithCore = hasTailwindGenerationSource(generatorTransformRawSource) || require_hmr_timing.hasBundlerGeneratedCssMarker(rawSource);
|
|
5803
|
+
const bundleUserRawSource = vitePipelineCssAsset && !require_hmr_timing.hasBundlerGeneratedCssMarker(rawSource) && normalizeCssSourceForCompare(rawSource) !== normalizeCssSourceForCompare(generatorRawSource) ? normalizeMiniProgramGeneratorRawSource(normalizeGeneratorUserRawSource(rawSource, generatorSourceFile, assetSourceFile), outputFile) : void 0;
|
|
5649
5804
|
const generatorUserRawSource = [generatorUserLayerRawSource, bundleUserRawSource].filter((source) => typeof source === "string" && source.trim().length > 0).join("\n");
|
|
5650
5805
|
const generated = shouldGenerateCssWithCore ? await require_source_candidate_scan_signature.generateTailwindV4Css({
|
|
5651
5806
|
opts,
|
|
@@ -5719,6 +5874,7 @@ function createGenerateBundleHook(context) {
|
|
|
5719
5874
|
continue;
|
|
5720
5875
|
}
|
|
5721
5876
|
if (type !== "js") continue;
|
|
5877
|
+
if (!processMarkupAndScripts) continue;
|
|
5722
5878
|
if (!shouldTransformJsBundle) {
|
|
5723
5879
|
debug("js skip web target: %s", file);
|
|
5724
5880
|
continue;
|
|
@@ -5752,7 +5908,7 @@ function createGenerateBundleHook(context) {
|
|
|
5752
5908
|
useIncrementalMode
|
|
5753
5909
|
});
|
|
5754
5910
|
}
|
|
5755
|
-
if (shouldProcessTailwindGeneration || useIncrementalMode || isNativeAppStyleTarget) await processRememberedCssReplay({
|
|
5911
|
+
if (processStyles && (shouldProcessTailwindGeneration || useIncrementalMode || isNativeAppStyleTarget)) await processRememberedCssReplay({
|
|
5756
5912
|
addWatchFile,
|
|
5757
5913
|
activeViteCssCacheFiles,
|
|
5758
5914
|
bundle,
|
|
@@ -5814,7 +5970,7 @@ function createGenerateBundleHook(context) {
|
|
|
5814
5970
|
generatorRuntime,
|
|
5815
5971
|
getCssHandlerOptions,
|
|
5816
5972
|
getSourceCandidateSourcesForEntries,
|
|
5817
|
-
getSourceCandidatesForEntries,
|
|
5973
|
+
getSourceCandidatesForEntries: getCombinedSourceCandidatesForEntries,
|
|
5818
5974
|
getViteCssCacheStats,
|
|
5819
5975
|
getViteProcessedCssAssetResults,
|
|
5820
5976
|
hmrTimingRecorder,
|
|
@@ -5854,6 +6010,7 @@ function createGenerateBundleHook(context) {
|
|
|
5854
6010
|
transformWebTargetCss,
|
|
5855
6011
|
useIncrementalMode
|
|
5856
6012
|
});
|
|
6013
|
+
state.bundleMarkupCandidatesByFile = bundleMarkupCandidates.candidatesByFile;
|
|
5857
6014
|
};
|
|
5858
6015
|
}
|
|
5859
6016
|
//#endregion
|
|
@@ -6073,10 +6230,15 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
6073
6230
|
const file = output.fileName || bundleFile;
|
|
6074
6231
|
const rawSource = output.source.toString();
|
|
6075
6232
|
if (isViteProcessedCssAsset?.(output, file)) {
|
|
6076
|
-
const
|
|
6233
|
+
const cleanRawSource = require_hmr_timing.stripBundlerGeneratedCssMarkers(rawSource);
|
|
6234
|
+
const cssHandlerOptions = createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, file, outDir, cssPipelineStrategy?.getCssHandlerExtraOptions?.({
|
|
6077
6235
|
...createCssPipelineContext(file),
|
|
6078
6236
|
file
|
|
6079
|
-
}
|
|
6237
|
+
}) ?? {});
|
|
6238
|
+
const nextCss = annotateCss(generatorBranch.isWeb ? finalizeWebCss(cleanRawSource, {
|
|
6239
|
+
...createCssPipelineContext(file),
|
|
6240
|
+
file
|
|
6241
|
+
}, cssPipelineStrategy) : (await opts.styleHandler(cleanRawSource, cssHandlerOptions)).css);
|
|
6080
6242
|
output.source = nextCss;
|
|
6081
6243
|
markCssAssetProcessed(output, file);
|
|
6082
6244
|
recordCssAssetResult?.(file, nextCss);
|
|
@@ -6091,7 +6253,7 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
6091
6253
|
...cssHandlerOptions,
|
|
6092
6254
|
isMainChunk: false
|
|
6093
6255
|
};
|
|
6094
|
-
const cleanRawSource =
|
|
6256
|
+
const cleanRawSource = require_hmr_timing.stripBundlerGeneratedCssMarkers(rawSource);
|
|
6095
6257
|
if (cleanRawSource !== rawSource && cleanRawSource.trim().length === 0) {
|
|
6096
6258
|
output.source = cleanRawSource;
|
|
6097
6259
|
markCssAssetProcessed(output, file);
|
|
@@ -6218,7 +6380,7 @@ function normalizeCssSourceIdentity(sourceFile) {
|
|
|
6218
6380
|
const { filename, query } = parseVueRequest(cleanSourceFile);
|
|
6219
6381
|
const normalizedFile = require_source_candidate_scan_signature.normalizeOutputPathKey(filename);
|
|
6220
6382
|
if (query.type === "style") return `${normalizedFile}?type=style&index=${query.index ?? 0}`;
|
|
6221
|
-
return require_source_candidate_scan_signature.normalizeOutputPathKey(
|
|
6383
|
+
return require_source_candidate_scan_signature.normalizeOutputPathKey(require_hmr_timing.stripRequestQuery(cleanSourceFile));
|
|
6222
6384
|
}
|
|
6223
6385
|
function hasSfcStyleBlocks(source) {
|
|
6224
6386
|
SFC_STYLE_BLOCK_RE.lastIndex = 0;
|
|
@@ -6321,19 +6483,19 @@ function createViteCssMemory(options) {
|
|
|
6321
6483
|
for (const [rememberedKey, remembered] of relatedRememberedEntries) refreshRememberedCssSourceEntry(rememberedKey, remembered, sourceFile, rawSource);
|
|
6322
6484
|
};
|
|
6323
6485
|
const resolveCachedStyleSource = (sourceFile) => {
|
|
6324
|
-
const file = (0, _weapp_tailwindcss_shared.cleanUrl)(
|
|
6486
|
+
const file = (0, _weapp_tailwindcss_shared.cleanUrl)(require_hmr_timing.stripRequestQuery(sourceFile));
|
|
6325
6487
|
if (SFC_COMPONENT_FILE_RE.test(file)) return getKnownSfcSource(file);
|
|
6326
|
-
if (
|
|
6488
|
+
if (require_hmr_timing.isSourceStyleRequest(file)) return options.getSourceCandidateSource(file);
|
|
6327
6489
|
};
|
|
6328
6490
|
const resolveCurrentStyleSource = async (sourceFile) => {
|
|
6329
6491
|
const cached = resolveCachedStyleSource(sourceFile);
|
|
6330
6492
|
if (cached != null) return cached;
|
|
6331
|
-
const file = (0, _weapp_tailwindcss_shared.cleanUrl)(
|
|
6493
|
+
const file = (0, _weapp_tailwindcss_shared.cleanUrl)(require_hmr_timing.stripRequestQuery(sourceFile));
|
|
6332
6494
|
const knownSource = knownCssSources.get(normalizeCssSourceIdentity(sourceFile));
|
|
6333
6495
|
if (knownSource != null) return knownSource;
|
|
6334
6496
|
const candidateSource = options.getSourceCandidateSource(file);
|
|
6335
6497
|
if (candidateSource != null) return candidateSource;
|
|
6336
|
-
if (!
|
|
6498
|
+
if (!require_hmr_timing.isSourceStyleRequest(file)) return;
|
|
6337
6499
|
try {
|
|
6338
6500
|
return await (0, node_fs_promises.readFile)(file, "utf8");
|
|
6339
6501
|
} catch (error) {
|
|
@@ -6344,7 +6506,7 @@ function createViteCssMemory(options) {
|
|
|
6344
6506
|
const refreshRememberedCssSourceByCurrentFile = async (sourceFile) => {
|
|
6345
6507
|
const file = (0, _weapp_tailwindcss_shared.cleanUrl)(sourceFile);
|
|
6346
6508
|
const normalizedSourceFile = require_source_candidate_scan_signature.normalizeOutputPathKey(file);
|
|
6347
|
-
const matchedRememberedSources = [...rememberedCssSources.values()].filter((remembered) => require_source_candidate_scan_signature.normalizeOutputPathKey(
|
|
6509
|
+
const matchedRememberedSources = [...rememberedCssSources.values()].filter((remembered) => require_source_candidate_scan_signature.normalizeOutputPathKey(require_hmr_timing.stripRequestQuery((0, _weapp_tailwindcss_shared.cleanUrl)(remembered.sourceFile))) === normalizedSourceFile);
|
|
6348
6510
|
if (matchedRememberedSources.length === 0) return;
|
|
6349
6511
|
const source = await resolveCurrentStyleSource(file);
|
|
6350
6512
|
if (source == null) {
|
|
@@ -6359,10 +6521,10 @@ function createViteCssMemory(options) {
|
|
|
6359
6521
|
}
|
|
6360
6522
|
return;
|
|
6361
6523
|
}
|
|
6362
|
-
if (
|
|
6524
|
+
if (require_hmr_timing.isSourceStyleRequest(file)) refreshRememberedCssSourceBySourceFile(file, source);
|
|
6363
6525
|
};
|
|
6364
6526
|
const refreshRememberedCssSource = async (remembered) => {
|
|
6365
|
-
const file = (0, _weapp_tailwindcss_shared.cleanUrl)(
|
|
6527
|
+
const file = (0, _weapp_tailwindcss_shared.cleanUrl)(require_hmr_timing.stripRequestQuery(remembered.sourceFile));
|
|
6366
6528
|
const rememberedKey = [...rememberedCssSources.entries()].find(([, entry]) => entry === remembered)?.[0];
|
|
6367
6529
|
if (!rememberedKey || !node_path.default.isAbsolute(file)) return;
|
|
6368
6530
|
const source = await resolveCurrentStyleSource(file);
|
|
@@ -6375,7 +6537,7 @@ function createViteCssMemory(options) {
|
|
|
6375
6537
|
const styleSource = extractSfcStyleSource(source, query.type === "style" ? query.index : void 0);
|
|
6376
6538
|
return styleSource === void 0 ? void 0 : refreshRememberedCssSourceEntry(rememberedKey, remembered, remembered.sourceFile, styleSource);
|
|
6377
6539
|
}
|
|
6378
|
-
if (
|
|
6540
|
+
if (require_hmr_timing.isSourceStyleRequest(file)) return refreshRememberedCssSourceEntry(rememberedKey, remembered, remembered.sourceFile, source);
|
|
6379
6541
|
};
|
|
6380
6542
|
const prune = (pruneOptions) => {
|
|
6381
6543
|
const activeFiles = new Set([...pruneOptions.activeFiles].map(require_source_candidate_scan_signature.normalizeOutputPathKey));
|
|
@@ -6431,7 +6593,7 @@ function resolveHotTailwindCssModules(ctx, tailwindRootCssModuleIds) {
|
|
|
6431
6593
|
const root = ctx.server.config?.root ?? node_process.default.cwd();
|
|
6432
6594
|
const outDir = ctx.server.config?.build?.outDir ? normalizeAbsoluteFilePath(node_path.default.resolve(root, ctx.server.config.build.outDir)) : void 0;
|
|
6433
6595
|
const isHotSourceStyleModule = (id) => {
|
|
6434
|
-
if (!
|
|
6596
|
+
if (!require_hmr_timing.isSourceStyleRequest(id)) return false;
|
|
6435
6597
|
const file = (0, _weapp_tailwindcss_shared.cleanUrl)(id);
|
|
6436
6598
|
if (isRootMiniProgramStyleUrl(file) || !isAbsoluteFilePath(file) && !file.startsWith("/")) return false;
|
|
6437
6599
|
if (outDir && isAbsoluteFilePath(file)) {
|
|
@@ -6464,7 +6626,7 @@ function resolveHotSourceModules(ctx) {
|
|
|
6464
6626
|
const seenModules = /* @__PURE__ */ new Set();
|
|
6465
6627
|
const collectModule = (mod) => {
|
|
6466
6628
|
if (mod == null || seenModules.has(mod)) return;
|
|
6467
|
-
if (
|
|
6629
|
+
if (require_hmr_timing.isSourceStyleRequest(mod.id ?? mod.url)) return;
|
|
6468
6630
|
seenModules.add(mod);
|
|
6469
6631
|
modules.push(mod);
|
|
6470
6632
|
};
|
|
@@ -6522,7 +6684,7 @@ function createSupplementalHotUpdate(hotUrl, timestamp) {
|
|
|
6522
6684
|
}
|
|
6523
6685
|
function hasSelfAcceptingNonStyleHotModule(modules) {
|
|
6524
6686
|
return modules.some((mod) => {
|
|
6525
|
-
return !
|
|
6687
|
+
return !require_hmr_timing.isSourceStyleRequest(mod.id ?? mod.url) && mod.isSelfAccepting === true;
|
|
6526
6688
|
});
|
|
6527
6689
|
}
|
|
6528
6690
|
function sendSupplementalCssHotUpdates(ctx, cssModules, fallbackCssIds = []) {
|
|
@@ -6530,7 +6692,7 @@ function sendSupplementalCssHotUpdates(ctx, cssModules, fallbackCssIds = []) {
|
|
|
6530
6692
|
const root = ctx.server.config?.root ?? node_process.default.cwd();
|
|
6531
6693
|
const updates = [];
|
|
6532
6694
|
for (const id of fallbackCssIds) {
|
|
6533
|
-
if (!
|
|
6695
|
+
if (!require_hmr_timing.isSourceStyleRequest(id)) continue;
|
|
6534
6696
|
const hotUrl = resolveCssHotUrl(id, root);
|
|
6535
6697
|
if (!hotUrl || seenUrls.has(hotUrl)) continue;
|
|
6536
6698
|
seenUrls.add(hotUrl);
|
|
@@ -6668,7 +6830,7 @@ function joinPosixPath(base, subpath) {
|
|
|
6668
6830
|
function isCssLikeImporter(importer) {
|
|
6669
6831
|
if (!importer) return false;
|
|
6670
6832
|
const normalized = (0, _weapp_tailwindcss_shared.cleanUrl)(importer);
|
|
6671
|
-
return
|
|
6833
|
+
return require_hmr_timing.isSourceStyleRequest(importer) || require_source_candidate_scan_signature.isCSSRequest(normalized) || normalized.endsWith("/*");
|
|
6672
6834
|
}
|
|
6673
6835
|
function stripTailwindConfigDirectives(code) {
|
|
6674
6836
|
return code.replace(/^\s*@config\s+(?:"[^"]+"|'[^']+')[^;\n]*;\s*$/gm, "");
|
|
@@ -6887,57 +7049,79 @@ function replaceViteCssHmrModuleCss(code, css) {
|
|
|
6887
7049
|
return `${code.slice(0, extracted.start)}${encodeJsStringLiteral(css)}${code.slice(extracted.end)}`;
|
|
6888
7050
|
}
|
|
6889
7051
|
function isViteServeStyleRequest(id, command) {
|
|
6890
|
-
return command === "serve" &&
|
|
7052
|
+
return command === "serve" && require_hmr_timing.isSourceStyleRequest(id) && !SPECIAL_QUERY_RE$1.test(id) && !COMMON_JS_PROXY_RE.test(id);
|
|
6891
7053
|
}
|
|
6892
7054
|
function isViteServeCssRootRequest(id, command) {
|
|
6893
|
-
return command === "serve" &&
|
|
7055
|
+
return command === "serve" && require_hmr_timing.isSourceStyleRequest(id) && !SPECIAL_QUERY_RE$1.test(id) && !COMMON_JS_PROXY_RE.test(id);
|
|
7056
|
+
}
|
|
7057
|
+
function isViteBuildStyleRequest(id, command) {
|
|
7058
|
+
return command === "build" && require_hmr_timing.isSourceStyleRequest(id) && !SPECIAL_QUERY_RE$1.test(id) && !COMMON_JS_PROXY_RE.test(id);
|
|
6894
7059
|
}
|
|
6895
7060
|
function isViteCssHmrModule(code, id, command) {
|
|
6896
7061
|
return isViteServeStyleRequest(id, command) && VITE_CSS_HMR_MODULE_RE.test(code) && (/[?&](?:direct|vue)(?:&|$)/.test(id) || DEFERRED_CSS_HMR_QUERY_RE.test(id));
|
|
6897
7062
|
}
|
|
6898
|
-
function
|
|
7063
|
+
function hasViteCssGenerationDirective(code) {
|
|
6899
7064
|
return require_generator.hasTailwindRootDirectives(code) || require_generator.hasTailwindSourceDirectives(code, { importFallback: true }) || require_generator.hasTailwindApplyDirective(code);
|
|
6900
7065
|
}
|
|
6901
7066
|
function hasViteServeCssRootDirective(code) {
|
|
6902
7067
|
return require_generator.hasTailwindRootDirectives(code);
|
|
6903
7068
|
}
|
|
6904
|
-
function
|
|
6905
|
-
return [
|
|
6906
|
-
|
|
6907
|
-
|
|
6908
|
-
|
|
6909
|
-
|
|
6910
|
-
|
|
6911
|
-
|
|
6912
|
-
|
|
6913
|
-
|
|
6914
|
-
|
|
6915
|
-
|
|
6916
|
-
|
|
6917
|
-
|
|
6918
|
-
|
|
6919
|
-
|
|
6920
|
-
|
|
6921
|
-
|
|
6922
|
-
|
|
6923
|
-
|
|
6924
|
-
|
|
6925
|
-
|
|
6926
|
-
|
|
6927
|
-
|
|
6928
|
-
|
|
6929
|
-
|
|
6930
|
-
|
|
6931
|
-
|
|
6932
|
-
|
|
6933
|
-
|
|
6934
|
-
|
|
6935
|
-
|
|
6936
|
-
|
|
6937
|
-
|
|
6938
|
-
|
|
7069
|
+
function createViteCssGenerationPlugins(options) {
|
|
7070
|
+
return [
|
|
7071
|
+
{
|
|
7072
|
+
name: `${require_context.vitePluginName}:generate:serve`,
|
|
7073
|
+
apply: "serve",
|
|
7074
|
+
enforce: "pre",
|
|
7075
|
+
async transform(code, id) {
|
|
7076
|
+
if (!options.shouldGenerate() || !isViteServeCssRootRequest(id, options.getCommand())) return;
|
|
7077
|
+
if (!require_generator.hasTailwindRootDirectives(code)) return;
|
|
7078
|
+
if (DEFERRED_CSS_HMR_QUERY_RE.test(id)) return;
|
|
7079
|
+
await options.onTailwindRootCss?.(id, code);
|
|
7080
|
+
const generatedCss = await options.generateCss(id, code, this);
|
|
7081
|
+
if (generatedCss === void 0 || generatedCss === code) return;
|
|
7082
|
+
return {
|
|
7083
|
+
code: generatedCss,
|
|
7084
|
+
map: null
|
|
7085
|
+
};
|
|
7086
|
+
}
|
|
7087
|
+
},
|
|
7088
|
+
{
|
|
7089
|
+
name: `${require_context.vitePluginName}:generate:build`,
|
|
7090
|
+
apply: "build",
|
|
7091
|
+
enforce: "pre",
|
|
7092
|
+
async transform(code, id) {
|
|
7093
|
+
if (!options.shouldGenerate() || options.shouldGenerateBuild?.() === false || !isViteBuildStyleRequest(id, options.getCommand())) return;
|
|
7094
|
+
if (!hasViteCssGenerationDirective(code)) return;
|
|
7095
|
+
if (hasViteServeCssRootDirective(code)) await options.onTailwindRootCss?.(id, code);
|
|
7096
|
+
const generatedCss = await options.generateCss(id, code, this);
|
|
7097
|
+
if (generatedCss === void 0 || generatedCss === code) return;
|
|
7098
|
+
return {
|
|
7099
|
+
code: generatedCss,
|
|
7100
|
+
map: null
|
|
7101
|
+
};
|
|
7102
|
+
}
|
|
7103
|
+
},
|
|
7104
|
+
{
|
|
7105
|
+
name: `${require_context.vitePluginName}:generate:serve-hmr`,
|
|
7106
|
+
apply: "serve",
|
|
7107
|
+
enforce: "post",
|
|
7108
|
+
async transform(code, id) {
|
|
7109
|
+
if (!options.shouldGenerate() || !isViteCssHmrModule(code, id, options.getCommand())) return;
|
|
7110
|
+
const extracted = extractViteCssHmrModuleCss(code);
|
|
7111
|
+
if (!extracted) return;
|
|
7112
|
+
if (!hasViteCssGenerationDirective(extracted.css)) return;
|
|
7113
|
+
if (hasViteServeCssRootDirective(extracted.css)) await options.onTailwindRootCss?.(id, extracted.css);
|
|
7114
|
+
const generatedCss = await options.generateCss(id, extracted.css, this);
|
|
7115
|
+
if (generatedCss === void 0 || generatedCss === extracted.css) return;
|
|
7116
|
+
const nextCode = replaceViteCssHmrModuleCss(code, generatedCss);
|
|
7117
|
+
if (nextCode === void 0 || nextCode === code) return;
|
|
7118
|
+
return {
|
|
7119
|
+
code: nextCode,
|
|
7120
|
+
map: null
|
|
7121
|
+
};
|
|
7122
|
+
}
|
|
6939
7123
|
}
|
|
6940
|
-
|
|
7124
|
+
];
|
|
6941
7125
|
}
|
|
6942
7126
|
//#endregion
|
|
6943
7127
|
//#region src/bundlers/vite/serve-js-transform.ts
|
|
@@ -7002,6 +7186,40 @@ function resolveImplicitTailwindcssBasedirFromViteRoot(root) {
|
|
|
7002
7186
|
return resolvedRoot;
|
|
7003
7187
|
}
|
|
7004
7188
|
//#endregion
|
|
7189
|
+
//#region src/bundlers/vite/watch-css-post.ts
|
|
7190
|
+
const wrappedCssPostPlugins = /* @__PURE__ */ new WeakSet();
|
|
7191
|
+
function isWebOrNativeAppPlatform$1(platform) {
|
|
7192
|
+
return platform === "h5" || platform === "web" || platform?.startsWith("web-") === true || platform === "app" || platform === "app-plus" || platform?.startsWith("app-") === true;
|
|
7193
|
+
}
|
|
7194
|
+
function shouldAdaptFrameworkWatchCssBeforeCache(options) {
|
|
7195
|
+
return options.enabled && options.ownsTailwindGeneration && options.isWatchBuild && (options.platform ? !isWebOrNativeAppPlatform$1(options.platform) : !options.isWebGeneratorBranch);
|
|
7196
|
+
}
|
|
7197
|
+
function resolveTransformHandler(plugin) {
|
|
7198
|
+
const hook = plugin.transform;
|
|
7199
|
+
if (typeof hook === "function") return hook;
|
|
7200
|
+
if (hook && typeof hook === "object" && typeof hook.handler === "function") return hook.handler;
|
|
7201
|
+
}
|
|
7202
|
+
/**
|
|
7203
|
+
* 在框架的 CSS post hook 持久化样式前完成转换,保证 watch 重放缓存时不会重新输出原始 CSS。
|
|
7204
|
+
*/
|
|
7205
|
+
function wrapViteCssPostTransform(config, transformCss) {
|
|
7206
|
+
const plugin = config.plugins?.find((candidate) => candidate.name === "vite:css-post");
|
|
7207
|
+
if (!plugin || wrappedCssPostPlugins.has(plugin)) return false;
|
|
7208
|
+
const originalHandler = resolveTransformHandler(plugin);
|
|
7209
|
+
if (!originalHandler) return false;
|
|
7210
|
+
const wrappedHandler = async function(code, id, ...args) {
|
|
7211
|
+
const transformedCss = await transformCss(code, id);
|
|
7212
|
+
return originalHandler.call(this, transformedCss, id, ...args);
|
|
7213
|
+
};
|
|
7214
|
+
const originalHook = plugin.transform;
|
|
7215
|
+
plugin.transform = originalHook && typeof originalHook === "object" ? {
|
|
7216
|
+
...originalHook,
|
|
7217
|
+
handler: wrappedHandler
|
|
7218
|
+
} : wrappedHandler;
|
|
7219
|
+
wrappedCssPostPlugins.add(plugin);
|
|
7220
|
+
return true;
|
|
7221
|
+
}
|
|
7222
|
+
//#endregion
|
|
7005
7223
|
//#region src/bundlers/vite/shared/create-framework-plugins.ts
|
|
7006
7224
|
const debug = require_wxml.createDebug();
|
|
7007
7225
|
const weappTailwindcssPackageDir = require_source_candidate_scan_signature.resolvePackageDir("weapp-tailwindcss");
|
|
@@ -7328,7 +7546,7 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7328
7546
|
const createViteSourceCandidateChange = (file, change, options = {}) => ({
|
|
7329
7547
|
...change,
|
|
7330
7548
|
file,
|
|
7331
|
-
runtimeAffecting: options.runtimeAffecting === true ||
|
|
7549
|
+
runtimeAffecting: options.runtimeAffecting === true || require_hmr_timing.isSourceStyleRequest(file) || hasWebHmrRuntimeAffectingDirectives(sourceCandidateCollector.source(file))
|
|
7332
7550
|
});
|
|
7333
7551
|
const clearPendingHmrCandidateChange = () => {
|
|
7334
7552
|
pendingHmrCandidateChange = void 0;
|
|
@@ -7360,7 +7578,7 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7360
7578
|
pendingFullHmrCssRegeneration = true;
|
|
7361
7579
|
};
|
|
7362
7580
|
const applySourceCandidateHmrState = (change) => {
|
|
7363
|
-
if (
|
|
7581
|
+
if (require_hmr_timing.isSourceStyleRequest(change.file)) {
|
|
7364
7582
|
clearPendingHmrCandidateChange();
|
|
7365
7583
|
return change;
|
|
7366
7584
|
}
|
|
@@ -7500,7 +7718,7 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7500
7718
|
if (sourceScanMatcher && !sourceScanMatcher(file)) {
|
|
7501
7719
|
const change = sourceCandidateCollector.remove(file);
|
|
7502
7720
|
cacheCurrentSourceCandidateScan();
|
|
7503
|
-
if (
|
|
7721
|
+
if (require_hmr_timing.isSourceStyleRequest(file)) return (0, node_fs_promises.readFile)(file, "utf8").then((source) => cssMemory.refreshRememberedCssSourceBySourceFile(file, source)).catch((error) => {
|
|
7504
7722
|
if ((typeof error === "object" && error !== null && "code" in error ? error.code : void 0) !== "ENOENT") debug("remembered css source watch refresh failed: %s %O", file, error);
|
|
7505
7723
|
}).then(() => cssMemory.refreshRememberedCssSourceByCurrentFile(file)).then(() => applySourceCandidateHmrState(createViteSourceCandidateChange(file, change, { runtimeAffecting: true })));
|
|
7506
7724
|
return cssMemory.refreshRememberedCssSourceByCurrentFile(file).then(() => applySourceCandidateHmrState(createViteSourceCandidateChange(file, change, { runtimeAffecting: true })));
|
|
@@ -7572,7 +7790,7 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7572
7790
|
if (!shouldOwnTailwindGeneration) return;
|
|
7573
7791
|
tailwindRootCssModuleIds.add(id);
|
|
7574
7792
|
const cleanId = (0, _weapp_tailwindcss_shared.cleanUrl)(id);
|
|
7575
|
-
if (
|
|
7793
|
+
if (require_hmr_timing.isSourceStyleRequest(cleanId)) tailwindRootCssModuleIds.add(cleanId);
|
|
7576
7794
|
};
|
|
7577
7795
|
const registerTailwindRootCss = async (id, code) => {
|
|
7578
7796
|
rememberTailwindRootCssModule(id);
|
|
@@ -7586,7 +7804,7 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7586
7804
|
return viteProcessedCssSourceFiles.has(normalized);
|
|
7587
7805
|
};
|
|
7588
7806
|
const isViteProcessedCssAsset = (asset, file) => {
|
|
7589
|
-
if (
|
|
7807
|
+
if (require_hmr_timing.hasBundlerGeneratedCssMarker(asset.source)) return true;
|
|
7590
7808
|
return [
|
|
7591
7809
|
file,
|
|
7592
7810
|
asset.originalFileName,
|
|
@@ -7611,12 +7829,23 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7611
7829
|
getMajorVersion: () => runtimeState.tailwindRuntime.majorVersion,
|
|
7612
7830
|
moduleGraph: void 0
|
|
7613
7831
|
});
|
|
7832
|
+
const shouldAdaptFrameworkWatchCss = () => {
|
|
7833
|
+
const platform = resolveViteStylePlatform();
|
|
7834
|
+
return shouldAdaptFrameworkWatchCssBeforeCache({
|
|
7835
|
+
enabled: frameworkBranch.adaptWatchCssBeforeFrameworkCache === true,
|
|
7836
|
+
ownsTailwindGeneration: shouldOwnTailwindGeneration,
|
|
7837
|
+
isWatchBuild: isWatchBuild(),
|
|
7838
|
+
isWebGeneratorBranch: resolveCurrentGeneratorBranch().isWeb,
|
|
7839
|
+
platform
|
|
7840
|
+
});
|
|
7841
|
+
};
|
|
7614
7842
|
const generateTailwindCssForVitePipeline = async (id, code, hookContext) => {
|
|
7615
7843
|
if (!shouldOwnTailwindGeneration) return;
|
|
7616
7844
|
await runtimeState.readyPromise;
|
|
7617
7845
|
await waitForSourceCandidateSyncs();
|
|
7618
7846
|
const file = (0, _weapp_tailwindcss_shared.cleanUrl)(id);
|
|
7619
|
-
const
|
|
7847
|
+
const inferredSfcStyleRequest = isSfcStyleSourceFile(file) ? resolveSfcStyleRequestFromKnownSource(file, cssMemory.getKnownSfcSource(file), code) : file;
|
|
7848
|
+
const requestFile = require_source_candidate_scan_signature.isCSSRequest(id) ? inferredSfcStyleRequest === file ? id : inferredSfcStyleRequest : inferredSfcStyleRequest;
|
|
7620
7849
|
if (!require_source_candidate_scan_signature.isCSSRequest(requestFile) || opts.htmlMatcher(file) || require_source_candidate_scan_signature.isHTMLRequest(file)) return;
|
|
7621
7850
|
const generatorCode = require_generator.normalizeEmptyTailwindCustomVariants(code);
|
|
7622
7851
|
const rootDir = resolvedConfig?.root ? node_path.default.resolve(resolvedConfig.root) : node_process.default.cwd();
|
|
@@ -7667,7 +7896,7 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7667
7896
|
const previousTracedCss = tracedGeneratedCssByFile.get(fileKey);
|
|
7668
7897
|
if (previousTracedCss !== void 0) {
|
|
7669
7898
|
finishPendingHmrCssTargetFile(file);
|
|
7670
|
-
return `${
|
|
7899
|
+
return `${require_hmr_timing.createBundlerGeneratedCssMarker("vite", normalizeViteProcessedCssFile(file))}\n${previousTracedCss}`;
|
|
7671
7900
|
}
|
|
7672
7901
|
}
|
|
7673
7902
|
const sourceCssHandlerOptions = transformCssHandlerOptions.getCssHandlerOptions(requestFile);
|
|
@@ -7688,7 +7917,7 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7688
7917
|
}) ?? true);
|
|
7689
7918
|
const previousCss = pendingHmrChange && !forceFullHmrCssRegeneration ? cleanGeneratedCssByFile.get(fileKey) : void 0;
|
|
7690
7919
|
const previousGeneratorCss = previousCss && !currentGeneratorBranch.isWeb ? require_hmr_timing.normalizeMiniProgramGeneratorCssSource(previousCss, outputFile) : previousCss;
|
|
7691
|
-
const generated = await hmrTimingRecorder.measure(
|
|
7920
|
+
const generated = await hmrTimingRecorder.measure(`generateCss.${resolvedConfig?.command ?? "unknown"}`, () => require_source_candidate_scan_signature.generateTailwindV4Css({
|
|
7692
7921
|
opts,
|
|
7693
7922
|
runtimeState,
|
|
7694
7923
|
runtime,
|
|
@@ -7705,6 +7934,7 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7705
7934
|
previousCss: previousGeneratorCss,
|
|
7706
7935
|
previousClassSet: pendingHmrChange && !forceFullHmrCssRegeneration ? generatedClassSetByFile.get(fileKey) : void 0,
|
|
7707
7936
|
deferEmptyScopedCssSource: shouldDeferEmptyScopedCssSource,
|
|
7937
|
+
deferCssAdaptation: !currentGeneratorBranch.isWeb && !shouldAdaptFrameworkWatchCss(),
|
|
7708
7938
|
disableSourceScan: false,
|
|
7709
7939
|
restoreLocalCssImports: !currentGeneratorBranch.isWeb
|
|
7710
7940
|
}), {
|
|
@@ -7765,7 +7995,7 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7765
7995
|
sourceFile: requestFile
|
|
7766
7996
|
});
|
|
7767
7997
|
debug("css generated for vite postcss pipeline: %s bytes=%d", requestFile, tracedCss.length);
|
|
7768
|
-
return `${
|
|
7998
|
+
return `${require_hmr_timing.createBundlerGeneratedCssMarker("vite", normalizeViteProcessedCssFile(file))}\n${tracedCss}`;
|
|
7769
7999
|
};
|
|
7770
8000
|
const rewritePlugins = createRewriteCssImportsPlugins({
|
|
7771
8001
|
getAppType: () => opts.appType,
|
|
@@ -7780,7 +8010,7 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7780
8010
|
weappTailwindcssDirPosix
|
|
7781
8011
|
});
|
|
7782
8012
|
if (disabledOptions.plugin) return rewritePlugins.length ? rewritePlugins : void 0;
|
|
7783
|
-
const
|
|
8013
|
+
const generateBundleContext = {
|
|
7784
8014
|
opts,
|
|
7785
8015
|
runtimeState,
|
|
7786
8016
|
ensureRuntimeClassSet,
|
|
@@ -7797,6 +8027,11 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7797
8027
|
getSourceCandidates,
|
|
7798
8028
|
getSourceCandidateSource: (file) => sourceCandidateCollector.source(file),
|
|
7799
8029
|
getSourceCandidateSources: () => sourceCandidateCollector.sources(),
|
|
8030
|
+
extractSourceCandidates: (file, source) => require_hmr_timing.extractCandidatesFromSource(source, node_path.default.extname((0, _weapp_tailwindcss_shared.cleanUrl)(file)).slice(1) || "html", {
|
|
8031
|
+
bareArbitraryValues: opts.arbitraryValues?.bareArbitraryValues,
|
|
8032
|
+
customAttributesEntities,
|
|
8033
|
+
disabledDefaultTemplateHandler
|
|
8034
|
+
}),
|
|
7800
8035
|
getSourceCandidatesForEntries,
|
|
7801
8036
|
getSourceCandidateSourcesForEntries,
|
|
7802
8037
|
waitForSourceCandidateSyncs,
|
|
@@ -7814,6 +8049,16 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7814
8049
|
hmrTimingRecorder,
|
|
7815
8050
|
cssPipelineStrategy: frameworkCssPipelineStrategy,
|
|
7816
8051
|
frameworkRootImportShellTargetByFile
|
|
8052
|
+
};
|
|
8053
|
+
const shouldSplitGenerateBundlePhases = () => opts.appType === "weapp-vite" && getResolvedConfig()?.mode !== "production";
|
|
8054
|
+
const preGenerateBundleHook = createGenerateBundleHook({
|
|
8055
|
+
...generateBundleContext,
|
|
8056
|
+
processMarkupAndScripts: false,
|
|
8057
|
+
shouldProcessBundle: shouldSplitGenerateBundlePhases
|
|
8058
|
+
});
|
|
8059
|
+
const generateBundleHook = createGenerateBundleHook({
|
|
8060
|
+
...generateBundleContext,
|
|
8061
|
+
shouldProcessStyles: () => !shouldSplitGenerateBundlePhases()
|
|
7817
8062
|
});
|
|
7818
8063
|
const cssFinalizerOutputPlugin = createViteCssFinalizerOutputPlugin({
|
|
7819
8064
|
opts,
|
|
@@ -7860,6 +8105,21 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7860
8105
|
styleHandler,
|
|
7861
8106
|
uniAppX
|
|
7862
8107
|
}) ?? [];
|
|
8108
|
+
const installFrameworkWatchCssCacheAdapter = async (config) => {
|
|
8109
|
+
if (!shouldAdaptFrameworkWatchCss()) return;
|
|
8110
|
+
if (wrapViteCssPostTransform(config, async (css, id) => {
|
|
8111
|
+
if (!require_source_candidate_scan_signature.isCSSRequest(id)) return css;
|
|
8112
|
+
if (require_hmr_timing.hasBundlerGeneratedCssMarker(css)) {
|
|
8113
|
+
debug("preserve adapted generated css before uni-app watch cache: %s", id);
|
|
8114
|
+
return css;
|
|
8115
|
+
}
|
|
8116
|
+
const file = (0, _weapp_tailwindcss_shared.cleanUrl)(id);
|
|
8117
|
+
const styleRequest = isSfcStyleSourceFile(file) ? resolveSfcStyleRequestFromKnownSource(file, cssMemory.getKnownSfcSource(file), css, id) : id;
|
|
8118
|
+
const transformedCss = (await styleHandler(css, transformCssHandlerOptions.getCssHandlerOptions(styleRequest))).css;
|
|
8119
|
+
debug("adapt css before uni-app watch cache: %s inputRaw=%s outputRaw=%s", id, css.includes("\\[") || css.includes("\\:"), transformedCss.includes("\\[") || transformedCss.includes("\\:"));
|
|
8120
|
+
return transformedCss;
|
|
8121
|
+
})) debug("adapt uni-app watch css before vite:css-post cache");
|
|
8122
|
+
};
|
|
7863
8123
|
const plugins = [
|
|
7864
8124
|
...rewritePlugins,
|
|
7865
8125
|
{
|
|
@@ -7927,7 +8187,7 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7927
8187
|
async handleHotUpdate(ctx) {
|
|
7928
8188
|
return hmrTimingRecorder.measure("sourceCandidates.handleHotUpdate", async () => {
|
|
7929
8189
|
const isSourceCandidateHotUpdate = shouldOwnTailwindGeneration && require_hmr_timing.isSourceCandidateRequest(ctx.file);
|
|
7930
|
-
if (isSourceCandidateHotUpdate &&
|
|
8190
|
+
if (isSourceCandidateHotUpdate && require_hmr_timing.isSourceStyleRequest(ctx.file)) for (const mod of ctx.modules) {
|
|
7931
8191
|
if (mod.id) rememberTailwindRootCssModule(mod.id);
|
|
7932
8192
|
if (mod.url) rememberTailwindRootCssModule(mod.url);
|
|
7933
8193
|
if (mod.file) rememberTailwindRootCssModule(mod.file);
|
|
@@ -7941,11 +8201,11 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7941
8201
|
if (isSourceCandidateHotUpdate) {
|
|
7942
8202
|
invalidateRecordedGeneratorCandidates();
|
|
7943
8203
|
const preserveDeletedCssInHmr = resolveCurrentGeneratorOptions().hmr.preserveDeletedCss;
|
|
7944
|
-
canUseHmrCandidateAppend = preserveDeletedCssInHmr && !
|
|
8204
|
+
canUseHmrCandidateAppend = preserveDeletedCssInHmr && !require_hmr_timing.isSourceStyleRequest(ctx.file) && sourceCandidateChange !== void 0 && !sourceCandidateChange.runtimeAffecting;
|
|
7945
8205
|
if (!canUseHmrCandidateAppend) {
|
|
7946
8206
|
if (sourceCandidateChange === void 0) {
|
|
7947
8207
|
clearPendingHmrCandidateChange();
|
|
7948
|
-
if (!preserveDeletedCssInHmr && !
|
|
8208
|
+
if (!preserveDeletedCssInHmr && !require_hmr_timing.isSourceStyleRequest(ctx.file)) queueFullHmrCssRegeneration();
|
|
7949
8209
|
}
|
|
7950
8210
|
if (isWebLikeHotUpdate) {
|
|
7951
8211
|
await refreshRuntimeStateForAutoCssSources?.(true);
|
|
@@ -7955,22 +8215,22 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7955
8215
|
}
|
|
7956
8216
|
if (isSourceCandidateHotUpdate) await waitForSourceCandidateSyncs();
|
|
7957
8217
|
const cssModules = resolveHotTailwindCssModules(ctx, tailwindRootCssModuleIds);
|
|
7958
|
-
const sourceModules = isSourceCandidateHotUpdate && !
|
|
8218
|
+
const sourceModules = isSourceCandidateHotUpdate && !require_hmr_timing.isSourceStyleRequest(ctx.file) ? resolveHotSourceModules(ctx) : ctx.modules;
|
|
7959
8219
|
const hasHmrCandidateAppend = pendingHmrCandidateChange !== void 0 && !pendingHmrCandidateChange.runtimeAffecting && pendingHmrCandidateChange.addedCandidates.size > 0 || canUseHmrCandidateAppend && sourceCandidateChange !== void 0 && sourceCandidateChange.addedCandidates.size > 0;
|
|
7960
|
-
if (isSourceCandidateHotUpdate && !
|
|
8220
|
+
if (isSourceCandidateHotUpdate && !require_hmr_timing.isSourceStyleRequest(ctx.file) && !hasHmrCandidateAppend && !isWebLikeHotUpdate && (!hasSelfAcceptingNonStyleHotModule(sourceModules) && cssModules.length === 0 || cssModules.length > 0 && isUniViteProject())) {
|
|
7961
8221
|
sendFullReloadForUnresolvedHotUpdate(ctx);
|
|
7962
8222
|
return [];
|
|
7963
8223
|
}
|
|
7964
|
-
if (isWebLikeHotUpdate && isSourceCandidateHotUpdate && !
|
|
8224
|
+
if (isWebLikeHotUpdate && isSourceCandidateHotUpdate && !require_hmr_timing.isSourceStyleRequest(ctx.file) && ctx.modules.some((mod) => isNuxtPageMacroHotModule(mod.id ?? mod.url))) {
|
|
7965
8225
|
sendFullReloadForUnresolvedHotUpdate(ctx);
|
|
7966
8226
|
return [];
|
|
7967
8227
|
}
|
|
7968
|
-
const shouldSendSupplementalCssHotUpdates = !(isWebLikeHotUpdate && isSourceCandidateHotUpdate && !
|
|
8228
|
+
const shouldSendSupplementalCssHotUpdates = !(isWebLikeHotUpdate && isSourceCandidateHotUpdate && !require_hmr_timing.isSourceStyleRequest(ctx.file) && resolveCurrentGeneratorOptions().hmr.preserveDeletedCss && sourceCandidateChange !== void 0 && !sourceCandidateChange.runtimeAffecting && sourceCandidateChange.addedCandidates.size === 0 && sourceCandidateChange.removedCandidates.size > 0);
|
|
7969
8229
|
const supplementalCssFallbackIds = /* @__PURE__ */ new Set([...tailwindRootCssModuleIds, ...viteProcessedCssSourceFiles]);
|
|
7970
8230
|
if (hasHmrCandidateAppend) armPendingHmrCssTargetFiles(cssModules, supplementalCssFallbackIds);
|
|
7971
8231
|
if (shouldSendSupplementalCssHotUpdates) sendSupplementalCssHotUpdates(ctx, cssModules, supplementalCssFallbackIds);
|
|
7972
|
-
if (isWebLikeHotUpdate && isSourceCandidateHotUpdate && !
|
|
7973
|
-
if (isSourceCandidateHotUpdate && !
|
|
8232
|
+
if (isWebLikeHotUpdate && isSourceCandidateHotUpdate && !require_hmr_timing.isSourceStyleRequest(ctx.file)) return;
|
|
8233
|
+
if (isSourceCandidateHotUpdate && !require_hmr_timing.isSourceStyleRequest(ctx.file) && cssModules.length > 0) return [...sourceModules, ...cssModules];
|
|
7974
8234
|
return cssModules.length > 0 ? [...ctx.modules, ...cssModules] : void 0;
|
|
7975
8235
|
}, { emit: false });
|
|
7976
8236
|
},
|
|
@@ -7978,13 +8238,15 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7978
8238
|
await hmrTimingRecorder.measure("sourceCandidates.buildStart", async () => {
|
|
7979
8239
|
await prepareTailwindGeneration();
|
|
7980
8240
|
}, { emit: false });
|
|
7981
|
-
}
|
|
8241
|
+
},
|
|
8242
|
+
generateBundle: preGenerateBundleHook
|
|
7982
8243
|
},
|
|
7983
|
-
...
|
|
8244
|
+
...createViteCssGenerationPlugins({
|
|
7984
8245
|
generateCss: generateTailwindCssForVitePipeline,
|
|
7985
8246
|
getCommand: () => resolvedConfig?.command,
|
|
7986
8247
|
onTailwindRootCss: registerTailwindRootCss,
|
|
7987
|
-
shouldGenerate: () => shouldOwnTailwindGeneration
|
|
8248
|
+
shouldGenerate: () => shouldOwnTailwindGeneration,
|
|
8249
|
+
shouldGenerateBuild: () => resolveCurrentGeneratorBranch().isWeb
|
|
7988
8250
|
}),
|
|
7989
8251
|
createViteServeJsTransformPlugin({
|
|
7990
8252
|
createHandlerOptions: (file) => serveJsHandlerOptions(file, frameworkCssPipelineStrategy?.getServeJsHandlerOptions?.({
|
|
@@ -7996,6 +8258,13 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7996
8258
|
shouldTransform: () => shouldOwnTailwindGeneration && (frameworkCssPipelineStrategy?.shouldTransformServeJs?.(createCssPipelineContext()) ?? !resolveCurrentGeneratorBranch().isWeb),
|
|
7997
8259
|
transformRuntime: ensureRuntimeClassSet
|
|
7998
8260
|
}),
|
|
8261
|
+
{
|
|
8262
|
+
name: `${require_context.vitePluginName}:watch-css-cache`,
|
|
8263
|
+
configResolved: {
|
|
8264
|
+
order: "post",
|
|
8265
|
+
handler: installFrameworkWatchCssCacheAdapter
|
|
8266
|
+
}
|
|
8267
|
+
},
|
|
7999
8268
|
{
|
|
8000
8269
|
name: `${require_context.vitePluginName}:post`,
|
|
8001
8270
|
enforce: "post",
|
|
@@ -8003,7 +8272,10 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
8003
8272
|
if (!shouldOwnTailwindGeneration) return;
|
|
8004
8273
|
if (Array.isArray(config.plugins)) {
|
|
8005
8274
|
const removed = disableAndRemoveTailwindVitePlugins(config.plugins);
|
|
8006
|
-
if (removed > 0)
|
|
8275
|
+
if (removed > 0) {
|
|
8276
|
+
_weapp_tailwindcss_logger.logger.warn("检测到 @tailwindcss/vite,生成模式下已移除该插件以避免 Tailwind CSS 重复生成。");
|
|
8277
|
+
debug("disable official tailwind vite plugins in generator mode: %d", removed);
|
|
8278
|
+
}
|
|
8007
8279
|
}
|
|
8008
8280
|
const root = config.root ? node_path.default.resolve(config.root) : node_process.default.cwd();
|
|
8009
8281
|
const baseConfig = { resolve: { alias: [{
|
|
@@ -8057,7 +8329,10 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
8057
8329
|
const postcssPlugins = config.css.postcss.plugins;
|
|
8058
8330
|
if (shouldOwnTailwindGeneration) {
|
|
8059
8331
|
const removed = (0, _weapp_tailwindcss_postcss.removeTailwindPostcssPlugins)(postcssPlugins);
|
|
8060
|
-
if (removed > 0)
|
|
8332
|
+
if (removed > 0) {
|
|
8333
|
+
_weapp_tailwindcss_logger.logger.warn("检测到 @tailwindcss/postcss,生成模式下已移除该插件以避免 Tailwind CSS 重复生成。");
|
|
8334
|
+
debug("remove official tailwind postcss plugins in generator mode: %d", removed);
|
|
8335
|
+
}
|
|
8061
8336
|
}
|
|
8062
8337
|
}
|
|
8063
8338
|
}, { emit: false });
|
|
@@ -8182,6 +8457,7 @@ const uniAppCssPipelineStrategy = {
|
|
|
8182
8457
|
function createUniAppVitePlugins(options = {}) {
|
|
8183
8458
|
return createViteFrameworkPlugins(options, {
|
|
8184
8459
|
frameworkName: "uni-app",
|
|
8460
|
+
adaptWatchCssBeforeFrameworkCache: true,
|
|
8185
8461
|
cssPipelineStrategy: uniAppCssPipelineStrategy,
|
|
8186
8462
|
styleInjectorDelegate: require_source_candidate_scan_signature.viteStyleInjectorDelegates.uniApp
|
|
8187
8463
|
});
|
|
@@ -8307,6 +8583,7 @@ const uniAppXCssPipelineStrategy = {
|
|
|
8307
8583
|
function createUniAppXVitePlugins(options = {}) {
|
|
8308
8584
|
return createViteFrameworkPlugins(options, {
|
|
8309
8585
|
frameworkName: "uni-app-x",
|
|
8586
|
+
adaptWatchCssBeforeFrameworkCache: true,
|
|
8310
8587
|
cssPipelineStrategy: uniAppXCssPipelineStrategy,
|
|
8311
8588
|
getExtraPluginPlatform: () => ({ isIosPlatform: require_generator.resolveUniUtsPlatform().isAppIos }),
|
|
8312
8589
|
styleInjectorDelegate: require_source_candidate_scan_signature.viteStyleInjectorDelegates.uniApp,
|