weapp-tailwindcss 5.1.0 → 5.1.2
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/README.en.md +2 -0
- package/README.md +2 -0
- package/dist/bundlers/shared/generator-css/class-selectors.d.ts +2 -0
- package/dist/bundlers/shared/generator-css/generation-helpers.d.ts +6 -14
- package/dist/bundlers/shared/generator-css/source-resolver/metadata.d.ts +1 -1
- package/dist/bundlers/shared/generator-css/source-resolver.d.ts +2 -2
- package/dist/bundlers/shared/generator-css/validate.d.ts +1 -0
- package/dist/bundlers/vite/css-memory.d.ts +6 -0
- package/dist/bundlers/vite/generate-bundle/css-assets.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/css-output-helpers.d.ts +39 -0
- package/dist/bundlers/vite/generate-bundle/env-flags.d.ts +1 -0
- package/dist/bundlers/vite/generate-bundle/final-css-assets.d.ts +2 -1
- package/dist/bundlers/vite/generate-bundle/finalize.d.ts +2 -0
- package/dist/bundlers/vite/generate-bundle/html-processing.d.ts +26 -0
- package/dist/bundlers/vite/generate-bundle/js-processing.d.ts +4 -0
- package/dist/bundlers/vite/generate-bundle/remembered-css-replay.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/remembered-css.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/root-style-output.d.ts +6 -0
- package/dist/bundlers/vite/generate-bundle/runtime-linked-source-memory.d.ts +25 -0
- package/dist/bundlers/vite/generate-bundle/source-candidate-source.d.ts +9 -0
- package/dist/bundlers/vite/generate-bundle/tailwind-v4-css-source.d.ts +9 -0
- package/dist/bundlers/vite/generate-bundle/transform-filter.d.ts +15 -0
- package/dist/bundlers/vite/generate-bundle/types.d.ts +1 -0
- package/dist/bundlers/vite/generate-bundle.d.ts +1 -2
- package/dist/bundlers/vite/plugin-cache.d.ts +15 -0
- package/dist/bundlers/vite/runtime-class-set.d.ts +2 -1
- package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +3 -3
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/css-source-resolvers.d.ts +34 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/js-module-graph.d.ts +37 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers.d.ts +199 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/source-candidate-refresh.d.ts +11 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets.d.ts +1 -0
- package/dist/cli.js +15 -8
- package/dist/cli.mjs +15 -8
- package/dist/context/style-options.d.ts +1 -0
- package/dist/{context-Mbzkek1q.mjs → context-C-r8ki7x.mjs} +15 -10
- package/dist/{context-BHxLe743.js → context-CH4HFZP2.js} +20 -9
- package/dist/core.js +1 -1
- package/dist/core.mjs +1 -1
- package/dist/css-macro/index.d.ts +3 -7
- package/dist/{defaults-ZElj1zKc.mjs → defaults-BhE26nSw.mjs} +7 -3
- package/dist/{defaults-CVcKbXBG.js → defaults-CmFBmxsr.js} +7 -3
- package/dist/defaults.d.ts +1 -1
- package/dist/defaults.js +1 -1
- package/dist/defaults.mjs +1 -1
- package/dist/generator/options.d.ts +3 -1
- package/dist/generator/types.d.ts +1 -1
- package/dist/{generator-9rUz4Hcb.js → generator-B6pUjNdD.js} +3 -1
- package/dist/{generator-Dc4qaPmT.mjs → generator-BsPIaLtV.mjs} +3 -1
- package/dist/generator.js +2 -2
- package/dist/generator.mjs +2 -2
- package/dist/{gulp-B_sdP6dx.js → gulp-BBCeA7ky.js} +11 -9
- package/dist/{gulp-uM36oIJs.mjs → gulp-CTdcASq8.mjs} +11 -9
- package/dist/gulp.js +1 -1
- package/dist/gulp.mjs +1 -1
- package/dist/{hmr-timing-BXMLsF4b.mjs → hmr-timing-BRx-KnBh.mjs} +128 -86
- package/dist/{hmr-timing-CogqkFaF.js → hmr-timing-Da1eI8S0.js} +138 -84
- package/dist/index.js +4 -4
- package/dist/index.mjs +4 -4
- package/dist/postcss.js +2 -2
- package/dist/postcss.mjs +2 -2
- package/dist/presets.js +2 -2
- package/dist/presets.mjs +2 -2
- package/dist/{source-candidate-scan-signature-2ybpptAK.js → source-candidate-scan-signature-BO6JSskQ.js} +3 -3
- package/dist/{source-candidate-scan-signature-Cvb5z1ha.mjs → source-candidate-scan-signature-Dugfplms.mjs} +3 -3
- package/dist/tailwindcss/runtime-types.d.ts +1 -0
- package/dist/tailwindcss/v4-engine/source.d.ts +5 -14
- package/dist/tailwindcss/v4-engine/types.d.ts +10 -2
- package/dist/{tailwindcss-wyUHrfil.mjs → tailwindcss-B5mRo0-M.mjs} +12 -7
- package/dist/{tailwindcss-DHIYcqXT.js → tailwindcss-dbrbY4cd.js} +11 -6
- package/dist/{transform-CQVOgmzM.js → transform-BLleu_bA.js} +1 -1
- package/dist/{transform-tExdt40m.mjs → transform-DeqFRp1D.mjs} +1 -1
- package/dist/types/user-defined-options/matcher.d.ts +7 -0
- package/dist/{v4-engine-CF9zt4Cw.mjs → v4-engine-C3qSwQ-e.mjs} +7 -27
- package/dist/{v4-engine-D4ubP7N5.js → v4-engine-ON_oSLfO.js} +5 -31
- package/dist/{vite-CPO83EhA.mjs → vite-CXmUiI9f.mjs} +734 -393
- package/dist/{vite-CP0ylSxZ.js → vite-Da4uEG_u.js} +734 -392
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/weapp-tw-css-import-rewrite-loader.js +130 -85
- package/dist/{webpack-BzqhJ8yK.mjs → webpack-CrFZmdo7.mjs} +923 -671
- package/dist/{webpack-Bsek8VhR.js → webpack-Cwqnznng.js} +923 -671
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +3 -3
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import { resolveImplicitAppTypeFromViteRoot } from "./framework.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import { a as resolveGeneratorRuntimeBranch, c as shouldUseNativeAppCssBranch, i as normalizeWeappTailwindcssGeneratorOptions, s as shouldUseMiniProgramCssBranch } from "./generator-
|
|
2
|
+
import { C as hasTailwindRootDirectives, D as normalizeTailwindSourceForGenerator, F as hasTailwindGeneratedCssMarkers, G as getTailwindV4IncrementalGenerateCacheStats, O as parseImportRequest, S as hasTailwindNonRootGenerationDirectives, T as normalizeTailwindConfigDirectives, _ as resolveTailwindcssOptions, a as filterTailwindV4CssSourceRoots, b as hasLocalCssImport, d as normalizeCssEntries, f as findNearestPackageRoot, k as removeTailwindSourceDirectives, o as hasConfiguredTailwindV4CssRoots, ot as filterUnsupportedMiniProgramTailwindV4Candidates, rt as resolveTailwindV4CssSourceBase, s as upsertTailwindV4CssSource, st as omitUndefined, u as isTailwindV4CssEntry, w as hasTailwindSourceDirectives, x as hasTailwindApplyDirective } from "./v4-engine-C3qSwQ-e.mjs";
|
|
3
|
+
import { a as resolveGeneratorRuntimeBranch, c as shouldUseNativeAppCssBranch, i as normalizeWeappTailwindcssGeneratorOptions, s as shouldUseMiniProgramCssBranch } from "./generator-BsPIaLtV.mjs";
|
|
4
4
|
import { o as resolveUniUtsPlatform } from "./utils-DodxWHGz.mjs";
|
|
5
|
-
import {
|
|
6
|
-
import { _ as resolveViteTailwindV4CssDependencies, a as findTailwindConfig, f as createViteSourceScanMatcher, g as resolveTailwindV4EntriesFromCssCached, i as resolveUniAppXOptions, l as getRuntimeClassSetSignature, m as discoverTailwindV4CssEntries, p as resolveViteSourceScanEntries, r as isUniAppXEnabled } from "./tailwindcss-
|
|
7
|
-
import { A as
|
|
8
|
-
import { A as isSourceStyleRequest, C as resolvePluginDisabledState, D as isHTMLRequest, E as isCSSRequest, M as normalizeOutputPathKey, O as normalizePath, P as toAbsoluteOutputPath, S as resolvePackageDir, T as formatPostcssSourceMap, _ as generateTailwindV4Css, a as createJsHashSalt, b as parseBundlerGeneratedCssMarkerBlocks, c as hasRuntimeAffectingSourceChanges, f as createBundleBuildState, g as createBundleModuleGraphOptions, h as applyLinkedResults, i as createCandidateSignature, j as stripRequestQuery, k as slash, l as summarizeStringDiff, m as createRuntimeAffectingSourceSignature, n as createScopedGeneratorCandidateSignature, o as createLinkedImpactSignature, p as updateBundleBuildState, r as createScopedGeneratorRuntime, s as getSnapshotHash, t as createSourceCandidateScanSignature, u as buildBundleSnapshot, v as createBundlerGeneratedCssMarker, w as cleanUrl, x as stripBundlerGeneratedCssMarkers, y as hasBundlerGeneratedCssMarker } from "./source-candidate-scan-signature-
|
|
5
|
+
import { S as createDebug, _ as toCustomAttributesEntities, a as vitePluginName, l as shouldSkipJsTransform, m as replaceWxml, n as normalizeStyleHandlerMajorVersion, t as getCompilerContext, v as collectRuntimeClassSet, x as refreshTailwindRuntimeState, y as createTailwindRuntimeReadyPromise } from "./context-C-r8ki7x.mjs";
|
|
6
|
+
import { _ as resolveViteTailwindV4CssDependencies, a as findTailwindConfig, f as createViteSourceScanMatcher, g as resolveTailwindV4EntriesFromCssCached, i as resolveUniAppXOptions, l as getRuntimeClassSetSignature, m as discoverTailwindV4CssEntries, p as resolveViteSourceScanEntries, r as isUniAppXEnabled } from "./tailwindcss-B5mRo0-M.mjs";
|
|
7
|
+
import { A as hasMiniProgramCssSpecificityPlaceholders, F as createCssTokenSourceMap, L as processCachedTask, M as stripMiniProgramCssSpecificityPlaceholders, N as annotateCssSourceTrace, P as createCssSourceTraceCacheSignature, _ as isPureLocalCssImportWrapper, a as isSourceCandidateRequest, d as validateCandidatesByGenerator, g as mergeMarkedUserLayerComponentsCss, h as extractMarkedUserLayerComponentsCss, m as runWithConcurrency, r as createSourceCandidateCollector, s as createBundleRuntimeClassSetManager, t as createHmrTimingRecorder } from "./hmr-timing-BRx-KnBh.mjs";
|
|
8
|
+
import { A as isSourceStyleRequest, C as resolvePluginDisabledState, D as isHTMLRequest, E as isCSSRequest, M as normalizeOutputPathKey, O as normalizePath, P as toAbsoluteOutputPath, S as resolvePackageDir, T as formatPostcssSourceMap, _ as generateTailwindV4Css, a as createJsHashSalt, b as parseBundlerGeneratedCssMarkerBlocks, c as hasRuntimeAffectingSourceChanges, f as createBundleBuildState, g as createBundleModuleGraphOptions, h as applyLinkedResults, i as createCandidateSignature, j as stripRequestQuery, k as slash, l as summarizeStringDiff, m as createRuntimeAffectingSourceSignature, n as createScopedGeneratorCandidateSignature, o as createLinkedImpactSignature, p as updateBundleBuildState, r as createScopedGeneratorRuntime, s as getSnapshotHash, t as createSourceCandidateScanSignature, u as buildBundleSnapshot, v as createBundlerGeneratedCssMarker, w as cleanUrl, x as stripBundlerGeneratedCssMarkers, y as hasBundlerGeneratedCssMarker } from "./source-candidate-scan-signature-Dugfplms.mjs";
|
|
9
9
|
import { t as logger$1 } from "./logger-BNzxZbZj.mjs";
|
|
10
|
-
import fs, { existsSync } from "node:fs";
|
|
10
|
+
import fs, { existsSync, realpathSync } from "node:fs";
|
|
11
11
|
import path from "node:path";
|
|
12
12
|
import process$1 from "node:process";
|
|
13
13
|
import { splitCandidateTokens } from "@tailwindcss-mangle/engine";
|
|
14
14
|
import { containsCssAfterMinify, filterExistingCssRules, mergeCoveredCssRuleDeclarations, mergeMiniProgramPreflightRuleDeclarations, mergeMiniProgramThemeScopeRuleDeclarations, postcss, removeTailwindPostcssPlugins, resolveFilteredPostcssConfig } from "@weapp-tailwindcss/postcss";
|
|
15
15
|
import { LRUCache } from "lru-cache";
|
|
16
16
|
import { readFile } from "node:fs/promises";
|
|
17
|
+
import micromatch from "micromatch";
|
|
17
18
|
import { Buffer } from "node:buffer";
|
|
18
19
|
import { logger } from "@weapp-tailwindcss/logger";
|
|
19
20
|
import { parse } from "comment-json";
|
|
@@ -508,7 +509,7 @@ function resolveUniAppXStyleIsolationEnabled(root) {
|
|
|
508
509
|
//#region src/uni-app-x/vite.ts
|
|
509
510
|
let transformUVuePromise;
|
|
510
511
|
function loadTransformUVue() {
|
|
511
|
-
transformUVuePromise ?? (transformUVuePromise = import("./transform-
|
|
512
|
+
transformUVuePromise ?? (transformUVuePromise = import("./transform-DeqFRp1D.mjs").then((mod) => mod.transformUVue));
|
|
512
513
|
return transformUVuePromise;
|
|
513
514
|
}
|
|
514
515
|
const preprocessorLangs = new Set([
|
|
@@ -743,71 +744,6 @@ function createUniAppXAssetTask(file, originalSource, outDir, options) {
|
|
|
743
744
|
};
|
|
744
745
|
}
|
|
745
746
|
//#endregion
|
|
746
|
-
//#region src/bundlers/vite/generate-bundle/candidates.ts
|
|
747
|
-
const MUSTACHE_EXPRESSION_RE = /\{\{[\s\S]*?\}\}/g;
|
|
748
|
-
const QUOTED_LITERAL_RE = /'([^']*)'|"([^"]*)"|`([^`]*)`/g;
|
|
749
|
-
const CLASS_ATTRIBUTE_RE = /\bclass\s*=\s*/g;
|
|
750
|
-
const MUSTACHE_OPEN = "{{";
|
|
751
|
-
const MUSTACHE_CLOSE = "}}";
|
|
752
|
-
function isUrlLikeCandidate(candidate) {
|
|
753
|
-
return candidate.startsWith("//") || candidate.startsWith("http://") || candidate.startsWith("https://");
|
|
754
|
-
}
|
|
755
|
-
function isArbitraryValueCandidate(candidate) {
|
|
756
|
-
return candidate.includes("[") && candidate.includes("]") && !isUrlLikeCandidate(candidate.trim());
|
|
757
|
-
}
|
|
758
|
-
function collectClassAttributeValues(source) {
|
|
759
|
-
const values = [];
|
|
760
|
-
CLASS_ATTRIBUTE_RE.lastIndex = 0;
|
|
761
|
-
let matched = CLASS_ATTRIBUTE_RE.exec(source);
|
|
762
|
-
while (matched !== null) {
|
|
763
|
-
const quoteIndex = CLASS_ATTRIBUTE_RE.lastIndex;
|
|
764
|
-
const quote = source[quoteIndex];
|
|
765
|
-
if (quote !== "\"" && quote !== "'") {
|
|
766
|
-
matched = CLASS_ATTRIBUTE_RE.exec(source);
|
|
767
|
-
continue;
|
|
768
|
-
}
|
|
769
|
-
let expressionDepth = 0;
|
|
770
|
-
for (let index = quoteIndex + 1; index < source.length; index++) {
|
|
771
|
-
if (source.startsWith(MUSTACHE_OPEN, index)) {
|
|
772
|
-
expressionDepth++;
|
|
773
|
-
index += 1;
|
|
774
|
-
continue;
|
|
775
|
-
}
|
|
776
|
-
if (expressionDepth > 0 && source.startsWith(MUSTACHE_CLOSE, index)) {
|
|
777
|
-
expressionDepth--;
|
|
778
|
-
index += 1;
|
|
779
|
-
continue;
|
|
780
|
-
}
|
|
781
|
-
if (expressionDepth === 0 && source[index] === quote) {
|
|
782
|
-
values.push(source.slice(quoteIndex + 1, index));
|
|
783
|
-
CLASS_ATTRIBUTE_RE.lastIndex = index + 1;
|
|
784
|
-
break;
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
matched = CLASS_ATTRIBUTE_RE.exec(source);
|
|
788
|
-
}
|
|
789
|
-
return values;
|
|
790
|
-
}
|
|
791
|
-
function collectUnescapedDynamicCandidates(source, allowedCandidates) {
|
|
792
|
-
const matches = /* @__PURE__ */ new Set();
|
|
793
|
-
const shouldFilterByAllowedCandidates = allowedCandidates !== void 0 && allowedCandidates.size > 0;
|
|
794
|
-
for (const classValue of collectClassAttributeValues(source)) for (const expression of classValue.match(MUSTACHE_EXPRESSION_RE) ?? []) {
|
|
795
|
-
QUOTED_LITERAL_RE.lastIndex = 0;
|
|
796
|
-
let quoted = QUOTED_LITERAL_RE.exec(expression);
|
|
797
|
-
while (quoted !== null) {
|
|
798
|
-
const literal = quoted[1] ?? quoted[2] ?? quoted[3] ?? "";
|
|
799
|
-
for (const candidate of splitCandidateTokens(literal)) {
|
|
800
|
-
const normalized = candidate.trim();
|
|
801
|
-
if (!normalized || !isArbitraryValueCandidate(normalized)) continue;
|
|
802
|
-
if (shouldFilterByAllowedCandidates && !allowedCandidates.has(normalized)) continue;
|
|
803
|
-
matches.add(normalized);
|
|
804
|
-
}
|
|
805
|
-
quoted = QUOTED_LITERAL_RE.exec(expression);
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
return [...matches];
|
|
809
|
-
}
|
|
810
|
-
//#endregion
|
|
811
747
|
//#region src/bundlers/vite/generate-bundle/configured-css-sources.ts
|
|
812
748
|
function collectConfiguredTailwindV4CssSources(opts) {
|
|
813
749
|
const runtimeCssSources = opts.tailwindcssRuntimeOptions?.tailwindcss?.v4?.cssSources ?? [];
|
|
@@ -865,16 +801,15 @@ function registerGeneratorDependencies$1(ctx, dependencies) {
|
|
|
865
801
|
//#region src/bundlers/vite/generate-bundle/css-assets.ts
|
|
866
802
|
function createCssAssetEmitter(context) {
|
|
867
803
|
return (fileName, source) => {
|
|
868
|
-
const replayAsset = createReplayCssAsset(fileName, source);
|
|
869
804
|
if (context.emitFile) {
|
|
870
805
|
context.emitFile({
|
|
871
806
|
type: "asset",
|
|
872
807
|
fileName,
|
|
873
808
|
source
|
|
874
809
|
});
|
|
875
|
-
return
|
|
810
|
+
return;
|
|
876
811
|
}
|
|
877
|
-
return
|
|
812
|
+
return createReplayCssAsset(fileName, source);
|
|
878
813
|
};
|
|
879
814
|
}
|
|
880
815
|
function resolveAssetSourceFile(asset, fallbackFile) {
|
|
@@ -894,6 +829,23 @@ const COMMON_MINI_PROGRAM_STYLE_OUTPUT_EXTENSIONS = [
|
|
|
894
829
|
".jxss",
|
|
895
830
|
".tyss"
|
|
896
831
|
];
|
|
832
|
+
function resolveCssOutputRealPath(value) {
|
|
833
|
+
const resolved = path.resolve(value);
|
|
834
|
+
let current = resolved;
|
|
835
|
+
const pendingSegments = [];
|
|
836
|
+
while (!existsSync(current)) {
|
|
837
|
+
const parent = path.dirname(current);
|
|
838
|
+
if (parent === current) return resolved;
|
|
839
|
+
pendingSegments.unshift(path.basename(current));
|
|
840
|
+
current = parent;
|
|
841
|
+
}
|
|
842
|
+
try {
|
|
843
|
+
const realPath = realpathSync.native(current);
|
|
844
|
+
return pendingSegments.length > 0 ? path.join(realPath, ...pendingSegments) : realPath;
|
|
845
|
+
} catch {
|
|
846
|
+
return resolved;
|
|
847
|
+
}
|
|
848
|
+
}
|
|
897
849
|
function normalizeStyleOutputExtension(value) {
|
|
898
850
|
if (typeof value !== "string" || value.trim().length === 0) return;
|
|
899
851
|
const normalized = value.trim().toLowerCase();
|
|
@@ -933,7 +885,7 @@ function resolveStyleOutputFileFromFiles(files, cssMatcher, stem) {
|
|
|
933
885
|
if (!extension || extension === ".css") continue;
|
|
934
886
|
const outputStem = cleanFile.slice(0, -extension.length);
|
|
935
887
|
const outputStemSuffix = `/${outputStem}`;
|
|
936
|
-
if (outputStem === cleanStem || outputStem.endsWith(stemSuffix) || cleanStem.endsWith(outputStemSuffix)) matchedFiles.add(cleanFile);
|
|
888
|
+
if (outputStem === cleanStem || outputStem.endsWith(stemSuffix) || cleanStem.endsWith(outputStemSuffix) || cleanStem.endsWith(`/${outputStem}`)) matchedFiles.add(cleanFile);
|
|
937
889
|
}
|
|
938
890
|
return matchedFiles.size === 1 ? [...matchedFiles][0] : void 0;
|
|
939
891
|
}
|
|
@@ -941,7 +893,7 @@ function resolveMiniProgramStyleOutputExtension(options = {}) {
|
|
|
941
893
|
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;
|
|
942
894
|
}
|
|
943
895
|
function resolveReplayCssOutputFile(rootDir, file) {
|
|
944
|
-
const normalizedFile = normalizeOutputPathKey(path.isAbsolute(file) ? path.relative(rootDir, file) : file);
|
|
896
|
+
const normalizedFile = normalizeOutputPathKey(path.isAbsolute(file) ? path.relative(resolveCssOutputRealPath(rootDir), resolveCssOutputRealPath(file)) : file);
|
|
945
897
|
if (normalizedFile.length === 0 || normalizedFile === "." || normalizedFile === ".." || normalizedFile.startsWith("../")) return normalizeOutputPathKey(path.basename(file));
|
|
946
898
|
return normalizedFile;
|
|
947
899
|
}
|
|
@@ -1012,6 +964,23 @@ function stripStyleFileExtension(file) {
|
|
|
1012
964
|
}
|
|
1013
965
|
//#endregion
|
|
1014
966
|
//#region src/bundlers/vite/generate-bundle/style-matching.ts
|
|
967
|
+
function resolveStyleMatchingRealPath(value) {
|
|
968
|
+
const resolved = path.resolve(value);
|
|
969
|
+
let current = resolved;
|
|
970
|
+
const pendingSegments = [];
|
|
971
|
+
while (!existsSync(current)) {
|
|
972
|
+
const parent = path.dirname(current);
|
|
973
|
+
if (parent === current) return resolved;
|
|
974
|
+
pendingSegments.unshift(path.basename(current));
|
|
975
|
+
current = parent;
|
|
976
|
+
}
|
|
977
|
+
try {
|
|
978
|
+
const realPath = realpathSync.native(current);
|
|
979
|
+
return pendingSegments.length > 0 ? path.join(realPath, ...pendingSegments) : realPath;
|
|
980
|
+
} catch {
|
|
981
|
+
return resolved;
|
|
982
|
+
}
|
|
983
|
+
}
|
|
1015
984
|
function isMatchingCssSourceFile(outputFile, cssSourceFile, outputRoot) {
|
|
1016
985
|
return stripStyleFileExtension(path.resolve(outputRoot, outputFile)) === stripStyleFileExtension(path.resolve(cssSourceFile));
|
|
1017
986
|
}
|
|
@@ -1025,7 +994,7 @@ function collectStyleFileMatchBases(file, roots) {
|
|
|
1025
994
|
addBase(normalizedFile);
|
|
1026
995
|
const resolvedRoots = roots.filter((root) => typeof root === "string" && root.length > 0).map((root) => path.resolve(root));
|
|
1027
996
|
if (path.isAbsolute(normalizedFile)) for (const root of resolvedRoots) {
|
|
1028
|
-
const relative = path.relative(root, normalizedFile);
|
|
997
|
+
const relative = path.relative(resolveStyleMatchingRealPath(root), resolveStyleMatchingRealPath(normalizedFile));
|
|
1029
998
|
if (relative && !relative.startsWith("..") && !path.isAbsolute(relative)) addBase(relative);
|
|
1030
999
|
}
|
|
1031
1000
|
else for (const root of resolvedRoots) addBase(path.resolve(root, normalizedFile));
|
|
@@ -1135,7 +1104,7 @@ function createCssHandlerOptionsCache(options) {
|
|
|
1135
1104
|
isMainChunk,
|
|
1136
1105
|
...extraOptions,
|
|
1137
1106
|
postcssOptions: { options: { from } },
|
|
1138
|
-
majorVersion,
|
|
1107
|
+
majorVersion: normalizeStyleHandlerMajorVersion(majorVersion),
|
|
1139
1108
|
sourceOptions: { outputRoot }
|
|
1140
1109
|
};
|
|
1141
1110
|
cssHandlerOptionsCache.set(cacheKey, created);
|
|
@@ -1160,6 +1129,95 @@ function createCssHandlerOptionsCache(options) {
|
|
|
1160
1129
|
};
|
|
1161
1130
|
}
|
|
1162
1131
|
//#endregion
|
|
1132
|
+
//#region src/bundlers/vite/generate-bundle/root-style-output.ts
|
|
1133
|
+
function isRootMiniProgramStyleOutputFile$1(file) {
|
|
1134
|
+
const normalized = normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
1135
|
+
return !normalized.includes("/") && /\.(?:wxss|acss|ttss|qss|jxss|tyss)$/i.test(normalized);
|
|
1136
|
+
}
|
|
1137
|
+
function createRelativeCssImportRequest$1(targetFile, importedFile) {
|
|
1138
|
+
const normalizedTargetFile = normalizeOutputPathKey(targetFile.replace(/[?#].*$/, ""));
|
|
1139
|
+
const normalizedImportedFile = normalizeOutputPathKey(importedFile.replace(/[?#].*$/, ""));
|
|
1140
|
+
const targetDir = path.posix.dirname(normalizedTargetFile);
|
|
1141
|
+
const baseDir = targetDir === "." ? "" : targetDir;
|
|
1142
|
+
const relative = path.posix.relative(baseDir, normalizedImportedFile);
|
|
1143
|
+
return relative.startsWith(".") ? relative : `./${relative}`;
|
|
1144
|
+
}
|
|
1145
|
+
function createCssImportShell$1(targetFile, importedFile) {
|
|
1146
|
+
return `@import "${createRelativeCssImportRequest$1(targetFile, importedFile)}";\n`;
|
|
1147
|
+
}
|
|
1148
|
+
function createRootMiniProgramOriginStyleOutputFile(file) {
|
|
1149
|
+
const normalized = normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
1150
|
+
if (/(?:^|\/)[^/]+-origin\.[^.]+$/i.test(normalized)) return normalized;
|
|
1151
|
+
return normalized.replace(/(\.[^.]+)$/, "-origin$1");
|
|
1152
|
+
}
|
|
1153
|
+
function shouldKeepRootMiniProgramStyleAsImportShell(appType) {
|
|
1154
|
+
return appType === "uni-app-vite" || appType === "uni-app-x" || appType === "taro";
|
|
1155
|
+
}
|
|
1156
|
+
function shouldMoveRootMiniProgramStyleToImportShellOrigin(appType) {
|
|
1157
|
+
return appType === "taro";
|
|
1158
|
+
}
|
|
1159
|
+
//#endregion
|
|
1160
|
+
//#region src/bundlers/vite/generate-bundle/css-output-helpers.ts
|
|
1161
|
+
function resolveCssBundleOutputFile(options) {
|
|
1162
|
+
const { bundleFiles, defaultStyleOutputExtension, file, isWebGeneratorTarget, opts, shouldPreserveAppCssExtension } = options;
|
|
1163
|
+
let outputFile = resolveViteCssOutputFile(file, opts, isWebGeneratorTarget, shouldPreserveAppCssExtension, defaultStyleOutputExtension, bundleFiles);
|
|
1164
|
+
if (outputFile === file && isRootMiniProgramStyleOutputFile$1(file) && shouldMoveRootMiniProgramStyleToImportShellOrigin(opts.appType)) outputFile = createRootMiniProgramOriginStyleOutputFile(file);
|
|
1165
|
+
return outputFile;
|
|
1166
|
+
}
|
|
1167
|
+
function shouldSkipRawSourceStyleAsset(outputFile, file, rawSource, assetSourceFile = file, cssMatcher) {
|
|
1168
|
+
const source = rawSource.trim();
|
|
1169
|
+
if (source.length === 0) return false;
|
|
1170
|
+
if (canProcessViteSourceStyleAsCss(source, file)) return false;
|
|
1171
|
+
const isKnownStyleSource = isSourceStyleRequest(assetSourceFile) || cssMatcher?.(assetSourceFile) === true;
|
|
1172
|
+
return outputFile !== file || !isKnownStyleSource;
|
|
1173
|
+
}
|
|
1174
|
+
function resolveOutputFileFromMatchedCssSource(options) {
|
|
1175
|
+
const { bundleFiles, defaultStyleOutputExtension, isWebGeneratorTarget, opts, rootDir, shouldPreserveAppCssExtension, sourceFile, sourceRoot } = options;
|
|
1176
|
+
if (!sourceFile) return;
|
|
1177
|
+
if (isWebGeneratorTarget) return;
|
|
1178
|
+
const outputFile = resolveViteCssPipelineOutputFileFromSourceFile(sourceFile, opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension, sourceRoot, defaultStyleOutputExtension, bundleFiles);
|
|
1179
|
+
return opts.cssMatcher(outputFile) ? outputFile : void 0;
|
|
1180
|
+
}
|
|
1181
|
+
function createMatchedCssSourceOutputResolver(options) {
|
|
1182
|
+
const { assetSourceFile, file, originalFileNames, resolveOutputFileFromMatchedCssSource } = options;
|
|
1183
|
+
return (sourceFile) => {
|
|
1184
|
+
if (!sourceFile) return;
|
|
1185
|
+
if (normalizeOutputPathKey(assetSourceFile.replace(/[?#].*$/, "")) === normalizeOutputPathKey(sourceFile.replace(/[?#].*$/, "")) || originalFileNames?.some((originalFile) => normalizeOutputPathKey(originalFile.replace(/[?#].*$/, "")) === normalizeOutputPathKey(sourceFile.replace(/[?#].*$/, "")))) return file;
|
|
1186
|
+
return resolveOutputFileFromMatchedCssSource(sourceFile);
|
|
1187
|
+
};
|
|
1188
|
+
}
|
|
1189
|
+
function hasViteProcessedCssResultForSource(sourceFile, getViteProcessedCssAssetResults) {
|
|
1190
|
+
const sourceKey = normalizeOutputPathKey(sourceFile);
|
|
1191
|
+
for (const [file] of getViteProcessedCssAssetResults?.() ?? []) if (normalizeOutputPathKey(file) === sourceKey) return true;
|
|
1192
|
+
return false;
|
|
1193
|
+
}
|
|
1194
|
+
function applyCssResultToBundle(options) {
|
|
1195
|
+
const { appType, assetSourceFile, bundle, emitOrReplayCssAsset, file, originalSource, outputFile, source, viteProcessedCssAsset } = options;
|
|
1196
|
+
if (outputFile === file) {
|
|
1197
|
+
originalSource.source = source;
|
|
1198
|
+
return;
|
|
1199
|
+
}
|
|
1200
|
+
const importShellSource = isRootMiniProgramStyleOutputFile$1(file) && isRootMiniProgramStyleOutputFile$1(outputFile) && shouldKeepRootMiniProgramStyleAsImportShell(appType) ? createCssImportShell$1(file, outputFile) : void 0;
|
|
1201
|
+
if (bundle[file] === originalSource && originalSource.originalFileNames?.includes(assetSourceFile)) {
|
|
1202
|
+
const existingOutput = bundle[outputFile];
|
|
1203
|
+
if (existingOutput?.type === "asset") existingOutput.source = source;
|
|
1204
|
+
else {
|
|
1205
|
+
const replayAsset = emitOrReplayCssAsset(outputFile, source);
|
|
1206
|
+
if (replayAsset) bundle[outputFile] = replayAsset;
|
|
1207
|
+
}
|
|
1208
|
+
originalSource.source = importShellSource ?? source;
|
|
1209
|
+
return;
|
|
1210
|
+
}
|
|
1211
|
+
const existingOutput = bundle[outputFile];
|
|
1212
|
+
if (existingOutput?.type === "asset") existingOutput.source = source;
|
|
1213
|
+
else {
|
|
1214
|
+
const replayAsset = emitOrReplayCssAsset(outputFile, source);
|
|
1215
|
+
if (replayAsset) bundle[outputFile] = replayAsset;
|
|
1216
|
+
}
|
|
1217
|
+
if (!viteProcessedCssAsset && SOURCE_STYLE_OUTPUT_EXT_RE.test(file)) delete bundle[file];
|
|
1218
|
+
else originalSource.source = importShellSource ?? "";
|
|
1219
|
+
}
|
|
1220
|
+
//#endregion
|
|
1163
1221
|
//#region src/bundlers/vite/generate-bundle/css-share-scope.ts
|
|
1164
1222
|
const CSS_URL_FUNCTION_RE = /url\((?:"([^"]*)"|'([^']*)'|([^)]*))\)/gi;
|
|
1165
1223
|
const CSS_PATH_INDEPENDENT_URL_RE = /^(?:[a-z][a-z\d+.-]*:|\/\/|\/|#)/i;
|
|
@@ -1200,11 +1258,13 @@ function hasOmittedKnownBundleFiles(currentBundleFiles, previousBundleFiles) {
|
|
|
1200
1258
|
//#endregion
|
|
1201
1259
|
//#region src/bundlers/vite/generate-bundle/env-flags.ts
|
|
1202
1260
|
function resolveGenerateBundleEnvFlags() {
|
|
1261
|
+
const slowJsAstWarnMs = Number(process$1.env["WEAPP_TW_VITE_SLOW_JS_AST_WARN_MS"] ?? 1e3);
|
|
1203
1262
|
return {
|
|
1204
1263
|
forceRuntimeRefreshByEnv: process$1.env["WEAPP_TW_VITE_FORCE_RUNTIME_REFRESH"] === "1",
|
|
1205
1264
|
disableDirtyOptimization: process$1.env["WEAPP_TW_VITE_DISABLE_DIRTY"] === "1",
|
|
1206
1265
|
disableJsPrecheck: process$1.env["WEAPP_TW_VITE_DISABLE_JS_PRECHECK"] === "1",
|
|
1207
|
-
debugCssDiff: process$1.env["WEAPP_TW_VITE_DEBUG_CSS_DIFF"] === "1"
|
|
1266
|
+
debugCssDiff: process$1.env["WEAPP_TW_VITE_DEBUG_CSS_DIFF"] === "1",
|
|
1267
|
+
slowJsAstWarnMs: Number.isFinite(slowJsAstWarnMs) && slowJsAstWarnMs >= 0 ? slowJsAstWarnMs : 1e3
|
|
1208
1268
|
};
|
|
1209
1269
|
}
|
|
1210
1270
|
//#endregion
|
|
@@ -1682,7 +1742,6 @@ function hasTailwindGenerationSource(source, options = {}) {
|
|
|
1682
1742
|
}
|
|
1683
1743
|
function hasTailwindGenerationSourceForFile(file, source) {
|
|
1684
1744
|
if (isTailwindV4CssEntry(file)) return hasTailwindGenerationSource(source);
|
|
1685
|
-
if (hasTailwindRootImportDirectives(source, { importFallback: true })) return false;
|
|
1686
1745
|
return hasTailwindGenerationSource(source, { allowRootDirectives: false });
|
|
1687
1746
|
}
|
|
1688
1747
|
async function resolveSfcStyleSourceFromOutputFile(outputFile, snapshot, outputRoot, sourceRoot, cssMatcher, getSfcSource, debug) {
|
|
@@ -1711,7 +1770,7 @@ async function resolveSfcStyleSourceFromOutputFile(outputFile, snapshot, outputR
|
|
|
1711
1770
|
function normalizeSfcSourceFileForCompare(file) {
|
|
1712
1771
|
return normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
1713
1772
|
}
|
|
1714
|
-
function collectChunkModuleIds$
|
|
1773
|
+
function collectChunkModuleIds$2(output) {
|
|
1715
1774
|
const moduleIds = Array.isArray(output.moduleIds) ? output.moduleIds : [];
|
|
1716
1775
|
return [
|
|
1717
1776
|
output.facadeModuleId,
|
|
@@ -1751,7 +1810,7 @@ function resolveSfcStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot, s
|
|
|
1751
1810
|
debug("sfc style sibling chunk skipped: missing chunk for %s -> %s", outputFile, siblingJsFile);
|
|
1752
1811
|
return;
|
|
1753
1812
|
}
|
|
1754
|
-
const sourceFiles = collectChunkModuleIds$
|
|
1813
|
+
const sourceFiles = collectChunkModuleIds$2(siblingChunk.output).map(normalizeSfcModuleId).filter((file, index, files) => Boolean(file) && files.indexOf(file) === index);
|
|
1755
1814
|
if (sourceFiles.length === 0) {
|
|
1756
1815
|
debug("sfc style sibling chunk skipped: no sfc modules for %s -> %s", outputFile, siblingJsFile);
|
|
1757
1816
|
return;
|
|
@@ -1771,7 +1830,7 @@ function resolveSfcStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot, s
|
|
|
1771
1830
|
return bestSources[0]?.sourceFile;
|
|
1772
1831
|
}
|
|
1773
1832
|
function resolveSourceStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot, sourceRoot, debug) {
|
|
1774
|
-
const siblingJsFile = resolveSiblingJsChunkFile(outputFile);
|
|
1833
|
+
const siblingJsFile = resolveSiblingJsChunkFile(outputFile, void 0);
|
|
1775
1834
|
if (!siblingJsFile) {
|
|
1776
1835
|
debug("source style sibling chunk skipped: no sibling js for %s", outputFile);
|
|
1777
1836
|
return;
|
|
@@ -1782,7 +1841,7 @@ function resolveSourceStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot
|
|
|
1782
1841
|
debug("source style sibling chunk skipped: missing chunk for %s -> %s", outputFile, siblingJsFile);
|
|
1783
1842
|
return;
|
|
1784
1843
|
}
|
|
1785
|
-
const sourceFiles = collectChunkModuleIds$
|
|
1844
|
+
const sourceFiles = collectChunkModuleIds$2(siblingChunk.output).map(normalizeSourceStyleModuleId).filter((file, index, files) => Boolean(file) && files.indexOf(file) === index);
|
|
1786
1845
|
if (sourceFiles.length === 0) {
|
|
1787
1846
|
debug("source style sibling chunk skipped: no source style modules for %s -> %s", outputFile, siblingJsFile);
|
|
1788
1847
|
return;
|
|
@@ -1804,7 +1863,7 @@ function resolveSourceStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot
|
|
|
1804
1863
|
function resolveSourceStyleSourceFromOutputFile(outputFile, snapshot, outputRoot, sourceRoot, getSourceStyleSource, getSourceStyleSources, configuredSourceEntries, debug) {
|
|
1805
1864
|
let sourceFile = resolveSourceStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot, sourceRoot, debug);
|
|
1806
1865
|
let rawSource = sourceFile ? getSourceStyleSource?.(sourceFile) : void 0;
|
|
1807
|
-
if (!rawSource || !hasTailwindGenerationSourceForFile(sourceFile, rawSource)) {
|
|
1866
|
+
if (!sourceFile || !rawSource || !hasTailwindGenerationSourceForFile(sourceFile, rawSource)) {
|
|
1808
1867
|
const scoredSources = [...getSourceStyleSources?.() ?? [], ...configuredSourceEntries ?? []].filter(([file, source]) => CSS_SOURCE_OUTPUT_EXT_RE.test(file) && hasTailwindGenerationSourceForFile(file, source)).map(([file, source]) => ({
|
|
1809
1868
|
file,
|
|
1810
1869
|
source,
|
|
@@ -1879,7 +1938,7 @@ function collectMiniProgramSubpackageSourceEntries(snapshot, subpackageRoots, so
|
|
|
1879
1938
|
if (entry.output.type !== "chunk" || !isSubpackageOutputFile(entry.file, subpackageRoots)) continue;
|
|
1880
1939
|
const matchedSubpackageRoot = [...subpackageRoots].find((root) => isSubpackageOutputFile(entry.file, new Set([root])));
|
|
1881
1940
|
if (!matchedSubpackageRoot) continue;
|
|
1882
|
-
for (const moduleId of collectChunkModuleIds$
|
|
1941
|
+
for (const moduleId of collectChunkModuleIds$2(entry.output)) {
|
|
1883
1942
|
if (!path.isAbsolute(moduleId.replace(/[?#].*$/, ""))) continue;
|
|
1884
1943
|
const sourceRoot = resolveSubpackageSourceRootFromModuleId(moduleId, matchedSubpackageRoot);
|
|
1885
1944
|
if (sourceRoot) sourceRoots.add(sourceRoot);
|
|
@@ -1913,7 +1972,7 @@ function readAssetSource$2(asset) {
|
|
|
1913
1972
|
function clearAssetSource(asset) {
|
|
1914
1973
|
asset.source = "";
|
|
1915
1974
|
}
|
|
1916
|
-
function appendCss(baseCss, css) {
|
|
1975
|
+
function appendCss$1(baseCss, css) {
|
|
1917
1976
|
if (baseCss.length === 0) return css;
|
|
1918
1977
|
if (css.length === 0) return baseCss;
|
|
1919
1978
|
return `${baseCss}\n${css}`;
|
|
@@ -2063,6 +2122,7 @@ function resolvePreservedImportShellInjectionTarget(opts, bundle, file, css) {
|
|
|
2063
2122
|
const importedStyleFiles = collectImportedStyleFiles(css, file);
|
|
2064
2123
|
if (importedStyleFiles.size !== 1) return;
|
|
2065
2124
|
const [importedFile] = importedStyleFiles;
|
|
2125
|
+
if (!importedFile) return;
|
|
2066
2126
|
if (!isRootStyleOutputFile(importedFile)) return;
|
|
2067
2127
|
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2068
2128
|
if (output.type !== "asset") continue;
|
|
@@ -2245,13 +2305,13 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
2245
2305
|
let css = stripBundlerGeneratedCssMarkers(record.css).trim();
|
|
2246
2306
|
css = removeCssCoveredByImportedViteResults(css, importedCssSources).trim();
|
|
2247
2307
|
if (css.length === 0) continue;
|
|
2248
|
-
if (containsCssAfterMinify(nextCss, css) || filterExistingCssRules(nextCss, css).length === 0) continue;
|
|
2249
2308
|
const mergedLayerCss = mergeMarkedUserLayerComponentsCss(nextCss, css);
|
|
2250
2309
|
if (mergedLayerCss.merged) {
|
|
2251
2310
|
nextCss = mergedLayerCss.css;
|
|
2252
2311
|
css = extractMarkedUserLayerComponentsCss(css).rest.trim();
|
|
2253
2312
|
if (css.length === 0) continue;
|
|
2254
2313
|
}
|
|
2314
|
+
if (containsCssAfterMinify(nextCss, css) || filterExistingCssRules(nextCss, css).length === 0) continue;
|
|
2255
2315
|
if (containsCssAfterMinify(nextCss, css)) continue;
|
|
2256
2316
|
const mergedPreflightDeclarations = mergeMiniProgramPreflightRuleDeclarations(nextCss, css);
|
|
2257
2317
|
if (mergedPreflightDeclarations.changed) {
|
|
@@ -2273,7 +2333,7 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
2273
2333
|
}
|
|
2274
2334
|
const missingCss = filterExistingCssRules(nextCss, css);
|
|
2275
2335
|
if (missingCss.length === 0 || containsCssAfterMinify(nextCss, missingCss)) continue;
|
|
2276
|
-
nextCss = appendCss(nextCss, missingCss);
|
|
2336
|
+
nextCss = appendCss$1(nextCss, missingCss);
|
|
2277
2337
|
}
|
|
2278
2338
|
if (nextCss === originalSource) continue;
|
|
2279
2339
|
output.source = nextCss;
|
|
@@ -2346,9 +2406,9 @@ async function finalizeMiniProgramCssAssets(bundle, options) {
|
|
|
2346
2406
|
cssOptions: {
|
|
2347
2407
|
...cssHandlerOptions.cssOptions ?? {},
|
|
2348
2408
|
autoprefixer: false,
|
|
2349
|
-
cssPresetEnv:
|
|
2409
|
+
cssPresetEnv: {}
|
|
2350
2410
|
},
|
|
2351
|
-
cssPresetEnv:
|
|
2411
|
+
cssPresetEnv: {}
|
|
2352
2412
|
});
|
|
2353
2413
|
const outputCss = stripMiniProgramCssSpecificityPlaceholders(css);
|
|
2354
2414
|
if (outputCss === rawSource) continue;
|
|
@@ -2450,6 +2510,27 @@ function formatMs(value) {
|
|
|
2450
2510
|
}
|
|
2451
2511
|
//#endregion
|
|
2452
2512
|
//#region src/bundlers/vite/generate-bundle/uni-app-x-postprocess.ts
|
|
2513
|
+
function appendCss(baseCss, css) {
|
|
2514
|
+
if (baseCss.length === 0) return css;
|
|
2515
|
+
if (css.length === 0) return baseCss;
|
|
2516
|
+
return `${baseCss}\n${css}`;
|
|
2517
|
+
}
|
|
2518
|
+
function injectHarmonyCssIntoMainAsset(bundle, cssSources, onUpdate, debug) {
|
|
2519
|
+
const output = bundle["main.css"];
|
|
2520
|
+
if (output?.type !== "asset" || cssSources.length === 0) return false;
|
|
2521
|
+
const currentSource = String(output.source);
|
|
2522
|
+
let nextSource = currentSource;
|
|
2523
|
+
for (const css of cssSources) {
|
|
2524
|
+
const trimmedCss = css.trim();
|
|
2525
|
+
if (trimmedCss.length === 0 || nextSource.includes(trimmedCss)) continue;
|
|
2526
|
+
nextSource = appendCss(nextSource, trimmedCss);
|
|
2527
|
+
}
|
|
2528
|
+
if (nextSource === currentSource) return false;
|
|
2529
|
+
output.source = nextSource;
|
|
2530
|
+
onUpdate("main.css", currentSource, nextSource);
|
|
2531
|
+
debug("uni-app-x harmony main css inject");
|
|
2532
|
+
return true;
|
|
2533
|
+
}
|
|
2453
2534
|
async function handleUniAppXPostCssTasks(options) {
|
|
2454
2535
|
const { bundle, debug, generatorRuntime, getCssHandlerOptions, getSourceCandidateSourcesForEntries, getSourceCandidatesForEntries, getViteProcessedCssAssetResults, isHarmonyAppStyleTarget, isNativeAppStyleTarget, onUpdate, opts, runtimeState, styleHandler } = options;
|
|
2455
2536
|
const applyStyleSources = collectUniAppXHarmonyApplyStyleSources(bundle);
|
|
@@ -2482,6 +2563,7 @@ async function handleUniAppXPostCssTasks(options) {
|
|
|
2482
2563
|
}));
|
|
2483
2564
|
}
|
|
2484
2565
|
if (isHarmonyAppStyleTarget && injectUniAppXHarmonyBundleStyles(bundle, { cssSources: viteProcessedCssSources })) debug("uni-app-x harmony bundle styles inject");
|
|
2566
|
+
if (isHarmonyAppStyleTarget) injectHarmonyCssIntoMainAsset(bundle, viteProcessedCssSources, onUpdate, debug);
|
|
2485
2567
|
for (const [file, item] of Object.entries(bundle)) {
|
|
2486
2568
|
if (item.type !== "asset" || !file.endsWith(".uvue.ts")) continue;
|
|
2487
2569
|
const currentSource = String(item.source);
|
|
@@ -2547,11 +2629,11 @@ function readAssetSource(asset) {
|
|
|
2547
2629
|
function getAssetFile(bundleFile, asset) {
|
|
2548
2630
|
return asset.fileName || bundleFile;
|
|
2549
2631
|
}
|
|
2550
|
-
function isRootMiniProgramStyleOutputFile
|
|
2632
|
+
function isRootMiniProgramStyleOutputFile(file) {
|
|
2551
2633
|
const normalized = normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
2552
2634
|
return !normalized.includes("/") && /\.(?:wxss|acss|ttss|qss|jxss|tyss)$/i.test(normalized);
|
|
2553
2635
|
}
|
|
2554
|
-
function createRelativeCssImportRequest
|
|
2636
|
+
function createRelativeCssImportRequest(targetFile, importedFile) {
|
|
2555
2637
|
const normalizedTargetFile = normalizeOutputPathKey(targetFile.replace(/[?#].*$/, ""));
|
|
2556
2638
|
const normalizedImportedFile = normalizeOutputPathKey(importedFile.replace(/[?#].*$/, ""));
|
|
2557
2639
|
const targetDir = path.posix.dirname(normalizedTargetFile);
|
|
@@ -2559,12 +2641,12 @@ function createRelativeCssImportRequest$1(targetFile, importedFile) {
|
|
|
2559
2641
|
const relative = path.posix.relative(baseDir, normalizedImportedFile);
|
|
2560
2642
|
return relative.startsWith(".") ? relative : `./${relative}`;
|
|
2561
2643
|
}
|
|
2562
|
-
function createCssImportShell
|
|
2563
|
-
return `@import "${createRelativeCssImportRequest
|
|
2644
|
+
function createCssImportShell(targetFile, importedFile) {
|
|
2645
|
+
return `@import "${createRelativeCssImportRequest(targetFile, importedFile)}";\n`;
|
|
2564
2646
|
}
|
|
2565
2647
|
function resolveRootMiniProgramOriginStyleFile(file) {
|
|
2566
2648
|
const normalized = normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
2567
|
-
if (!isRootMiniProgramStyleOutputFile
|
|
2649
|
+
if (!isRootMiniProgramStyleOutputFile(normalized)) return;
|
|
2568
2650
|
if (/(?:^|\/)[^/]+-origin\.[^.]+$/i.test(normalized)) return;
|
|
2569
2651
|
return normalized.replace(/(\.[^.]+)$/, "-origin$1");
|
|
2570
2652
|
}
|
|
@@ -2589,7 +2671,7 @@ function normalizeTaroRootImportShellAssets(bundle, options) {
|
|
|
2589
2671
|
for (const [rootBundleFile, rootOutput] of Object.entries(bundle)) {
|
|
2590
2672
|
if (rootOutput.type !== "asset") continue;
|
|
2591
2673
|
const rootFile = getAssetFile(rootBundleFile, rootOutput);
|
|
2592
|
-
if (!isRootMiniProgramStyleOutputFile
|
|
2674
|
+
if (!isRootMiniProgramStyleOutputFile(rootFile) || !options.cssMatcher(rootFile)) continue;
|
|
2593
2675
|
const originFile = resolveRootMiniProgramOriginStyleFile(rootFile);
|
|
2594
2676
|
if (!originFile || !options.cssMatcher(originFile)) continue;
|
|
2595
2677
|
const originOutput = Object.entries(bundle).find(([bundleFile, output]) => output.type === "asset" && normalizeOutputPathKey(getAssetFile(bundleFile, output)) === normalizeOutputPathKey(originFile))?.[1];
|
|
@@ -2601,7 +2683,7 @@ function normalizeTaroRootImportShellAssets(bundle, options) {
|
|
|
2601
2683
|
const importedFile = resolveSingleCssImportOutputFile(originFile, originSource);
|
|
2602
2684
|
if (importedFile && normalizeOutputPathKey(importedFile) !== normalizeOutputPathKey(rootFile)) continue;
|
|
2603
2685
|
} else if (originSource.trim().length > 0 && originSource.trim() !== rootSource.trim()) continue;
|
|
2604
|
-
const nextRootSource = createCssImportShell
|
|
2686
|
+
const nextRootSource = createCssImportShell(rootFile, originFile);
|
|
2605
2687
|
if (rootSource === nextRootSource) continue;
|
|
2606
2688
|
rootOutput.source = nextRootSource;
|
|
2607
2689
|
originOutput.source = rootSource;
|
|
@@ -2615,12 +2697,14 @@ function normalizeTaroRootImportShellAssets(bundle, options) {
|
|
|
2615
2697
|
return updated;
|
|
2616
2698
|
}
|
|
2617
2699
|
async function finalizeGenerateBundle(options) {
|
|
2618
|
-
const { activeProcessCacheKeys, activeProcessHashKeys, activeViteCssCacheFiles, bundle, bundleFiles, cache, cssTaskFactories, debug, defaultStyleOutputExtension, formatIteration, generatorCandidateSignature, generatorRuntime, getCssHandlerOptions, getSourceCandidateSourcesForEntries, getSourceCandidatesForEntries, getViteCssCacheStats, getViteProcessedCssAssetResults, hmrTimingRecorder, hmrTimingStartedAt, isHarmonyAppStyleTarget, isNativeAppStyleTarget, isViteProcessedCssAsset, isWebGeneratorTarget, lastCssResultByFile, lastCssSourceHashByFile, linkedByEntry, markCssAssetProcessed, metrics, onEnd, onUpdate, opts, pendingLinkedUpdates, pruneViteCssCaches, recordCssAssetResult, recordTimingDetail, recordViteProcessedCssAssetResult, rootDir, runtime, runtimeState, shouldPreserveAppCssExtension, snapshot, sourceCandidates, sourceRoot, state, styleHandler, tasks, timingDetails, transformRuntime, useIncrementalMode } = options;
|
|
2700
|
+
const { activeProcessCacheKeys, activeProcessHashKeys, activeViteCssCacheFiles, bundle, bundleFiles, cache, cssTaskFactories, debug, defaultStyleOutputExtension, formatIteration, generatorCandidateSignature, generatorRuntime, getCssHandlerOptions, getSourceCandidateSourcesForEntries, getSourceCandidatesForEntries, getViteCssCacheStats, getViteProcessedCssAssetResults, hmrTimingRecorder, hmrTimingStartedAt, isHarmonyAppStyleTarget, isNativeAppStyleTarget, isViteProcessedCssAsset, isWebGeneratorTarget, jsAfterCss, jsTaskFactories, lastCssResultByFile, lastCssSourceHashByFile, linkedByEntry, markCssAssetProcessed, metrics, onEnd, onUpdate, opts, pendingLinkedUpdates, pruneViteCssCaches, recordCssAssetResult, recordTimingDetail, recordViteProcessedCssAssetResult, rootDir, runtime, runtimeState, shouldPreserveAppCssExtension, snapshot, sourceCandidates, sourceRoot, state, styleHandler, tasks, timingDetails, transformRuntime, useIncrementalMode } = options;
|
|
2701
|
+
const tasksStart = performance.now();
|
|
2619
2702
|
if (cssTaskFactories.length > 0) {
|
|
2620
|
-
const
|
|
2621
|
-
|
|
2703
|
+
const cssTask = runWithConcurrency(cssTaskFactories, resolveViteCssTaskConcurrency(useIncrementalMode, runtimeState.tailwindRuntime.majorVersion)).then(() => void 0);
|
|
2704
|
+
if (jsAfterCss) await cssTask;
|
|
2705
|
+
else tasks.push(cssTask);
|
|
2622
2706
|
}
|
|
2623
|
-
|
|
2707
|
+
if (jsTaskFactories.length > 0) tasks.push(runWithConcurrency(jsTaskFactories).then(() => void 0));
|
|
2624
2708
|
await Promise.all(tasks);
|
|
2625
2709
|
recordTimingDetail("tasks", tasksStart);
|
|
2626
2710
|
for (const apply of pendingLinkedUpdates) apply();
|
|
@@ -2740,6 +2824,120 @@ async function finalizeGenerateBundle(options) {
|
|
|
2740
2824
|
debug("end");
|
|
2741
2825
|
}
|
|
2742
2826
|
//#endregion
|
|
2827
|
+
//#region src/bundlers/vite/generate-bundle/candidates.ts
|
|
2828
|
+
const MUSTACHE_EXPRESSION_RE = /\{\{[\s\S]*?\}\}/g;
|
|
2829
|
+
const QUOTED_LITERAL_RE = /'([^']*)'|"([^"]*)"|`([^`]*)`/g;
|
|
2830
|
+
const CLASS_ATTRIBUTE_RE = /\bclass\s*=\s*/g;
|
|
2831
|
+
const MUSTACHE_OPEN = "{{";
|
|
2832
|
+
const MUSTACHE_CLOSE = "}}";
|
|
2833
|
+
function isUrlLikeCandidate(candidate) {
|
|
2834
|
+
return candidate.startsWith("//") || candidate.startsWith("http://") || candidate.startsWith("https://");
|
|
2835
|
+
}
|
|
2836
|
+
function isArbitraryValueCandidate(candidate) {
|
|
2837
|
+
return candidate.includes("[") && candidate.includes("]") && !isUrlLikeCandidate(candidate.trim());
|
|
2838
|
+
}
|
|
2839
|
+
function collectClassAttributeValues(source) {
|
|
2840
|
+
const values = [];
|
|
2841
|
+
CLASS_ATTRIBUTE_RE.lastIndex = 0;
|
|
2842
|
+
let matched = CLASS_ATTRIBUTE_RE.exec(source);
|
|
2843
|
+
while (matched !== null) {
|
|
2844
|
+
const quoteIndex = CLASS_ATTRIBUTE_RE.lastIndex;
|
|
2845
|
+
const quote = source[quoteIndex];
|
|
2846
|
+
if (quote !== "\"" && quote !== "'") {
|
|
2847
|
+
matched = CLASS_ATTRIBUTE_RE.exec(source);
|
|
2848
|
+
continue;
|
|
2849
|
+
}
|
|
2850
|
+
let expressionDepth = 0;
|
|
2851
|
+
for (let index = quoteIndex + 1; index < source.length; index++) {
|
|
2852
|
+
if (source.startsWith(MUSTACHE_OPEN, index)) {
|
|
2853
|
+
expressionDepth++;
|
|
2854
|
+
index += 1;
|
|
2855
|
+
continue;
|
|
2856
|
+
}
|
|
2857
|
+
if (expressionDepth > 0 && source.startsWith(MUSTACHE_CLOSE, index)) {
|
|
2858
|
+
expressionDepth--;
|
|
2859
|
+
index += 1;
|
|
2860
|
+
continue;
|
|
2861
|
+
}
|
|
2862
|
+
if (expressionDepth === 0 && source[index] === quote) {
|
|
2863
|
+
values.push(source.slice(quoteIndex + 1, index));
|
|
2864
|
+
CLASS_ATTRIBUTE_RE.lastIndex = index + 1;
|
|
2865
|
+
break;
|
|
2866
|
+
}
|
|
2867
|
+
}
|
|
2868
|
+
matched = CLASS_ATTRIBUTE_RE.exec(source);
|
|
2869
|
+
}
|
|
2870
|
+
return values;
|
|
2871
|
+
}
|
|
2872
|
+
function collectUnescapedDynamicCandidates(source, allowedCandidates) {
|
|
2873
|
+
const matches = /* @__PURE__ */ new Set();
|
|
2874
|
+
const shouldFilterByAllowedCandidates = allowedCandidates !== void 0 && allowedCandidates.size > 0;
|
|
2875
|
+
for (const classValue of collectClassAttributeValues(source)) for (const expression of classValue.match(MUSTACHE_EXPRESSION_RE) ?? []) {
|
|
2876
|
+
QUOTED_LITERAL_RE.lastIndex = 0;
|
|
2877
|
+
let quoted = QUOTED_LITERAL_RE.exec(expression);
|
|
2878
|
+
while (quoted !== null) {
|
|
2879
|
+
const literal = quoted[1] ?? quoted[2] ?? quoted[3] ?? "";
|
|
2880
|
+
for (const candidate of splitCandidateTokens(literal)) {
|
|
2881
|
+
const normalized = candidate.trim();
|
|
2882
|
+
if (!normalized || !isArbitraryValueCandidate(normalized)) continue;
|
|
2883
|
+
if (shouldFilterByAllowedCandidates && !allowedCandidates.has(normalized)) continue;
|
|
2884
|
+
matches.add(normalized);
|
|
2885
|
+
}
|
|
2886
|
+
quoted = QUOTED_LITERAL_RE.exec(expression);
|
|
2887
|
+
}
|
|
2888
|
+
}
|
|
2889
|
+
return [...matches];
|
|
2890
|
+
}
|
|
2891
|
+
//#endregion
|
|
2892
|
+
//#region src/bundlers/vite/generate-bundle/html-processing.ts
|
|
2893
|
+
function processHtmlBundleEntry(options) {
|
|
2894
|
+
const { cache, context, debug, dynamicRetryCandidates, file, metrics, onUpdate, originalEntrySource, originalSource, rememberProcessCacheKey, resolveCurrentSourceCandidateSource, tasks, templateHandler, timeTask, transformRuntime, transformRuntimeSignature } = options;
|
|
2895
|
+
const rawSource = resolveCurrentSourceCandidateSource(file) ?? originalEntrySource;
|
|
2896
|
+
const currentRawDynamicCandidates = collectUnescapedDynamicCandidates(rawSource);
|
|
2897
|
+
const templateRuntime = currentRawDynamicCandidates.length > 0 ? new Set([...transformRuntime, ...currentRawDynamicCandidates]) : transformRuntime;
|
|
2898
|
+
const templateRuntimeSignature = templateRuntime === transformRuntime ? transformRuntimeSignature : createCandidateSignature(templateRuntime);
|
|
2899
|
+
const htmlProcessHash = `${cache.computeHash(rawSource)}:${cache.computeHash(createRuntimeAffectingSourceSignature(rawSource, "html"))}:${templateRuntimeSignature}`;
|
|
2900
|
+
const cacheKey = `${file}:html:${htmlProcessHash}`;
|
|
2901
|
+
const hashKey = cacheKey;
|
|
2902
|
+
rememberProcessCacheKey(cacheKey, hashKey);
|
|
2903
|
+
tasks.push(timeTask("html", () => processCachedTask({
|
|
2904
|
+
cache,
|
|
2905
|
+
cacheKey,
|
|
2906
|
+
hashKey,
|
|
2907
|
+
hash: htmlProcessHash,
|
|
2908
|
+
applyResult(source) {
|
|
2909
|
+
originalSource.source = source;
|
|
2910
|
+
},
|
|
2911
|
+
onCacheHit() {
|
|
2912
|
+
metrics.html.cacheHits++;
|
|
2913
|
+
debug("html cache hit: %s", file);
|
|
2914
|
+
},
|
|
2915
|
+
async transform() {
|
|
2916
|
+
const start = performance.now();
|
|
2917
|
+
let transformed = await templateHandler(rawSource, { runtimeSet: templateRuntime });
|
|
2918
|
+
let unresolvedDynamicCandidates = collectUnescapedDynamicCandidates(transformed);
|
|
2919
|
+
let retryRuntimeSet;
|
|
2920
|
+
if (unresolvedDynamicCandidates.length > 0) {
|
|
2921
|
+
const fullRuntimeSet = await context.ensureRuntimeClassSet(true);
|
|
2922
|
+
const allowedRetryCandidates = fullRuntimeSet.size === 0 ? unresolvedDynamicCandidates : unresolvedDynamicCandidates.filter((candidate) => dynamicRetryCandidates.has(candidate) || fullRuntimeSet.has(candidate));
|
|
2923
|
+
retryRuntimeSet = new Set([...fullRuntimeSet, ...allowedRetryCandidates]);
|
|
2924
|
+
unresolvedDynamicCandidates = unresolvedDynamicCandidates.filter((candidate) => retryRuntimeSet?.has(candidate) === true);
|
|
2925
|
+
}
|
|
2926
|
+
if (retryRuntimeSet && unresolvedDynamicCandidates.length > 0) {
|
|
2927
|
+
logger.warn("检测到已提取 WXML 动态类名未完成转译,已回退到完整 runtimeSet 重试: %s -> %O", file, unresolvedDynamicCandidates);
|
|
2928
|
+
transformed = await templateHandler(rawSource, { runtimeSet: retryRuntimeSet });
|
|
2929
|
+
unresolvedDynamicCandidates = collectUnescapedDynamicCandidates(transformed, retryRuntimeSet);
|
|
2930
|
+
if (unresolvedDynamicCandidates.length > 0) logger.warn("已提取 WXML 动态类名在完整 runtimeSet 重试后仍未完成转译: %s -> %O", file, unresolvedDynamicCandidates);
|
|
2931
|
+
}
|
|
2932
|
+
metrics.html.elapsed += measureElapsed(start);
|
|
2933
|
+
metrics.html.transformed++;
|
|
2934
|
+
onUpdate(file, rawSource, transformed);
|
|
2935
|
+
debug("html handle: %s", file);
|
|
2936
|
+
return { result: transformed };
|
|
2937
|
+
}
|
|
2938
|
+
})));
|
|
2939
|
+
}
|
|
2940
|
+
//#endregion
|
|
2743
2941
|
//#region src/bundlers/vite/generate-bundle/js-entries.ts
|
|
2744
2942
|
function createJsEntryResolver(jsEntries) {
|
|
2745
2943
|
const normalizedJsEntries = /* @__PURE__ */ new Map();
|
|
@@ -2796,7 +2994,7 @@ function collectLinkedFileNames(linked, getJsEntry, linkedSet) {
|
|
|
2796
2994
|
//#endregion
|
|
2797
2995
|
//#region src/bundlers/vite/generate-bundle/js-processing.ts
|
|
2798
2996
|
function processJsBundleEntry(options) {
|
|
2799
|
-
const { applyLinkedUpdates, bundle, cache, createHandlerOptions, debug, disableJsPrecheck, entry, getJsEntry, jsHandler, jsTaskFactories, linkedByEntry, metrics, onUpdate, outDir, processFiles, rememberProcessCacheKey, runtimeSignature, snapshot, timeTask, transformRuntime, uniAppX, useIncrementalMode } = options;
|
|
2997
|
+
const { applyLinkedUpdates, bundle, cache, createHandlerOptions, debug, disableJsPrecheck, entry, getJsEntry, jsHandler, jsTaskFactories, linkedByEntry, metrics, onUpdate, outDir, processFiles, rememberProcessCacheKey, runtimeSignature, snapshot, shouldSkipAstTransform, slowJsAstWarnMs, timeTask, transformRuntime, transformRuntimeSignature, transformFilterSignature, uniAppX, useIncrementalMode } = options;
|
|
2800
2998
|
const { file, output: originalSource, source: originalEntrySource } = entry;
|
|
2801
2999
|
metrics.js.total++;
|
|
2802
3000
|
const shouldTransformJs = !useIncrementalMode || processFiles.js.has(file);
|
|
@@ -2806,7 +3004,8 @@ function processJsBundleEntry(options) {
|
|
|
2806
3004
|
const initialRawSource = originalEntrySource;
|
|
2807
3005
|
const linkedSet = useIncrementalMode ? /* @__PURE__ */ new Set() : void 0;
|
|
2808
3006
|
if (linkedByEntry && linkedSet) linkedByEntry.set(file, linkedSet);
|
|
2809
|
-
const
|
|
3007
|
+
const linkedImpactSignature = useIncrementalMode ? createLinkedImpactSignature(file, snapshot.linkedImpactsByEntry, snapshot.sourceHashByFile) : void 0;
|
|
3008
|
+
const hashSalt = createJsHashSalt(`${transformRuntimeSignature}:transform-filter:${transformFilterSignature}`, linkedImpactSignature);
|
|
2810
3009
|
const hashKey = `${file}:js`;
|
|
2811
3010
|
const processHash = `${getSnapshotHash(snapshot.sourceHashByFile, file, initialRawSource)}:${hashSalt}`;
|
|
2812
3011
|
rememberProcessCacheKey(file, hashKey);
|
|
@@ -2837,15 +3036,24 @@ function processJsBundleEntry(options) {
|
|
|
2837
3036
|
const start = performance.now();
|
|
2838
3037
|
const rawSource = originalSource.code;
|
|
2839
3038
|
if (!shouldTransformJs) debug("js cache replay miss, fallback transform: %s", file);
|
|
3039
|
+
if (shouldSkipAstTransform?.(originalSource)) {
|
|
3040
|
+
metrics.js.elapsed += measureElapsed(start);
|
|
3041
|
+
metrics.js.transformed++;
|
|
3042
|
+
debug("js skip ast transform (filtered): %s", file);
|
|
3043
|
+
return { result: rawSource };
|
|
3044
|
+
}
|
|
2840
3045
|
const handlerOptions = createHandlerOptions(absoluteFile);
|
|
2841
3046
|
if (!disableJsPrecheck && shouldSkipJsTransform(rawSource, handlerOptions)) {
|
|
2842
3047
|
metrics.js.elapsed += measureElapsed(start);
|
|
2843
3048
|
metrics.js.transformed++;
|
|
2844
3049
|
return { result: rawSource };
|
|
2845
3050
|
}
|
|
3051
|
+
const handlerStart = performance.now();
|
|
2846
3052
|
const { code, linked } = await jsHandler(rawSource, transformRuntime, handlerOptions);
|
|
3053
|
+
const handlerElapsed = measureElapsed(handlerStart);
|
|
2847
3054
|
metrics.js.elapsed += measureElapsed(start);
|
|
2848
3055
|
metrics.js.transformed++;
|
|
3056
|
+
if (handlerElapsed >= slowJsAstWarnMs) logger$1.warn("JS AST 转译耗时较长: %s 用时 %sms,源码约 %d bytes。若这是大型生成 TS/JS chunk,请配置 weapp-tailwindcss 的 transform.exclude 排除 generated/openapi 等目录。", file, handlerElapsed.toFixed(1), rawSource.length);
|
|
2849
3057
|
onUpdate(file, rawSource, code);
|
|
2850
3058
|
debug("js handle: %s", file);
|
|
2851
3059
|
collectLinkedFileNames(linked, getJsEntry, linkedSet);
|
|
@@ -2972,7 +3180,8 @@ function mergeRememberedCssSources(sources, outputFile) {
|
|
|
2972
3180
|
function collectRememberedCssReplayGroups(sources, opts, rootDir, isWebGeneratorTarget, preserveCssExtension, sourceRoot, styleOutputExtension, styleOutputFiles) {
|
|
2973
3181
|
const groups = /* @__PURE__ */ new Map();
|
|
2974
3182
|
for (const [key, remembered] of sources ?? []) {
|
|
2975
|
-
const
|
|
3183
|
+
const cleanSourceFile = remembered.sourceFile.replace(/[?#].*$/, "");
|
|
3184
|
+
const outputKey = normalizeOutputPathKey(CSS_SOURCE_OUTPUT_EXT_RE.test(cleanSourceFile) ? resolveViteCssPipelineOutputFileFromSourceFile(remembered.sourceFile, opts, rootDir, isWebGeneratorTarget, preserveCssExtension, sourceRoot, styleOutputExtension, styleOutputFiles) : resolveViteCssPipelineOutputFileFromSourceFile(remembered.outputFile, opts, rootDir, isWebGeneratorTarget, preserveCssExtension, sourceRoot, styleOutputExtension, styleOutputFiles));
|
|
2976
3185
|
const group = groups.get(outputKey) ?? [];
|
|
2977
3186
|
group.push({
|
|
2978
3187
|
key,
|
|
@@ -3055,7 +3264,7 @@ async function processRememberedCssReplay(options) {
|
|
|
3055
3264
|
}
|
|
3056
3265
|
if (shouldEmitRememberedReplayCssAsset) {
|
|
3057
3266
|
const replayAsset = emitOrReplayCssAsset(outputFile, css);
|
|
3058
|
-
markCssAssetProcessed?.(replayAsset, outputFile);
|
|
3267
|
+
if (replayAsset) markCssAssetProcessed?.(replayAsset, outputFile);
|
|
3059
3268
|
}
|
|
3060
3269
|
metrics.css.elapsed += measureElapsed(start);
|
|
3061
3270
|
metrics.css.transformed++;
|
|
@@ -3110,6 +3319,26 @@ function collectJsImportedCssFiles(snapshot) {
|
|
|
3110
3319
|
return files;
|
|
3111
3320
|
}
|
|
3112
3321
|
//#endregion
|
|
3322
|
+
//#region src/bundlers/vite/generate-bundle/runtime-linked-source-memory.ts
|
|
3323
|
+
function rememberRuntimeLinkedCssSources(options) {
|
|
3324
|
+
const { bundleFiles, defaultStyleOutputExtension, debug, getConfiguredTailwindV4CssSourceEntries, getSourceCandidateSource, getSourceCandidateSources, isWebGeneratorTarget, jsImportedCssFiles, opts, outDir, rememberCssSource, rootDir, runtimeLinkedCssFiles, shouldPreserveAppCssExtension, snapshot, sourceRoot } = options;
|
|
3325
|
+
for (const file of runtimeLinkedCssFiles) {
|
|
3326
|
+
if (snapshot.sourceHashByFile.has(file)) {
|
|
3327
|
+
snapshot.processFiles.css.add(file);
|
|
3328
|
+
continue;
|
|
3329
|
+
}
|
|
3330
|
+
const outputFile = resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension, sourceRoot, defaultStyleOutputExtension, bundleFiles);
|
|
3331
|
+
const inferredSourceStyle = resolveSourceStyleSourceFromOutputFile(outputFile, snapshot, outDir, sourceRoot, getSourceCandidateSource, jsImportedCssFiles.has(file) ? getSourceCandidateSources : void 0, getConfiguredTailwindV4CssSourceEntries().map((entry) => [entry.file, entry.source]), debug);
|
|
3332
|
+
const rawSource = inferredSourceStyle?.rawSource ?? getSourceCandidateSource?.(path.resolve(outDir, file)) ?? getSourceCandidateSource?.(file);
|
|
3333
|
+
if (rawSource === void 0 || !hasTailwindGenerationSource(rawSource)) continue;
|
|
3334
|
+
rememberCssSource?.({
|
|
3335
|
+
outputFile,
|
|
3336
|
+
rawSource,
|
|
3337
|
+
sourceFile: inferredSourceStyle?.sourceFile ?? path.resolve(outDir, file)
|
|
3338
|
+
});
|
|
3339
|
+
}
|
|
3340
|
+
}
|
|
3341
|
+
//#endregion
|
|
3113
3342
|
//#region src/bundlers/vite/generate-bundle/source-candidate-scope.ts
|
|
3114
3343
|
function intersectCandidateSets(left, right) {
|
|
3115
3344
|
if (left.size === 0 || right.size === 0) return /* @__PURE__ */ new Set();
|
|
@@ -3235,6 +3464,111 @@ function createSubpackageSourceCandidateScope(options) {
|
|
|
3235
3464
|
};
|
|
3236
3465
|
}
|
|
3237
3466
|
//#endregion
|
|
3467
|
+
//#region src/bundlers/vite/generate-bundle/source-candidate-source.ts
|
|
3468
|
+
function normalizeSourceCandidatePathKey(file) {
|
|
3469
|
+
return normalizeOutputPathKey(path.resolve(file));
|
|
3470
|
+
}
|
|
3471
|
+
function resolveCurrentSourceCandidateSource(options) {
|
|
3472
|
+
const { file, getSourceCandidateSource, getSourceCandidateSources, outDir, rootDir, sourceRoot } = options;
|
|
3473
|
+
const cleanedFile = file.replace(/[?#].*$/, "");
|
|
3474
|
+
const normalizedFile = normalizeOutputPathKey(cleanedFile);
|
|
3475
|
+
const absoluteFile = path.isAbsolute(cleanedFile) ? cleanedFile : path.resolve(rootDir, cleanedFile);
|
|
3476
|
+
const relativeFromOutDir = normalizeOutputPathKey(path.relative(outDir, absoluteFile));
|
|
3477
|
+
const sourceCandidates = [
|
|
3478
|
+
sourceRoot ? path.resolve(sourceRoot, file) : void 0,
|
|
3479
|
+
path.resolve(rootDir, file),
|
|
3480
|
+
path.resolve(path.dirname(outDir), file),
|
|
3481
|
+
path.resolve(outDir, file),
|
|
3482
|
+
!path.isAbsolute(relativeFromOutDir) && !relativeFromOutDir.startsWith("../") ? path.resolve(rootDir, relativeFromOutDir) : void 0,
|
|
3483
|
+
!path.isAbsolute(relativeFromOutDir) && !relativeFromOutDir.startsWith("../") ? path.resolve(path.dirname(outDir), relativeFromOutDir) : void 0,
|
|
3484
|
+
file
|
|
3485
|
+
];
|
|
3486
|
+
const explicitSource = sourceCandidates.reduce((source, candidate) => {
|
|
3487
|
+
if (source || !candidate) return source;
|
|
3488
|
+
return getSourceCandidateSource?.(candidate);
|
|
3489
|
+
}, void 0);
|
|
3490
|
+
if (explicitSource) return explicitSource;
|
|
3491
|
+
const normalizedSourceCandidates = sourceCandidates.filter((candidate) => Boolean(candidate)).map((candidate) => ({
|
|
3492
|
+
absolute: path.isAbsolute(candidate),
|
|
3493
|
+
key: normalizeSourceCandidatePathKey(candidate)
|
|
3494
|
+
}));
|
|
3495
|
+
let bestSource;
|
|
3496
|
+
for (const [sourceFile, source] of getSourceCandidateSources?.() ?? []) {
|
|
3497
|
+
const normalizedSourceFile = normalizeSourceCandidatePathKey(sourceFile);
|
|
3498
|
+
let score = 0;
|
|
3499
|
+
for (const candidate of normalizedSourceCandidates) if (normalizedSourceFile === candidate.key) {
|
|
3500
|
+
score = Math.max(score, candidate.absolute ? 100 : 80);
|
|
3501
|
+
continue;
|
|
3502
|
+
}
|
|
3503
|
+
if (normalizedSourceFile.endsWith(`/${normalizedFile}`)) score = Math.max(score, 20);
|
|
3504
|
+
if (score > (bestSource?.score ?? 0)) bestSource = {
|
|
3505
|
+
score,
|
|
3506
|
+
source
|
|
3507
|
+
};
|
|
3508
|
+
}
|
|
3509
|
+
return bestSource?.source;
|
|
3510
|
+
}
|
|
3511
|
+
//#endregion
|
|
3512
|
+
//#region src/bundlers/vite/generate-bundle/tailwind-v4-css-source.ts
|
|
3513
|
+
function collectTailwindV4SourceFingerprint(source) {
|
|
3514
|
+
const tokens = /* @__PURE__ */ new Set();
|
|
3515
|
+
const add = (prefix, value) => {
|
|
3516
|
+
tokens.add(`${prefix}:${value.trim()}`);
|
|
3517
|
+
};
|
|
3518
|
+
for (const match of source.matchAll(/@config\s+(["'])(.+?)\1\s*;?/g)) {
|
|
3519
|
+
const configRequest = match[2];
|
|
3520
|
+
add("config", path.basename(configRequest));
|
|
3521
|
+
add("config-request", configRequest.replace(/\\/g, "/"));
|
|
3522
|
+
}
|
|
3523
|
+
for (const match of source.matchAll(/@source\s+(not\s+)?(["'])(.+?)\2\s*;?/g)) add(match[1] ? "source:not" : "source", match[3]);
|
|
3524
|
+
for (const match of source.matchAll(/@custom-variant\s+([^{\s]+)/g)) add("custom-variant", match[1]);
|
|
3525
|
+
for (const match of source.matchAll(/@(?:theme|utility|variant|layer)\s+([^{;\s]+)/g)) add("directive", match[1]);
|
|
3526
|
+
for (const match of source.matchAll(/--[\w-]+(?=\s*:)/g)) add("theme-token", match[0]);
|
|
3527
|
+
for (const match of source.matchAll(/\.([_a-z][\w-]*)\s*[{,]/gi)) add("selector", match[1]);
|
|
3528
|
+
return tokens;
|
|
3529
|
+
}
|
|
3530
|
+
function scoreConfiguredTailwindV4SourceForRawSource(rawSource, entrySource) {
|
|
3531
|
+
if (!rawSource) return 0;
|
|
3532
|
+
const rawTokens = collectTailwindV4SourceFingerprint(rawSource);
|
|
3533
|
+
if (rawTokens.size === 0) return 0;
|
|
3534
|
+
const entryTokens = collectTailwindV4SourceFingerprint(entrySource);
|
|
3535
|
+
let score = 0;
|
|
3536
|
+
for (const token of entryTokens) if (rawTokens.has(token)) score += token.startsWith("config:") ? 100 : 1;
|
|
3537
|
+
return score;
|
|
3538
|
+
}
|
|
3539
|
+
function resolveSubpackageRootForFile(file, subpackageRoots) {
|
|
3540
|
+
if (!file || !subpackageRoots) return;
|
|
3541
|
+
return [...subpackageRoots].find((root) => isSubpackageOutputFile(file, new Set([root])));
|
|
3542
|
+
}
|
|
3543
|
+
function isSameSubpackageScope(outputFile, sourceFile, subpackageRoots) {
|
|
3544
|
+
return resolveSubpackageRootForFile(outputFile, subpackageRoots) === resolveSubpackageRootForFile(sourceFile, subpackageRoots);
|
|
3545
|
+
}
|
|
3546
|
+
function selectTailwindV4GenerationCssSourceForOutput(outputFile, entries, rawSource, subpackageRoots) {
|
|
3547
|
+
const generationSources = entries.filter((entry) => hasTailwindGenerationSource(entry.source));
|
|
3548
|
+
if (generationSources.length <= 1) return generationSources[0];
|
|
3549
|
+
const selectByRawSourceFingerprint = (candidates) => {
|
|
3550
|
+
const scoredSources = candidates.map((entry) => ({
|
|
3551
|
+
entry,
|
|
3552
|
+
score: scoreConfiguredTailwindV4SourceForRawSource(rawSource, entry.source)
|
|
3553
|
+
})).filter((item) => item.score > 0).sort((a, b) => b.score - a.score);
|
|
3554
|
+
const bestScore = scoredSources[0]?.score;
|
|
3555
|
+
const bestSources = bestScore ? scoredSources.filter((item) => item.score === bestScore) : [];
|
|
3556
|
+
return bestSources.length === 1 ? bestSources[0]?.entry : void 0;
|
|
3557
|
+
};
|
|
3558
|
+
const rawSourceMatched = selectByRawSourceFingerprint(generationSources);
|
|
3559
|
+
if (rawSourceMatched) return rawSourceMatched;
|
|
3560
|
+
const scopedSources = subpackageRoots ? generationSources.filter((entry) => {
|
|
3561
|
+
const outputMatchesSubpackage = isSubpackageOutputFile(outputFile, subpackageRoots);
|
|
3562
|
+
const sourceMatchesSubpackage = isSubpackageOutputFile(entry.file, subpackageRoots);
|
|
3563
|
+
if (!outputMatchesSubpackage) return !sourceMatchesSubpackage;
|
|
3564
|
+
return sourceMatchesSubpackage && [...subpackageRoots].some((root) => isSubpackageOutputFile(outputFile, new Set([root])) && isSubpackageOutputFile(entry.file, new Set([root])));
|
|
3565
|
+
}) : generationSources;
|
|
3566
|
+
const explicitSources = scopedSources.filter((entry) => /@(?:config|source|plugin|custom-variant|theme|utility|variant|apply)\b/.test(entry.source));
|
|
3567
|
+
const candidates = explicitSources.length === 1 ? explicitSources : scopedSources;
|
|
3568
|
+
if (candidates.length === 1) return candidates[0];
|
|
3569
|
+
return selectByRawSourceFingerprint(candidates);
|
|
3570
|
+
}
|
|
3571
|
+
//#endregion
|
|
3238
3572
|
//#region src/bundlers/vite/generate-bundle/timing.ts
|
|
3239
3573
|
function createBundleTaskTimer(recordTimingDetail) {
|
|
3240
3574
|
return async (name, task) => {
|
|
@@ -3247,6 +3581,102 @@ function createBundleTaskTimer(recordTimingDetail) {
|
|
|
3247
3581
|
};
|
|
3248
3582
|
}
|
|
3249
3583
|
//#endregion
|
|
3584
|
+
//#region src/bundlers/vite/generate-bundle/transform-filter.ts
|
|
3585
|
+
function toArray(value) {
|
|
3586
|
+
return Array.isArray(value) ? value : value === void 0 ? [] : [value];
|
|
3587
|
+
}
|
|
3588
|
+
function normalizeSourceId(id) {
|
|
3589
|
+
const file = cleanUrl(id);
|
|
3590
|
+
return path.isAbsolute(file) ? path.resolve(file) : void 0;
|
|
3591
|
+
}
|
|
3592
|
+
function collectChunkModuleIds$1(chunk) {
|
|
3593
|
+
const ids = /* @__PURE__ */ new Set();
|
|
3594
|
+
for (const id of chunk.moduleIds ?? []) {
|
|
3595
|
+
const normalized = normalizeSourceId(id);
|
|
3596
|
+
if (normalized) ids.add(normalized);
|
|
3597
|
+
}
|
|
3598
|
+
for (const id of Object.keys(chunk.modules ?? {})) {
|
|
3599
|
+
const normalized = normalizeSourceId(id);
|
|
3600
|
+
if (normalized) ids.add(normalized);
|
|
3601
|
+
}
|
|
3602
|
+
return ids;
|
|
3603
|
+
}
|
|
3604
|
+
function collectAssetSourceIds(asset, fallbackFile, rootDir) {
|
|
3605
|
+
const ids = /* @__PURE__ */ new Set();
|
|
3606
|
+
const sourceCandidates = [asset.originalFileName, ...asset.originalFileNames ?? []].filter((candidate) => typeof candidate === "string" && candidate.length > 0);
|
|
3607
|
+
const candidates = sourceCandidates.length > 0 ? sourceCandidates : [fallbackFile];
|
|
3608
|
+
for (const candidate of candidates) {
|
|
3609
|
+
if (typeof candidate !== "string" || candidate.length === 0) continue;
|
|
3610
|
+
const cleanCandidate = cleanUrl(candidate);
|
|
3611
|
+
const resolved = path.isAbsolute(cleanCandidate) ? path.resolve(cleanCandidate) : path.resolve(rootDir, cleanCandidate);
|
|
3612
|
+
ids.add(resolved);
|
|
3613
|
+
}
|
|
3614
|
+
return ids;
|
|
3615
|
+
}
|
|
3616
|
+
function isStringRuleMatched(rule, id, rootDir) {
|
|
3617
|
+
const normalizedId = slash(id);
|
|
3618
|
+
const normalizedRule = slash(rule);
|
|
3619
|
+
if (path.isAbsolute(rule)) return micromatch.isMatch(normalizedId, normalizedRule);
|
|
3620
|
+
const relative = slash(path.relative(rootDir, id));
|
|
3621
|
+
return relative.length > 0 && !relative.startsWith("../") && !path.isAbsolute(relative) && micromatch.isMatch(relative, normalizedRule);
|
|
3622
|
+
}
|
|
3623
|
+
function isRuleMatched(rule, id, rootDir) {
|
|
3624
|
+
if (typeof rule === "string") return isStringRuleMatched(rule, id, rootDir);
|
|
3625
|
+
if (rule instanceof RegExp) {
|
|
3626
|
+
rule.lastIndex = 0;
|
|
3627
|
+
return rule.test(slash(id));
|
|
3628
|
+
}
|
|
3629
|
+
return rule(id) === true;
|
|
3630
|
+
}
|
|
3631
|
+
function createTransformMatcher(rules, rootDir) {
|
|
3632
|
+
const normalizedRules = toArray(rules);
|
|
3633
|
+
if (normalizedRules.length === 0) return;
|
|
3634
|
+
return (id) => normalizedRules.some((rule) => isRuleMatched(rule, id, rootDir));
|
|
3635
|
+
}
|
|
3636
|
+
function shouldSkipSourceIds(sourceIds, filter) {
|
|
3637
|
+
if (sourceIds.size === 0) return false;
|
|
3638
|
+
if (filter.exclude) {
|
|
3639
|
+
let excluded = true;
|
|
3640
|
+
for (const id of sourceIds) if (!filter.exclude(id)) {
|
|
3641
|
+
excluded = false;
|
|
3642
|
+
break;
|
|
3643
|
+
}
|
|
3644
|
+
if (excluded) return true;
|
|
3645
|
+
}
|
|
3646
|
+
if (filter.include) {
|
|
3647
|
+
for (const id of sourceIds) if (filter.include(id)) return false;
|
|
3648
|
+
return true;
|
|
3649
|
+
}
|
|
3650
|
+
return false;
|
|
3651
|
+
}
|
|
3652
|
+
function createTransformFilter(options, rootDir) {
|
|
3653
|
+
const include = createTransformMatcher(options?.include, rootDir);
|
|
3654
|
+
const exclude = createTransformMatcher(options?.exclude, rootDir);
|
|
3655
|
+
if (!include && !exclude) return;
|
|
3656
|
+
return {
|
|
3657
|
+
include,
|
|
3658
|
+
exclude
|
|
3659
|
+
};
|
|
3660
|
+
}
|
|
3661
|
+
function shouldSkipViteJsChunkTransform(chunk, filter) {
|
|
3662
|
+
if (!filter) return false;
|
|
3663
|
+
return shouldSkipSourceIds(collectChunkModuleIds$1(chunk), filter);
|
|
3664
|
+
}
|
|
3665
|
+
function shouldSkipViteAssetTransform(asset, file, rootDir, filter) {
|
|
3666
|
+
if (!filter) return false;
|
|
3667
|
+
return shouldSkipSourceIds(collectAssetSourceIds(asset, file, rootDir), filter);
|
|
3668
|
+
}
|
|
3669
|
+
function createRuleSignature(rules) {
|
|
3670
|
+
return toArray(rules).map((rule) => {
|
|
3671
|
+
if (typeof rule === "string") return `s:${rule}`;
|
|
3672
|
+
if (rule instanceof RegExp) return `r:${rule.source}/${rule.flags}`;
|
|
3673
|
+
return "f";
|
|
3674
|
+
}).join("|") || "none";
|
|
3675
|
+
}
|
|
3676
|
+
function createTransformFilterSignature(options) {
|
|
3677
|
+
return [`include:${createRuleSignature(options?.include)}`, `exclude:${createRuleSignature(options?.exclude)}`].join(";");
|
|
3678
|
+
}
|
|
3679
|
+
//#endregion
|
|
3250
3680
|
//#region src/bundlers/vite/uni-app-x-css-options.ts
|
|
3251
3681
|
function resolveUniAppXNativeCssHandlerOptions(opts) {
|
|
3252
3682
|
const uniUtsPlatform = resolveUniUtsPlatform();
|
|
@@ -3279,7 +3709,7 @@ function resolveWeappViteSourceRoot(config, _appType) {
|
|
|
3279
3709
|
const root = typeof viteConfig?.root === "string" && viteConfig.root.length > 0 ? path.resolve(viteConfig.root) : process$1.cwd();
|
|
3280
3710
|
const configuredSrcRoot = resolveSourceRootCandidate(root, viteConfig?.weapp?.srcRoot);
|
|
3281
3711
|
if (configuredSrcRoot) return configuredSrcRoot;
|
|
3282
|
-
const envSrcRoot = resolveSourceRootCandidate(root, process$1.env
|
|
3712
|
+
const envSrcRoot = resolveSourceRootCandidate(root, process$1.env["UNI_INPUT_DIR"]) ?? resolveSourceRootCandidate(root, process$1.env["UNI_INPUT_ROOT"]) ?? resolveSourceRootCandidate(root, process$1.env["UNI_APP_INPUT_DIR"]);
|
|
3283
3713
|
if (envSrcRoot) return envSrcRoot;
|
|
3284
3714
|
}
|
|
3285
3715
|
function stripFileExtension(file) {
|
|
@@ -3323,32 +3753,6 @@ function resolveSourceRootFromBundleGraph(config, bundle) {
|
|
|
3323
3753
|
}
|
|
3324
3754
|
//#endregion
|
|
3325
3755
|
//#region src/bundlers/vite/generate-bundle.ts
|
|
3326
|
-
function isRootMiniProgramStyleOutputFile(file) {
|
|
3327
|
-
const normalized = normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
3328
|
-
return !normalized.includes("/") && /\.(?:wxss|acss|ttss|qss|jxss|tyss)$/i.test(normalized);
|
|
3329
|
-
}
|
|
3330
|
-
function createRelativeCssImportRequest(targetFile, importedFile) {
|
|
3331
|
-
const normalizedTargetFile = normalizeOutputPathKey(targetFile.replace(/[?#].*$/, ""));
|
|
3332
|
-
const normalizedImportedFile = normalizeOutputPathKey(importedFile.replace(/[?#].*$/, ""));
|
|
3333
|
-
const targetDir = path.posix.dirname(normalizedTargetFile);
|
|
3334
|
-
const baseDir = targetDir === "." ? "" : targetDir;
|
|
3335
|
-
const relative = path.posix.relative(baseDir, normalizedImportedFile);
|
|
3336
|
-
return relative.startsWith(".") ? relative : `./${relative}`;
|
|
3337
|
-
}
|
|
3338
|
-
function createCssImportShell(targetFile, importedFile) {
|
|
3339
|
-
return `@import "${createRelativeCssImportRequest(targetFile, importedFile)}";\n`;
|
|
3340
|
-
}
|
|
3341
|
-
function createRootMiniProgramOriginStyleOutputFile(file) {
|
|
3342
|
-
const normalized = normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
3343
|
-
if (/(?:^|\/)[^/]+-origin\.[^.]+$/i.test(normalized)) return normalized;
|
|
3344
|
-
return normalized.replace(/(\.[^.]+)$/, "-origin$1");
|
|
3345
|
-
}
|
|
3346
|
-
function shouldKeepRootMiniProgramStyleAsImportShell(appType) {
|
|
3347
|
-
return appType === "uni-app-vite" || appType === "uni-app-x" || appType === "taro";
|
|
3348
|
-
}
|
|
3349
|
-
function shouldMoveRootMiniProgramStyleToImportShellOrigin(appType) {
|
|
3350
|
-
return appType === "taro";
|
|
3351
|
-
}
|
|
3352
3756
|
function createGenerateBundleHook(context) {
|
|
3353
3757
|
const state = createBundleBuildState();
|
|
3354
3758
|
const lastCssResultByFile = /* @__PURE__ */ new Map();
|
|
@@ -3438,119 +3842,17 @@ function createGenerateBundleHook(context) {
|
|
|
3438
3842
|
}
|
|
3439
3843
|
}
|
|
3440
3844
|
}, opts.tailwindcssBasedir ?? rootDir);
|
|
3441
|
-
const collectTailwindV4SourceFingerprint = (source) => {
|
|
3442
|
-
const tokens = /* @__PURE__ */ new Set();
|
|
3443
|
-
const add = (prefix, value) => {
|
|
3444
|
-
const normalized = value?.trim();
|
|
3445
|
-
if (normalized) tokens.add(`${prefix}:${normalized}`);
|
|
3446
|
-
};
|
|
3447
|
-
for (const match of source.matchAll(/@config\s+(["'])(.+?)\1\s*;?/g)) {
|
|
3448
|
-
const configRequest = match[2] ?? "";
|
|
3449
|
-
add("config", path.basename(configRequest));
|
|
3450
|
-
add("config-request", configRequest.replace(/\\/g, "/"));
|
|
3451
|
-
}
|
|
3452
|
-
for (const match of source.matchAll(/@source\s+(not\s+)?(["'])(.+?)\2\s*;?/g)) add(match[1] ? "source:not" : "source", match[3]);
|
|
3453
|
-
for (const match of source.matchAll(/@custom-variant\s+([^{\s]+)/g)) add("custom-variant", match[1]);
|
|
3454
|
-
for (const match of source.matchAll(/@(?:theme|utility|variant|layer)\s+([^{;\s]+)/g)) add("directive", match[1]);
|
|
3455
|
-
for (const match of source.matchAll(/--[\w-]+(?=\s*:)/g)) add("theme-token", match[0]);
|
|
3456
|
-
for (const match of source.matchAll(/\.([_a-z][\w-]*)\s*[{,]/gi)) add("selector", match[1]);
|
|
3457
|
-
return tokens;
|
|
3458
|
-
};
|
|
3459
|
-
const scoreConfiguredTailwindV4SourceForRawSource = (rawSource, entrySource) => {
|
|
3460
|
-
if (!rawSource) return 0;
|
|
3461
|
-
const rawTokens = collectTailwindV4SourceFingerprint(rawSource);
|
|
3462
|
-
if (rawTokens.size === 0) return 0;
|
|
3463
|
-
const entryTokens = collectTailwindV4SourceFingerprint(entrySource);
|
|
3464
|
-
let score = 0;
|
|
3465
|
-
for (const token of entryTokens) if (rawTokens.has(token)) score += token.startsWith("config:") ? 100 : 1;
|
|
3466
|
-
return score;
|
|
3467
|
-
};
|
|
3468
|
-
const selectTailwindV4GenerationCssSourceForOutput = (outputFile, entries, rawSource) => {
|
|
3469
|
-
const generationSources = entries.filter((entry) => hasTailwindGenerationSource(entry.source));
|
|
3470
|
-
if (generationSources.length <= 1) return generationSources[0];
|
|
3471
|
-
const selectByRawSourceFingerprint = (candidates) => {
|
|
3472
|
-
const scoredSources = candidates.map((entry) => ({
|
|
3473
|
-
entry,
|
|
3474
|
-
score: scoreConfiguredTailwindV4SourceForRawSource(rawSource, entry.source)
|
|
3475
|
-
})).filter((item) => item.score > 0).sort((a, b) => b.score - a.score);
|
|
3476
|
-
const bestScore = scoredSources[0]?.score;
|
|
3477
|
-
const bestSources = bestScore ? scoredSources.filter((item) => item.score === bestScore) : [];
|
|
3478
|
-
return bestSources.length === 1 ? bestSources[0]?.entry : void 0;
|
|
3479
|
-
};
|
|
3480
|
-
const rawSourceMatched = selectByRawSourceFingerprint(generationSources);
|
|
3481
|
-
if (rawSourceMatched) return rawSourceMatched;
|
|
3482
|
-
const scopedSources = currentSubpackageRoots ? generationSources.filter((entry) => {
|
|
3483
|
-
const outputMatchesSubpackage = isSubpackageOutputFile(outputFile, currentSubpackageRoots);
|
|
3484
|
-
const sourceMatchesSubpackage = isSubpackageOutputFile(entry.file, currentSubpackageRoots);
|
|
3485
|
-
if (!outputMatchesSubpackage) return !sourceMatchesSubpackage;
|
|
3486
|
-
return sourceMatchesSubpackage && [...currentSubpackageRoots].some((root) => isSubpackageOutputFile(outputFile, new Set([root])) && isSubpackageOutputFile(entry.file, new Set([root])));
|
|
3487
|
-
}) : generationSources;
|
|
3488
|
-
const explicitSources = scopedSources.filter((entry) => /@(?:config|source|plugin|custom-variant|theme|utility|variant|apply)\b/.test(entry.source));
|
|
3489
|
-
const candidates = explicitSources.length === 1 ? explicitSources : scopedSources;
|
|
3490
|
-
if (candidates.length === 1) return candidates[0];
|
|
3491
|
-
return selectByRawSourceFingerprint(candidates);
|
|
3492
|
-
};
|
|
3493
|
-
const resolveSubpackageRootForFile = (file) => {
|
|
3494
|
-
if (!file || !currentSubpackageRoots) return;
|
|
3495
|
-
return [...currentSubpackageRoots].find((root) => isSubpackageOutputFile(file, new Set([root])));
|
|
3496
|
-
};
|
|
3497
|
-
const isSameSubpackageScope = (outputFile, sourceFile) => {
|
|
3498
|
-
return resolveSubpackageRootForFile(outputFile) === resolveSubpackageRootForFile(sourceFile);
|
|
3499
|
-
};
|
|
3500
3845
|
const normalizeGeneratorUserRawSource = (source, sourceFile, fallbackFile) => normalizeRelativeCssConfigDirectives(source, sourceFile || fallbackFile, outDir, opts);
|
|
3501
|
-
const
|
|
3502
|
-
|
|
3503
|
-
|
|
3504
|
-
|
|
3505
|
-
|
|
3506
|
-
|
|
3507
|
-
|
|
3508
|
-
|
|
3509
|
-
|
|
3510
|
-
|
|
3511
|
-
path.resolve(outDir, file),
|
|
3512
|
-
!path.isAbsolute(relativeFromOutDir) && !relativeFromOutDir.startsWith("../") ? path.resolve(rootDir, relativeFromOutDir) : void 0,
|
|
3513
|
-
!path.isAbsolute(relativeFromOutDir) && !relativeFromOutDir.startsWith("../") ? path.resolve(path.dirname(outDir), relativeFromOutDir) : void 0,
|
|
3514
|
-
file
|
|
3515
|
-
];
|
|
3516
|
-
const explicitSource = sourceCandidates.reduce((source, candidate) => {
|
|
3517
|
-
if (source || !candidate) return source;
|
|
3518
|
-
return getSourceCandidateSource?.(candidate);
|
|
3519
|
-
}, void 0);
|
|
3520
|
-
if (explicitSource) return explicitSource;
|
|
3521
|
-
const normalizedSourceCandidates = sourceCandidates.filter((candidate) => Boolean(candidate)).map((candidate) => ({
|
|
3522
|
-
absolute: path.isAbsolute(candidate),
|
|
3523
|
-
key: normalizeSourceCandidatePathKey(candidate)
|
|
3524
|
-
}));
|
|
3525
|
-
let bestSource;
|
|
3526
|
-
for (const [sourceFile, source] of getSourceCandidateSources?.() ?? []) {
|
|
3527
|
-
const normalizedSourceFile = normalizeSourceCandidatePathKey(sourceFile);
|
|
3528
|
-
let score = 0;
|
|
3529
|
-
for (const candidate of normalizedSourceCandidates) {
|
|
3530
|
-
if (normalizedSourceFile === candidate.key) {
|
|
3531
|
-
score = Math.max(score, candidate.absolute ? 100 : 80);
|
|
3532
|
-
continue;
|
|
3533
|
-
}
|
|
3534
|
-
if (normalizedSourceFile.endsWith(`/${candidate.key}`)) score = Math.max(score, candidate.absolute ? 60 : 40);
|
|
3535
|
-
}
|
|
3536
|
-
if (normalizedSourceFile.endsWith(`/${normalizedFile}`)) score = Math.max(score, 20);
|
|
3537
|
-
if (score > (bestSource?.score ?? 0)) bestSource = {
|
|
3538
|
-
score,
|
|
3539
|
-
source
|
|
3540
|
-
};
|
|
3541
|
-
}
|
|
3542
|
-
return bestSource?.source;
|
|
3543
|
-
};
|
|
3544
|
-
const resolveOutputFileFromMatchedCssSource = (sourceFile) => {
|
|
3545
|
-
if (!sourceFile) return;
|
|
3546
|
-
const outputFile = resolveViteCssPipelineOutputFileFromSourceFile(sourceFile, opts, rootDir, isWebGeneratorTarget, false, sourceRoot, defaultStyleOutputExtension, bundleFiles);
|
|
3547
|
-
return opts.cssMatcher(outputFile) ? outputFile : void 0;
|
|
3548
|
-
};
|
|
3549
|
-
const hasViteProcessedCssResultForSource = (sourceFile) => {
|
|
3550
|
-
const sourceKey = normalizeOutputPathKey(sourceFile);
|
|
3551
|
-
for (const [file] of getViteProcessedCssAssetResults?.() ?? []) if (normalizeOutputPathKey(file) === sourceKey) return true;
|
|
3552
|
-
return false;
|
|
3553
|
-
};
|
|
3846
|
+
const resolveMatchedCssSourceOutputFile = (sourceFile) => resolveOutputFileFromMatchedCssSource({
|
|
3847
|
+
bundleFiles,
|
|
3848
|
+
defaultStyleOutputExtension,
|
|
3849
|
+
isWebGeneratorTarget,
|
|
3850
|
+
opts,
|
|
3851
|
+
rootDir,
|
|
3852
|
+
shouldPreserveAppCssExtension: false,
|
|
3853
|
+
sourceFile,
|
|
3854
|
+
sourceRoot
|
|
3855
|
+
});
|
|
3554
3856
|
const usedConfiguredTailwindV4CssSourceFiles = /* @__PURE__ */ new Set();
|
|
3555
3857
|
const buildCommand = resolvedConfig?.command === "build";
|
|
3556
3858
|
const hasPreviousBundleState = state.iteration > 0 || state.sourceHashByFile.size > 0;
|
|
@@ -3600,33 +3902,47 @@ function createGenerateBundleHook(context) {
|
|
|
3600
3902
|
});
|
|
3601
3903
|
const jsEntries = snapshot.jsEntries;
|
|
3602
3904
|
const getJsEntry = createJsEntryResolver(jsEntries);
|
|
3905
|
+
const transformFilter = createTransformFilter(opts.transform, rootDir);
|
|
3906
|
+
const transformFilterSignature = createTransformFilterSignature(opts.transform);
|
|
3603
3907
|
const moduleGraphOptions = createBundleModuleGraphOptions(outDir, jsEntries);
|
|
3604
3908
|
const hasRuntimeAffectingChanges = hasRuntimeAffectingSourceChanges(snapshot.runtimeAffectingChangedByType);
|
|
3605
3909
|
const runtimeStart = performance.now();
|
|
3606
3910
|
const forceV4RuntimeRefreshBySource = forceRuntimeRefreshBySource;
|
|
3607
|
-
const runtime = isWebGeneratorTarget
|
|
3911
|
+
const runtime = isWebGeneratorTarget ? /* @__PURE__ */ new Set() : useBundleRuntimeClassSet ? await ensureBundleRuntimeClassSet(snapshot, envFlags.forceRuntimeRefreshByEnv, {
|
|
3912
|
+
allowBaselineOnlyInitialSync: buildCommand,
|
|
3913
|
+
refreshBySource: forceV4RuntimeRefreshBySource
|
|
3914
|
+
}) : await context.ensureRuntimeClassSet(envFlags.forceRuntimeRefreshByEnv);
|
|
3608
3915
|
const shouldFilterTailwindV4MiniProgramCandidates = shouldUseMiniProgramCssBranch(generatorBranch);
|
|
3609
3916
|
const collectedGeneratorCandidates = new Set([...runtime, ...sourceCandidates]);
|
|
3610
3917
|
const filteredGeneratorCandidates = shouldFilterTailwindV4MiniProgramCandidates ? filterUnsupportedMiniProgramTailwindV4Candidates(collectedGeneratorCandidates) : collectedGeneratorCandidates;
|
|
3611
|
-
const
|
|
3918
|
+
const filteredSourceCandidates = shouldFilterTailwindV4MiniProgramCandidates ? filterUnsupportedMiniProgramTailwindV4Candidates(sourceCandidates) : sourceCandidates;
|
|
3919
|
+
const transformRuntime = shouldFilterTailwindV4MiniProgramCandidates ? new Set(runtime) : new Set(filteredGeneratorCandidates);
|
|
3612
3920
|
const generatorRuntime = filteredGeneratorCandidates;
|
|
3613
3921
|
const cssEntries = snapshot.entries.filter((entry) => entry.type === "css" && entry.output.type === "asset");
|
|
3614
|
-
|
|
3922
|
+
const hasMultipleConfiguredCssEntries = (opts.cssEntries?.length ?? 0) > 1;
|
|
3923
|
+
if (sourceCandidates.size > 0 && !hasMultipleConfiguredCssEntries) {
|
|
3615
3924
|
const mainCssEntry = cssEntries.find((entry) => getCssHandlerOptions(entry.file).isMainChunk) ?? cssEntries[0];
|
|
3616
3925
|
if (mainCssEntry) {
|
|
3617
|
-
const
|
|
3618
|
-
|
|
3619
|
-
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
|
|
3623
|
-
|
|
3624
|
-
|
|
3625
|
-
|
|
3626
|
-
|
|
3627
|
-
|
|
3628
|
-
|
|
3629
|
-
|
|
3926
|
+
const mainCssRawSource = typeof mainCssEntry.output.source === "string" ? mainCssEntry.output.source : Buffer.from(mainCssEntry.output.source).toString();
|
|
3927
|
+
if (!hasTailwindApplyDirective(mainCssRawSource)) {
|
|
3928
|
+
const generatedCssSources = /* @__PURE__ */ new Set();
|
|
3929
|
+
for (const [, record] of getViteProcessedCssAssetResults?.() ?? []) if (typeof record === "string") generatedCssSources.add(record);
|
|
3930
|
+
else if (typeof record?.css === "string") generatedCssSources.add(record.css);
|
|
3931
|
+
const validatedSourceRuntime = await validateCandidatesByGenerator({
|
|
3932
|
+
opts,
|
|
3933
|
+
runtimeState,
|
|
3934
|
+
candidates: filteredSourceCandidates,
|
|
3935
|
+
rawSource: mainCssRawSource,
|
|
3936
|
+
generatedCssSources,
|
|
3937
|
+
file: mainCssEntry.file,
|
|
3938
|
+
cssHandlerOptions: getCssHandlerOptions(mainCssEntry.file),
|
|
3939
|
+
cssUserHandlerOptions: getCssUserHandlerOptions(mainCssEntry.file),
|
|
3940
|
+
styleHandler,
|
|
3941
|
+
debug,
|
|
3942
|
+
skipGenerateFallback: false
|
|
3943
|
+
});
|
|
3944
|
+
if (validatedSourceRuntime.size > 0) for (const candidate of validatedSourceRuntime) transformRuntime.add(candidate);
|
|
3945
|
+
}
|
|
3630
3946
|
}
|
|
3631
3947
|
}
|
|
3632
3948
|
const generatorCandidateSignature = createCandidateSignature(generatorRuntime);
|
|
@@ -3634,21 +3950,24 @@ function createGenerateBundleHook(context) {
|
|
|
3634
3950
|
const cssExtensionByStem = collectCssExtensionByStem(bundleFiles, opts.cssMatcher);
|
|
3635
3951
|
const jsImportedCssFiles = collectJsImportedCssFiles(snapshot);
|
|
3636
3952
|
const runtimeLinkedCssFiles = new Set([...collectRuntimeLinkedCssFiles(snapshot, cssExtensionByStem, defaultStyleOutputExtension), ...jsImportedCssFiles]);
|
|
3637
|
-
|
|
3638
|
-
|
|
3639
|
-
|
|
3640
|
-
|
|
3641
|
-
|
|
3642
|
-
|
|
3643
|
-
|
|
3644
|
-
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
|
|
3648
|
-
|
|
3649
|
-
|
|
3650
|
-
|
|
3651
|
-
|
|
3953
|
+
rememberRuntimeLinkedCssSources({
|
|
3954
|
+
bundleFiles,
|
|
3955
|
+
debug,
|
|
3956
|
+
defaultStyleOutputExtension,
|
|
3957
|
+
getConfiguredTailwindV4CssSourceEntries,
|
|
3958
|
+
getSourceCandidateSource,
|
|
3959
|
+
getSourceCandidateSources,
|
|
3960
|
+
isWebGeneratorTarget,
|
|
3961
|
+
jsImportedCssFiles,
|
|
3962
|
+
opts,
|
|
3963
|
+
outDir,
|
|
3964
|
+
rememberCssSource,
|
|
3965
|
+
rootDir,
|
|
3966
|
+
runtimeLinkedCssFiles,
|
|
3967
|
+
shouldPreserveAppCssExtension,
|
|
3968
|
+
snapshot,
|
|
3969
|
+
sourceRoot
|
|
3970
|
+
});
|
|
3652
3971
|
recordGeneratorCandidates?.(generatorRuntime);
|
|
3653
3972
|
const dynamicRetryCandidates = new Set([
|
|
3654
3973
|
...sourceCandidates,
|
|
@@ -3690,90 +4009,86 @@ function createGenerateBundleHook(context) {
|
|
|
3690
4009
|
debug("html skip web target: %s", file);
|
|
3691
4010
|
continue;
|
|
3692
4011
|
}
|
|
4012
|
+
if (shouldSkipViteAssetTransform(originalSource, file, rootDir, transformFilter)) {
|
|
4013
|
+
metrics.html.transformed++;
|
|
4014
|
+
debug("html skip transform (filtered): %s", file);
|
|
4015
|
+
continue;
|
|
4016
|
+
}
|
|
3693
4017
|
if (!processFiles.html.has(file)) continue;
|
|
3694
|
-
|
|
3695
|
-
const currentRawDynamicCandidates = collectUnescapedDynamicCandidates(rawSource);
|
|
3696
|
-
const templateRuntime = currentRawDynamicCandidates.length > 0 ? new Set([...transformRuntime, ...currentRawDynamicCandidates]) : transformRuntime;
|
|
3697
|
-
const templateRuntimeSignature = templateRuntime === transformRuntime ? transformRuntimeSignature : createCandidateSignature(templateRuntime);
|
|
3698
|
-
const htmlProcessHash = `${cache.computeHash(rawSource)}:${cache.computeHash(createRuntimeAffectingSourceSignature(rawSource, "html"))}:${templateRuntimeSignature}`;
|
|
3699
|
-
const cacheKey = `${file}:html:${htmlProcessHash}`;
|
|
3700
|
-
const hashKey = cacheKey;
|
|
3701
|
-
rememberProcessCacheKey(cacheKey, hashKey);
|
|
3702
|
-
tasks.push(timeTask("html", () => processCachedTask({
|
|
4018
|
+
processHtmlBundleEntry({
|
|
3703
4019
|
cache,
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
|
|
3711
|
-
|
|
3712
|
-
|
|
3713
|
-
|
|
3714
|
-
|
|
3715
|
-
|
|
3716
|
-
|
|
3717
|
-
|
|
3718
|
-
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
|
-
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
|
|
3726
|
-
|
|
3727
|
-
transformed = await templateHandler(rawSource, { runtimeSet: retryRuntimeSet });
|
|
3728
|
-
unresolvedDynamicCandidates = collectUnescapedDynamicCandidates(transformed, retryRuntimeSet);
|
|
3729
|
-
if (unresolvedDynamicCandidates.length > 0) logger.warn("已提取 WXML 动态类名在完整 runtimeSet 重试后仍未完成转译: %s -> %O", file, unresolvedDynamicCandidates);
|
|
3730
|
-
}
|
|
3731
|
-
metrics.html.elapsed += measureElapsed(start);
|
|
3732
|
-
metrics.html.transformed++;
|
|
3733
|
-
onUpdate(file, rawSource, transformed);
|
|
3734
|
-
debug("html handle: %s", file);
|
|
3735
|
-
return { result: transformed };
|
|
3736
|
-
}
|
|
3737
|
-
})));
|
|
4020
|
+
context,
|
|
4021
|
+
debug,
|
|
4022
|
+
dynamicRetryCandidates,
|
|
4023
|
+
file,
|
|
4024
|
+
metrics,
|
|
4025
|
+
onUpdate,
|
|
4026
|
+
originalEntrySource,
|
|
4027
|
+
originalSource,
|
|
4028
|
+
rememberProcessCacheKey,
|
|
4029
|
+
resolveCurrentSourceCandidateSource: (file) => resolveCurrentSourceCandidateSource({
|
|
4030
|
+
file,
|
|
4031
|
+
getSourceCandidateSource,
|
|
4032
|
+
getSourceCandidateSources,
|
|
4033
|
+
outDir,
|
|
4034
|
+
rootDir,
|
|
4035
|
+
sourceRoot
|
|
4036
|
+
}),
|
|
4037
|
+
tasks,
|
|
4038
|
+
templateHandler,
|
|
4039
|
+
timeTask,
|
|
4040
|
+
transformRuntime,
|
|
4041
|
+
transformRuntimeSignature
|
|
4042
|
+
});
|
|
3738
4043
|
continue;
|
|
3739
4044
|
}
|
|
3740
4045
|
if (type === "css" && originalSource.type === "asset") {
|
|
3741
4046
|
metrics.css.total++;
|
|
3742
4047
|
const assetSourceFile = resolveAssetSourceFile(originalSource, file);
|
|
3743
4048
|
const rawSource = normalizeRelativeCssConfigDirectives(originalEntrySource, assetSourceFile, outDir, opts);
|
|
3744
|
-
let outputFile =
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
};
|
|
4049
|
+
let outputFile = resolveCssBundleOutputFile({
|
|
4050
|
+
bundleFiles,
|
|
4051
|
+
defaultStyleOutputExtension,
|
|
4052
|
+
file,
|
|
4053
|
+
isWebGeneratorTarget,
|
|
4054
|
+
opts,
|
|
4055
|
+
shouldPreserveAppCssExtension
|
|
4056
|
+
});
|
|
4057
|
+
const resolveMatchedOutputFileForCurrentAsset = createMatchedCssSourceOutputResolver({
|
|
4058
|
+
assetSourceFile,
|
|
4059
|
+
file,
|
|
4060
|
+
originalFileNames: originalSource.originalFileNames,
|
|
4061
|
+
resolveOutputFileFromMatchedCssSource: resolveMatchedCssSourceOutputFile
|
|
4062
|
+
});
|
|
3752
4063
|
activeViteCssCacheFiles.add(normalizeViteCssCacheKey(outputFile));
|
|
3753
|
-
if (outputFile
|
|
4064
|
+
if (shouldSkipRawSourceStyleAsset(outputFile, file, rawSource, assetSourceFile, opts.cssMatcher)) {
|
|
3754
4065
|
delete bundle[file];
|
|
3755
4066
|
debug("css skip raw source style asset: %s -> %s", file, outputFile);
|
|
3756
4067
|
continue;
|
|
3757
4068
|
}
|
|
4069
|
+
const hasViteProcessedCssRecord = getViteProcessedCssAssetResult?.(file) != null;
|
|
4070
|
+
const viteProcessedCssAsset = isViteProcessedCssAsset?.(originalSource, file) === true || hasViteProcessedCssRecord;
|
|
3758
4071
|
const applyCssResult = (source) => {
|
|
3759
|
-
|
|
3760
|
-
|
|
3761
|
-
|
|
3762
|
-
|
|
3763
|
-
|
|
3764
|
-
|
|
3765
|
-
|
|
3766
|
-
|
|
3767
|
-
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
else emitOrReplayCssAsset(outputFile, source);
|
|
3771
|
-
if (!viteProcessedCssAsset && SOURCE_STYLE_OUTPUT_EXT_RE.test(file)) delete bundle[file];
|
|
3772
|
-
else originalSource.source = importShellSource ?? "";
|
|
3773
|
-
return;
|
|
3774
|
-
}
|
|
3775
|
-
originalSource.source = source;
|
|
4072
|
+
applyCssResultToBundle({
|
|
4073
|
+
appType: opts.appType,
|
|
4074
|
+
assetSourceFile,
|
|
4075
|
+
bundle,
|
|
4076
|
+
emitOrReplayCssAsset,
|
|
4077
|
+
file,
|
|
4078
|
+
originalSource,
|
|
4079
|
+
outputFile,
|
|
4080
|
+
source,
|
|
4081
|
+
viteProcessedCssAsset
|
|
4082
|
+
});
|
|
3776
4083
|
};
|
|
4084
|
+
if (shouldSkipViteAssetTransform(originalSource, file, rootDir, transformFilter)) {
|
|
4085
|
+
applyCssResult(rawSource);
|
|
4086
|
+
markCssAssetProcessed?.(originalSource, outputFile);
|
|
4087
|
+
onUpdate(outputFile, rawSource, rawSource);
|
|
4088
|
+
metrics.css.transformed++;
|
|
4089
|
+
debug("css skip transform (filtered): %s", outputFile);
|
|
4090
|
+
continue;
|
|
4091
|
+
}
|
|
3777
4092
|
if (isWebGeneratorTarget && !shouldGenerateWebCssByGenerator) {
|
|
3778
4093
|
applyCssResult(rawSource);
|
|
3779
4094
|
markCssAssetProcessed?.(originalSource, outputFile);
|
|
@@ -3781,12 +4096,12 @@ function createGenerateBundleHook(context) {
|
|
|
3781
4096
|
debug("css skip web target: %s", outputFile);
|
|
3782
4097
|
continue;
|
|
3783
4098
|
}
|
|
3784
|
-
const hasViteProcessedCssRecord = getViteProcessedCssAssetResult?.(file) != null;
|
|
3785
|
-
const viteProcessedCssAsset = isViteProcessedCssAsset?.(originalSource, file) === true || hasViteProcessedCssRecord;
|
|
3786
4099
|
const cssAssetProcessed = isCssAssetProcessed?.(originalSource, file) === true;
|
|
3787
4100
|
const alreadyProcessedCssAsset = viteProcessedCssAsset || cssAssetProcessed;
|
|
3788
4101
|
let rememberedCssSources = findRememberedCssSources(getRememberedCssSources?.(), outputFile, file, originalSource, outDir, opts.tailwindcssBasedir);
|
|
3789
|
-
if (rememberedCssSources.length > 0) rememberedCssSources = await Promise.all(rememberedCssSources.map(async (remembered) =>
|
|
4102
|
+
if (rememberedCssSources.length > 0) rememberedCssSources = await Promise.all(rememberedCssSources.map(async (remembered) => {
|
|
4103
|
+
return await refreshRememberedCssSource?.(remembered) ?? remembered;
|
|
4104
|
+
}));
|
|
3790
4105
|
let hasUsableRememberedTailwindSource = rememberedCssSources.some((remembered) => hasTailwindGenerationSource(remembered.rawSource) && normalizeOutputPathKey(remembered.sourceFile.replace(/[?#].*$/, "")) !== normalizeOutputPathKey(file));
|
|
3791
4106
|
const inferredSfcStyleSource = await resolveSfcStyleSourceFromOutputFile(outputFile, snapshot, outDir, opts.tailwindcssBasedir, opts.cssMatcher, getSfcSource, debug);
|
|
3792
4107
|
if (inferredSfcStyleSource) {
|
|
@@ -3795,7 +4110,7 @@ function createGenerateBundleHook(context) {
|
|
|
3795
4110
|
if (!hasUsableRememberedTailwindSource || rememberedSourcesBelongToInferredSfc) rememberedCssSources = [inferredSfcStyleSource];
|
|
3796
4111
|
}
|
|
3797
4112
|
let outputCssHandlerOptions = getCssHandlerOptions(outputFile);
|
|
3798
|
-
if (currentSubpackageRoots && rememberedCssSources.length > 0 && rememberedCssSources.some((remembered) => configuredTailwindV4CssSourceFileKeysForScope.has(normalizeOutputPathKey(remembered.sourceFile.replace(/[?#].*$/, ""))) && !isSameSubpackageScope(outputFile, remembered.sourceFile))) {
|
|
4113
|
+
if (currentSubpackageRoots && rememberedCssSources.length > 0 && rememberedCssSources.some((remembered) => configuredTailwindV4CssSourceFileKeysForScope.has(normalizeOutputPathKey(remembered.sourceFile.replace(/[?#].*$/, ""))) && !isSameSubpackageScope(outputFile, remembered.sourceFile, currentSubpackageRoots))) {
|
|
3799
4114
|
rememberedCssSources = [];
|
|
3800
4115
|
hasUsableRememberedTailwindSource = false;
|
|
3801
4116
|
}
|
|
@@ -3812,8 +4127,8 @@ function createGenerateBundleHook(context) {
|
|
|
3812
4127
|
}];
|
|
3813
4128
|
} else if (hasTailwindGenerationSource(rawSource) && (originalSource.originalFileNames?.length ?? 0) === 0) {
|
|
3814
4129
|
const availableConfiguredTailwindV4CssSourceEntries = configuredTailwindV4CssSourceEntries.filter((entry) => !usedConfiguredTailwindV4CssSourceFiles.has(normalizeOutputPathKey(entry.file)));
|
|
3815
|
-
const configuredGenerationSource = selectTailwindV4GenerationCssSourceForOutput(outputFile, availableConfiguredTailwindV4CssSourceEntries, rawSource);
|
|
3816
|
-
if (configuredGenerationSource && !hasViteProcessedCssResultForSource(configuredGenerationSource.file)) {
|
|
4130
|
+
const configuredGenerationSource = selectTailwindV4GenerationCssSourceForOutput(outputFile, availableConfiguredTailwindV4CssSourceEntries, rawSource, currentSubpackageRoots);
|
|
4131
|
+
if (configuredGenerationSource && !hasViteProcessedCssResultForSource(configuredGenerationSource.file, getViteProcessedCssAssetResults)) {
|
|
3817
4132
|
outputFile = resolveMatchedOutputFileForCurrentAsset(configuredGenerationSource.file) ?? outputFile;
|
|
3818
4133
|
activeViteCssCacheFiles.add(normalizeViteCssCacheKey(outputFile));
|
|
3819
4134
|
outputCssHandlerOptions = getCssHandlerOptions(outputFile);
|
|
@@ -3893,8 +4208,10 @@ function createGenerateBundleHook(context) {
|
|
|
3893
4208
|
const shouldInjectVitePipelineCssIntoMain = vitePipelineCssAsset && outputCssHandlerOptions.isMainChunk !== true && shouldInjectCssIntoMainFromOutput(outputFile, generatorSourceFile, outputCssHandlerOptions);
|
|
3894
4209
|
const shouldTrackGeneratorRuntime = hasStaleViteProcessedCssSource || shouldRegenerateMainPackageCssWithScopedCandidates || hasCurrentTailwindGenerationDirective || hasSameOutputRememberedTailwindGenerationSource || shouldProcessTailwindGeneration && (!useIncrementalMode || cssHandlerOptions.isMainChunk || processFiles.css.has(file) || runtimeLinkedCssFiles.has(file) || runtimeLinkedCssFiles.has(outputFile) || shouldRegenerateCollectedViteCss || hasRuntimeAffectingChanges && (alreadyProcessedCssAsset || vitePipelineCssAsset));
|
|
3895
4210
|
const shouldPreserveCollectedViteCssAsset = !shouldRegenerateCollectedViteCss && (state.generatorCandidateSignature === void 0 || !generatorCandidatesChanged) && (collectedBundlerGeneratedCssFiles.has(file) || hasBundlerGeneratedCssMarker(rawSource));
|
|
3896
|
-
|
|
3897
|
-
|
|
4211
|
+
const strippedViteProcessedCss = stripBundlerGeneratedCssMarkers(rawSource);
|
|
4212
|
+
const shouldPreserveStaleGeneratedCssAsset = hasStaleViteProcessedCssSource && shouldPreserveCollectedViteCssAsset && strippedViteProcessedCss.trim().length > 0 && !strippedViteProcessedCss.includes("weapp-tailwindcss generator-placeholder") && !strippedViteProcessedCss.includes("vite-placeholder") && !hasTailwindGenerationSource(strippedViteProcessedCss) && !hasTailwindApplyDirective(strippedViteProcessedCss);
|
|
4213
|
+
if (alreadyProcessedCssAsset && !shouldRefreshViteProcessedCssByCandidates && (!hasStaleViteProcessedCssSource || shouldPreserveStaleGeneratedCssAsset) && !hasRememberedApplySource && !shouldRegenerateMainPackageCssWithScopedCandidates && (!shouldTrackGeneratorRuntime || shouldPreserveCollectedViteCssAsset)) {
|
|
4214
|
+
const nextCss = strippedViteProcessedCss;
|
|
3898
4215
|
applyCssResult(nextCss);
|
|
3899
4216
|
markCssAssetProcessed?.(originalSource, outputFile);
|
|
3900
4217
|
recordCssAssetResult?.(outputFile, nextCss);
|
|
@@ -3913,9 +4230,9 @@ function createGenerateBundleHook(context) {
|
|
|
3913
4230
|
}) : trackedGeneratorCandidateSignature;
|
|
3914
4231
|
const cssRuntimeSignature = createCssRuntimeSignature(runtimeSignature, scopedGeneratorCandidateSignature);
|
|
3915
4232
|
const rememberedCssRuntimeSignature = createRememberedCssRuntimeSignature(cssRuntimeSignature, cssRuntimeAffectingHash);
|
|
3916
|
-
const cssSharedCacheKey = `${cssShareScope}:${cssRuntimeSignature}:${runtimeState.tailwindRuntime.majorVersion ?? "unknown"}:${cssHandlerOptions.isMainChunk ? "1" : "0"}:${
|
|
3917
|
-
const cssCacheKey =
|
|
3918
|
-
const cssHashKey = `${
|
|
4233
|
+
const cssSharedCacheKey = `${cssShareScope}:${cssRuntimeSignature}:${runtimeState.tailwindRuntime.majorVersion ?? "unknown"}:${cssHandlerOptions.isMainChunk ? "1" : "0"}:${cssRuntimeAffectingHash}:${scopedGeneratorCandidateSignature}:${sourceTraceSignature}`;
|
|
4234
|
+
const cssCacheKey = outputFile;
|
|
4235
|
+
const cssHashKey = `${outputFile}:css:${cssRuntimeSignature}:${runtimeState.tailwindRuntime.majorVersion ?? "unknown"}`;
|
|
3919
4236
|
const cssLinkedImpactSignature = runtimeLinkedCssFiles.has(file) || runtimeLinkedCssFiles.has(outputFile) ? [...[...snapshot.runtimeAffectingChangedByType.html].sort().map((changedFile) => snapshot.runtimeAffectingSignatureByFile.get(changedFile) ?? ""), ...[...snapshot.runtimeAffectingChangedByType.js].sort().map((changedFile) => snapshot.runtimeAffectingSignatureByFile.get(changedFile) ?? "")].join(":") : "";
|
|
3920
4237
|
if (!shouldTrackGeneratorRuntime && !runtimeLinkedCssFiles.has(file) && !runtimeLinkedCssFiles.has(outputFile)) {
|
|
3921
4238
|
const lastCss = getLastCssResult(lastCssResultByFile, outputFile, file);
|
|
@@ -3984,6 +4301,7 @@ function createGenerateBundleHook(context) {
|
|
|
3984
4301
|
registerGeneratorDependencies$1({ addWatchFile }, generated.dependencies);
|
|
3985
4302
|
if (envFlags.debugCssDiff) debug("css diff %s: %s", generatorSourceFile, summarizeStringDiff(generatorRawSource, tracedCss));
|
|
3986
4303
|
debug("css generated result: %s bytes=%d", file, tracedCss.length);
|
|
4304
|
+
for (const candidate of generated.classSet ?? []) transformRuntime.add(candidate);
|
|
3987
4305
|
recordCssAssetResult?.(outputFile, tracedCss);
|
|
3988
4306
|
recordViteProcessedCssAssetResult?.(outputFile, tracedCss, {
|
|
3989
4307
|
injectIntoMain: outputCssHandlerOptions.isMainChunk ? false : shouldInjectVitePipelineCssIntoMain,
|
|
@@ -4045,8 +4363,12 @@ function createGenerateBundleHook(context) {
|
|
|
4045
4363
|
rememberProcessCacheKey,
|
|
4046
4364
|
runtimeSignature,
|
|
4047
4365
|
snapshot,
|
|
4366
|
+
transformFilterSignature,
|
|
4367
|
+
shouldSkipAstTransform: transformFilter ? (chunk) => shouldSkipViteJsChunkTransform(chunk, transformFilter) : void 0,
|
|
4368
|
+
slowJsAstWarnMs: envFlags.slowJsAstWarnMs,
|
|
4048
4369
|
timeTask,
|
|
4049
4370
|
transformRuntime,
|
|
4371
|
+
transformRuntimeSignature,
|
|
4050
4372
|
uniAppX,
|
|
4051
4373
|
useIncrementalMode
|
|
4052
4374
|
});
|
|
@@ -4057,10 +4379,10 @@ function createGenerateBundleHook(context) {
|
|
|
4057
4379
|
bundle,
|
|
4058
4380
|
bundleFiles,
|
|
4059
4381
|
cache,
|
|
4382
|
+
cssTaskFactories,
|
|
4060
4383
|
createScopedGeneratorRuntime: createScopedGeneratorRuntime$1,
|
|
4061
4384
|
createScopedSourceCandidateGetter,
|
|
4062
4385
|
createScopedSourceCandidateSourceGetter,
|
|
4063
|
-
cssTaskFactories,
|
|
4064
4386
|
debug,
|
|
4065
4387
|
defaultStyleOutputExtension,
|
|
4066
4388
|
emitOrReplayCssAsset,
|
|
@@ -4091,7 +4413,6 @@ function createGenerateBundleHook(context) {
|
|
|
4091
4413
|
timeTask,
|
|
4092
4414
|
useIncrementalMode
|
|
4093
4415
|
});
|
|
4094
|
-
pushConcurrentTaskFactories(tasks, jsTaskFactories);
|
|
4095
4416
|
await finalizeGenerateBundle({
|
|
4096
4417
|
activeProcessCacheKeys,
|
|
4097
4418
|
activeProcessHashKeys,
|
|
@@ -4116,6 +4437,8 @@ function createGenerateBundleHook(context) {
|
|
|
4116
4437
|
isNativeAppStyleTarget,
|
|
4117
4438
|
isViteProcessedCssAsset,
|
|
4118
4439
|
isWebGeneratorTarget,
|
|
4440
|
+
jsAfterCss: shouldFilterTailwindV4MiniProgramCandidates && cssTaskFactories.length > 0,
|
|
4441
|
+
jsTaskFactories,
|
|
4119
4442
|
lastCssResultByFile,
|
|
4120
4443
|
lastCssSourceHashByFile,
|
|
4121
4444
|
linkedByEntry,
|
|
@@ -4169,7 +4492,7 @@ function createCssHandlerOptions(opts, majorVersion, file) {
|
|
|
4169
4492
|
...resolveUniAppXNativeCssHandlerOptions(opts),
|
|
4170
4493
|
isMainChunk: opts.mainCssChunkMatcher(file, opts.appType),
|
|
4171
4494
|
postcssOptions: { options: { from: file } },
|
|
4172
|
-
...majorVersion === void 0 ? {} : { majorVersion }
|
|
4495
|
+
...normalizeStyleHandlerMajorVersion(majorVersion) === void 0 ? {} : { majorVersion: 4 }
|
|
4173
4496
|
};
|
|
4174
4497
|
}
|
|
4175
4498
|
function shouldGenerateCssByGenerator(opts, majorVersion, file, rawSource, processed) {
|
|
@@ -4454,6 +4777,7 @@ function shouldCollectTransformedSourceCandidates(id) {
|
|
|
4454
4777
|
function createViteCssMemory(options) {
|
|
4455
4778
|
const rememberedCssSources = /* @__PURE__ */ new Map();
|
|
4456
4779
|
const rememberedCssSignatureByFile = /* @__PURE__ */ new Map();
|
|
4780
|
+
const knownCssSources = /* @__PURE__ */ new Map();
|
|
4457
4781
|
const knownSfcSources = /* @__PURE__ */ new Map();
|
|
4458
4782
|
const rememberKnownSfcSource = (id, code) => {
|
|
4459
4783
|
if (id.search(/[?#]/) >= 0) return;
|
|
@@ -4505,6 +4829,7 @@ function createViteCssMemory(options) {
|
|
|
4505
4829
|
return nextRemembered;
|
|
4506
4830
|
};
|
|
4507
4831
|
const refreshRememberedCssSourceBySourceFile = (sourceFile, rawSource) => {
|
|
4832
|
+
touchMapEntry(knownCssSources, normalizeCssSourceIdentity(sourceFile), rawSource);
|
|
4508
4833
|
const normalizedSourceFile = normalizeCssSourceIdentity(sourceFile);
|
|
4509
4834
|
const relatedRememberedEntries = [...rememberedCssSources].filter(([, remembered]) => normalizeCssSourceIdentity(remembered.sourceFile) === normalizedSourceFile);
|
|
4510
4835
|
for (const [rememberedKey, remembered] of relatedRememberedEntries) refreshRememberedCssSourceEntry(rememberedKey, remembered, sourceFile, rawSource);
|
|
@@ -4518,6 +4843,10 @@ function createViteCssMemory(options) {
|
|
|
4518
4843
|
const cached = resolveCachedStyleSource(sourceFile);
|
|
4519
4844
|
if (cached != null) return cached;
|
|
4520
4845
|
const file = cleanUrl(stripRequestQuery(sourceFile));
|
|
4846
|
+
const knownSource = knownCssSources.get(normalizeCssSourceIdentity(sourceFile));
|
|
4847
|
+
if (knownSource != null) return knownSource;
|
|
4848
|
+
const candidateSource = options.getSourceCandidateSource(file);
|
|
4849
|
+
if (candidateSource != null) return candidateSource;
|
|
4521
4850
|
if (!isSourceStyleRequest(file)) return;
|
|
4522
4851
|
try {
|
|
4523
4852
|
return await readFile(file, "utf8");
|
|
@@ -4579,6 +4908,7 @@ function createViteCssMemory(options) {
|
|
|
4579
4908
|
pruneMapToMaxSize(rememberedCssSources, VITE_REMEMBERED_CSS_CACHE_MAX, (rememberedKey) => {
|
|
4580
4909
|
rememberedCssSignatureByFile.delete(String(rememberedKey));
|
|
4581
4910
|
});
|
|
4911
|
+
pruneMapToMaxSize(knownCssSources, VITE_REMEMBERED_CSS_CACHE_MAX);
|
|
4582
4912
|
pruneMapToMaxSize(knownSfcSources, VITE_KNOWN_SFC_SOURCE_CACHE_MAX);
|
|
4583
4913
|
};
|
|
4584
4914
|
return {
|
|
@@ -4590,6 +4920,8 @@ function createViteCssMemory(options) {
|
|
|
4590
4920
|
rememberedCssSources: rememberedCssSources.size,
|
|
4591
4921
|
rememberedCssSourcesRaw: summarizeRememberedCssSources(rememberedCssSources),
|
|
4592
4922
|
rememberedCssSignatureByFile: rememberedCssSignatureByFile.size,
|
|
4923
|
+
knownCssSources: knownCssSources.size,
|
|
4924
|
+
knownCssSourcesRaw: summarizeStringMapCache(knownCssSources),
|
|
4593
4925
|
knownSfcSources: knownSfcSources.size,
|
|
4594
4926
|
knownSfcSourcesRaw: summarizeStringMapCache(knownSfcSources)
|
|
4595
4927
|
}),
|
|
@@ -4716,6 +5048,35 @@ function disableAndRemoveTailwindVitePlugins(plugins) {
|
|
|
4716
5048
|
return removed;
|
|
4717
5049
|
}
|
|
4718
5050
|
//#endregion
|
|
5051
|
+
//#region src/bundlers/vite/plugin-cache.ts
|
|
5052
|
+
function isMissingInternalCssSource(file, packageDir) {
|
|
5053
|
+
return !existsSync(file) && path.resolve(file).startsWith(`${packageDir}${path.sep}`);
|
|
5054
|
+
}
|
|
5055
|
+
function normalizeVitePersistentCacheKey(file) {
|
|
5056
|
+
return normalizeOutputPathKey(file);
|
|
5057
|
+
}
|
|
5058
|
+
function toMb(bytes) {
|
|
5059
|
+
return Math.round(bytes / 1024 / 1024);
|
|
5060
|
+
}
|
|
5061
|
+
function summarizeStringCache(map) {
|
|
5062
|
+
let bytes = 0;
|
|
5063
|
+
for (const value of map.values()) bytes += value.length;
|
|
5064
|
+
return {
|
|
5065
|
+
bytes,
|
|
5066
|
+
mb: toMb(bytes),
|
|
5067
|
+
size: map.size
|
|
5068
|
+
};
|
|
5069
|
+
}
|
|
5070
|
+
function summarizeViteProcessedCssResults(map) {
|
|
5071
|
+
let bytes = 0;
|
|
5072
|
+
for (const record of map.values()) bytes += record.css.length;
|
|
5073
|
+
return {
|
|
5074
|
+
bytes,
|
|
5075
|
+
mb: toMb(bytes),
|
|
5076
|
+
size: map.size
|
|
5077
|
+
};
|
|
5078
|
+
}
|
|
5079
|
+
//#endregion
|
|
4719
5080
|
//#region src/bundlers/shared/css-imports.ts
|
|
4720
5081
|
const tailwindcssImportRE = /^(?:tailwindcss|weapp-tailwindcss)(?:\/.*)?$/;
|
|
4721
5082
|
const tailwindcssCssImportStatementRE = /(@import\s+(?:url\(\s*)?)(["'])((?:tailwindcss|weapp-tailwindcss)(?:\/[^"']*)?\$?)(\2\s*\)?)/gi;
|
|
@@ -4887,7 +5248,7 @@ function createViteRuntimeClassSet(options) {
|
|
|
4887
5248
|
if (runtimeSetPromise === task) runtimeSetPromise = void 0;
|
|
4888
5249
|
}
|
|
4889
5250
|
}
|
|
4890
|
-
async function ensureBundleRuntimeClassSet(snapshot, forceRefresh = false,
|
|
5251
|
+
async function ensureBundleRuntimeClassSet(snapshot, forceRefresh = false, options = {}) {
|
|
4891
5252
|
const forceRuntimeRefresh = forceRefresh || process$1.env["WEAPP_TW_VITE_FORCE_RUNTIME_REFRESH"] === "1";
|
|
4892
5253
|
const invalidation = resolveRuntimeRefreshOptions();
|
|
4893
5254
|
const shouldRefreshRuntime = forceRuntimeRefresh || invalidation.changed;
|
|
@@ -4901,7 +5262,14 @@ function createViteRuntimeClassSet(options) {
|
|
|
4901
5262
|
await transformRuntimeClassSetManager.reset();
|
|
4902
5263
|
}
|
|
4903
5264
|
if (!forceRuntimeRefresh) try {
|
|
4904
|
-
const
|
|
5265
|
+
const baseClassSet = options.baseClassSet ?? runtimeSet ?? await collectRuntimeClassSet(runtimeState.tailwindRuntime, {
|
|
5266
|
+
force: invalidation.changed,
|
|
5267
|
+
clearCache: invalidation.changed
|
|
5268
|
+
});
|
|
5269
|
+
const nextRuntimeSet = await bundleRuntimeClassSetManager.sync(runtimeState.tailwindRuntime, snapshot, {
|
|
5270
|
+
baseClassSet,
|
|
5271
|
+
skipInitialFullScanWithBase: options.allowBaselineOnlyInitialSync
|
|
5272
|
+
});
|
|
4905
5273
|
runtimeSet = nextRuntimeSet;
|
|
4906
5274
|
return nextRuntimeSet;
|
|
4907
5275
|
} catch (error) {
|
|
@@ -5033,33 +5401,6 @@ const weappTailwindcssPackageDir = resolvePackageDir("weapp-tailwindcss");
|
|
|
5033
5401
|
const weappTailwindcssDirPosix = slash(weappTailwindcssPackageDir);
|
|
5034
5402
|
const SOURCE_CANDIDATE_SCAN_CACHE_MAX = 8;
|
|
5035
5403
|
const sourceCandidateScanSnapshotCache = new LRUCache({ max: SOURCE_CANDIDATE_SCAN_CACHE_MAX });
|
|
5036
|
-
function isMissingInternalCssSource(file) {
|
|
5037
|
-
return !existsSync(file) && path.resolve(file).startsWith(`${weappTailwindcssPackageDir}${path.sep}`);
|
|
5038
|
-
}
|
|
5039
|
-
function normalizeVitePersistentCacheKey(file) {
|
|
5040
|
-
return normalizeOutputPathKey(file);
|
|
5041
|
-
}
|
|
5042
|
-
function toMb(bytes) {
|
|
5043
|
-
return Math.round(bytes / 1024 / 1024);
|
|
5044
|
-
}
|
|
5045
|
-
function summarizeStringCache(map) {
|
|
5046
|
-
let bytes = 0;
|
|
5047
|
-
for (const value of map.values()) bytes += value.length;
|
|
5048
|
-
return {
|
|
5049
|
-
bytes,
|
|
5050
|
-
mb: toMb(bytes),
|
|
5051
|
-
size: map.size
|
|
5052
|
-
};
|
|
5053
|
-
}
|
|
5054
|
-
function summarizeViteProcessedCssResults(map) {
|
|
5055
|
-
let bytes = 0;
|
|
5056
|
-
for (const record of map.values()) bytes += record.css.length;
|
|
5057
|
-
return {
|
|
5058
|
-
bytes,
|
|
5059
|
-
mb: toMb(bytes),
|
|
5060
|
-
size: map.size
|
|
5061
|
-
};
|
|
5062
|
-
}
|
|
5063
5404
|
/**
|
|
5064
5405
|
* @name WeappTailwindcss
|
|
5065
5406
|
* @description uni-app vite / uni-app-x 版本插件
|
|
@@ -5112,7 +5453,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
5112
5453
|
let autoCssSourcesRefresh;
|
|
5113
5454
|
let autoCssSourcesDiscovered = false;
|
|
5114
5455
|
const syncTailwindCssSourceCandidates = async (id, css) => {
|
|
5115
|
-
if (tailwindcssMajorVersion === 4 && isMissingInternalCssSource(cleanUrl(id))) return;
|
|
5456
|
+
if (tailwindcssMajorVersion === 4 && isMissingInternalCssSource(cleanUrl(id), weappTailwindcssPackageDir)) return;
|
|
5116
5457
|
await sourceCandidateCollector.syncCss(id, css);
|
|
5117
5458
|
cacheCurrentSourceCandidateScan();
|
|
5118
5459
|
};
|
|
@@ -5121,7 +5462,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
5121
5462
|
const file = cleanUrl(id);
|
|
5122
5463
|
if (!path.isAbsolute(file)) return;
|
|
5123
5464
|
if (!isTailwindV4CssEntry(file)) return;
|
|
5124
|
-
if (isMissingInternalCssSource(file)) return;
|
|
5465
|
+
if (isMissingInternalCssSource(file, weappTailwindcssPackageDir)) return;
|
|
5125
5466
|
const sourceFile = path.normalize(file);
|
|
5126
5467
|
const sourceBase = path.dirname(sourceFile);
|
|
5127
5468
|
const sourceCss = normalizeTailwindSourceForGenerator(normalizeTailwindConfigDirectives(css, sourceBase), { importFallback: true });
|
|
@@ -5232,7 +5573,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
5232
5573
|
recordedGeneratorCandidates = void 0;
|
|
5233
5574
|
};
|
|
5234
5575
|
const getSourceCandidates = () => sourceCandidateCollector.values();
|
|
5235
|
-
const getSourceCandidatesForEntries = (entries) => sourceCandidateCollector.valuesForEntries(entries);
|
|
5576
|
+
const getSourceCandidatesForEntries = (entries, options) => sourceCandidateCollector.valuesForEntries(entries, options);
|
|
5236
5577
|
const getSourceCandidateSourcesForEntries = (entries, options) => sourceCandidateCollector.sourcesForEntries(entries, options);
|
|
5237
5578
|
const isWatchBuild = () => resolvedConfig?.command === "build" && resolvedConfig.build.watch != null;
|
|
5238
5579
|
const isWatchLikeBuild = () => isWatchBuild() || resolvedConfig?.command === "serve" || process$1.env["WEAPP_TW_WATCH_REGRESSION"] === "1" || process$1.env["WEAPP_TW_HMR_TIMING"] === "1";
|