weapp-tailwindcss 5.0.6 → 5.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{bundle-state-CdNXQl-o.mjs → bundle-state-5FtFktJr.mjs} +2 -1
- package/dist/{bundle-state-CFgzVHFP.js → bundle-state-cHwTyrOS.js} +2 -1
- package/dist/bundlers/gulp/index.d.ts +3 -4
- package/dist/bundlers/gulp/module-graph.d.ts +2 -0
- package/dist/bundlers/gulp/runtime-snapshot.d.ts +5 -0
- package/dist/bundlers/gulp/vinyl-transform.d.ts +3 -0
- package/dist/bundlers/shared/css-cleanup.d.ts +1 -1
- package/dist/bundlers/shared/css-source-trace.d.ts +20 -0
- package/dist/bundlers/shared/generator-css/directives/fallback.d.ts +11 -0
- package/dist/bundlers/shared/generator-css/generation-helpers.d.ts +56 -0
- package/dist/bundlers/shared/generator-css/local-imports.d.ts +7 -0
- package/dist/bundlers/shared/generator-css/source-resolver.d.ts +1 -1
- package/dist/bundlers/shared/generator-css/types.d.ts +27 -0
- package/dist/bundlers/shared/generator-css/user-css.d.ts +26 -0
- package/dist/bundlers/shared/generator-css/validate.d.ts +5 -0
- package/dist/bundlers/shared/generator-css.d.ts +4 -32
- package/dist/bundlers/vite/css-finalizer.d.ts +3 -0
- package/dist/bundlers/vite/generate-bundle/css-config-directives.d.ts +2 -0
- package/dist/bundlers/vite/generate-bundle/css-output.d.ts +14 -0
- package/dist/bundlers/vite/generate-bundle/remembered-css.d.ts +11 -0
- package/dist/bundlers/vite/generate-bundle/sfc-style-source.d.ts +9 -0
- package/dist/bundlers/vite/generate-bundle/style-matching.d.ts +5 -0
- package/dist/bundlers/vite/generate-bundle/subpackages.d.ts +7 -0
- package/dist/bundlers/vite/generate-bundle/types.d.ts +68 -0
- package/dist/bundlers/vite/generate-bundle.d.ts +4 -62
- package/dist/bundlers/vite/incremental-runtime-class-set/entries.d.ts +4 -0
- package/dist/bundlers/vite/incremental-runtime-class-set/escaped-candidates.d.ts +2 -0
- package/dist/bundlers/vite/incremental-runtime-class-set/v3-candidates.d.ts +13 -0
- package/dist/bundlers/vite/incremental-runtime-class-set.d.ts +1 -0
- package/dist/bundlers/vite/processed-css-assets/css-rules.d.ts +17 -0
- package/dist/bundlers/vite/processed-css-assets.d.ts +2 -0
- package/dist/bundlers/vite/source-candidates/scan-root.d.ts +10 -0
- package/dist/bundlers/vite/source-candidates/script.d.ts +7 -0
- package/dist/bundlers/vite/source-candidates/tailwind-v3-default-extractor.d.ts +1 -0
- package/dist/bundlers/vite/source-candidates.d.ts +8 -3
- package/dist/bundlers/vite/source-scan/css-entries.d.ts +20 -0
- package/dist/bundlers/vite/source-scan/dependencies.d.ts +2 -0
- package/dist/bundlers/vite/source-scan.d.ts +2 -12
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/helpers.d.ts +48 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets.d.ts +1 -20
- package/dist/cli.js +71 -69
- package/dist/cli.mjs +71 -69
- package/dist/core.js +1 -1
- package/dist/core.mjs +1 -1
- package/dist/{defaults-BPUuNYcD.js → defaults-Boc26eel.js} +1 -0
- package/dist/{defaults-8xrgzxFY.mjs → defaults-DH0ZQRhy.mjs} +1 -0
- package/dist/defaults.js +1 -1
- package/dist/defaults.mjs +1 -1
- package/dist/{generator-C56PJYxA.js → generator-C--TrAod.js} +1 -1
- package/dist/{generator-Bgn4m8An.mjs → generator-DnwUQOXB.mjs} +1 -1
- package/dist/generator.js +2 -2
- package/dist/generator.mjs +2 -2
- package/dist/gulp-5Tan5bHG.js +473 -0
- package/dist/gulp-B22YSGU_.mjs +463 -0
- package/dist/gulp.js +4 -414
- package/dist/gulp.mjs +1 -406
- package/dist/{incremental-runtime-class-set-Bmzdjlk0.js → hmr-timing-CscCNKb9.js} +1205 -449
- package/dist/{incremental-runtime-class-set-BEYHQkZc.mjs → hmr-timing-DK-mine6.mjs} +1169 -467
- package/dist/index.js +5 -5
- package/dist/index.mjs +5 -5
- package/dist/{postcss-BgINK7Nm.mjs → postcss-CjWuDZwL.mjs} +4 -4
- package/dist/{postcss-B7QNe78h.js → postcss-R5pDVHUy.js} +7 -7
- package/dist/postcss.js +1 -1
- package/dist/postcss.mjs +1 -1
- package/dist/{precheck-CyPbGn38.js → precheck-B8y6tDvG.js} +19 -5
- package/dist/{precheck-Copn2SqE.mjs → precheck-CcxTR7E_.mjs} +19 -5
- package/dist/presets.js +2 -2
- package/dist/presets.mjs +2 -2
- package/dist/tailwindcss/source-scan/inline-source.d.ts +7 -0
- package/dist/tailwindcss/source-scan.d.ts +2 -7
- package/dist/tailwindcss/v3-engine/generator/cache-key.d.ts +3 -0
- package/dist/tailwindcss/v3-engine/generator/content.d.ts +10 -0
- package/dist/tailwindcss/v3-engine/generator/runtime-ready.d.ts +2 -0
- package/dist/tailwindcss/v4-engine/generator/css-compat.d.ts +2 -0
- package/dist/tailwindcss/v4-engine/generator/rpx-candidates.d.ts +6 -0
- package/dist/tailwindcss/v4-engine/generator/scan-sources.d.ts +2 -0
- package/dist/tailwindcss/v4-engine/types.d.ts +1 -1
- package/dist/{tailwindcss-C0Zgo3Es.mjs → tailwindcss-0DaftXcU.mjs} +2 -2
- package/dist/{tailwindcss-Tw6CSVHL.js → tailwindcss-DbZ4o4m_.js} +2 -2
- package/dist/{transform-DgCFGtQR.mjs → transform-DRyWUN5X.mjs} +11 -2
- package/dist/{transform-95ivJthq.js → transform-DiW_u3eD.js} +11 -2
- package/dist/types/typedoc-tailwindcss-patch.d.ts +4 -2
- package/dist/types/user-defined-options/general.d.ts +5 -0
- package/dist/uni-app-x/component-local-style.d.ts +1 -0
- package/dist/uni-app-x/harmony.d.ts +1 -0
- package/dist/uni-app-x/style-asset/style-value.d.ts +16 -0
- package/dist/uni-app-x/style-asset.d.ts +20 -0
- package/dist/uni-app-x/transform.d.ts +1 -0
- package/dist/uni-app-x/vite.d.ts +1 -0
- package/dist/{v3-engine-Ji6AXPh2.mjs → v3-engine-ArQVHEau.mjs} +786 -699
- package/dist/{v3-engine-6FVAcrZl.js → v3-engine-DdlvXpID.js} +788 -701
- package/dist/{vite-Bw6LOXvf.js → vite-C_IUnDBy.js} +1797 -386
- package/dist/{vite-ChZ2cbn4.mjs → vite-_iUhzc4t.mjs} +1779 -369
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/weapp-tw-css-import-rewrite-loader.js +1148 -987
- package/dist/{webpack-CMJ7iqN7.mjs → webpack-CqnI4Ymw.mjs} +104 -37
- package/dist/{webpack-nn3P8_S_.js → webpack-KLoTb5Dr.js} +113 -45
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +6 -5
- package/dist/source-candidates-BODCmzz5.mjs +0 -355
- package/dist/source-candidates-Caf2GDvx.js +0 -374
|
@@ -1,23 +1,28 @@
|
|
|
1
|
-
import { C as hasLocalCssImport, D as normalizeTailwindConfigDirectives, E as hasTailwindSourceDirectives, L as hasTailwindGeneratedCssMarkers, M as removeTailwindSourceDirectives, T as hasTailwindRootDirectives, Y as filterUnsupportedMiniProgramTailwindV4Candidates, _ as
|
|
2
|
-
import { i as normalizeWeappTailwindcssGeneratorOptions } from "./generator-
|
|
3
|
-
import { _ as collectRuntimeClassSet, a as vitePluginName, b as refreshTailwindRuntimeState, g as toCustomAttributesEntities, n as getCompilerContext, t as shouldSkipJsTransform, v as createTailwindRuntimeReadyPromise } from "./precheck-
|
|
1
|
+
import { C as hasLocalCssImport, D as normalizeTailwindConfigDirectives, E as hasTailwindSourceDirectives, L as hasTailwindGeneratedCssMarkers, M as removeTailwindSourceDirectives, T as hasTailwindRootDirectives, Y as filterUnsupportedMiniProgramTailwindV4Candidates, _ as resolveTailwindV4EntriesFromCssCached, ft as findTailwindConfig, gt as findNearestPackageRoot, h as discoverTailwindV4CssEntries, j as parseImportRequest, k as normalizeTailwindSourceForGenerator, l as getRuntimeClassSetSignature, lt as createDebug, m as resolveViteSourceScanEntries, ot as resolveTailwindV4CssSourceBase, p as createViteSourceScanMatcher, pt as resolveTailwindcssOptions, v as resolveViteTailwindV4CssDependencies, w as hasTailwindApplyDirective, yt as omitUndefined } from "./v3-engine-ArQVHEau.mjs";
|
|
2
|
+
import { i as normalizeWeappTailwindcssGeneratorOptions } from "./generator-DnwUQOXB.mjs";
|
|
3
|
+
import { _ as collectRuntimeClassSet, a as vitePluginName, b as refreshTailwindRuntimeState, g as toCustomAttributesEntities, n as getCompilerContext, p as replaceWxml, t as shouldSkipJsTransform, v as createTailwindRuntimeReadyPromise } from "./precheck-CcxTR7E_.mjs";
|
|
4
4
|
import { o as resolveUniUtsPlatform } from "./utils-DsaS975I.mjs";
|
|
5
|
-
import { a as normalizeCssEntries, c as hasConfiguredTailwindV4CssRoots, i as resolveUniAppXOptions, l as upsertTailwindV4CssSource, r as isUniAppXEnabled } from "./tailwindcss-
|
|
6
|
-
import { a as validateCandidatesByGenerator, i as
|
|
7
|
-
import { n as
|
|
8
|
-
import { C as toAbsoluteOutputPath, _ as normalizePath, a as applyLinkedResults, b as stripRequestQuery, c as createBundlerGeneratedCssMarker, d as stripBundlerGeneratedCssMarkers, f as resolvePackageDir, g as isCSSRequest, h as formatPostcssSourceMap, i as createRuntimeAffectingSourceSignature, l as hasBundlerGeneratedCssMarker, m as cleanUrl, n as createBundleBuildState, o as createBundleModuleGraphOptions, p as resolvePluginDisabledState, r as updateBundleBuildState, s as pushConcurrentTaskFactories, t as buildBundleSnapshot, u as parseBundlerGeneratedCssMarkerBlocks, v as slash, x as normalizeOutputPathKey, y as isSourceStyleRequest } from "./bundle-state-CdNXQl-o.mjs";
|
|
5
|
+
import { a as normalizeCssEntries, c as hasConfiguredTailwindV4CssRoots, i as resolveUniAppXOptions, l as upsertTailwindV4CssSource, r as isUniAppXEnabled } from "./tailwindcss-0DaftXcU.mjs";
|
|
6
|
+
import { a as createTailwindV3DefaultExtractor, c as validateCandidatesByGenerator, g as createCssTokenSourceMap, h as createCssSourceTraceCacheSignature, i as isSourceCandidateRequest, l as extractMarkedUserLayerComponentsCss, m as annotateCssSourceTrace, o as createBundleRuntimeClassSetManager, r as createSourceCandidateCollector, s as generateCssByGenerator, t as createHmrTimingRecorder, u as mergeMarkedUserLayerComponentsCss, v as processCachedTask } from "./hmr-timing-DK-mine6.mjs";
|
|
7
|
+
import { C as toAbsoluteOutputPath, _ as normalizePath, a as applyLinkedResults, b as stripRequestQuery, c as createBundlerGeneratedCssMarker, d as stripBundlerGeneratedCssMarkers, f as resolvePackageDir, g as isCSSRequest, h as formatPostcssSourceMap, i as createRuntimeAffectingSourceSignature, l as hasBundlerGeneratedCssMarker, m as cleanUrl, n as createBundleBuildState, o as createBundleModuleGraphOptions, p as resolvePluginDisabledState, r as updateBundleBuildState, s as pushConcurrentTaskFactories, t as buildBundleSnapshot, u as parseBundlerGeneratedCssMarkerBlocks, v as slash, x as normalizeOutputPathKey, y as isSourceStyleRequest } from "./bundle-state-5FtFktJr.mjs";
|
|
9
8
|
import { t as logger$1 } from "./logger-BNzxZbZj.mjs";
|
|
10
|
-
import fs, { existsSync, readFileSync } from "node:fs";
|
|
11
9
|
import postcss from "postcss";
|
|
12
10
|
import { splitCandidateTokens } from "tailwindcss-patch";
|
|
13
11
|
import process$1 from "node:process";
|
|
12
|
+
import fs, { existsSync, readFileSync } from "node:fs";
|
|
14
13
|
import path from "node:path";
|
|
15
14
|
import { logger } from "@weapp-tailwindcss/logger";
|
|
16
15
|
import { readFile } from "node:fs/promises";
|
|
17
16
|
import { Buffer } from "node:buffer";
|
|
18
17
|
import postcssHtmlTransform from "@weapp-tailwindcss/postcss/html-transform";
|
|
19
18
|
import { parse } from "comment-json";
|
|
19
|
+
import selectorParser from "postcss-selector-parser";
|
|
20
20
|
import postcssrc from "postcss-load-config";
|
|
21
|
+
//#region src/uni-app-x/harmony.ts
|
|
22
|
+
function isUniAppXHarmonyOutDir(outDir) {
|
|
23
|
+
return typeof outDir === "string" && /(?:^|[/\\])\.?app-harmony(?:[/\\]|$)/.test(outDir);
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
21
26
|
//#region src/bundlers/vite/query.ts
|
|
22
27
|
function parseVueRequest(id) {
|
|
23
28
|
const [filename = id, rawQuery] = id.split(`?`, 2);
|
|
@@ -37,6 +42,419 @@ function parseVueRequest(id) {
|
|
|
37
42
|
};
|
|
38
43
|
}
|
|
39
44
|
//#endregion
|
|
45
|
+
//#region src/uni-app-x/style-asset/style-value.ts
|
|
46
|
+
const GEN_APP_STYLES_RE = /const\s+GenAppStyles\s*=\s*\[_uM\(\[([\s\S]*?)\]\)\]/;
|
|
47
|
+
const STYLE_ENTRY_RE = /\[\s*("((?:\\.|[^"\\])+)")\s*,\s*(_pS\(_uM\(\[[\s\S]*?\]\)\))\s*\]/g;
|
|
48
|
+
const STRING_LITERAL_RE = /(['"`])((?:\\.|(?!\1)[\s\S])*?)\1/g;
|
|
49
|
+
const SFC_STYLE_BLOCK_RE$2 = /<style\b[^>]*>([\s\S]*?)<\/style>/gi;
|
|
50
|
+
const STYLE_EXPORT_PREFIX_RE = /^\s*export\s+default\s+/;
|
|
51
|
+
const CLASS_SELECTOR_PREFIX_RE = /^\.((?:\\[^\n\r\f]|[\w-])+)(?=$|[.:#[])/;
|
|
52
|
+
function toCamelCase(prop) {
|
|
53
|
+
return prop.replace(/-([a-z])/g, (_, char) => char.toUpperCase());
|
|
54
|
+
}
|
|
55
|
+
function normalizeValue(value) {
|
|
56
|
+
const trimmed = value.trim();
|
|
57
|
+
if (/^-?\d+(?:\.\d+)?px$/.test(trimmed)) return Number(trimmed.slice(0, -2));
|
|
58
|
+
return trimmed.replace(/\s*,\s*/g, ",");
|
|
59
|
+
}
|
|
60
|
+
function normalizeStyleValue(value) {
|
|
61
|
+
if (typeof value === "number") return value;
|
|
62
|
+
return normalizeValue(value);
|
|
63
|
+
}
|
|
64
|
+
function unescapeCssClassSelector(className) {
|
|
65
|
+
return className.replace(/\\([^\n\r\f0-9a-f])/gi, "$1");
|
|
66
|
+
}
|
|
67
|
+
function parseStyleExport(source) {
|
|
68
|
+
const json = source.replace(STYLE_EXPORT_PREFIX_RE, "").trim();
|
|
69
|
+
if (!json) return;
|
|
70
|
+
try {
|
|
71
|
+
return JSON.parse(json);
|
|
72
|
+
} catch {}
|
|
73
|
+
}
|
|
74
|
+
function parseStyleObject(source) {
|
|
75
|
+
try {
|
|
76
|
+
return JSON.parse(source);
|
|
77
|
+
} catch {}
|
|
78
|
+
}
|
|
79
|
+
function parseSourceMapSourcesContent(source) {
|
|
80
|
+
try {
|
|
81
|
+
const map = JSON.parse(source);
|
|
82
|
+
return Array.isArray(map.sourcesContent) ? map.sourcesContent.filter((item) => typeof item === "string") : [];
|
|
83
|
+
} catch {
|
|
84
|
+
return [];
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
function collectChunkMapSourcesContent(chunk) {
|
|
88
|
+
const map = chunk.map;
|
|
89
|
+
return Array.isArray(map?.sourcesContent) ? map.sourcesContent.filter((item) => typeof item === "string") : [];
|
|
90
|
+
}
|
|
91
|
+
function styleExportToUtsMap(styleExport) {
|
|
92
|
+
const classEntries = [];
|
|
93
|
+
for (const [className, styleStates] of Object.entries(styleExport)) {
|
|
94
|
+
const declarations = styleStates[""];
|
|
95
|
+
if (!declarations || Object.keys(declarations).length === 0) continue;
|
|
96
|
+
const declarationEntries = Object.entries(declarations).map(([prop, value]) => {
|
|
97
|
+
return `[${JSON.stringify(toCamelCase(prop))}, ${JSON.stringify(normalizeStyleValue(value))}]`;
|
|
98
|
+
});
|
|
99
|
+
if (declarationEntries.length === 0) continue;
|
|
100
|
+
classEntries.push(`[${JSON.stringify(className)}, _pS(_uM([${declarationEntries.join(", ")}]))]`);
|
|
101
|
+
}
|
|
102
|
+
if (classEntries.length === 0) return "[]";
|
|
103
|
+
return `[_uM([${classEntries.join(", ")}])]`;
|
|
104
|
+
}
|
|
105
|
+
function createUtsStyleArray(entries) {
|
|
106
|
+
if (entries.length === 0) return "[]";
|
|
107
|
+
return `[_uM([${entries.join(", ")}])]`;
|
|
108
|
+
}
|
|
109
|
+
function extractAppStyleEntries(source) {
|
|
110
|
+
const match = source.match(GEN_APP_STYLES_RE);
|
|
111
|
+
if (!match?.[1]) return;
|
|
112
|
+
const entries = /* @__PURE__ */ new Map();
|
|
113
|
+
for (const entry of match[1].matchAll(STYLE_ENTRY_RE)) {
|
|
114
|
+
const rawClassName = entry[1];
|
|
115
|
+
const className = entry[2];
|
|
116
|
+
const styleValue = entry[3];
|
|
117
|
+
if (!rawClassName || !className || !styleValue) continue;
|
|
118
|
+
entries.set(JSON.parse(rawClassName), `[${rawClassName}, ${styleValue}]`);
|
|
119
|
+
}
|
|
120
|
+
return entries.size > 0 ? entries : void 0;
|
|
121
|
+
}
|
|
122
|
+
function collectUsedClassNames(code, entries) {
|
|
123
|
+
const used = /* @__PURE__ */ new Set();
|
|
124
|
+
for (const literalMatch of code.matchAll(STRING_LITERAL_RE)) {
|
|
125
|
+
const literal = literalMatch[2];
|
|
126
|
+
if (!literal) continue;
|
|
127
|
+
for (const candidate of splitCandidateTokens(literal)) if (entries.has(candidate)) used.add(candidate);
|
|
128
|
+
}
|
|
129
|
+
return used;
|
|
130
|
+
}
|
|
131
|
+
function collectUsedStyleKeys(code, styleValue) {
|
|
132
|
+
return collectUsedClassNames(code, new Map(Object.keys(styleValue).map((className) => [className, className])));
|
|
133
|
+
}
|
|
134
|
+
function createUtsStyleArrayFromAppStyles(code, appSource) {
|
|
135
|
+
if (!appSource) return;
|
|
136
|
+
const entries = extractAppStyleEntries(appSource);
|
|
137
|
+
if (!entries) return;
|
|
138
|
+
const used = collectUsedClassNames(code, entries);
|
|
139
|
+
if (used.size === 0) return;
|
|
140
|
+
return createUtsStyleArray([...used].map((className) => entries.get(className)).filter(Boolean));
|
|
141
|
+
}
|
|
142
|
+
function cssToStyleExport(source) {
|
|
143
|
+
let root;
|
|
144
|
+
try {
|
|
145
|
+
root = postcss.parse(source);
|
|
146
|
+
} catch {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
const result = {};
|
|
150
|
+
root.walkRules((rule) => {
|
|
151
|
+
const selectors = rule.selectors ?? [];
|
|
152
|
+
for (const selector of selectors) {
|
|
153
|
+
const match = selector.trim().match(CLASS_SELECTOR_PREFIX_RE);
|
|
154
|
+
if (!match?.[1]) continue;
|
|
155
|
+
const declarations = {};
|
|
156
|
+
rule.walkDecls((decl) => {
|
|
157
|
+
declarations[toCamelCase(decl.prop)] = normalizeValue(decl.value);
|
|
158
|
+
});
|
|
159
|
+
if (Object.keys(declarations).length > 0) {
|
|
160
|
+
result[match[1]] = { "": declarations };
|
|
161
|
+
const className = unescapeCssClassSelector(match[1]);
|
|
162
|
+
result[className] = { "": declarations };
|
|
163
|
+
result[replaceWxml(className)] = { "": declarations };
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
return Object.keys(result).length > 0 ? result : void 0;
|
|
168
|
+
}
|
|
169
|
+
function cssSourceToStyleValue(source) {
|
|
170
|
+
return STYLE_EXPORT_PREFIX_RE.test(source) ? parseStyleExport(source) : cssToStyleExport(source);
|
|
171
|
+
}
|
|
172
|
+
function mergeStyleValues(...items) {
|
|
173
|
+
const result = {};
|
|
174
|
+
for (const item of items) {
|
|
175
|
+
if (!item) continue;
|
|
176
|
+
for (const [className, states] of Object.entries(item)) if (!result[className]) result[className] = states;
|
|
177
|
+
}
|
|
178
|
+
return Object.keys(result).length > 0 ? result : void 0;
|
|
179
|
+
}
|
|
180
|
+
function createStyleValueFromApplySources(sources, utilityStyles) {
|
|
181
|
+
if (!utilityStyles) return;
|
|
182
|
+
const result = {};
|
|
183
|
+
for (const source of sources) {
|
|
184
|
+
const styleSources = source.includes("<style") ? [...source.matchAll(SFC_STYLE_BLOCK_RE$2)].map((styleBlock) => styleBlock[1] ?? "") : [source];
|
|
185
|
+
for (const styleSource of styleSources) {
|
|
186
|
+
let root;
|
|
187
|
+
try {
|
|
188
|
+
root = postcss.parse(styleSource);
|
|
189
|
+
} catch {
|
|
190
|
+
continue;
|
|
191
|
+
}
|
|
192
|
+
root.walkRules((rule) => {
|
|
193
|
+
const applyRules = rule.nodes?.filter((node) => node.type === "atrule" && node.name === "apply") ?? [];
|
|
194
|
+
if (applyRules.length === 0) return;
|
|
195
|
+
const selectors = rule.selectors ?? [rule.selector];
|
|
196
|
+
for (const selector of selectors) {
|
|
197
|
+
const className = selector.trim().match(CLASS_SELECTOR_PREFIX_RE)?.[1];
|
|
198
|
+
if (!className) continue;
|
|
199
|
+
const declarations = {};
|
|
200
|
+
for (const applyRule of applyRules) for (const utility of splitCandidateTokens(applyRule.params)) {
|
|
201
|
+
const utilityDeclarations = utilityStyles[utility]?.[""] ?? utilityStyles[replaceWxml(utility)]?.[""];
|
|
202
|
+
if (utilityDeclarations) Object.assign(declarations, utilityDeclarations);
|
|
203
|
+
}
|
|
204
|
+
if (Object.keys(declarations).length > 0) {
|
|
205
|
+
const unescapedClassName = unescapeCssClassSelector(className);
|
|
206
|
+
result[className] = { "": declarations };
|
|
207
|
+
result[unescapedClassName] = { "": declarations };
|
|
208
|
+
result[replaceWxml(unescapedClassName)] = { "": declarations };
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return Object.keys(result).length > 0 ? result : void 0;
|
|
215
|
+
}
|
|
216
|
+
function collectUniAppXHarmonyApplyStyleSourcesFromSource(source) {
|
|
217
|
+
return (source.includes("<style") ? [...source.matchAll(SFC_STYLE_BLOCK_RE$2)].map((styleBlock) => styleBlock[1] ?? "") : [source]).map((styleSource) => styleSource.trim()).filter((styleSource) => styleSource.length > 0 && styleSource.includes("@apply"));
|
|
218
|
+
}
|
|
219
|
+
function collectUniAppXHarmonyApplyUtilitiesFromSources(sources) {
|
|
220
|
+
const utilities = /* @__PURE__ */ new Set();
|
|
221
|
+
for (const source of sources) for (const styleSource of collectUniAppXHarmonyApplyStyleSourcesFromSource(source)) {
|
|
222
|
+
let root;
|
|
223
|
+
try {
|
|
224
|
+
root = postcss.parse(styleSource);
|
|
225
|
+
} catch {
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
root.walkAtRules("apply", (rule) => {
|
|
229
|
+
for (const utility of splitCandidateTokens(rule.params)) utilities.add(utility);
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
return utilities;
|
|
233
|
+
}
|
|
234
|
+
function createMergedStyleValue(code, localStyle, appStyle) {
|
|
235
|
+
const used = collectUsedStyleKeys(code, appStyle);
|
|
236
|
+
if (used.size === 0) return;
|
|
237
|
+
const merged = { ...localStyle ?? {} };
|
|
238
|
+
let changed = false;
|
|
239
|
+
for (const className of used) {
|
|
240
|
+
if (merged[className] || !appStyle[className]) continue;
|
|
241
|
+
merged[className] = appStyle[className];
|
|
242
|
+
changed = true;
|
|
243
|
+
}
|
|
244
|
+
return changed ? merged : void 0;
|
|
245
|
+
}
|
|
246
|
+
//#endregion
|
|
247
|
+
//#region src/uni-app-x/style-asset.ts
|
|
248
|
+
const GEN_STYLES_PLACEHOLDER_RE = /\/\*(Gen[A-Za-z0-9]+Styles)\*\/|const\s+(Gen[A-Za-z0-9]+Styles)\s*=\s*\[\]/;
|
|
249
|
+
const UVUE_TS_RE = /\.uvue\.ts$/;
|
|
250
|
+
const JS_RE = /\.js$/;
|
|
251
|
+
const APP_JS_RE = /(?:^|\/)App\.js$/;
|
|
252
|
+
const COMPONENT_JS_RE = /(?:^|\/)components\/.+\.js$/;
|
|
253
|
+
const HARMONY_BUNDLE_MARKER_FILES = new Set([
|
|
254
|
+
"import/app-service.ets",
|
|
255
|
+
"import/dynamic.ets",
|
|
256
|
+
"uni_modules/oh-package.json5"
|
|
257
|
+
]);
|
|
258
|
+
const STYLE_DECL_RE = /const\s+(_style_\d+)\s*=\s*\{/g;
|
|
259
|
+
const EXPORT_SFC_RE = /_export_sfc\(_sfc_main\s*,\s*\[/;
|
|
260
|
+
const UNI_APP_X_STYLE_PLACEHOLDER_VERSION = "uni-app-x-style-placeholder-v2";
|
|
261
|
+
function createUniAppXHarmonyApplyGeneratorSource(applyStyleSources, _applyUtilities) {
|
|
262
|
+
return applyStyleSources.join("\n");
|
|
263
|
+
}
|
|
264
|
+
function collectUniAppXHarmonyApplyUtilities(bundle) {
|
|
265
|
+
const utilities = /* @__PURE__ */ new Set();
|
|
266
|
+
const getBundleSource = createUniAppXBundleAssetSourceGetter(bundle);
|
|
267
|
+
for (const [file, item] of Object.entries(bundle)) {
|
|
268
|
+
if (item.type !== "chunk" || !file.endsWith(".js") || APP_JS_RE.test(file)) continue;
|
|
269
|
+
const mapSources = collectChunkMapSourcesContent(item).concat(resolveSourceMapFiles(file).flatMap((mapFile) => {
|
|
270
|
+
const source = getBundleSource(mapFile);
|
|
271
|
+
return source ? parseSourceMapSourcesContent(source) : [];
|
|
272
|
+
}));
|
|
273
|
+
for (const source of mapSources) for (const utility of collectUniAppXHarmonyApplyUtilitiesFromSources([source])) utilities.add(utility);
|
|
274
|
+
}
|
|
275
|
+
return utilities;
|
|
276
|
+
}
|
|
277
|
+
function collectUniAppXHarmonyApplyStyleSources(bundle) {
|
|
278
|
+
const sources = /* @__PURE__ */ new Set();
|
|
279
|
+
const getBundleSource = createUniAppXBundleAssetSourceGetter(bundle);
|
|
280
|
+
const addSource = (source) => {
|
|
281
|
+
for (const styleSource of collectUniAppXHarmonyApplyStyleSourcesFromSource(source)) sources.add(styleSource);
|
|
282
|
+
};
|
|
283
|
+
for (const [file, item] of Object.entries(bundle)) {
|
|
284
|
+
if (item.type === "asset" && file.endsWith(".uvue")) {
|
|
285
|
+
addSource(String(item.source));
|
|
286
|
+
continue;
|
|
287
|
+
}
|
|
288
|
+
if (item.type !== "chunk" || !file.endsWith(".js") || APP_JS_RE.test(file)) continue;
|
|
289
|
+
for (const sourceContent of collectChunkMapSourcesContent(item)) addSource(sourceContent);
|
|
290
|
+
for (const mapFile of resolveSourceMapFiles(file)) {
|
|
291
|
+
const source = getBundleSource(mapFile);
|
|
292
|
+
if (!source) continue;
|
|
293
|
+
for (const sourceContent of parseSourceMapSourcesContent(source)) addSource(sourceContent);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return [...sources];
|
|
297
|
+
}
|
|
298
|
+
function resolveStyleAssetFile(file) {
|
|
299
|
+
if (!UVUE_TS_RE.test(file)) return;
|
|
300
|
+
return file.replace(/\.uvue\.ts$/, ".uvue");
|
|
301
|
+
}
|
|
302
|
+
function resolveStylePlaceholderFallbackFiles(file) {
|
|
303
|
+
const styleAssetFile = resolveStyleAssetFile(file);
|
|
304
|
+
if (!styleAssetFile) return [];
|
|
305
|
+
const base = styleAssetFile.replace(/\.uvue$/, "");
|
|
306
|
+
return [
|
|
307
|
+
styleAssetFile,
|
|
308
|
+
`${base}.wxss`,
|
|
309
|
+
`${base}.css`
|
|
310
|
+
];
|
|
311
|
+
}
|
|
312
|
+
function findBalancedObjectEnd(source, start) {
|
|
313
|
+
let depth = 0;
|
|
314
|
+
let quote;
|
|
315
|
+
let escaped = false;
|
|
316
|
+
for (let index = start; index < source.length; index++) {
|
|
317
|
+
const char = source[index];
|
|
318
|
+
if (quote) {
|
|
319
|
+
if (escaped) escaped = false;
|
|
320
|
+
else if (char === "\\") escaped = true;
|
|
321
|
+
else if (char === quote) quote = void 0;
|
|
322
|
+
continue;
|
|
323
|
+
}
|
|
324
|
+
if (char === "\"" || char === "'" || char === "`") {
|
|
325
|
+
quote = char;
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
if (char === "{") {
|
|
329
|
+
depth++;
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
332
|
+
if (char === "}") {
|
|
333
|
+
depth--;
|
|
334
|
+
if (depth === 0) return index + 1;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
function findFirstStyleObjectDecl(source) {
|
|
339
|
+
STYLE_DECL_RE.lastIndex = 0;
|
|
340
|
+
const match = STYLE_DECL_RE.exec(source);
|
|
341
|
+
const varName = match?.[1];
|
|
342
|
+
if (!match || !varName) return;
|
|
343
|
+
const objectStart = source.indexOf("{", match.index);
|
|
344
|
+
if (objectStart < 0) return;
|
|
345
|
+
const objectEnd = findBalancedObjectEnd(source, objectStart);
|
|
346
|
+
if (!objectEnd) return;
|
|
347
|
+
return {
|
|
348
|
+
end: source[objectEnd] === ";" ? objectEnd + 1 : objectEnd,
|
|
349
|
+
objectEnd,
|
|
350
|
+
objectStart,
|
|
351
|
+
objectText: source.slice(objectStart, objectEnd),
|
|
352
|
+
start: match.index,
|
|
353
|
+
varName
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
function resolveCssFallbackFiles(file) {
|
|
357
|
+
const files = [
|
|
358
|
+
"main.wxss",
|
|
359
|
+
"main.css",
|
|
360
|
+
"app.wxss",
|
|
361
|
+
"app.css"
|
|
362
|
+
];
|
|
363
|
+
if (file.startsWith("assets/") && file.endsWith(".js")) {
|
|
364
|
+
const withoutAssets = file.slice(7).replace(/\.js$/, "");
|
|
365
|
+
files.push(`${withoutAssets}.wxss`, `${withoutAssets}.css`);
|
|
366
|
+
}
|
|
367
|
+
return files;
|
|
368
|
+
}
|
|
369
|
+
function resolveSourceMapFiles(file) {
|
|
370
|
+
return [
|
|
371
|
+
`${file}.map`,
|
|
372
|
+
file.startsWith("assets/") ? `${file.slice(7)}.map` : void 0,
|
|
373
|
+
file.startsWith("assets/") ? void 0 : `assets/${file}.map`
|
|
374
|
+
].filter((item) => typeof item === "string");
|
|
375
|
+
}
|
|
376
|
+
function createStyleValueFromBundleSources(file, _code, getBundleSource, options = {}) {
|
|
377
|
+
const cssStyles = mergeStyleValues(...[...options.cssSources ?? []].map((source) => source ? cssSourceToStyleValue(source) : void 0), ...resolveCssFallbackFiles(file).map((cssFile) => {
|
|
378
|
+
const source = getBundleSource?.(cssFile);
|
|
379
|
+
return source ? cssSourceToStyleValue(source) : void 0;
|
|
380
|
+
}));
|
|
381
|
+
return mergeStyleValues(cssStyles, createStyleValueFromApplySources([...options.mapSources ?? [], ...resolveSourceMapFiles(file).flatMap((mapFile) => {
|
|
382
|
+
const source = getBundleSource?.(mapFile);
|
|
383
|
+
return source ? parseSourceMapSourcesContent(source) : [];
|
|
384
|
+
})].filter((source) => typeof source === "string"), cssStyles));
|
|
385
|
+
}
|
|
386
|
+
function injectStyleOption(code, styleVarName) {
|
|
387
|
+
if (code.includes("[\"styles\"")) return code;
|
|
388
|
+
const exportMatch = code.match(EXPORT_SFC_RE);
|
|
389
|
+
if (!exportMatch || exportMatch.index === void 0) return code;
|
|
390
|
+
const fileOptionIndex = code.indexOf("[\"__file\"", exportMatch.index);
|
|
391
|
+
if (fileOptionIndex < 0) return code;
|
|
392
|
+
return `${code.slice(0, fileOptionIndex)}["styles", [${styleVarName}]], ${code.slice(fileOptionIndex)}`;
|
|
393
|
+
}
|
|
394
|
+
function injectUniAppXStylePlaceholder(file, code, getAssetSource) {
|
|
395
|
+
const match = code.match(GEN_STYLES_PLACEHOLDER_RE);
|
|
396
|
+
const stylesName = match?.[1] ?? match?.[2];
|
|
397
|
+
if (!stylesName) return code;
|
|
398
|
+
if (!resolveStyleAssetFile(file)) return code;
|
|
399
|
+
const appStyleArray = createUtsStyleArrayFromAppStyles(code, getAssetSource?.("App.uvue.ts"));
|
|
400
|
+
if (appStyleArray) return code.replace(GEN_STYLES_PLACEHOLDER_RE, `const ${stylesName} = ${appStyleArray}`);
|
|
401
|
+
const styleSource = resolveStylePlaceholderFallbackFiles(file).map((candidate) => getAssetSource?.(candidate)).find((source) => typeof source === "string" && source.length > 0);
|
|
402
|
+
if (!styleSource) return code;
|
|
403
|
+
const styleExport = cssSourceToStyleValue(styleSource);
|
|
404
|
+
if (!styleExport) return code;
|
|
405
|
+
return code.replace(GEN_STYLES_PLACEHOLDER_RE, `const ${stylesName} = ${styleExportToUtsMap(styleExport)}`);
|
|
406
|
+
}
|
|
407
|
+
function injectUniAppXHarmonyGlobalStyles(file, code, getBundleSource, options = {}) {
|
|
408
|
+
if (!JS_RE.test(file) || APP_JS_RE.test(file)) return code;
|
|
409
|
+
if (options.excludeComponents && COMPONENT_JS_RE.test(file)) return code;
|
|
410
|
+
const appSource = getBundleSource?.("assets/App.js") ?? getBundleSource?.("App.js");
|
|
411
|
+
const appStyleDecl = appSource ? findFirstStyleObjectDecl(appSource) : void 0;
|
|
412
|
+
const appStyle = appStyleDecl ? parseStyleObject(appStyleDecl.objectText) : void 0;
|
|
413
|
+
const localStyleDecl = findFirstStyleObjectDecl(code);
|
|
414
|
+
const localStyle = localStyleDecl ? parseStyleObject(localStyleDecl.objectText) : void 0;
|
|
415
|
+
const styleSource = mergeStyleValues(appStyle, createStyleValueFromBundleSources(file, code, getBundleSource, options));
|
|
416
|
+
if (!styleSource) return code;
|
|
417
|
+
const mergedStyle = createMergedStyleValue(code, localStyle, styleSource);
|
|
418
|
+
if (!mergedStyle) return code;
|
|
419
|
+
const nextStyleSource = JSON.stringify(mergedStyle);
|
|
420
|
+
if (localStyleDecl) return `${code.slice(0, localStyleDecl.objectStart)}${nextStyleSource}${code.slice(localStyleDecl.objectEnd)}`;
|
|
421
|
+
const exportMatch = code.match(EXPORT_SFC_RE);
|
|
422
|
+
if (!exportMatch || exportMatch.index === void 0) return code;
|
|
423
|
+
const styleVarName = "_style_wt";
|
|
424
|
+
return injectStyleOption(`${code.slice(0, exportMatch.index)}const ${styleVarName} = ${nextStyleSource};\n${code.slice(exportMatch.index)}`, styleVarName);
|
|
425
|
+
}
|
|
426
|
+
function injectUniAppXHarmonyBundleStyles(bundle, options = {}) {
|
|
427
|
+
const getBundleSource = createUniAppXBundleAssetSourceGetter(bundle);
|
|
428
|
+
let changed = false;
|
|
429
|
+
for (const [file, item] of Object.entries(bundle)) {
|
|
430
|
+
if (item.type !== "chunk" || !file.endsWith(".js")) continue;
|
|
431
|
+
const currentSource = item.code;
|
|
432
|
+
const nextSource = injectUniAppXHarmonyGlobalStyles(file, currentSource, getBundleSource, {
|
|
433
|
+
...options,
|
|
434
|
+
mapSources: collectChunkMapSourcesContent(item)
|
|
435
|
+
});
|
|
436
|
+
if (nextSource !== currentSource) {
|
|
437
|
+
item.code = nextSource;
|
|
438
|
+
changed = true;
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
return changed;
|
|
442
|
+
}
|
|
443
|
+
function isUniAppXHarmonyBundle(bundle) {
|
|
444
|
+
for (const file of Object.keys(bundle)) if (HARMONY_BUNDLE_MARKER_FILES.has(file)) return true;
|
|
445
|
+
return false;
|
|
446
|
+
}
|
|
447
|
+
function createUniAppXBundleAssetSourceGetter(bundle) {
|
|
448
|
+
return (file) => {
|
|
449
|
+
const item = bundle[file] ?? Object.entries(bundle).find(([key, value]) => {
|
|
450
|
+
return (value.type === "asset" || value.type === "chunk") && (key === file || key.endsWith(`/${file}`));
|
|
451
|
+
})?.[1];
|
|
452
|
+
if (!item) return;
|
|
453
|
+
if (item.type === "asset") return String(item.source);
|
|
454
|
+
if (item.type === "chunk") return String(item.code);
|
|
455
|
+
};
|
|
456
|
+
}
|
|
457
|
+
//#endregion
|
|
40
458
|
//#region src/uni-app-x/style-isolation.ts
|
|
41
459
|
const manifestCache = /* @__PURE__ */ new Map();
|
|
42
460
|
function resolveUniAppXStyleIsolationEnabled(root) {
|
|
@@ -58,7 +476,7 @@ function resolveUniAppXStyleIsolationEnabled(root) {
|
|
|
58
476
|
//#region src/uni-app-x/vite.ts
|
|
59
477
|
let transformUVuePromise;
|
|
60
478
|
function loadTransformUVue() {
|
|
61
|
-
transformUVuePromise ?? (transformUVuePromise = import("./transform-
|
|
479
|
+
transformUVuePromise ?? (transformUVuePromise = import("./transform-DRyWUN5X.mjs").then((mod) => mod.transformUVue));
|
|
62
480
|
return transformUVuePromise;
|
|
63
481
|
}
|
|
64
482
|
const preprocessorLangs = new Set([
|
|
@@ -92,9 +510,21 @@ function isCssModuleExport(code) {
|
|
|
92
510
|
function createUniAppXPlugins(options) {
|
|
93
511
|
const { appType, customAttributesEntities, disabledDefaultTemplateHandler, isIosPlatform: providedIosPlatform, mainCssChunkMatcher, runtimeState, styleHandler, generateCss, jsHandler, ensureRuntimeClassSet, getResolvedConfig, uniAppX } = options;
|
|
94
512
|
const resolvedUniAppXOptions = resolveUniAppXOptions(uniAppX);
|
|
95
|
-
const
|
|
513
|
+
const utsPlatform = resolveUniUtsPlatform();
|
|
514
|
+
const isIosPlatform = providedIosPlatform ?? utsPlatform.isAppIos;
|
|
515
|
+
const isHarmonyPlatform = utsPlatform.isAppHarmony;
|
|
96
516
|
const cssHandlerOptionsCache = /* @__PURE__ */ new Map();
|
|
97
517
|
let componentLocalStyleEnabled;
|
|
518
|
+
const harmonyApplyStyleSources = /* @__PURE__ */ new Set();
|
|
519
|
+
const harmonyApplyUtilities = /* @__PURE__ */ new Set();
|
|
520
|
+
function rememberHarmonyApplySource(code) {
|
|
521
|
+
const styleSources = collectUniAppXHarmonyApplyStyleSourcesFromSource(code);
|
|
522
|
+
if (styleSources.length === 0) return;
|
|
523
|
+
for (const styleSource of styleSources) {
|
|
524
|
+
harmonyApplyStyleSources.add(styleSource);
|
|
525
|
+
for (const utility of collectUniAppXHarmonyApplyUtilitiesFromSources([styleSource])) harmonyApplyUtilities.add(utility);
|
|
526
|
+
}
|
|
527
|
+
}
|
|
98
528
|
function shouldEnableComponentLocalStyle() {
|
|
99
529
|
if (!resolvedUniAppXOptions.componentLocalStyles.enabled) {
|
|
100
530
|
componentLocalStyleEnabled = false;
|
|
@@ -109,11 +539,20 @@ function createUniAppXPlugins(options) {
|
|
|
109
539
|
componentLocalStyleEnabled = resolveUniAppXStyleIsolationEnabled(root);
|
|
110
540
|
return componentLocalStyleEnabled;
|
|
111
541
|
}
|
|
542
|
+
function shouldEnableHarmonyPageLocalStyle() {
|
|
543
|
+
return isHarmonyPlatform && resolvedUniAppXOptions.componentLocalStyles.enabled;
|
|
544
|
+
}
|
|
545
|
+
function isHarmonyBuildTarget() {
|
|
546
|
+
if (resolveUniUtsPlatform().isAppHarmony) return true;
|
|
547
|
+
return isUniAppXHarmonyOutDir(getResolvedConfig()?.build?.outDir);
|
|
548
|
+
}
|
|
112
549
|
async function transformStyle(code, id, query, hookContext) {
|
|
113
550
|
const parsed = query ?? parseVueRequest(id).query;
|
|
114
551
|
if (isCSSRequest(id) || parsed.vue && parsed.type === "style") {
|
|
115
552
|
if (isCssModuleExport(code)) return;
|
|
116
|
-
const
|
|
553
|
+
const shouldGenerateCss = hasTailwindSourceDirectives(code, { importFallback: true }) || hasTailwindApplyDirective(code);
|
|
554
|
+
rememberHarmonyApplySource(code);
|
|
555
|
+
const generatedCss = shouldGenerateCss ? await generateCss?.(id, code, hookContext) : void 0;
|
|
117
556
|
const styleCode = typeof generatedCss === "string" && generatedCss.trim().length > 0 ? generatedCss : code;
|
|
118
557
|
const cacheKey = `${mainCssChunkMatcher(id, appType) ? "1" : "0"}:${id}`;
|
|
119
558
|
let styleHandlerOptions = cssHandlerOptionsCache.get(cacheKey);
|
|
@@ -168,19 +607,21 @@ function createUniAppXPlugins(options) {
|
|
|
168
607
|
},
|
|
169
608
|
async transform(code, id) {
|
|
170
609
|
if (!UVUE_NVUE_QUERY_RE.test(id)) return;
|
|
610
|
+
rememberHarmonyApplySource(code);
|
|
171
611
|
const resolvedConfig = getResolvedConfig();
|
|
172
612
|
const isServeCommand = resolvedConfig?.command === "serve";
|
|
173
613
|
const isWatchBuild = resolvedConfig?.command === "build" && !!resolvedConfig.build?.watch;
|
|
174
614
|
const isNonWatchBuild = resolvedConfig?.command === "build" && !resolvedConfig.build?.watch;
|
|
175
615
|
const currentRuntimeSet = isServeCommand || isWatchBuild || isNonWatchBuild ? await ensureRuntimeClassSet(true) : await ensureRuntimeClassSet();
|
|
176
616
|
const transformUVue = await loadTransformUVue();
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
617
|
+
const enableComponentLocalStyle = shouldEnableComponentLocalStyle();
|
|
618
|
+
const enablePageLocalStyle = shouldEnableHarmonyPageLocalStyle();
|
|
619
|
+
if (customAttributesEntities.length > 0 || disabledDefaultTemplateHandler || enableComponentLocalStyle || enablePageLocalStyle) return transformUVue(code, id, jsHandler, currentRuntimeSet, omitUndefined({
|
|
620
|
+
...customAttributesEntities.length > 0 ? { customAttributesEntities } : {},
|
|
621
|
+
...disabledDefaultTemplateHandler ? { disabledDefaultTemplateHandler } : {},
|
|
622
|
+
...enableComponentLocalStyle ? { enableComponentLocalStyle } : {},
|
|
623
|
+
...enablePageLocalStyle ? { enablePageLocalStyle } : {}
|
|
624
|
+
}));
|
|
184
625
|
return transformUVue(code, id, jsHandler, currentRuntimeSet);
|
|
185
626
|
},
|
|
186
627
|
async handleHotUpdate(ctx) {
|
|
@@ -195,11 +636,49 @@ function createUniAppXPlugins(options) {
|
|
|
195
636
|
await ensureRuntimeClassSet(true);
|
|
196
637
|
}
|
|
197
638
|
};
|
|
198
|
-
|
|
639
|
+
const stylePlaceholderPlugin = {
|
|
640
|
+
name: "weapp-tailwindcss:uni-app-x:style-placeholder",
|
|
641
|
+
enforce: "post",
|
|
642
|
+
generateBundle: {
|
|
643
|
+
order: "post",
|
|
644
|
+
async handler(_options, bundle) {
|
|
645
|
+
const currentUtsPlatform = resolveUniUtsPlatform();
|
|
646
|
+
const canInferHarmonyTarget = !currentUtsPlatform.normalized || currentUtsPlatform.isApp;
|
|
647
|
+
const isHarmonyTarget = currentUtsPlatform.isAppHarmony || canInferHarmonyTarget && isHarmonyBuildTarget();
|
|
648
|
+
if (!currentUtsPlatform.isApp && !isHarmonyTarget) return;
|
|
649
|
+
const getAssetSource = createUniAppXBundleAssetSourceGetter(bundle);
|
|
650
|
+
if (isHarmonyTarget) {
|
|
651
|
+
const cssSources = [];
|
|
652
|
+
const applyStyleSources = [...harmonyApplyStyleSources, ...collectUniAppXHarmonyApplyStyleSources(bundle)];
|
|
653
|
+
const applyUtilities = new Set([...harmonyApplyUtilities, ...collectUniAppXHarmonyApplyUtilities(bundle)]);
|
|
654
|
+
if (applyStyleSources.length > 0 && applyUtilities.size > 0) {
|
|
655
|
+
const harmonyApplyCssFile = path.resolve(getResolvedConfig()?.root ?? process$1.cwd(), "uni-app-x-harmony-apply.css");
|
|
656
|
+
const generatedCss = await generateCss?.(harmonyApplyCssFile, createUniAppXHarmonyApplyGeneratorSource(applyStyleSources, applyUtilities), this);
|
|
657
|
+
if (typeof generatedCss === "string" && generatedCss.trim().length > 0) cssSources.push(generatedCss);
|
|
658
|
+
}
|
|
659
|
+
injectUniAppXHarmonyBundleStyles(bundle, {
|
|
660
|
+
cssSources,
|
|
661
|
+
excludeComponents: shouldEnableComponentLocalStyle()
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
for (const [file, item] of Object.entries(bundle)) {
|
|
665
|
+
if (item.type !== "asset" || !file.endsWith(".uvue.ts")) continue;
|
|
666
|
+
const currentSource = String(item.source);
|
|
667
|
+
const nextSource = injectUniAppXStylePlaceholder(file, currentSource, getAssetSource);
|
|
668
|
+
if (nextSource !== currentSource) item.source = nextSource;
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
};
|
|
673
|
+
return [
|
|
674
|
+
...cssPlugins,
|
|
675
|
+
nvuePlugin,
|
|
676
|
+
stylePlaceholderPlugin
|
|
677
|
+
];
|
|
199
678
|
}
|
|
200
679
|
function createUniAppXAssetTask(file, originalSource, outDir, options) {
|
|
201
680
|
return async () => {
|
|
202
|
-
const { cache, hashKey, createHandlerOptions, debug, jsHandler, onUpdate, runtimeSet, applyLinkedResults } = options;
|
|
681
|
+
const { cache, hashKey, createHandlerOptions, debug, getAssetSource, jsHandler, onUpdate, runtimeSet, applyLinkedResults } = options;
|
|
203
682
|
const absoluteFile = toAbsoluteOutputPath(file, outDir);
|
|
204
683
|
const rawSource = originalSource.source.toString();
|
|
205
684
|
await processCachedTask({
|
|
@@ -222,10 +701,11 @@ function createUniAppXAssetTask(file, originalSource, outDir, options) {
|
|
|
222
701
|
sourceType: "unambiguous"
|
|
223
702
|
}
|
|
224
703
|
}));
|
|
225
|
-
|
|
704
|
+
const nextCode = injectUniAppXStylePlaceholder(file, code, getAssetSource);
|
|
705
|
+
onUpdate(file, currentSource, nextCode);
|
|
226
706
|
debug("js handle: %s", file);
|
|
227
707
|
applyLinkedResults(linked);
|
|
228
|
-
return { result:
|
|
708
|
+
return { result: nextCode };
|
|
229
709
|
}
|
|
230
710
|
});
|
|
231
711
|
};
|
|
@@ -301,6 +781,163 @@ function collectLegacyContainerCompatCandidates(sourceCandidates, candidates) {
|
|
|
301
781
|
return new Set([...candidates, "container"]);
|
|
302
782
|
}
|
|
303
783
|
//#endregion
|
|
784
|
+
//#region src/bundlers/vite/generate-bundle/css-output.ts
|
|
785
|
+
const SOURCE_STYLE_OUTPUT_EXT_RE = /\.(?:less|sass|scss|styl|stylus|pcss|postcss)$/i;
|
|
786
|
+
const CSS_SOURCE_OUTPUT_EXT_RE = /\.(?:css|less|sass|scss|styl|stylus|pcss|postcss)$/i;
|
|
787
|
+
const MINI_PROGRAM_STYLE_OUTPUT_EXT_RE = /\.(?:wx|ac|jx|tt|q|ty)ss$/i;
|
|
788
|
+
const SOURCE_STYLE_NON_CSS_SYNTAX_RE = /(?:^|\n)\s*(?:\/\/|\$[\w-]+\s*:|@(?:use|forward|mixin|include|function)\b)/;
|
|
789
|
+
function resolveReplayCssOutputFile(rootDir, file) {
|
|
790
|
+
const normalizedFile = normalizeOutputPathKey(path.isAbsolute(file) ? path.relative(rootDir, file) : file);
|
|
791
|
+
if (normalizedFile.length === 0 || normalizedFile === "." || normalizedFile === ".." || normalizedFile.startsWith("../")) return normalizeOutputPathKey(path.basename(file));
|
|
792
|
+
return normalizedFile;
|
|
793
|
+
}
|
|
794
|
+
function resolveViteCssOutputFile(file, opts, isWebGeneratorTarget, preserveCssExtension = false) {
|
|
795
|
+
if (isWebGeneratorTarget || preserveCssExtension || opts.cssMatcher(file) || !SOURCE_STYLE_OUTPUT_EXT_RE.test(file) || !isCSSRequest(file)) return file;
|
|
796
|
+
return file.replace(SOURCE_STYLE_OUTPUT_EXT_RE, ".wxss");
|
|
797
|
+
}
|
|
798
|
+
function resolveViteCssPipelineOutputFile(file, _opts, rootDir, isWebGeneratorTarget = false, preserveCssExtension = false) {
|
|
799
|
+
const normalizedFile = resolveReplayCssOutputFile(rootDir, file);
|
|
800
|
+
if (isWebGeneratorTarget || preserveCssExtension || MINI_PROGRAM_STYLE_OUTPUT_EXT_RE.test(normalizedFile) || !CSS_SOURCE_OUTPUT_EXT_RE.test(normalizedFile) || !isCSSRequest(normalizedFile)) return normalizedFile;
|
|
801
|
+
return normalizedFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, ".wxss");
|
|
802
|
+
}
|
|
803
|
+
function canProcessViteSourceStyleAsCss(source, file) {
|
|
804
|
+
if (SOURCE_STYLE_NON_CSS_SYNTAX_RE.test(source)) return false;
|
|
805
|
+
try {
|
|
806
|
+
postcss.parse(source, { from: file });
|
|
807
|
+
return true;
|
|
808
|
+
} catch {
|
|
809
|
+
return false;
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
function normalizeCssSourceForCompare(css) {
|
|
813
|
+
return css.trim();
|
|
814
|
+
}
|
|
815
|
+
function stripStyleFileExtension(file) {
|
|
816
|
+
const normalized = file.replace(/[?#].*$/, "");
|
|
817
|
+
const ext = path.extname(normalized);
|
|
818
|
+
return ext ? normalized.slice(0, -ext.length) : normalized;
|
|
819
|
+
}
|
|
820
|
+
function isAppOriginCssFile(file) {
|
|
821
|
+
return path.basename(stripStyleFileExtension(file)) === "app-origin";
|
|
822
|
+
}
|
|
823
|
+
function isMainAppCssFile(file) {
|
|
824
|
+
return path.basename(stripStyleFileExtension(file)) === "app";
|
|
825
|
+
}
|
|
826
|
+
function isMainStyleEntryCssFile(file) {
|
|
827
|
+
const basename = path.basename(stripStyleFileExtension(file));
|
|
828
|
+
return basename === "app" || basename === "main";
|
|
829
|
+
}
|
|
830
|
+
function isTailwindEntryCssFile(file) {
|
|
831
|
+
return path.basename(stripStyleFileExtension(file)) === "tailwind";
|
|
832
|
+
}
|
|
833
|
+
//#endregion
|
|
834
|
+
//#region src/bundlers/vite/generate-bundle/style-matching.ts
|
|
835
|
+
function isMatchingCssSourceFile(outputFile, cssSourceFile, outputRoot) {
|
|
836
|
+
return stripStyleFileExtension(path.resolve(outputRoot, outputFile)) === stripStyleFileExtension(path.resolve(cssSourceFile));
|
|
837
|
+
}
|
|
838
|
+
function collectStyleFileMatchBases(file, roots) {
|
|
839
|
+
const normalizedFile = file.replace(/[?#].*$/, "");
|
|
840
|
+
const bases = /* @__PURE__ */ new Set();
|
|
841
|
+
const addBase = (candidate) => {
|
|
842
|
+
const base = slash(stripStyleFileExtension(candidate));
|
|
843
|
+
if (base.length > 0) bases.add(base);
|
|
844
|
+
};
|
|
845
|
+
addBase(normalizedFile);
|
|
846
|
+
const resolvedRoots = roots.filter((root) => typeof root === "string" && root.length > 0).map((root) => path.resolve(root));
|
|
847
|
+
if (path.isAbsolute(normalizedFile)) for (const root of resolvedRoots) {
|
|
848
|
+
const relative = path.relative(root, normalizedFile);
|
|
849
|
+
if (relative && !relative.startsWith("..") && !path.isAbsolute(relative)) addBase(relative);
|
|
850
|
+
}
|
|
851
|
+
else for (const root of resolvedRoots) addBase(path.resolve(root, normalizedFile));
|
|
852
|
+
return bases;
|
|
853
|
+
}
|
|
854
|
+
function collectParentDirectories(file) {
|
|
855
|
+
const directories = [];
|
|
856
|
+
let current = path.dirname(path.resolve(file.replace(/[?#].*$/, "")));
|
|
857
|
+
while (true) {
|
|
858
|
+
directories.push(current);
|
|
859
|
+
const parent = path.dirname(current);
|
|
860
|
+
if (parent === current) break;
|
|
861
|
+
current = parent;
|
|
862
|
+
}
|
|
863
|
+
return directories;
|
|
864
|
+
}
|
|
865
|
+
function hasMatchingStyleFileBase(outputFile, sourceFile, outputRoot, sourceRoot) {
|
|
866
|
+
return scoreMatchingStyleFileBase(outputFile, sourceFile, outputRoot, sourceRoot) > 0;
|
|
867
|
+
}
|
|
868
|
+
function scoreMatchingStyleFileBase(outputFile, sourceFile, outputRoot, sourceRoot) {
|
|
869
|
+
const outputBases = collectStyleFileMatchBases(outputFile, [outputRoot]);
|
|
870
|
+
const sourceBases = collectStyleFileMatchBases(sourceFile, [sourceRoot, ...collectParentDirectories(sourceFile)]);
|
|
871
|
+
let bestScore = 0;
|
|
872
|
+
const hasDirectorySegment = (value) => slash(value).includes("/");
|
|
873
|
+
for (const outputBase of outputBases) for (const sourceBase of sourceBases) if (outputBase === sourceBase) bestScore = Math.max(bestScore, 1e5 + outputBase.length);
|
|
874
|
+
else if (hasDirectorySegment(sourceBase) && outputBase.endsWith(`/${sourceBase}`)) bestScore = Math.max(bestScore, 5e4 + sourceBase.length);
|
|
875
|
+
else if (hasDirectorySegment(outputBase) && sourceBase.endsWith(`/${outputBase}`)) bestScore = Math.max(bestScore, 1e3 + outputBase.length);
|
|
876
|
+
return bestScore;
|
|
877
|
+
}
|
|
878
|
+
//#endregion
|
|
879
|
+
//#region src/bundlers/vite/generate-bundle/css-config-directives.ts
|
|
880
|
+
function isPackageJsonImportRequest(request) {
|
|
881
|
+
return request.startsWith("#");
|
|
882
|
+
}
|
|
883
|
+
function normalizeMatchedCssSourcePath(file) {
|
|
884
|
+
if (!file || !path.isAbsolute(file)) return;
|
|
885
|
+
return path.resolve(file.replace(/[?#].*$/, ""));
|
|
886
|
+
}
|
|
887
|
+
function collectConfiguredTailwindV4CssSources(opts) {
|
|
888
|
+
const patcherCssSources = opts.tailwindcssPatcherOptions?.tailwindcss?.v4?.cssSources ?? [];
|
|
889
|
+
return [...opts.tailwindcss?.v4?.cssSources ?? [], ...patcherCssSources ?? []];
|
|
890
|
+
}
|
|
891
|
+
function collectConfiguredCssEntries(opts) {
|
|
892
|
+
const patcherCssEntries = opts.tailwindcssPatcherOptions?.tailwindcss?.v4?.cssEntries ?? [];
|
|
893
|
+
return [
|
|
894
|
+
...opts.cssEntries ?? [],
|
|
895
|
+
...opts.tailwindcss?.v4?.cssEntries ?? [],
|
|
896
|
+
...patcherCssEntries ?? []
|
|
897
|
+
].filter((entry) => typeof entry === "string" && entry.length > 0);
|
|
898
|
+
}
|
|
899
|
+
function collectCssConfigBaseCandidates(source, file, outputRoot, opts) {
|
|
900
|
+
const candidates = [];
|
|
901
|
+
const seen = /* @__PURE__ */ new Set();
|
|
902
|
+
const addCandidate = (candidate) => {
|
|
903
|
+
if (!candidate) return;
|
|
904
|
+
const normalized = path.resolve(candidate);
|
|
905
|
+
if (seen.has(normalized)) return;
|
|
906
|
+
seen.add(normalized);
|
|
907
|
+
candidates.push(normalized);
|
|
908
|
+
};
|
|
909
|
+
addCandidate(path.dirname(path.resolve(outputRoot, file.replace(/[?#].*$/, ""))));
|
|
910
|
+
const normalizedSource = normalizeCssSourceForCompare(source);
|
|
911
|
+
const patcherProjectRoot = typeof opts.tailwindcssPatcherOptions?.projectRoot === "string" ? opts.tailwindcssPatcherOptions.projectRoot : void 0;
|
|
912
|
+
const sourceBaseFallback = opts.tailwindcss?.v4?.base ?? patcherProjectRoot ?? opts.tailwindcssBasedir ?? outputRoot;
|
|
913
|
+
const sourceRoot = opts.tailwindcssBasedir ?? patcherProjectRoot;
|
|
914
|
+
const configuredCssEntries = collectConfiguredCssEntries(opts);
|
|
915
|
+
for (const cssEntry of configuredCssEntries) {
|
|
916
|
+
const resolvedCssEntry = path.resolve(cssEntry);
|
|
917
|
+
if (configuredCssEntries.length === 1 || isMatchingCssSourceFile(file, resolvedCssEntry, outputRoot) || hasMatchingStyleFileBase(file, resolvedCssEntry, outputRoot, sourceRoot)) addCandidate(path.dirname(resolvedCssEntry));
|
|
918
|
+
}
|
|
919
|
+
for (const cssSource of collectConfiguredTailwindV4CssSources(opts)) {
|
|
920
|
+
const cssSourceFile = normalizeMatchedCssSourcePath(cssSource.file);
|
|
921
|
+
const cssSourceCss = typeof cssSource.css === "string" ? normalizeCssSourceForCompare(cssSource.css) : void 0;
|
|
922
|
+
if (cssSourceFile && !isMatchingCssSourceFile(file, cssSourceFile, outputRoot) && cssSourceCss !== normalizedSource) continue;
|
|
923
|
+
addCandidate(cssSourceFile ? path.dirname(cssSourceFile) : void 0);
|
|
924
|
+
addCandidate(resolveTailwindV4CssSourceBase(cssSource, sourceBaseFallback));
|
|
925
|
+
}
|
|
926
|
+
return candidates;
|
|
927
|
+
}
|
|
928
|
+
function normalizeRelativeCssConfigDirectives(source, file, outputRoot, opts) {
|
|
929
|
+
if (!source.includes("@config")) return source;
|
|
930
|
+
const baseCandidates = collectCssConfigBaseCandidates(source, file, outputRoot, opts);
|
|
931
|
+
return source.replace(/@config\s+(["'])(.+?)\1\s*;?/g, (full, quote, request) => {
|
|
932
|
+
if (path.isAbsolute(request) || isPackageJsonImportRequest(request)) return full;
|
|
933
|
+
for (const base of baseCandidates) {
|
|
934
|
+
const configFile = path.resolve(base, request);
|
|
935
|
+
if (existsSync(configFile)) return `@config ${quote}${slash(configFile)}${quote};`;
|
|
936
|
+
}
|
|
937
|
+
return full;
|
|
938
|
+
});
|
|
939
|
+
}
|
|
940
|
+
//#endregion
|
|
304
941
|
//#region src/bundlers/vite/generate-bundle/css-handler-options.ts
|
|
305
942
|
function createCssHandlerOptionsCache(options) {
|
|
306
943
|
const cssHandlerOptionsCache = /* @__PURE__ */ new Map();
|
|
@@ -481,6 +1118,169 @@ function logBundleProcessPlan(options) {
|
|
|
481
1118
|
debug("build mode full process html=%d[%s] js=%d[%s] css=%d[%s]", processFiles.html.size, formatDebugFileList(processFiles.html), processFiles.js.size, formatDebugFileList(processFiles.js), processFiles.css.size, formatDebugFileList(processFiles.css));
|
|
482
1119
|
}
|
|
483
1120
|
//#endregion
|
|
1121
|
+
//#region src/bundlers/vite/generate-bundle/sfc-style-source.ts
|
|
1122
|
+
const SFC_STYLE_SOURCE_EXTENSIONS = [
|
|
1123
|
+
".vue",
|
|
1124
|
+
".uvue",
|
|
1125
|
+
".nvue",
|
|
1126
|
+
".svelte",
|
|
1127
|
+
".mpx"
|
|
1128
|
+
];
|
|
1129
|
+
const SFC_STYLE_BLOCK_RE$1 = /<style\b[^>]*>([\s\S]*?)<\/style>/gi;
|
|
1130
|
+
function extractSfcStyleSources(source) {
|
|
1131
|
+
const styleSources = [];
|
|
1132
|
+
SFC_STYLE_BLOCK_RE$1.lastIndex = 0;
|
|
1133
|
+
let match = SFC_STYLE_BLOCK_RE$1.exec(source);
|
|
1134
|
+
while (match !== null) {
|
|
1135
|
+
styleSources.push(match[1] ?? "");
|
|
1136
|
+
match = SFC_STYLE_BLOCK_RE$1.exec(source);
|
|
1137
|
+
}
|
|
1138
|
+
return styleSources;
|
|
1139
|
+
}
|
|
1140
|
+
function hasSfcStyleSources(source) {
|
|
1141
|
+
return extractSfcStyleSources(source).length > 0;
|
|
1142
|
+
}
|
|
1143
|
+
function hasTailwindGenerationSource(source) {
|
|
1144
|
+
return hasTailwindSourceDirectives(source, { importFallback: true }) || hasTailwindRootDirectives(source, { importFallback: true }) || hasTailwindApplyDirective(source);
|
|
1145
|
+
}
|
|
1146
|
+
async function resolveSfcStyleSourceFromOutputFile(outputFile, snapshot, outputRoot, sourceRoot, getSfcSource, debug) {
|
|
1147
|
+
const sourceFile = resolveSfcStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot, sourceRoot, debug);
|
|
1148
|
+
if (!sourceFile) {
|
|
1149
|
+
debug("sfc style source infer skipped: no source file for %s", outputFile);
|
|
1150
|
+
return;
|
|
1151
|
+
}
|
|
1152
|
+
const source = getSfcSource?.(sourceFile);
|
|
1153
|
+
if (source == null) {
|
|
1154
|
+
debug("sfc style source infer skipped: missing known source for %s -> %s", outputFile, sourceFile);
|
|
1155
|
+
return;
|
|
1156
|
+
}
|
|
1157
|
+
const rawSource = extractSfcStyleSources(source).join("\n");
|
|
1158
|
+
if (!rawSource || !hasTailwindGenerationSource(rawSource)) {
|
|
1159
|
+
debug("sfc style source infer skipped: no tailwind generation source for %s -> %s", outputFile, sourceFile);
|
|
1160
|
+
return;
|
|
1161
|
+
}
|
|
1162
|
+
debug("sfc style source inferred: %s -> %s", outputFile, sourceFile);
|
|
1163
|
+
return {
|
|
1164
|
+
outputFile,
|
|
1165
|
+
rawSource,
|
|
1166
|
+
sourceFile
|
|
1167
|
+
};
|
|
1168
|
+
}
|
|
1169
|
+
function normalizeSfcSourceFileForCompare(file) {
|
|
1170
|
+
return normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
1171
|
+
}
|
|
1172
|
+
function collectChunkModuleIds(output) {
|
|
1173
|
+
const moduleIds = Array.isArray(output.moduleIds) ? output.moduleIds : [];
|
|
1174
|
+
return [
|
|
1175
|
+
output.facadeModuleId,
|
|
1176
|
+
...moduleIds,
|
|
1177
|
+
...Object.keys(output.modules ?? {})
|
|
1178
|
+
].filter((id, index, ids) => typeof id === "string" && id.length > 0 && ids.indexOf(id) === index);
|
|
1179
|
+
}
|
|
1180
|
+
function resolveSiblingJsChunkFile(outputFile) {
|
|
1181
|
+
const normalizedOutputFile = outputFile.replace(/[?#].*$/, "");
|
|
1182
|
+
if (MINI_PROGRAM_STYLE_OUTPUT_EXT_RE.test(normalizedOutputFile)) return normalizedOutputFile.replace(MINI_PROGRAM_STYLE_OUTPUT_EXT_RE, ".js");
|
|
1183
|
+
if (CSS_SOURCE_OUTPUT_EXT_RE.test(normalizedOutputFile)) return normalizedOutputFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, ".js");
|
|
1184
|
+
}
|
|
1185
|
+
function normalizeSfcModuleId(id) {
|
|
1186
|
+
const file = id.replace(/[?#].*$/, "");
|
|
1187
|
+
if (!SFC_STYLE_SOURCE_EXTENSIONS.some((extension) => file.endsWith(extension))) return;
|
|
1188
|
+
if (!path.isAbsolute(file)) return;
|
|
1189
|
+
return path.resolve(file);
|
|
1190
|
+
}
|
|
1191
|
+
function resolveSfcStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot, sourceRoot, debug) {
|
|
1192
|
+
const siblingJsFile = resolveSiblingJsChunkFile(outputFile);
|
|
1193
|
+
if (!siblingJsFile) {
|
|
1194
|
+
debug("sfc style sibling chunk skipped: no sibling js for %s", outputFile);
|
|
1195
|
+
return;
|
|
1196
|
+
}
|
|
1197
|
+
const normalizedSiblingJsFile = normalizeOutputPathKey(siblingJsFile);
|
|
1198
|
+
const siblingChunk = snapshot.entries.find((entry) => entry.type === "js" && entry.output.type === "chunk" && normalizeOutputPathKey(entry.file) === normalizedSiblingJsFile);
|
|
1199
|
+
if (!siblingChunk || siblingChunk.output.type !== "chunk") {
|
|
1200
|
+
debug("sfc style sibling chunk skipped: missing chunk for %s -> %s", outputFile, siblingJsFile);
|
|
1201
|
+
return;
|
|
1202
|
+
}
|
|
1203
|
+
const sourceFiles = collectChunkModuleIds(siblingChunk.output).map(normalizeSfcModuleId).filter((file, index, files) => Boolean(file) && files.indexOf(file) === index);
|
|
1204
|
+
if (sourceFiles.length === 0) {
|
|
1205
|
+
debug("sfc style sibling chunk skipped: no sfc modules for %s -> %s", outputFile, siblingJsFile);
|
|
1206
|
+
return;
|
|
1207
|
+
}
|
|
1208
|
+
const scoredSources = sourceFiles.map((sourceFile) => ({
|
|
1209
|
+
sourceFile,
|
|
1210
|
+
score: scoreMatchingStyleFileBase(outputFile, sourceFile, outputRoot, sourceRoot)
|
|
1211
|
+
})).filter((item) => item.score > 0).sort((a, b) => b.score - a.score);
|
|
1212
|
+
debug("sfc style sibling chunk candidates: %s -> %s %O", outputFile, siblingJsFile, scoredSources);
|
|
1213
|
+
const bestScore = scoredSources[0]?.score;
|
|
1214
|
+
if (!bestScore) return;
|
|
1215
|
+
const bestSources = scoredSources.filter((item) => item.score === bestScore);
|
|
1216
|
+
if (bestSources.length !== 1) {
|
|
1217
|
+
debug("sfc style sibling chunk skipped: ambiguous best sources for %s %O", outputFile, bestSources);
|
|
1218
|
+
return;
|
|
1219
|
+
}
|
|
1220
|
+
return bestSources[0]?.sourceFile;
|
|
1221
|
+
}
|
|
1222
|
+
//#endregion
|
|
1223
|
+
//#region src/bundlers/vite/generate-bundle/remembered-css.ts
|
|
1224
|
+
function createRememberedCssRuntimeSignature(cssRuntimeSignature, cssRuntimeAffectingHash) {
|
|
1225
|
+
return `${cssRuntimeSignature}:${cssRuntimeAffectingHash}`;
|
|
1226
|
+
}
|
|
1227
|
+
function findRememberedCssSources(sources, outputFile, file, originalSource, outputRoot, sourceRoot) {
|
|
1228
|
+
if (!sources) return [];
|
|
1229
|
+
const rememberedSources = [...sources].map(([, remembered]) => remembered);
|
|
1230
|
+
const source = typeof originalSource.source === "string" ? originalSource.source : originalSource.source.toString();
|
|
1231
|
+
const markerFiles = new Set(parseBundlerGeneratedCssMarkerBlocks(source).filter((block) => block.bundler === "vite" && typeof block.file === "string" && block.file.length > 0).map((block) => normalizeOutputPathKey(block.file)));
|
|
1232
|
+
if (markerFiles.size > 0) {
|
|
1233
|
+
const markerMatched = rememberedSources.filter((remembered) => markerFiles.has(normalizeOutputPathKey(remembered.sourceFile.replace(/[?#].*$/, ""))));
|
|
1234
|
+
if (markerMatched.length > 0) return markerMatched;
|
|
1235
|
+
}
|
|
1236
|
+
const originalFiles = [
|
|
1237
|
+
file,
|
|
1238
|
+
originalSource.originalFileName,
|
|
1239
|
+
...originalSource.originalFileNames ?? []
|
|
1240
|
+
].filter((item) => typeof item === "string" && item.length > 0);
|
|
1241
|
+
const sourceMatched = rememberedSources.filter((remembered) => originalFiles.some((originalFile) => normalizeOutputPathKey(remembered.sourceFile) === normalizeOutputPathKey(originalFile)));
|
|
1242
|
+
if (sourceMatched.length > 0) return sourceMatched;
|
|
1243
|
+
const outputMatched = rememberedSources.filter((remembered) => normalizeOutputPathKey(remembered.outputFile) === normalizeOutputPathKey(outputFile));
|
|
1244
|
+
if (outputMatched.length > 0) return outputMatched;
|
|
1245
|
+
const shouldUseRememberedApplyFallback = !hasBundlerGeneratedCssMarker(source) && !hasTailwindGenerationSource(source);
|
|
1246
|
+
if (shouldUseRememberedApplyFallback && !rememberedSources.some((remembered) => hasTailwindApplyDirective(remembered.rawSource))) return [];
|
|
1247
|
+
const scoredMatches = rememberedSources.filter((remembered) => !shouldUseRememberedApplyFallback || hasTailwindApplyDirective(remembered.rawSource)).filter((remembered) => !(isMainAppCssFile(outputFile) && isAppOriginCssFile(remembered.outputFile))).map((remembered) => ({
|
|
1248
|
+
remembered,
|
|
1249
|
+
score: Math.max(scoreMatchingStyleFileBase(outputFile, remembered.sourceFile, outputRoot, sourceRoot), scoreMatchingStyleFileBase(outputFile, remembered.outputFile, outputRoot, sourceRoot))
|
|
1250
|
+
})).filter((match) => match.score > 0).sort((a, b) => b.score - a.score);
|
|
1251
|
+
const bestScore = scoredMatches[0]?.score;
|
|
1252
|
+
return bestScore ? scoredMatches.filter((match) => match.score === bestScore).map((match) => match.remembered) : [];
|
|
1253
|
+
}
|
|
1254
|
+
function mergeRememberedCssSources(sources, outputFile) {
|
|
1255
|
+
if (sources.length <= 1) return sources[0];
|
|
1256
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1257
|
+
const rawSources = [];
|
|
1258
|
+
for (const source of sources) {
|
|
1259
|
+
const key = `${source.sourceFile}\0${source.rawSource}`;
|
|
1260
|
+
if (seen.has(key)) continue;
|
|
1261
|
+
seen.add(key);
|
|
1262
|
+
rawSources.push(source.rawSource);
|
|
1263
|
+
}
|
|
1264
|
+
return {
|
|
1265
|
+
outputFile,
|
|
1266
|
+
rawSource: rawSources.join("\n"),
|
|
1267
|
+
sourceFile: sources[0]?.sourceFile ?? outputFile
|
|
1268
|
+
};
|
|
1269
|
+
}
|
|
1270
|
+
function collectRememberedCssReplayGroups(sources, opts, rootDir, isWebGeneratorTarget, preserveCssExtension) {
|
|
1271
|
+
const groups = /* @__PURE__ */ new Map();
|
|
1272
|
+
for (const [key, remembered] of sources ?? []) {
|
|
1273
|
+
const outputKey = normalizeOutputPathKey(resolveViteCssPipelineOutputFile(remembered.outputFile, opts, rootDir, isWebGeneratorTarget, preserveCssExtension));
|
|
1274
|
+
const group = groups.get(outputKey) ?? [];
|
|
1275
|
+
group.push({
|
|
1276
|
+
key,
|
|
1277
|
+
remembered
|
|
1278
|
+
});
|
|
1279
|
+
groups.set(outputKey, group);
|
|
1280
|
+
}
|
|
1281
|
+
return groups;
|
|
1282
|
+
}
|
|
1283
|
+
//#endregion
|
|
484
1284
|
//#region src/bundlers/vite/generate-bundle/rollup-assets.ts
|
|
485
1285
|
function createReplayCssAsset(fileName, source) {
|
|
486
1286
|
return {
|
|
@@ -559,6 +1359,75 @@ function hasRuntimeAffectingSourceChanges(changedByType) {
|
|
|
559
1359
|
return changedByType.html.size > 0 || changedByType.js.size > 0;
|
|
560
1360
|
}
|
|
561
1361
|
//#endregion
|
|
1362
|
+
//#region src/bundlers/vite/generate-bundle/subpackages.ts
|
|
1363
|
+
function readBundleAssetSource(output) {
|
|
1364
|
+
if (output.type !== "asset") return;
|
|
1365
|
+
return typeof output.source === "string" ? output.source : output.source.toString();
|
|
1366
|
+
}
|
|
1367
|
+
function normalizePackageRoot(root) {
|
|
1368
|
+
return normalizeOutputPathKey(root).replace(/\/+$/, "");
|
|
1369
|
+
}
|
|
1370
|
+
function collectMiniProgramSubpackageRoots(bundle) {
|
|
1371
|
+
let hasAppJson = false;
|
|
1372
|
+
const roots = /* @__PURE__ */ new Set();
|
|
1373
|
+
for (const [file, output] of Object.entries(bundle)) {
|
|
1374
|
+
const outputFile = output.fileName || file;
|
|
1375
|
+
if (path.basename(outputFile) !== "app.json") continue;
|
|
1376
|
+
const source = readBundleAssetSource(output);
|
|
1377
|
+
if (!source) continue;
|
|
1378
|
+
hasAppJson = true;
|
|
1379
|
+
try {
|
|
1380
|
+
const appJson = JSON.parse(source);
|
|
1381
|
+
const subPackages = Array.isArray(appJson.subPackages) ? appJson.subPackages : Array.isArray(appJson.subpackages) ? appJson.subpackages : [];
|
|
1382
|
+
for (const subPackage of subPackages) {
|
|
1383
|
+
if (typeof subPackage.root !== "string" || subPackage.root.length === 0) continue;
|
|
1384
|
+
roots.add(normalizePackageRoot(subPackage.root));
|
|
1385
|
+
}
|
|
1386
|
+
} catch {}
|
|
1387
|
+
}
|
|
1388
|
+
return hasAppJson ? roots : void 0;
|
|
1389
|
+
}
|
|
1390
|
+
function isSubpackageOutputFile(file, subpackageRoots) {
|
|
1391
|
+
const normalizedFile = normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
1392
|
+
for (const root of subpackageRoots) if (root.length > 0 && (normalizedFile === root || normalizedFile.startsWith(`${root}/`) || normalizedFile.endsWith(`/${root}`) || normalizedFile.includes(`/${root}/`))) return true;
|
|
1393
|
+
return false;
|
|
1394
|
+
}
|
|
1395
|
+
function resolveSubpackageSourceRootFromModuleId(moduleId, subpackageRoot) {
|
|
1396
|
+
const file = slash(path.resolve(moduleId.replace(/[?#].*$/, "")));
|
|
1397
|
+
const normalizedRoot = normalizePackageRoot(subpackageRoot);
|
|
1398
|
+
const rootSegment = `/${normalizedRoot}/`;
|
|
1399
|
+
const rootIndex = file.lastIndexOf(rootSegment);
|
|
1400
|
+
if (rootIndex >= 0) return file.slice(0, rootIndex + rootSegment.length - 1);
|
|
1401
|
+
const rootSuffix = `/${normalizedRoot}`;
|
|
1402
|
+
if (file.endsWith(rootSuffix)) return file;
|
|
1403
|
+
}
|
|
1404
|
+
function collectMiniProgramSubpackageSourceEntries(snapshot, subpackageRoots, sourceBaseRoots) {
|
|
1405
|
+
const sourceRoots = /* @__PURE__ */ new Set();
|
|
1406
|
+
const sourceEntries = [];
|
|
1407
|
+
for (const entry of snapshot.entries) {
|
|
1408
|
+
if (entry.output.type !== "chunk" || !isSubpackageOutputFile(entry.file, subpackageRoots)) continue;
|
|
1409
|
+
const matchedSubpackageRoot = [...subpackageRoots].find((root) => isSubpackageOutputFile(entry.file, new Set([root])));
|
|
1410
|
+
if (!matchedSubpackageRoot) continue;
|
|
1411
|
+
for (const moduleId of collectChunkModuleIds(entry.output)) {
|
|
1412
|
+
if (!path.isAbsolute(moduleId.replace(/[?#].*$/, ""))) continue;
|
|
1413
|
+
const sourceRoot = resolveSubpackageSourceRootFromModuleId(moduleId, matchedSubpackageRoot);
|
|
1414
|
+
if (sourceRoot) sourceRoots.add(sourceRoot);
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
sourceEntries.push(...[...sourceRoots].map((sourceRoot) => ({
|
|
1418
|
+
base: sourceRoot,
|
|
1419
|
+
negated: false,
|
|
1420
|
+
pattern: "**/*"
|
|
1421
|
+
})));
|
|
1422
|
+
const resolvedBaseRoots = sourceBaseRoots.filter((baseRoot) => typeof baseRoot === "string" && baseRoot.length > 0).map((baseRoot) => path.resolve(baseRoot)).filter((baseRoot, index, roots) => roots.indexOf(baseRoot) === index);
|
|
1423
|
+
for (const baseRoot of resolvedBaseRoots) for (const subpackageRoot of subpackageRoots) sourceEntries.push({
|
|
1424
|
+
base: baseRoot,
|
|
1425
|
+
negated: false,
|
|
1426
|
+
pattern: `**/${normalizePackageRoot(subpackageRoot)}/**`
|
|
1427
|
+
});
|
|
1428
|
+
return sourceEntries;
|
|
1429
|
+
}
|
|
1430
|
+
//#endregion
|
|
562
1431
|
//#region ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs
|
|
563
1432
|
let _lazyMatch = () => {
|
|
564
1433
|
var __lib__ = (() => {
|
|
@@ -1005,11 +1874,372 @@ const mix = (del = delimiter) => {
|
|
|
1005
1874
|
const posix = /* @__PURE__ */ mix(":");
|
|
1006
1875
|
const win32 = /* @__PURE__ */ mix(";");
|
|
1007
1876
|
//#endregion
|
|
1877
|
+
//#region src/bundlers/vite/processed-css-assets/css-rules.ts
|
|
1878
|
+
const MINI_PROGRAM_PREFLIGHT_SELECTOR_KEY = "view,text,::after,::before";
|
|
1879
|
+
const MINI_PROGRAM_PREFLIGHT_SELECTOR_KEYS = new Set([
|
|
1880
|
+
"view",
|
|
1881
|
+
"text",
|
|
1882
|
+
"::after",
|
|
1883
|
+
"::before"
|
|
1884
|
+
]);
|
|
1885
|
+
const MINI_PROGRAM_THEME_SCOPE_SELECTOR_KEY = ":host,page,.tw-root,wx-root-portal-content";
|
|
1886
|
+
const MINI_PROGRAM_THEME_SCOPE_SELECTOR_KEYS = new Set([
|
|
1887
|
+
":host",
|
|
1888
|
+
"page",
|
|
1889
|
+
".tw-root",
|
|
1890
|
+
"wx-root-portal-content"
|
|
1891
|
+
]);
|
|
1892
|
+
function normalizeCssForContainment(css) {
|
|
1893
|
+
return css.replace(/\/\*[\s\S]*?\*\//g, "").replace(/::(before|after)\b/g, ":$1").replace(/\s+/g, " ").replace(/\s*([{}:;,>+~()])\s*/g, "$1").replace(/;\}/g, "}").trim();
|
|
1894
|
+
}
|
|
1895
|
+
function collectNormalizedCssNodes(css) {
|
|
1896
|
+
try {
|
|
1897
|
+
return (postcss.parse(css).nodes ?? []).filter((node) => node.type !== "comment").map((node) => normalizeCssForContainment(node.toString())).filter(Boolean);
|
|
1898
|
+
} catch {
|
|
1899
|
+
const normalizedCss = normalizeCssForContainment(css);
|
|
1900
|
+
return normalizedCss ? [normalizedCss] : [];
|
|
1901
|
+
}
|
|
1902
|
+
}
|
|
1903
|
+
function normalizeCssRuleKeyPart(value) {
|
|
1904
|
+
return value.replace(/::(before|after)\b/g, ":$1").replace(/\s+/g, " ").replace(/\s*([>+~(),])\s*/g, "$1").trim();
|
|
1905
|
+
}
|
|
1906
|
+
function getRuleAtRuleChain(rule) {
|
|
1907
|
+
const chain = [];
|
|
1908
|
+
let parent = rule.parent;
|
|
1909
|
+
while (parent && parent.type !== "root") {
|
|
1910
|
+
if (parent.type === "atrule") chain.unshift(`@${parent.name} ${normalizeCssRuleKeyPart(parent.params)}`);
|
|
1911
|
+
parent = parent.parent;
|
|
1912
|
+
}
|
|
1913
|
+
return chain;
|
|
1914
|
+
}
|
|
1915
|
+
function getCssRuleStructuralKey(rule) {
|
|
1916
|
+
const selector = normalizeCssRuleKeyPart(rule.selector);
|
|
1917
|
+
if (selector.length === 0) return;
|
|
1918
|
+
return [...getRuleAtRuleChain(rule), selector].join("|");
|
|
1919
|
+
}
|
|
1920
|
+
function getCssRuleStructuralKeyWithSelectorKey(rule, selectorKey) {
|
|
1921
|
+
return [...getRuleAtRuleChain(rule), selectorKey].join("|");
|
|
1922
|
+
}
|
|
1923
|
+
function getCssRuleContentKey(rule) {
|
|
1924
|
+
const structuralKey = getCssRuleStructuralKey(rule);
|
|
1925
|
+
if (!structuralKey) return;
|
|
1926
|
+
return [structuralKey, normalizeCssForContainment(rule.toString())].join("|");
|
|
1927
|
+
}
|
|
1928
|
+
function collectCssRuleContentKeys(css) {
|
|
1929
|
+
const keys = /* @__PURE__ */ new Set();
|
|
1930
|
+
try {
|
|
1931
|
+
postcss.parse(css).walkRules((rule) => {
|
|
1932
|
+
const key = getCssRuleContentKey(rule);
|
|
1933
|
+
if (key) keys.add(key);
|
|
1934
|
+
});
|
|
1935
|
+
} catch {}
|
|
1936
|
+
return keys;
|
|
1937
|
+
}
|
|
1938
|
+
function normalizeCssDeclarationKey(decl) {
|
|
1939
|
+
return [
|
|
1940
|
+
decl.prop.trim(),
|
|
1941
|
+
normalizeCssForContainment(decl.value),
|
|
1942
|
+
decl.important ? "!important" : ""
|
|
1943
|
+
].join(":");
|
|
1944
|
+
}
|
|
1945
|
+
function collectCssRuleDeclarationKeys(rule) {
|
|
1946
|
+
const keys = /* @__PURE__ */ new Set();
|
|
1947
|
+
for (const node of rule.nodes ?? []) if (node.type === "decl") keys.add(normalizeCssDeclarationKey(node));
|
|
1948
|
+
return keys;
|
|
1949
|
+
}
|
|
1950
|
+
function collectCssRuleDeclarationProps(rule) {
|
|
1951
|
+
const props = /* @__PURE__ */ new Set();
|
|
1952
|
+
for (const node of rule.nodes ?? []) if (node.type === "decl") props.add(node.prop.trim());
|
|
1953
|
+
return props;
|
|
1954
|
+
}
|
|
1955
|
+
function collectCssRuleDeclarations(rule) {
|
|
1956
|
+
return (rule.nodes ?? []).filter((node) => node.type === "decl");
|
|
1957
|
+
}
|
|
1958
|
+
function collectCssRuleDeclarationKeyMap(css) {
|
|
1959
|
+
const map = /* @__PURE__ */ new Map();
|
|
1960
|
+
try {
|
|
1961
|
+
postcss.parse(css).walkRules((rule) => {
|
|
1962
|
+
const key = getCssRuleStructuralKey(rule);
|
|
1963
|
+
if (!key) return;
|
|
1964
|
+
const declarations = collectCssRuleDeclarationKeys(rule);
|
|
1965
|
+
if (declarations.size === 0) return;
|
|
1966
|
+
let existing = map.get(key);
|
|
1967
|
+
if (!existing) {
|
|
1968
|
+
existing = /* @__PURE__ */ new Set();
|
|
1969
|
+
map.set(key, existing);
|
|
1970
|
+
}
|
|
1971
|
+
for (const declaration of declarations) existing.add(declaration);
|
|
1972
|
+
});
|
|
1973
|
+
} catch {}
|
|
1974
|
+
return map;
|
|
1975
|
+
}
|
|
1976
|
+
function collectCssRuleDeclarationRecords(root, resolveRuleKey = getCssRuleStructuralKey) {
|
|
1977
|
+
const map = /* @__PURE__ */ new Map();
|
|
1978
|
+
root.walkRules((rule) => {
|
|
1979
|
+
const key = resolveRuleKey(rule);
|
|
1980
|
+
if (!key) return;
|
|
1981
|
+
const keys = collectCssRuleDeclarationKeys(rule);
|
|
1982
|
+
if (keys.size === 0) return;
|
|
1983
|
+
const records = map.get(key) ?? [];
|
|
1984
|
+
records.push({
|
|
1985
|
+
rule,
|
|
1986
|
+
keys,
|
|
1987
|
+
props: collectCssRuleDeclarationProps(rule)
|
|
1988
|
+
});
|
|
1989
|
+
map.set(key, records);
|
|
1990
|
+
});
|
|
1991
|
+
return map;
|
|
1992
|
+
}
|
|
1993
|
+
function normalizeSimpleMiniProgramSelectorNode(node) {
|
|
1994
|
+
if (node.type === "tag") {
|
|
1995
|
+
const value = node.value.toLowerCase();
|
|
1996
|
+
if (value === "view" || value === "text" || value === "page" || value === "wx-root-portal-content") return value;
|
|
1997
|
+
return;
|
|
1998
|
+
}
|
|
1999
|
+
if (node.type === "class") return node.value.toLowerCase() === "tw-root" ? ".tw-root" : void 0;
|
|
2000
|
+
if (node.type === "pseudo") {
|
|
2001
|
+
if (node.nodes && node.nodes.length > 0) return;
|
|
2002
|
+
const value = node.value.toLowerCase();
|
|
2003
|
+
if (value === ":before" || value === "::before") return "::before";
|
|
2004
|
+
if (value === ":after" || value === "::after") return "::after";
|
|
2005
|
+
if (value === ":host") return ":host";
|
|
2006
|
+
}
|
|
2007
|
+
}
|
|
2008
|
+
function normalizeSimpleMiniProgramSelector(selector) {
|
|
2009
|
+
if (selector.nodes.length !== 1) return;
|
|
2010
|
+
return normalizeSimpleMiniProgramSelectorNode(selector.nodes[0]);
|
|
2011
|
+
}
|
|
2012
|
+
function collectMiniProgramSelectorSet(selector) {
|
|
2013
|
+
try {
|
|
2014
|
+
const selectorSet = /* @__PURE__ */ new Set();
|
|
2015
|
+
const ast = selectorParser().astSync(selector);
|
|
2016
|
+
for (const child of ast.nodes) {
|
|
2017
|
+
const key = normalizeSimpleMiniProgramSelector(child);
|
|
2018
|
+
if (!key || selectorSet.has(key)) return;
|
|
2019
|
+
selectorSet.add(key);
|
|
2020
|
+
}
|
|
2021
|
+
return selectorSet;
|
|
2022
|
+
} catch {
|
|
2023
|
+
return;
|
|
2024
|
+
}
|
|
2025
|
+
}
|
|
2026
|
+
function isSameSelectorSet(actual, expected) {
|
|
2027
|
+
return actual?.size === expected.size && [...expected].every((key) => actual.has(key));
|
|
2028
|
+
}
|
|
2029
|
+
function getMiniProgramPreflightRuleStructuralKey(rule) {
|
|
2030
|
+
if (!isSameSelectorSet(collectMiniProgramSelectorSet(rule.selector), MINI_PROGRAM_PREFLIGHT_SELECTOR_KEYS)) return;
|
|
2031
|
+
return getCssRuleStructuralKeyWithSelectorKey(rule, MINI_PROGRAM_PREFLIGHT_SELECTOR_KEY);
|
|
2032
|
+
}
|
|
2033
|
+
function getMiniProgramThemeScopeRuleStructuralKey(rule) {
|
|
2034
|
+
if (!isSameSelectorSet(collectMiniProgramSelectorSet(rule.selector), MINI_PROGRAM_THEME_SCOPE_SELECTOR_KEYS)) return;
|
|
2035
|
+
return getCssRuleStructuralKeyWithSelectorKey(rule, MINI_PROGRAM_THEME_SCOPE_SELECTOR_KEY);
|
|
2036
|
+
}
|
|
2037
|
+
function mergeMiniProgramPreflightRuleDeclarations(baseCss, css) {
|
|
2038
|
+
try {
|
|
2039
|
+
const baseRoot = postcss.parse(baseCss);
|
|
2040
|
+
const root = postcss.parse(css);
|
|
2041
|
+
const baseRuleRecords = collectCssRuleDeclarationRecords(baseRoot, getMiniProgramPreflightRuleStructuralKey);
|
|
2042
|
+
let changedBase = false;
|
|
2043
|
+
let changedCss = false;
|
|
2044
|
+
root.walkRules((rule) => {
|
|
2045
|
+
const key = getMiniProgramPreflightRuleStructuralKey(rule);
|
|
2046
|
+
if (!key) return;
|
|
2047
|
+
const records = baseRuleRecords.get(key);
|
|
2048
|
+
const targetRecord = records?.[0];
|
|
2049
|
+
if (!targetRecord) return;
|
|
2050
|
+
const existingProps = new Set(records.flatMap((record) => [...record.props]));
|
|
2051
|
+
for (const decl of collectCssRuleDeclarations(rule)) {
|
|
2052
|
+
const prop = decl.prop.trim();
|
|
2053
|
+
if (existingProps.has(prop)) continue;
|
|
2054
|
+
targetRecord.rule.append(decl.clone());
|
|
2055
|
+
targetRecord.keys.add(normalizeCssDeclarationKey(decl));
|
|
2056
|
+
targetRecord.props.add(prop);
|
|
2057
|
+
existingProps.add(prop);
|
|
2058
|
+
changedBase = true;
|
|
2059
|
+
}
|
|
2060
|
+
rule.remove();
|
|
2061
|
+
changedCss = true;
|
|
2062
|
+
});
|
|
2063
|
+
if (!changedBase && !changedCss) return {
|
|
2064
|
+
baseCss,
|
|
2065
|
+
css,
|
|
2066
|
+
changed: false
|
|
2067
|
+
};
|
|
2068
|
+
removeEmptyAtRules(root);
|
|
2069
|
+
return {
|
|
2070
|
+
baseCss: changedBase ? baseRoot.toString() : baseCss,
|
|
2071
|
+
css: changedCss ? root.toString().trim() : css,
|
|
2072
|
+
changed: true
|
|
2073
|
+
};
|
|
2074
|
+
} catch {
|
|
2075
|
+
return {
|
|
2076
|
+
baseCss,
|
|
2077
|
+
css,
|
|
2078
|
+
changed: false
|
|
2079
|
+
};
|
|
2080
|
+
}
|
|
2081
|
+
}
|
|
2082
|
+
function mergeMiniProgramThemeScopeRuleDeclarations(baseCss, css) {
|
|
2083
|
+
try {
|
|
2084
|
+
const baseRoot = postcss.parse(baseCss);
|
|
2085
|
+
const root = postcss.parse(css);
|
|
2086
|
+
const baseRuleRecords = collectCssRuleDeclarationRecords(baseRoot, getMiniProgramThemeScopeRuleStructuralKey);
|
|
2087
|
+
let changedBase = false;
|
|
2088
|
+
let changedCss = false;
|
|
2089
|
+
root.walkRules((rule) => {
|
|
2090
|
+
const key = getMiniProgramThemeScopeRuleStructuralKey(rule);
|
|
2091
|
+
if (!key) return;
|
|
2092
|
+
const records = baseRuleRecords.get(key);
|
|
2093
|
+
const targetRecord = records?.[0];
|
|
2094
|
+
if (!targetRecord) return;
|
|
2095
|
+
const incomingDeclarations = collectCssRuleDeclarations(rule);
|
|
2096
|
+
if (incomingDeclarations.length === 0) return;
|
|
2097
|
+
const existingKeys = new Set(records.flatMap((record) => [...record.keys]));
|
|
2098
|
+
const existingProps = new Set(records.flatMap((record) => [...record.props]));
|
|
2099
|
+
if (incomingDeclarations.some((decl) => {
|
|
2100
|
+
const prop = decl.prop.trim();
|
|
2101
|
+
return existingProps.has(prop) && !existingKeys.has(normalizeCssDeclarationKey(decl));
|
|
2102
|
+
})) return;
|
|
2103
|
+
for (const decl of incomingDeclarations) {
|
|
2104
|
+
const declarationKey = normalizeCssDeclarationKey(decl);
|
|
2105
|
+
if (existingKeys.has(declarationKey)) continue;
|
|
2106
|
+
targetRecord.rule.append(decl.clone());
|
|
2107
|
+
targetRecord.keys.add(declarationKey);
|
|
2108
|
+
targetRecord.props.add(decl.prop.trim());
|
|
2109
|
+
existingKeys.add(declarationKey);
|
|
2110
|
+
existingProps.add(decl.prop.trim());
|
|
2111
|
+
changedBase = true;
|
|
2112
|
+
}
|
|
2113
|
+
rule.remove();
|
|
2114
|
+
changedCss = true;
|
|
2115
|
+
});
|
|
2116
|
+
if (!changedBase && !changedCss) return {
|
|
2117
|
+
baseCss,
|
|
2118
|
+
css,
|
|
2119
|
+
changed: false
|
|
2120
|
+
};
|
|
2121
|
+
removeEmptyAtRules(root);
|
|
2122
|
+
return {
|
|
2123
|
+
baseCss: changedBase ? baseRoot.toString() : baseCss,
|
|
2124
|
+
css: changedCss ? root.toString().trim() : css,
|
|
2125
|
+
changed: true
|
|
2126
|
+
};
|
|
2127
|
+
} catch {
|
|
2128
|
+
return {
|
|
2129
|
+
baseCss,
|
|
2130
|
+
css,
|
|
2131
|
+
changed: false
|
|
2132
|
+
};
|
|
2133
|
+
}
|
|
2134
|
+
}
|
|
2135
|
+
function isCssRuleCoveredByDeclarations(rule, baseRuleDeclarationKeys) {
|
|
2136
|
+
const key = getCssRuleStructuralKey(rule);
|
|
2137
|
+
if (!key) return false;
|
|
2138
|
+
const baseDeclarations = baseRuleDeclarationKeys.get(key);
|
|
2139
|
+
if (!baseDeclarations) return false;
|
|
2140
|
+
const declarations = collectCssRuleDeclarationKeys(rule);
|
|
2141
|
+
return declarations.size > 0 && [...declarations].every((declaration) => baseDeclarations.has(declaration));
|
|
2142
|
+
}
|
|
2143
|
+
function mergeCoveredCssRuleDeclarations(baseCss, css) {
|
|
2144
|
+
try {
|
|
2145
|
+
const baseRoot = postcss.parse(baseCss);
|
|
2146
|
+
const root = postcss.parse(css);
|
|
2147
|
+
const baseRuleRecords = collectCssRuleDeclarationRecords(baseRoot);
|
|
2148
|
+
let changedBase = false;
|
|
2149
|
+
let changedCss = false;
|
|
2150
|
+
root.walkRules((rule) => {
|
|
2151
|
+
const key = getCssRuleStructuralKey(rule);
|
|
2152
|
+
const records = key ? baseRuleRecords.get(key) : void 0;
|
|
2153
|
+
if (!records || records.length === 0) return;
|
|
2154
|
+
const incomingDeclarations = collectCssRuleDeclarations(rule);
|
|
2155
|
+
if (incomingDeclarations.length === 0) return;
|
|
2156
|
+
const baseKeys = new Set(records.flatMap((record) => [...record.keys]));
|
|
2157
|
+
if (incomingDeclarations.filter((decl) => baseKeys.has(normalizeCssDeclarationKey(decl))).length === 0) return;
|
|
2158
|
+
const missingDeclarations = incomingDeclarations.filter((decl) => !baseKeys.has(normalizeCssDeclarationKey(decl)));
|
|
2159
|
+
if (missingDeclarations.length === 0) {
|
|
2160
|
+
rule.remove();
|
|
2161
|
+
changedCss = true;
|
|
2162
|
+
return;
|
|
2163
|
+
}
|
|
2164
|
+
const baseProps = new Set(records.flatMap((record) => [...record.props]));
|
|
2165
|
+
if (missingDeclarations.filter((decl) => baseProps.has(decl.prop.trim())).length > 0) return;
|
|
2166
|
+
const targetRecord = records[0];
|
|
2167
|
+
if (!targetRecord) return;
|
|
2168
|
+
for (const decl of missingDeclarations) {
|
|
2169
|
+
targetRecord.rule.append(decl.clone());
|
|
2170
|
+
targetRecord.keys.add(normalizeCssDeclarationKey(decl));
|
|
2171
|
+
targetRecord.props.add(decl.prop.trim());
|
|
2172
|
+
}
|
|
2173
|
+
rule.remove();
|
|
2174
|
+
changedBase = true;
|
|
2175
|
+
changedCss = true;
|
|
2176
|
+
});
|
|
2177
|
+
if (!changedBase && !changedCss) return {
|
|
2178
|
+
baseCss,
|
|
2179
|
+
css,
|
|
2180
|
+
changed: false
|
|
2181
|
+
};
|
|
2182
|
+
removeEmptyAtRules(root);
|
|
2183
|
+
return {
|
|
2184
|
+
baseCss: changedBase ? baseRoot.toString() : baseCss,
|
|
2185
|
+
css: changedCss ? root.toString().trim() : css,
|
|
2186
|
+
changed: true
|
|
2187
|
+
};
|
|
2188
|
+
} catch {
|
|
2189
|
+
return {
|
|
2190
|
+
baseCss,
|
|
2191
|
+
css,
|
|
2192
|
+
changed: false
|
|
2193
|
+
};
|
|
2194
|
+
}
|
|
2195
|
+
}
|
|
2196
|
+
function removeEmptyAtRules(root) {
|
|
2197
|
+
root.walkAtRules((atRule) => {
|
|
2198
|
+
if (atRule.nodes && atRule.nodes.every((node) => node.type === "comment")) atRule.remove();
|
|
2199
|
+
});
|
|
2200
|
+
}
|
|
2201
|
+
function filterExistingCssRules(baseCss, css) {
|
|
2202
|
+
const baseRuleKeys = collectCssRuleContentKeys(baseCss);
|
|
2203
|
+
if (baseRuleKeys.size === 0) return css;
|
|
2204
|
+
try {
|
|
2205
|
+
const root = postcss.parse(css);
|
|
2206
|
+
const baseRuleDeclarationKeys = collectCssRuleDeclarationKeyMap(baseCss);
|
|
2207
|
+
let changed = false;
|
|
2208
|
+
root.walkRules((rule) => {
|
|
2209
|
+
const key = getCssRuleContentKey(rule);
|
|
2210
|
+
if (key && baseRuleKeys.has(key) || isCssRuleCoveredByDeclarations(rule, baseRuleDeclarationKeys)) {
|
|
2211
|
+
rule.remove();
|
|
2212
|
+
changed = true;
|
|
2213
|
+
}
|
|
2214
|
+
});
|
|
2215
|
+
if (!changed) return css;
|
|
2216
|
+
removeEmptyAtRules(root);
|
|
2217
|
+
return root.toString().trim();
|
|
2218
|
+
} catch {
|
|
2219
|
+
return css;
|
|
2220
|
+
}
|
|
2221
|
+
}
|
|
2222
|
+
function containsCssAfterMinify(baseCss, css) {
|
|
2223
|
+
if (baseCss.includes(css)) return true;
|
|
2224
|
+
const normalizedBaseCss = normalizeCssForContainment(baseCss);
|
|
2225
|
+
const normalizedCss = normalizeCssForContainment(css);
|
|
2226
|
+
if (normalizedCss.length > 0 && normalizedBaseCss.includes(normalizedCss)) return true;
|
|
2227
|
+
const normalizedNodes = collectNormalizedCssNodes(css);
|
|
2228
|
+
if (normalizedNodes.length > 0 && normalizedNodes.every((node) => normalizedBaseCss.includes(node))) return true;
|
|
2229
|
+
const baseRuleKeys = collectCssRuleContentKeys(baseCss);
|
|
2230
|
+
const ruleKeys = collectCssRuleContentKeys(css);
|
|
2231
|
+
return ruleKeys.size > 0 && [...ruleKeys].every((key) => baseRuleKeys.has(key));
|
|
2232
|
+
}
|
|
2233
|
+
//#endregion
|
|
1008
2234
|
//#region src/bundlers/vite/processed-css-assets.ts
|
|
1009
2235
|
const CSS_OUTPUT_FILE_RE = /\.(?:css|wxss|acss|ttss|qss|jxss|tyss)(?:$|[?#])/i;
|
|
1010
2236
|
function isCssOutputFile(file) {
|
|
1011
2237
|
return CSS_OUTPUT_FILE_RE.test(file);
|
|
1012
2238
|
}
|
|
2239
|
+
function isMainStyleAssetFile(file) {
|
|
2240
|
+
const basename = normalizeOutputPathKey(file.replace(/[?#].*$/, "")).replace(/\.(?:css|wxss|acss|ttss|qss|jxss|tyss)$/i, "").split("/").pop();
|
|
2241
|
+
return basename === "app" || basename === "main";
|
|
2242
|
+
}
|
|
1013
2243
|
function getAssetFile(bundleFile, asset) {
|
|
1014
2244
|
return asset.fileName || bundleFile;
|
|
1015
2245
|
}
|
|
@@ -1082,6 +2312,9 @@ function resolveViteProcessedCssAssetSource(file, rawSource, resolveViteProcesse
|
|
|
1082
2312
|
const matchedCss = blocks.filter((block) => isMatchingGeneratedCssMarkerFile(file, block.file, resolveViteProcessedCssOutputFile)).map((block) => block.css);
|
|
1083
2313
|
return matchedCss.length > 0 ? matchedCss.join("\n") : stripBundlerGeneratedCssMarkers(rawSource);
|
|
1084
2314
|
}
|
|
2315
|
+
function collectMatchingGeneratedCssMarkerFiles(file, rawSource, resolveViteProcessedCssOutputFile) {
|
|
2316
|
+
return parseBundlerGeneratedCssMarkerBlocks(rawSource).filter((block) => block.bundler === "vite").filter((block) => isMatchingGeneratedCssMarkerFile(file, block.file, resolveViteProcessedCssOutputFile)).map((block) => block.file).filter((markerFile) => typeof markerFile === "string" && markerFile.length > 0);
|
|
2317
|
+
}
|
|
1085
2318
|
function shouldInjectViteProcessedCssResult(opts, targetFile, sourceFile, options) {
|
|
1086
2319
|
if (options.injectIntoMain === true) return true;
|
|
1087
2320
|
if (options.injectIntoMain === false) return false;
|
|
@@ -1090,6 +2323,28 @@ function shouldInjectViteProcessedCssResult(opts, targetFile, sourceFile, option
|
|
|
1090
2323
|
const sourceBaseName = sourceFileKey.replace(/\.(?:css|wxss|acss|ttss|qss|jxss|tyss)$/i, "").split("/").pop();
|
|
1091
2324
|
return sourceFileKey !== targetFileKey && (opts.mainCssChunkMatcher(sourceFile, opts.appType) || sourceBaseName === "app" || sourceBaseName === "main");
|
|
1092
2325
|
}
|
|
2326
|
+
function isViteProcessedCssResultImported(record, importedStyleFiles) {
|
|
2327
|
+
const importedFileNames = new Set([...importedStyleFiles].map((file) => posix.posix.basename(file)));
|
|
2328
|
+
return importedStyleFiles.has(normalizeOutputPathKey(record.file)) || typeof record.outputFile === "string" && (importedStyleFiles.has(normalizeOutputPathKey(record.outputFile)) || importedFileNames.has(posix.posix.basename(normalizeOutputPathKey(record.outputFile))));
|
|
2329
|
+
}
|
|
2330
|
+
function removeCssCoveredByImportedViteResults(css, importedCssSources) {
|
|
2331
|
+
if (importedCssSources.length === 0) return css;
|
|
2332
|
+
const importedCss = importedCssSources.map((source) => stripBundlerGeneratedCssMarkers(source).trim()).filter(Boolean).join("\n");
|
|
2333
|
+
if (importedCss.length === 0) return css;
|
|
2334
|
+
return filterExistingCssRules(importedCss, css);
|
|
2335
|
+
}
|
|
2336
|
+
function collectImportedBundleCssSources(bundle, importedStyleFiles) {
|
|
2337
|
+
if (importedStyleFiles.size === 0) return [];
|
|
2338
|
+
const importedFileNames = new Set([...importedStyleFiles].map((file) => posix.posix.basename(file)));
|
|
2339
|
+
const importedSources = [];
|
|
2340
|
+
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2341
|
+
if (output.type !== "asset") continue;
|
|
2342
|
+
const file = normalizeOutputPathKey(getAssetFile(bundleFile, output));
|
|
2343
|
+
if (!(importedStyleFiles.has(file) || !file.includes("/") && importedFileNames.has(posix.posix.basename(file)))) continue;
|
|
2344
|
+
importedSources.push(readAssetSource(output));
|
|
2345
|
+
}
|
|
2346
|
+
return importedSources;
|
|
2347
|
+
}
|
|
1093
2348
|
function collectViteProcessedCssAssetResults(bundle, options) {
|
|
1094
2349
|
let collected = 0;
|
|
1095
2350
|
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
@@ -1102,8 +2357,18 @@ function collectViteProcessedCssAssetResults(bundle, options) {
|
|
|
1102
2357
|
options.markCssAssetProcessed?.(output, file);
|
|
1103
2358
|
options.recordCssAssetResult?.(file, nextCss);
|
|
1104
2359
|
const resolvedOutputFile = options.resolveViteProcessedCssOutputFile?.(file) ?? file;
|
|
1105
|
-
const shouldReplayIntoMainCss = options.opts != null && normalizeOutputPathKey(resolvedOutputFile) !== normalizeOutputPathKey(file)
|
|
1106
|
-
options.recordViteProcessedCssAssetResult?.(file, nextCss, {
|
|
2360
|
+
const shouldReplayIntoMainCss = options.opts != null && isMainStyleAssetFile(file) && (normalizeOutputPathKey(resolvedOutputFile) !== normalizeOutputPathKey(file) || !options.opts.mainCssChunkMatcher(file, options.opts.appType));
|
|
2361
|
+
options.recordViteProcessedCssAssetResult?.(file, nextCss, {
|
|
2362
|
+
injectIntoMain: shouldReplayIntoMainCss || void 0,
|
|
2363
|
+
outputFile: resolvedOutputFile
|
|
2364
|
+
});
|
|
2365
|
+
for (const markerFile of collectMatchingGeneratedCssMarkerFiles(file, rawSource, options.resolveViteProcessedCssOutputFile)) {
|
|
2366
|
+
if (normalizeOutputPathKey(markerFile) === normalizeOutputPathKey(file)) continue;
|
|
2367
|
+
options.recordViteProcessedCssAssetResult?.(markerFile, nextCss, {
|
|
2368
|
+
injectIntoMain: shouldReplayIntoMainCss || void 0,
|
|
2369
|
+
outputFile: resolvedOutputFile
|
|
2370
|
+
});
|
|
2371
|
+
}
|
|
1107
2372
|
options.debug?.("collect vite-processed css asset: %s bytes=%d", file, nextCss.length);
|
|
1108
2373
|
collected++;
|
|
1109
2374
|
}
|
|
@@ -1118,10 +2383,10 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
1118
2383
|
} : {
|
|
1119
2384
|
file,
|
|
1120
2385
|
css: record.css,
|
|
1121
|
-
injectIntoMain: record.injectIntoMain
|
|
2386
|
+
injectIntoMain: record.injectIntoMain,
|
|
2387
|
+
outputFile: record.outputFile
|
|
1122
2388
|
};
|
|
1123
2389
|
}).filter((record) => record.css.length > 0);
|
|
1124
|
-
if (viteCssResults.length === 0) return 0;
|
|
1125
2390
|
let injected = 0;
|
|
1126
2391
|
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
1127
2392
|
if (output.type !== "asset") continue;
|
|
@@ -1131,18 +2396,45 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
1131
2396
|
const originalSource = readAssetSource(output);
|
|
1132
2397
|
let nextCss = removeTailwindEntryDirectivesFromCss(originalSource);
|
|
1133
2398
|
const importedStyleFiles = collectImportedStyleFiles(nextCss, file);
|
|
2399
|
+
const importedBundleCssSources = collectImportedBundleCssSources(bundle, importedStyleFiles);
|
|
2400
|
+
nextCss = removeCssCoveredByImportedViteResults(nextCss, importedBundleCssSources);
|
|
2401
|
+
const importedViteCssResults = viteCssResults.filter((record) => isViteProcessedCssResultImported(record, importedStyleFiles));
|
|
2402
|
+
const importedCssSources = [...importedBundleCssSources, ...importedViteCssResults.map((record) => record.css)];
|
|
2403
|
+
nextCss = removeCssCoveredByImportedViteResults(nextCss, importedViteCssResults.map((record) => record.css));
|
|
1134
2404
|
for (const record of viteCssResults) {
|
|
1135
2405
|
if (!shouldInjectViteProcessedCssResult(options.opts, mainFileKey, record.file, record)) continue;
|
|
1136
|
-
if (
|
|
1137
|
-
|
|
2406
|
+
if (isViteProcessedCssResultImported(record, importedStyleFiles)) continue;
|
|
2407
|
+
let css = stripBundlerGeneratedCssMarkers(record.css).trim();
|
|
2408
|
+
css = removeCssCoveredByImportedViteResults(css, importedCssSources).trim();
|
|
1138
2409
|
if (css.length === 0) continue;
|
|
1139
2410
|
const mergedLayerCss = mergeMarkedUserLayerComponentsCss(nextCss, css);
|
|
1140
2411
|
if (mergedLayerCss.merged) {
|
|
1141
2412
|
nextCss = mergedLayerCss.css;
|
|
1142
|
-
|
|
2413
|
+
css = extractMarkedUserLayerComponentsCss(css).rest.trim();
|
|
2414
|
+
if (css.length === 0) continue;
|
|
2415
|
+
}
|
|
2416
|
+
if (containsCssAfterMinify(nextCss, css)) continue;
|
|
2417
|
+
const mergedPreflightDeclarations = mergeMiniProgramPreflightRuleDeclarations(nextCss, css);
|
|
2418
|
+
if (mergedPreflightDeclarations.changed) {
|
|
2419
|
+
nextCss = mergedPreflightDeclarations.baseCss;
|
|
2420
|
+
css = mergedPreflightDeclarations.css.trim();
|
|
2421
|
+
if (css.length === 0) continue;
|
|
2422
|
+
}
|
|
2423
|
+
const mergedThemeScopeDeclarations = mergeMiniProgramThemeScopeRuleDeclarations(nextCss, css);
|
|
2424
|
+
if (mergedThemeScopeDeclarations.changed) {
|
|
2425
|
+
nextCss = mergedThemeScopeDeclarations.baseCss;
|
|
2426
|
+
css = mergedThemeScopeDeclarations.css.trim();
|
|
2427
|
+
if (css.length === 0) continue;
|
|
2428
|
+
}
|
|
2429
|
+
const mergedRuleDeclarations = mergeCoveredCssRuleDeclarations(nextCss, css);
|
|
2430
|
+
if (mergedRuleDeclarations.changed) {
|
|
2431
|
+
nextCss = mergedRuleDeclarations.baseCss;
|
|
2432
|
+
css = mergedRuleDeclarations.css.trim();
|
|
2433
|
+
if (css.length === 0) continue;
|
|
1143
2434
|
}
|
|
1144
|
-
|
|
1145
|
-
|
|
2435
|
+
const missingCss = filterExistingCssRules(nextCss, css);
|
|
2436
|
+
if (missingCss.length === 0 || containsCssAfterMinify(nextCss, missingCss)) continue;
|
|
2437
|
+
nextCss = appendCss(nextCss, missingCss);
|
|
1146
2438
|
}
|
|
1147
2439
|
if (nextCss === originalSource) continue;
|
|
1148
2440
|
output.source = nextCss;
|
|
@@ -1151,81 +2443,30 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
1151
2443
|
options.onUpdate?.(file, originalSource, nextCss);
|
|
1152
2444
|
options.debug?.("inject vite-processed css into main css asset: %s bytes=%d", file, nextCss.length);
|
|
1153
2445
|
injected++;
|
|
1154
|
-
}
|
|
1155
|
-
return injected;
|
|
1156
|
-
}
|
|
1157
|
-
//#endregion
|
|
1158
|
-
//#region src/bundlers/vite/uni-app-x-css-options.ts
|
|
1159
|
-
function resolveUniAppXNativeCssHandlerOptions(opts) {
|
|
1160
|
-
if (opts.appType !== "uni-app-x" || !isUniAppXEnabled(opts.uniAppX) || !resolveUniUtsPlatform().isApp) return {};
|
|
1161
|
-
return {
|
|
1162
|
-
uniAppX: true,
|
|
1163
|
-
uniAppXCssTarget: "uvue",
|
|
1164
|
-
uniAppXUnsupported: resolveUniAppXOptions(opts.uniAppX).uvueUnsupported
|
|
1165
|
-
};
|
|
1166
|
-
}
|
|
1167
|
-
//#endregion
|
|
1168
|
-
//#region src/bundlers/vite/generate-bundle.ts
|
|
1169
|
-
function addSiblingCssFile(files, file) {
|
|
1170
|
-
if (file.endsWith(".wxml")) files.add(file.replace(/\.wxml$/, ".wxss"));
|
|
1171
|
-
else if (file.endsWith(".js")) files.add(file.replace(/\.js$/, ".wxss"));
|
|
1172
|
-
}
|
|
1173
|
-
function collectRuntimeLinkedCssFiles(snapshot) {
|
|
1174
|
-
const files = /* @__PURE__ */ new Set();
|
|
1175
|
-
for (const file of snapshot.runtimeAffectingChangedByType.html) addSiblingCssFile(files, file);
|
|
1176
|
-
for (const file of snapshot.runtimeAffectingChangedByType.js) addSiblingCssFile(files, file);
|
|
1177
|
-
return files;
|
|
1178
|
-
}
|
|
1179
|
-
function resolveReplayCssOutputFile(rootDir, file) {
|
|
1180
|
-
const normalizedFile = normalizeOutputPathKey(path.isAbsolute(file) ? path.relative(rootDir, file) : file);
|
|
1181
|
-
if (normalizedFile.length === 0 || normalizedFile === "." || normalizedFile === ".." || normalizedFile.startsWith("../")) return normalizeOutputPathKey(path.basename(file));
|
|
1182
|
-
return normalizedFile;
|
|
1183
|
-
}
|
|
1184
|
-
const SOURCE_STYLE_OUTPUT_EXT_RE = /\.(?:less|sass|scss|styl|stylus|pcss|postcss)$/i;
|
|
1185
|
-
const CSS_SOURCE_OUTPUT_EXT_RE = /\.(?:css|less|sass|scss|styl|stylus|pcss|postcss)$/i;
|
|
1186
|
-
const MINI_PROGRAM_STYLE_OUTPUT_EXT_RE = /\.(?:wx|ac|jx|tt|q|ty)ss$/i;
|
|
1187
|
-
const SOURCE_STYLE_NON_CSS_SYNTAX_RE = /(?:^|\n)\s*(?:\/\/|\$[\w-]+\s*:|@(?:use|forward|mixin|include|function)\b)/;
|
|
1188
|
-
function resolveViteCssOutputFile(file, opts, isWebGeneratorTarget) {
|
|
1189
|
-
if (isWebGeneratorTarget || opts.cssMatcher(file) || !SOURCE_STYLE_OUTPUT_EXT_RE.test(file) || !isCSSRequest(file)) return file;
|
|
1190
|
-
return file.replace(SOURCE_STYLE_OUTPUT_EXT_RE, ".wxss");
|
|
1191
|
-
}
|
|
1192
|
-
function resolveViteCssPipelineOutputFile(file, _opts, rootDir, isWebGeneratorTarget = false, preserveCssExtension = false) {
|
|
1193
|
-
const normalizedFile = resolveReplayCssOutputFile(rootDir, file);
|
|
1194
|
-
if (isWebGeneratorTarget || preserveCssExtension || MINI_PROGRAM_STYLE_OUTPUT_EXT_RE.test(normalizedFile) || !CSS_SOURCE_OUTPUT_EXT_RE.test(normalizedFile) || !isCSSRequest(normalizedFile)) return normalizedFile;
|
|
1195
|
-
return normalizedFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, ".wxss");
|
|
1196
|
-
}
|
|
1197
|
-
function canProcessViteSourceStyleAsCss(source, file) {
|
|
1198
|
-
if (SOURCE_STYLE_NON_CSS_SYNTAX_RE.test(source)) return false;
|
|
1199
|
-
try {
|
|
1200
|
-
postcss.parse(source, { from: file });
|
|
1201
|
-
return true;
|
|
1202
|
-
} catch {
|
|
1203
|
-
return false;
|
|
1204
|
-
}
|
|
1205
|
-
}
|
|
1206
|
-
function isPackageJsonImportRequest(request) {
|
|
1207
|
-
return request.startsWith("#");
|
|
1208
|
-
}
|
|
1209
|
-
function normalizeMatchedCssSourcePath(file) {
|
|
1210
|
-
if (!file || !path.isAbsolute(file)) return;
|
|
1211
|
-
return path.resolve(file.replace(/[?#].*$/, ""));
|
|
1212
|
-
}
|
|
1213
|
-
function stripStyleFileExtension(file) {
|
|
1214
|
-
const normalized = file.replace(/[?#].*$/, "");
|
|
1215
|
-
const ext = path.extname(normalized);
|
|
1216
|
-
return ext ? normalized.slice(0, -ext.length) : normalized;
|
|
1217
|
-
}
|
|
1218
|
-
function isAppOriginCssFile(file) {
|
|
1219
|
-
return path.basename(stripStyleFileExtension(file)) === "app-origin";
|
|
2446
|
+
}
|
|
2447
|
+
return injected;
|
|
1220
2448
|
}
|
|
1221
|
-
|
|
1222
|
-
|
|
2449
|
+
//#endregion
|
|
2450
|
+
//#region src/bundlers/vite/uni-app-x-css-options.ts
|
|
2451
|
+
function resolveUniAppXNativeCssHandlerOptions(opts) {
|
|
2452
|
+
if (opts.appType !== "uni-app-x" || !isUniAppXEnabled(opts.uniAppX) || !resolveUniUtsPlatform().isApp) return {};
|
|
2453
|
+
return {
|
|
2454
|
+
uniAppX: true,
|
|
2455
|
+
uniAppXCssTarget: "uvue",
|
|
2456
|
+
uniAppXUnsupported: resolveUniAppXOptions(opts.uniAppX).uvueUnsupported
|
|
2457
|
+
};
|
|
1223
2458
|
}
|
|
1224
|
-
|
|
1225
|
-
|
|
2459
|
+
//#endregion
|
|
2460
|
+
//#region src/bundlers/vite/generate-bundle.ts
|
|
2461
|
+
function addSiblingCssFile(files, file) {
|
|
2462
|
+
if (file.endsWith(".wxml")) files.add(file.replace(/\.wxml$/, ".wxss"));
|
|
2463
|
+
else if (file.endsWith(".js")) files.add(file.replace(/\.js$/, ".wxss"));
|
|
1226
2464
|
}
|
|
1227
|
-
function
|
|
1228
|
-
|
|
2465
|
+
function collectRuntimeLinkedCssFiles(snapshot) {
|
|
2466
|
+
const files = /* @__PURE__ */ new Set();
|
|
2467
|
+
for (const file of snapshot.runtimeAffectingChangedByType.html) addSiblingCssFile(files, file);
|
|
2468
|
+
for (const file of snapshot.runtimeAffectingChangedByType.js) addSiblingCssFile(files, file);
|
|
2469
|
+
return files;
|
|
1229
2470
|
}
|
|
1230
2471
|
async function createScopedGeneratorCandidateSignature(rawSource, sourceFile, fallbackSignature, getSourceCandidatesForEntries, options = {}) {
|
|
1231
2472
|
if (!getSourceCandidatesForEntries || !rawSource.includes("@source")) return fallbackSignature;
|
|
@@ -1234,124 +2475,11 @@ async function createScopedGeneratorCandidateSignature(rawSource, sourceFile, fa
|
|
|
1234
2475
|
const scopedSignature = createCandidateSignature(getSourceCandidatesForEntries(resolved.entries));
|
|
1235
2476
|
return options.includeFallbackSignature === true ? `${scopedSignature}:${fallbackSignature}` : scopedSignature;
|
|
1236
2477
|
}
|
|
1237
|
-
function isMatchingCssSourceFile(outputFile, cssSourceFile, outputRoot) {
|
|
1238
|
-
return stripStyleFileExtension(path.resolve(outputRoot, outputFile)) === stripStyleFileExtension(path.resolve(cssSourceFile));
|
|
1239
|
-
}
|
|
1240
|
-
function collectStyleFileMatchBases(file, roots) {
|
|
1241
|
-
const normalizedFile = file.replace(/[?#].*$/, "");
|
|
1242
|
-
const bases = /* @__PURE__ */ new Set();
|
|
1243
|
-
const addBase = (candidate) => {
|
|
1244
|
-
const base = slash(stripStyleFileExtension(candidate));
|
|
1245
|
-
if (base.length > 0) bases.add(base);
|
|
1246
|
-
};
|
|
1247
|
-
addBase(normalizedFile);
|
|
1248
|
-
const resolvedRoots = roots.filter((root) => typeof root === "string" && root.length > 0).map((root) => path.resolve(root));
|
|
1249
|
-
if (path.isAbsolute(normalizedFile)) for (const root of resolvedRoots) {
|
|
1250
|
-
const relative = path.relative(root, normalizedFile);
|
|
1251
|
-
if (relative && !relative.startsWith("..") && !path.isAbsolute(relative)) addBase(relative);
|
|
1252
|
-
}
|
|
1253
|
-
else for (const root of resolvedRoots) addBase(path.resolve(root, normalizedFile));
|
|
1254
|
-
return bases;
|
|
1255
|
-
}
|
|
1256
|
-
function collectParentDirectories(file) {
|
|
1257
|
-
const directories = [];
|
|
1258
|
-
let current = path.dirname(path.resolve(file.replace(/[?#].*$/, "")));
|
|
1259
|
-
while (true) {
|
|
1260
|
-
directories.push(current);
|
|
1261
|
-
const parent = path.dirname(current);
|
|
1262
|
-
if (parent === current) break;
|
|
1263
|
-
current = parent;
|
|
1264
|
-
}
|
|
1265
|
-
return directories;
|
|
1266
|
-
}
|
|
1267
|
-
function hasMatchingStyleFileBase(outputFile, sourceFile, outputRoot, sourceRoot) {
|
|
1268
|
-
return scoreMatchingStyleFileBase(outputFile, sourceFile, outputRoot, sourceRoot) > 0;
|
|
1269
|
-
}
|
|
1270
|
-
function scoreMatchingStyleFileBase(outputFile, sourceFile, outputRoot, sourceRoot) {
|
|
1271
|
-
const outputBases = collectStyleFileMatchBases(outputFile, [outputRoot]);
|
|
1272
|
-
const sourceBases = collectStyleFileMatchBases(sourceFile, [sourceRoot, ...collectParentDirectories(sourceFile)]);
|
|
1273
|
-
let bestScore = 0;
|
|
1274
|
-
for (const outputBase of outputBases) for (const sourceBase of sourceBases) if (outputBase === sourceBase) bestScore = Math.max(bestScore, 1e5 + outputBase.length);
|
|
1275
|
-
else if (outputBase.endsWith(`/${sourceBase}`)) bestScore = Math.max(bestScore, 5e4 + sourceBase.length);
|
|
1276
|
-
else if (sourceBase.endsWith(`/${outputBase}`)) bestScore = Math.max(bestScore, 1e3 + outputBase.length);
|
|
1277
|
-
return bestScore;
|
|
1278
|
-
}
|
|
1279
|
-
function findRememberedCssSource(sources, outputFile, file, originalSource, outputRoot, sourceRoot) {
|
|
1280
|
-
if (!sources) return;
|
|
1281
|
-
const rememberedSources = [...sources].map(([, remembered]) => remembered);
|
|
1282
|
-
const originalFiles = [
|
|
1283
|
-
file,
|
|
1284
|
-
originalSource.originalFileName,
|
|
1285
|
-
...originalSource.originalFileNames ?? []
|
|
1286
|
-
].filter((item) => typeof item === "string" && item.length > 0);
|
|
1287
|
-
const sourceMatched = rememberedSources.find((remembered) => originalFiles.some((originalFile) => normalizeOutputPathKey(remembered.sourceFile) === normalizeOutputPathKey(originalFile)));
|
|
1288
|
-
if (sourceMatched) return sourceMatched;
|
|
1289
|
-
const outputMatched = rememberedSources.find((remembered) => normalizeOutputPathKey(remembered.outputFile) === normalizeOutputPathKey(outputFile));
|
|
1290
|
-
if (outputMatched) return outputMatched;
|
|
1291
|
-
const scoredMatches = rememberedSources.filter((remembered) => !(isMainAppCssFile(outputFile) && isAppOriginCssFile(remembered.outputFile))).map((remembered) => ({
|
|
1292
|
-
remembered,
|
|
1293
|
-
score: Math.max(scoreMatchingStyleFileBase(outputFile, remembered.sourceFile, outputRoot, sourceRoot), scoreMatchingStyleFileBase(outputFile, remembered.outputFile, outputRoot, sourceRoot))
|
|
1294
|
-
})).filter((match) => match.score > 0).sort((a, b) => b.score - a.score);
|
|
1295
|
-
const bestScore = scoredMatches[0]?.score;
|
|
1296
|
-
return bestScore && scoredMatches.filter((match) => match.score === bestScore).length === 1 ? scoredMatches[0]?.remembered : void 0;
|
|
1297
|
-
}
|
|
1298
|
-
function collectConfiguredTailwindV4CssSources(opts) {
|
|
1299
|
-
const patcherCssSources = opts.tailwindcssPatcherOptions?.tailwindcss?.v4?.cssSources ?? [];
|
|
1300
|
-
return [...opts.tailwindcss?.v4?.cssSources ?? [], ...patcherCssSources ?? []];
|
|
1301
|
-
}
|
|
1302
|
-
function collectConfiguredCssEntries(opts) {
|
|
1303
|
-
const patcherCssEntries = opts.tailwindcssPatcherOptions?.tailwindcss?.v4?.cssEntries ?? [];
|
|
1304
|
-
return [
|
|
1305
|
-
...opts.cssEntries ?? [],
|
|
1306
|
-
...opts.tailwindcss?.v4?.cssEntries ?? [],
|
|
1307
|
-
...patcherCssEntries ?? []
|
|
1308
|
-
].filter((entry) => typeof entry === "string" && entry.length > 0);
|
|
1309
|
-
}
|
|
1310
|
-
function collectCssConfigBaseCandidates(source, file, outputRoot, opts) {
|
|
1311
|
-
const candidates = [];
|
|
1312
|
-
const seen = /* @__PURE__ */ new Set();
|
|
1313
|
-
const addCandidate = (candidate) => {
|
|
1314
|
-
if (!candidate) return;
|
|
1315
|
-
const normalized = path.resolve(candidate);
|
|
1316
|
-
if (seen.has(normalized)) return;
|
|
1317
|
-
seen.add(normalized);
|
|
1318
|
-
candidates.push(normalized);
|
|
1319
|
-
};
|
|
1320
|
-
addCandidate(path.dirname(path.resolve(outputRoot, file.replace(/[?#].*$/, ""))));
|
|
1321
|
-
const normalizedSource = normalizeCssSourceForCompare(source);
|
|
1322
|
-
const patcherProjectRoot = typeof opts.tailwindcssPatcherOptions?.projectRoot === "string" ? opts.tailwindcssPatcherOptions.projectRoot : void 0;
|
|
1323
|
-
const sourceBaseFallback = opts.tailwindcss?.v4?.base ?? patcherProjectRoot ?? opts.tailwindcssBasedir ?? outputRoot;
|
|
1324
|
-
const sourceRoot = opts.tailwindcssBasedir ?? patcherProjectRoot;
|
|
1325
|
-
const configuredCssEntries = collectConfiguredCssEntries(opts);
|
|
1326
|
-
for (const cssEntry of configuredCssEntries) {
|
|
1327
|
-
const resolvedCssEntry = path.resolve(cssEntry);
|
|
1328
|
-
if (configuredCssEntries.length === 1 || isMatchingCssSourceFile(file, resolvedCssEntry, outputRoot) || hasMatchingStyleFileBase(file, resolvedCssEntry, outputRoot, sourceRoot)) addCandidate(path.dirname(resolvedCssEntry));
|
|
1329
|
-
}
|
|
1330
|
-
for (const cssSource of collectConfiguredTailwindV4CssSources(opts)) {
|
|
1331
|
-
const cssSourceFile = normalizeMatchedCssSourcePath(cssSource.file);
|
|
1332
|
-
const cssSourceCss = typeof cssSource.css === "string" ? normalizeCssSourceForCompare(cssSource.css) : void 0;
|
|
1333
|
-
if (cssSourceFile && !isMatchingCssSourceFile(file, cssSourceFile, outputRoot) && cssSourceCss !== normalizedSource) continue;
|
|
1334
|
-
addCandidate(cssSourceFile ? path.dirname(cssSourceFile) : void 0);
|
|
1335
|
-
addCandidate(resolveTailwindV4CssSourceBase(cssSource, sourceBaseFallback));
|
|
1336
|
-
}
|
|
1337
|
-
return candidates;
|
|
1338
|
-
}
|
|
1339
|
-
function normalizeRelativeCssConfigDirectives(source, file, outputRoot, opts) {
|
|
1340
|
-
if (!source.includes("@config")) return source;
|
|
1341
|
-
const baseCandidates = collectCssConfigBaseCandidates(source, file, outputRoot, opts);
|
|
1342
|
-
return source.replace(/@config\s+(["'])(.+?)\1\s*;?/g, (full, quote, request) => {
|
|
1343
|
-
if (path.isAbsolute(request) || isPackageJsonImportRequest(request)) return full;
|
|
1344
|
-
for (const base of baseCandidates) {
|
|
1345
|
-
const configFile = path.resolve(base, request);
|
|
1346
|
-
if (existsSync(configFile)) return `@config ${quote}${slash(configFile)}${quote};`;
|
|
1347
|
-
}
|
|
1348
|
-
return full;
|
|
1349
|
-
});
|
|
1350
|
-
}
|
|
1351
2478
|
function createGenerateBundleHook(context) {
|
|
1352
2479
|
const state = createBundleBuildState();
|
|
1353
2480
|
const lastCssResultByFile = /* @__PURE__ */ new Map();
|
|
1354
2481
|
let currentOutDir;
|
|
2482
|
+
let currentSubpackageRoots;
|
|
1355
2483
|
const cssHandlerOptions = createCssHandlerOptionsCache({
|
|
1356
2484
|
getAppType: () => context.opts.appType,
|
|
1357
2485
|
mainCssChunkMatcher: context.opts.mainCssChunkMatcher,
|
|
@@ -1361,26 +2489,36 @@ function createGenerateBundleHook(context) {
|
|
|
1361
2489
|
});
|
|
1362
2490
|
return async function generateBundle(_opt, bundle) {
|
|
1363
2491
|
const addWatchFile = (id) => this.addWatchFile?.(id);
|
|
1364
|
-
const { opts, runtimeState, ensureBundleRuntimeClassSet, debug, getResolvedConfig, markCssAssetProcessed, isCssAssetProcessed, isViteProcessedCssAsset, recordCssAssetResult, recordViteProcessedCssAssetResult, getViteProcessedCssAssetResults, getViteProcessedCssAssetResult, getSourceCandidates, getSourceCandidatesForEntries, waitForSourceCandidateSyncs, rememberCssSource, refreshRememberedCssSource, getRememberedCssSources, getRememberedCssSignature, setRememberedCssSignature, recordGeneratorCandidates, hmrTimingRecorder } = context;
|
|
2492
|
+
const { opts, runtimeState, ensureBundleRuntimeClassSet, debug, getResolvedConfig, markCssAssetProcessed, isCssAssetProcessed, isViteProcessedCssAsset, recordCssAssetResult, recordViteProcessedCssAssetResult, getViteProcessedCssAssetResults, getViteProcessedCssAssetResult, getSourceCandidates, getSourceCandidatesForEntries, getSourceCandidateSourcesForEntries, waitForSourceCandidateSyncs, rememberCssSource, refreshRememberedCssSource, getRememberedCssSources, getRememberedCssSignature, setRememberedCssSignature, getKnownSfcSource, recordGeneratorCandidates, hmrTimingRecorder } = context;
|
|
2493
|
+
const getBundlerSfcSource = (sourceFile) => {
|
|
2494
|
+
const code = this.getModuleInfo?.(sourceFile)?.code;
|
|
2495
|
+
return typeof code === "string" && hasSfcStyleSources(code) ? code : void 0;
|
|
2496
|
+
};
|
|
2497
|
+
const getSfcSource = (sourceFile) => getBundlerSfcSource(sourceFile) ?? getKnownSfcSource?.(sourceFile);
|
|
1365
2498
|
const { cache, onEnd, onStart, onUpdate, styleHandler, templateHandler, jsHandler, uniAppX } = opts;
|
|
1366
2499
|
const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(opts.generator);
|
|
1367
2500
|
const isWebGeneratorTarget = generatorOptions.target === "web";
|
|
1368
|
-
const
|
|
2501
|
+
const resolvedConfig = getResolvedConfig();
|
|
2502
|
+
const uniUtsPlatform = resolveUniUtsPlatform();
|
|
2503
|
+
const isNativeAppStyleTarget = uniUtsPlatform.isApp;
|
|
2504
|
+
const canInferHarmonyAppStyleTarget = !uniUtsPlatform.normalized || uniUtsPlatform.isApp;
|
|
2505
|
+
const isHarmonyAppStyleTarget = uniUtsPlatform.isAppHarmony || canInferHarmonyAppStyleTarget && (isUniAppXHarmonyBundle(bundle) || isUniAppXHarmonyOutDir(resolvedConfig?.build?.outDir));
|
|
2506
|
+
const shouldPreserveAppCssExtension = isNativeAppStyleTarget || isHarmonyAppStyleTarget;
|
|
1369
2507
|
const shouldGenerateWebCssByGenerator = isWebGeneratorTarget && runtimeState.twPatcher.majorVersion === 3;
|
|
1370
2508
|
const { getCssHandlerOptions, getCssUserHandlerOptions } = cssHandlerOptions;
|
|
1371
|
-
const resolvedConfig = getResolvedConfig();
|
|
1372
2509
|
const rootDir = resolvedConfig?.root ? path.resolve(resolvedConfig.root) : process$1.cwd();
|
|
1373
2510
|
const outDir = resolvedConfig?.build?.outDir ? path.resolve(rootDir, resolvedConfig.build.outDir) : rootDir;
|
|
1374
2511
|
await runtimeState.readyPromise;
|
|
1375
2512
|
debug("start");
|
|
1376
2513
|
onStart();
|
|
2514
|
+
const collectedBundlerGeneratedCssFiles = new Set(Object.entries(bundle).filter(([, output]) => output.type === "asset" && hasBundlerGeneratedCssMarker(output.source)).map(([file]) => file));
|
|
1377
2515
|
collectViteProcessedCssAssetResults(bundle, {
|
|
1378
2516
|
opts,
|
|
1379
2517
|
isViteProcessedCssAsset,
|
|
1380
2518
|
markCssAssetProcessed,
|
|
1381
2519
|
recordCssAssetResult,
|
|
1382
2520
|
recordViteProcessedCssAssetResult,
|
|
1383
|
-
resolveViteProcessedCssOutputFile: (file) => resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget,
|
|
2521
|
+
resolveViteProcessedCssOutputFile: (file) => resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension),
|
|
1384
2522
|
debug
|
|
1385
2523
|
});
|
|
1386
2524
|
const hmrTimingStartedAt = performance.now();
|
|
@@ -1403,6 +2541,9 @@ function createGenerateBundleHook(context) {
|
|
|
1403
2541
|
const debugCssDiff = process$1.env["WEAPP_TW_VITE_DEBUG_CSS_DIFF"] === "1";
|
|
1404
2542
|
const disableV3OxideSourceRuntime = process$1.env["WEAPP_TW_VITE_DISABLE_V3_OXIDE_RUNTIME"] === "1";
|
|
1405
2543
|
const bundleFiles = Object.keys(bundle);
|
|
2544
|
+
const subpackageRoots = collectMiniProgramSubpackageRoots(bundle);
|
|
2545
|
+
if (subpackageRoots) currentSubpackageRoots = subpackageRoots;
|
|
2546
|
+
const isMainPackageStyleOutputFile = (file) => currentSubpackageRoots != null && !isSubpackageOutputFile(file, currentSubpackageRoots);
|
|
1406
2547
|
const buildCommand = resolvedConfig?.command === "build";
|
|
1407
2548
|
const hasPreviousBundleState = state.iteration > 0 || state.sourceHashByFile.size > 0;
|
|
1408
2549
|
const hasOmittedKnownFiles = hasOmittedKnownBundleFiles(bundleFiles, state.sourceHashByFile.keys());
|
|
@@ -1410,6 +2551,29 @@ function createGenerateBundleHook(context) {
|
|
|
1410
2551
|
currentOutDir = outDir;
|
|
1411
2552
|
const snapshotStart = performance.now();
|
|
1412
2553
|
const snapshot = buildBundleSnapshot(bundle, opts, outDir, state, disableDirtyOptimization || !useIncrementalMode, { hasOmittedKnownFiles });
|
|
2554
|
+
const subpackageSourceExcludeEntries = currentSubpackageRoots ? collectMiniProgramSubpackageSourceEntries(snapshot, currentSubpackageRoots, [
|
|
2555
|
+
rootDir,
|
|
2556
|
+
opts.tailwindcssBasedir,
|
|
2557
|
+
opts.tailwindcssPatcherOptions?.projectRoot
|
|
2558
|
+
]) : [];
|
|
2559
|
+
const shouldExcludeSubpackageSourceCandidates = (outputFile, cssHandlerOptions) => cssHandlerOptions.isMainChunk === true && subpackageSourceExcludeEntries.length > 0 && isMainPackageStyleOutputFile(outputFile);
|
|
2560
|
+
const createScopedSourceCandidateGetter = (outputFile, cssHandlerOptions) => {
|
|
2561
|
+
if (!getSourceCandidatesForEntries) return;
|
|
2562
|
+
if (!shouldExcludeSubpackageSourceCandidates(outputFile, cssHandlerOptions)) return getSourceCandidatesForEntries;
|
|
2563
|
+
return (entries, options) => getSourceCandidatesForEntries(entries, {
|
|
2564
|
+
...options,
|
|
2565
|
+
excludeEntries: [...options?.excludeEntries ?? [], ...subpackageSourceExcludeEntries]
|
|
2566
|
+
});
|
|
2567
|
+
};
|
|
2568
|
+
const createScopedSourceCandidateSourceGetter = (outputFile, cssHandlerOptions) => {
|
|
2569
|
+
if (!getSourceCandidateSourcesForEntries) return;
|
|
2570
|
+
if (!shouldExcludeSubpackageSourceCandidates(outputFile, cssHandlerOptions)) return getSourceCandidateSourcesForEntries;
|
|
2571
|
+
return (entries, options) => getSourceCandidateSourcesForEntries(entries, {
|
|
2572
|
+
...options,
|
|
2573
|
+
excludeEntries: [...options?.excludeEntries ?? [], ...subpackageSourceExcludeEntries]
|
|
2574
|
+
});
|
|
2575
|
+
};
|
|
2576
|
+
const shouldInjectCssIntoMainFromOutput = (outputFile, sourceFile, outputCssHandlerOptions) => isMainStyleEntryCssFile(sourceFile) || isTailwindEntryCssFile(outputFile) || useIncrementalMode && (outputCssHandlerOptions.isMainChunk || isMainPackageStyleOutputFile(outputFile));
|
|
1413
2577
|
recordTimingDetail("snapshot", snapshotStart);
|
|
1414
2578
|
const useBundleRuntimeClassSet = !isWebGeneratorTarget && (useIncrementalMode || runtimeState.twPatcher.majorVersion === 4);
|
|
1415
2579
|
const forceRuntimeRefreshBySource = useIncrementalMode && hasRuntimeAffectingSourceChanges(snapshot.runtimeAffectingChangedByType);
|
|
@@ -1424,6 +2588,12 @@ function createGenerateBundleHook(context) {
|
|
|
1424
2588
|
await waitForSourceCandidateSyncs?.();
|
|
1425
2589
|
recordTimingDetail("sourceCandidates.wait", sourceCandidateWaitStart);
|
|
1426
2590
|
const sourceCandidates = getSourceCandidates?.() ?? /* @__PURE__ */ new Set();
|
|
2591
|
+
const createScopedGeneratorRuntime = (outputFile, cssHandlerOptions, runtime) => {
|
|
2592
|
+
if (!shouldExcludeSubpackageSourceCandidates(outputFile, cssHandlerOptions)) return runtime;
|
|
2593
|
+
const filteredSourceCandidates = createScopedSourceCandidateGetter(outputFile, cssHandlerOptions)?.(void 0);
|
|
2594
|
+
if (!filteredSourceCandidates) return runtime;
|
|
2595
|
+
return filteredSourceCandidates.size > 0 ? filteredSourceCandidates : runtime;
|
|
2596
|
+
};
|
|
1427
2597
|
const jsEntries = snapshot.jsEntries;
|
|
1428
2598
|
const getJsEntry = createJsEntryResolver(jsEntries);
|
|
1429
2599
|
const moduleGraphOptions = createBundleModuleGraphOptions(outDir, jsEntries);
|
|
@@ -1432,10 +2602,11 @@ function createGenerateBundleHook(context) {
|
|
|
1432
2602
|
const useV3OxideSourceRuntime = runtimeState.twPatcher.majorVersion === 3 && sourceCandidates.size > 0 && hasCssAssetEntry && !forceRuntimeRefreshByEnv && !disableV3OxideSourceRuntime;
|
|
1433
2603
|
const runtimeStart = performance.now();
|
|
1434
2604
|
const transformBaseRuntime = useV3OxideSourceRuntime ? await ensureBundleRuntimeClassSet(snapshot, forceRuntimeRefreshByEnv, { transformOnly: true }) : void 0;
|
|
2605
|
+
const forceV4RuntimeRefreshBySource = runtimeState.twPatcher.majorVersion === 4 && forceRuntimeRefreshBySource;
|
|
1435
2606
|
const runtime = isWebGeneratorTarget && !shouldGenerateWebCssByGenerator ? /* @__PURE__ */ new Set() : useV3OxideSourceRuntime ? await ensureBundleRuntimeClassSet(snapshot, forceRuntimeRefreshByEnv, {
|
|
1436
2607
|
allowBaselineOnlyInitialSync: true,
|
|
1437
2608
|
baseClassSet: sourceCandidates
|
|
1438
|
-
}) : useBundleRuntimeClassSet ? await ensureBundleRuntimeClassSet(snapshot, forceRuntimeRefreshByEnv, { allowBaselineOnlyInitialSync: buildCommand }) : await context.ensureRuntimeClassSet(forceRuntimeRefreshByEnv);
|
|
2609
|
+
}) : useBundleRuntimeClassSet ? await ensureBundleRuntimeClassSet(snapshot, forceRuntimeRefreshByEnv || forceV4RuntimeRefreshBySource, { allowBaselineOnlyInitialSync: buildCommand }) : await context.ensureRuntimeClassSet(forceRuntimeRefreshByEnv);
|
|
1439
2610
|
if (useV3OxideSourceRuntime) debug("[tailwindcss:v3] use oxide source candidates as runtime input, candidates=%d", sourceCandidates.size);
|
|
1440
2611
|
const shouldFilterTailwindV4MiniProgramCandidates = runtimeState.twPatcher.majorVersion === 4 && generatorOptions.target === "weapp";
|
|
1441
2612
|
const collectedGeneratorCandidates = new Set([...runtime, ...sourceCandidates]);
|
|
@@ -1546,7 +2717,7 @@ function createGenerateBundleHook(context) {
|
|
|
1546
2717
|
if (type === "css" && originalSource.type === "asset") {
|
|
1547
2718
|
metrics.css.total++;
|
|
1548
2719
|
const rawSource = normalizeRelativeCssConfigDirectives(originalEntrySource, file, outDir, opts);
|
|
1549
|
-
const outputFile = resolveViteCssOutputFile(file, opts, isWebGeneratorTarget);
|
|
2720
|
+
const outputFile = resolveViteCssOutputFile(file, opts, isWebGeneratorTarget, shouldPreserveAppCssExtension);
|
|
1550
2721
|
if (outputFile !== file && !canProcessViteSourceStyleAsCss(rawSource, file)) {
|
|
1551
2722
|
delete bundle[file];
|
|
1552
2723
|
debug("css skip raw source style asset: %s -> %s", file, outputFile);
|
|
@@ -1576,43 +2747,66 @@ function createGenerateBundleHook(context) {
|
|
|
1576
2747
|
const viteProcessedCssAsset = isViteProcessedCssAsset?.(originalSource, file) === true || hasViteProcessedCssRecord;
|
|
1577
2748
|
const cssAssetProcessed = isCssAssetProcessed?.(originalSource, file) === true;
|
|
1578
2749
|
const alreadyProcessedCssAsset = viteProcessedCssAsset || cssAssetProcessed;
|
|
1579
|
-
let
|
|
1580
|
-
if (
|
|
2750
|
+
let rememberedCssSources = findRememberedCssSources(getRememberedCssSources?.(), outputFile, file, originalSource, outDir, opts.tailwindcssBasedir);
|
|
2751
|
+
if (rememberedCssSources.length > 0) rememberedCssSources = await Promise.all(rememberedCssSources.map(async (remembered) => await refreshRememberedCssSource?.(remembered) ?? remembered));
|
|
2752
|
+
const hasUsableRememberedTailwindSource = rememberedCssSources.some((remembered) => hasTailwindGenerationSource(remembered.rawSource) && normalizeOutputPathKey(remembered.sourceFile.replace(/[?#].*$/, "")) !== normalizeOutputPathKey(file));
|
|
2753
|
+
const inferredSfcStyleSource = await resolveSfcStyleSourceFromOutputFile(outputFile, snapshot, outDir, opts.tailwindcssBasedir, getSfcSource, debug);
|
|
2754
|
+
if (inferredSfcStyleSource) {
|
|
2755
|
+
const inferredSourceFile = normalizeSfcSourceFileForCompare(inferredSfcStyleSource.sourceFile);
|
|
2756
|
+
const rememberedSourcesBelongToInferredSfc = rememberedCssSources.length > 0 && rememberedCssSources.every((remembered) => normalizeSfcSourceFileForCompare(remembered.sourceFile) === inferredSourceFile);
|
|
2757
|
+
if (!hasUsableRememberedTailwindSource || rememberedSourcesBelongToInferredSfc) rememberedCssSources = [inferredSfcStyleSource];
|
|
2758
|
+
}
|
|
2759
|
+
const rememberedCssSource = mergeRememberedCssSources(rememberedCssSources, outputFile);
|
|
1581
2760
|
const useRememberedCssSource = rememberedCssSource != null && normalizeOutputPathKey(rememberedCssSource.sourceFile) !== normalizeOutputPathKey(file);
|
|
1582
2761
|
const vitePipelineCssAsset = viteProcessedCssAsset || useRememberedCssSource;
|
|
1583
2762
|
const generatorRawSource = vitePipelineCssAsset ? rememberedCssSource?.rawSource ?? rawSource : rawSource;
|
|
1584
2763
|
const hasRememberedApplySource = vitePipelineCssAsset && rememberedCssSource != null && hasTailwindApplyDirective(generatorRawSource);
|
|
1585
2764
|
const hasDifferentRememberedCssSource = rememberedCssSource != null && normalizeCssSourceForCompare(rememberedCssSource.rawSource) !== normalizeCssSourceForCompare(rawSource);
|
|
1586
|
-
const hasCurrentTailwindGenerationDirective = hasTailwindRootDirectives(rawSource, { importFallback: true }) || hasTailwindApplyDirective(rawSource);
|
|
2765
|
+
const hasCurrentTailwindGenerationDirective = hasTailwindSourceDirectives(rawSource, { importFallback: true }) || hasTailwindRootDirectives(rawSource, { importFallback: true }) || hasTailwindApplyDirective(rawSource);
|
|
1587
2766
|
const hasRememberedApplyDirective = rememberedCssSource != null && hasTailwindApplyDirective(rememberedCssSource.rawSource);
|
|
1588
2767
|
const hasStaleViteProcessedCssSource = vitePipelineCssAsset && hasDifferentRememberedCssSource && (hasCurrentTailwindGenerationDirective || hasRememberedApplyDirective);
|
|
1589
2768
|
const generatorSourceFile = vitePipelineCssAsset ? rememberedCssSource?.sourceFile ?? file : file;
|
|
1590
2769
|
const outputCssHandlerOptions = getCssHandlerOptions(outputFile);
|
|
1591
2770
|
const cssHandlerOptions = vitePipelineCssAsset ? {
|
|
1592
2771
|
...getCssHandlerOptions(generatorSourceFile),
|
|
1593
|
-
isMainChunk: outputCssHandlerOptions.isMainChunk || isAppOriginCssFile(file)
|
|
2772
|
+
isMainChunk: outputCssHandlerOptions.isMainChunk || isAppOriginCssFile(file) || isMainStyleEntryCssFile(generatorSourceFile)
|
|
1594
2773
|
} : getCssHandlerOptions(file);
|
|
2774
|
+
const scopedSourceCandidateGetter = createScopedSourceCandidateGetter(outputFile, cssHandlerOptions);
|
|
2775
|
+
const scopedSourceCandidateSourceGetter = createScopedSourceCandidateSourceGetter(outputFile, cssHandlerOptions);
|
|
2776
|
+
const sourceTraceTokenSources = scopedSourceCandidateSourceGetter ? createCssTokenSourceMap(scopedSourceCandidateSourceGetter(void 0), opts) : void 0;
|
|
2777
|
+
const sourceTraceSignature = createCssSourceTraceCacheSignature(sourceTraceTokenSources, opts);
|
|
2778
|
+
const scopedGeneratorRuntime = createScopedGeneratorRuntime(outputFile, cssHandlerOptions, generatorRuntime);
|
|
2779
|
+
const annotateCss = (css) => annotateCssSourceTrace(css, {
|
|
2780
|
+
opts,
|
|
2781
|
+
tokenSources: sourceTraceTokenSources
|
|
2782
|
+
});
|
|
2783
|
+
const shouldRegenerateMainPackageCssWithScopedCandidates = vitePipelineCssAsset && shouldExcludeSubpackageSourceCandidates(outputFile, cssHandlerOptions);
|
|
1595
2784
|
const generatorCssUserHandlerOptions = getCssUserHandlerOptions(generatorSourceFile);
|
|
1596
2785
|
const cssRuntimeAffectingSignature = vitePipelineCssAsset ? createRuntimeAffectingSourceSignature(generatorRawSource, "css") : snapshot.runtimeAffectingSignatureByFile.get(file) ?? createRuntimeAffectingSourceSignature(generatorRawSource, "css");
|
|
1597
2786
|
const cssRuntimeAffectingHash = vitePipelineCssAsset ? cache.computeHash(cssRuntimeAffectingSignature) : snapshot.runtimeAffectingHashByFile.get(file) ?? cache.computeHash(cssRuntimeAffectingSignature);
|
|
1598
2787
|
const cssShareScope = createCssTransformShareScopeKey(opts, generatorSourceFile, generatorRawSource);
|
|
1599
2788
|
const shouldRegenerateAppOriginCss = viteProcessedCssAsset && isAppOriginCssFile(file);
|
|
1600
|
-
const shouldTrackGeneratorRuntime = hasStaleViteProcessedCssSource || shouldProcessTailwindGeneration && (!useIncrementalMode || cssHandlerOptions.isMainChunk || processFiles.css.has(file) || runtimeLinkedCssFiles.has(file) || shouldRegenerateAppOriginCss);
|
|
1601
|
-
const
|
|
1602
|
-
if (alreadyProcessedCssAsset && !hasStaleViteProcessedCssSource && !hasRememberedApplySource && (!shouldTrackGeneratorRuntime ||
|
|
2789
|
+
const shouldTrackGeneratorRuntime = hasStaleViteProcessedCssSource || shouldRegenerateMainPackageCssWithScopedCandidates || hasCurrentTailwindGenerationDirective || shouldProcessTailwindGeneration && (!useIncrementalMode || cssHandlerOptions.isMainChunk || processFiles.css.has(file) || runtimeLinkedCssFiles.has(file) || shouldRegenerateAppOriginCss || hasRuntimeAffectingChanges && (alreadyProcessedCssAsset || vitePipelineCssAsset));
|
|
2790
|
+
const shouldPreserveCollectedViteCssAsset = !shouldRegenerateAppOriginCss && (collectedBundlerGeneratedCssFiles.has(file) || hasBundlerGeneratedCssMarker(rawSource));
|
|
2791
|
+
if (alreadyProcessedCssAsset && !hasStaleViteProcessedCssSource && !hasRememberedApplySource && !shouldRegenerateMainPackageCssWithScopedCandidates && (!shouldTrackGeneratorRuntime || shouldPreserveCollectedViteCssAsset)) {
|
|
1603
2792
|
const nextCss = stripBundlerGeneratedCssMarkers(rawSource);
|
|
1604
2793
|
applyCssResult(nextCss);
|
|
1605
2794
|
markCssAssetProcessed?.(originalSource, outputFile);
|
|
1606
2795
|
recordCssAssetResult?.(outputFile, nextCss);
|
|
2796
|
+
const shouldInjectPreservedViteCssIntoMain = vitePipelineCssAsset && !isAppOriginCssFile(file) && shouldInjectCssIntoMainFromOutput(outputFile, generatorSourceFile, outputCssHandlerOptions);
|
|
2797
|
+
recordViteProcessedCssAssetResult?.(outputFile, nextCss, {
|
|
2798
|
+
injectIntoMain: isAppOriginCssFile(file) ? false : shouldInjectPreservedViteCssIntoMain,
|
|
2799
|
+
outputFile
|
|
2800
|
+
});
|
|
1607
2801
|
onUpdate(outputFile, rawSource, nextCss);
|
|
1608
2802
|
debug("css skip vite-processed asset: %s", outputFile);
|
|
1609
2803
|
continue;
|
|
1610
2804
|
}
|
|
1611
|
-
const trackedGeneratorCandidateSignature = shouldTrackGeneratorRuntime ?
|
|
1612
|
-
const scopedGeneratorCandidateSignature = shouldTrackGeneratorRuntime ? await createScopedGeneratorCandidateSignature(generatorRawSource, generatorSourceFile, trackedGeneratorCandidateSignature,
|
|
2805
|
+
const trackedGeneratorCandidateSignature = shouldTrackGeneratorRuntime ? createCandidateSignature(scopedGeneratorRuntime) : "generator:stable";
|
|
2806
|
+
const scopedGeneratorCandidateSignature = shouldTrackGeneratorRuntime ? await createScopedGeneratorCandidateSignature(generatorRawSource, generatorSourceFile, trackedGeneratorCandidateSignature, scopedSourceCandidateGetter, { includeFallbackSignature: cssHandlerOptions.isMainChunk }) : trackedGeneratorCandidateSignature;
|
|
1613
2807
|
const cssRuntimeSignature = createCssRuntimeSignature(runtimeSignature, scopedGeneratorCandidateSignature);
|
|
1614
2808
|
const rememberedCssRuntimeSignature = createRememberedCssRuntimeSignature(cssRuntimeSignature, cssRuntimeAffectingHash);
|
|
1615
|
-
const cssSharedCacheKey = `${cssShareScope}:${cssRuntimeSignature}:${runtimeState.twPatcher.majorVersion ?? "unknown"}:${cssHandlerOptions.isMainChunk ? "1" : "0"}:${cssRuntimeAffectingSignature}`;
|
|
2809
|
+
const cssSharedCacheKey = `${cssShareScope}:${cssRuntimeSignature}:${runtimeState.twPatcher.majorVersion ?? "unknown"}:${cssHandlerOptions.isMainChunk ? "1" : "0"}:${cssRuntimeAffectingSignature}:${sourceTraceSignature}`;
|
|
1616
2810
|
if (!shouldTrackGeneratorRuntime) {
|
|
1617
2811
|
const lastCss = lastCssResultByFile.get(outputFile) ?? lastCssResultByFile.get(file);
|
|
1618
2812
|
if (lastCss != null) {
|
|
@@ -1627,12 +2821,12 @@ function createGenerateBundleHook(context) {
|
|
|
1627
2821
|
cache,
|
|
1628
2822
|
cacheKey: file,
|
|
1629
2823
|
hashKey: `${file}:css:${cssRuntimeSignature}:${runtimeState.twPatcher.majorVersion ?? "unknown"}`,
|
|
1630
|
-
hash: `${cssRuntimeAffectingHash}:${scopedGeneratorCandidateSignature}`,
|
|
2824
|
+
hash: `${cssRuntimeAffectingHash}:${scopedGeneratorCandidateSignature}:${sourceTraceSignature}`,
|
|
1631
2825
|
applyResult(source) {
|
|
1632
2826
|
applyCssResult(source);
|
|
1633
2827
|
lastCssResultByFile.set(outputFile, source);
|
|
1634
2828
|
markCssAssetProcessed?.(originalSource, outputFile);
|
|
1635
|
-
rememberCssSource?.({
|
|
2829
|
+
if (rememberedCssSources.length <= 1) rememberCssSource?.({
|
|
1636
2830
|
outputFile,
|
|
1637
2831
|
rawSource: generatorRawSource,
|
|
1638
2832
|
sourceFile: generatorSourceFile
|
|
@@ -1656,43 +2850,51 @@ function createGenerateBundleHook(context) {
|
|
|
1656
2850
|
const runTransform = async () => {
|
|
1657
2851
|
const start = performance.now();
|
|
1658
2852
|
await runtimeState.readyPromise;
|
|
1659
|
-
const previousCss = !vitePipelineCssAsset && useIncrementalMode && !hasRuntimeAffectingChanges && !snapshot.changedByType.css.has(file) ? lastCssResultByFile.get(outputFile) ?? lastCssResultByFile.get(file) : void 0;
|
|
1660
2853
|
const generated = await generateCssByGenerator({
|
|
1661
2854
|
opts,
|
|
1662
2855
|
runtimeState,
|
|
1663
|
-
runtime:
|
|
2856
|
+
runtime: scopedGeneratorRuntime,
|
|
1664
2857
|
rawSource: generatorRawSource,
|
|
1665
2858
|
file: generatorSourceFile,
|
|
1666
2859
|
cssHandlerOptions,
|
|
1667
2860
|
cssUserHandlerOptions: generatorCssUserHandlerOptions,
|
|
1668
|
-
getSourceCandidatesForEntries,
|
|
2861
|
+
getSourceCandidatesForEntries: scopedSourceCandidateGetter,
|
|
1669
2862
|
styleHandler,
|
|
1670
2863
|
debug,
|
|
1671
|
-
previousCss
|
|
2864
|
+
previousCss: !vitePipelineCssAsset && useIncrementalMode && !hasRuntimeAffectingChanges && !snapshot.changedByType.css.has(file) ? lastCssResultByFile.get(outputFile) ?? lastCssResultByFile.get(file) : void 0
|
|
1672
2865
|
});
|
|
1673
2866
|
if (generated) {
|
|
2867
|
+
const tracedCss = annotateCss(generated.css);
|
|
1674
2868
|
registerGeneratorDependencies$1({ addWatchFile }, generated.dependencies);
|
|
1675
|
-
if (debugCssDiff) debug("css diff %s: %s", generatorSourceFile, summarizeStringDiff(generatorRawSource,
|
|
1676
|
-
debug("css generated result: %s bytes=%d", file,
|
|
1677
|
-
recordCssAssetResult?.(outputFile,
|
|
1678
|
-
|
|
1679
|
-
|
|
2869
|
+
if (debugCssDiff) debug("css diff %s: %s", generatorSourceFile, summarizeStringDiff(generatorRawSource, tracedCss));
|
|
2870
|
+
debug("css generated result: %s bytes=%d", file, tracedCss.length);
|
|
2871
|
+
recordCssAssetResult?.(outputFile, tracedCss);
|
|
2872
|
+
const shouldInjectVitePipelineCssIntoMain = vitePipelineCssAsset && !isAppOriginCssFile(file) && shouldInjectCssIntoMainFromOutput(outputFile, generatorSourceFile, outputCssHandlerOptions);
|
|
2873
|
+
recordViteProcessedCssAssetResult?.(outputFile, tracedCss, {
|
|
2874
|
+
injectIntoMain: isAppOriginCssFile(file) ? false : shouldInjectVitePipelineCssIntoMain,
|
|
2875
|
+
outputFile
|
|
2876
|
+
});
|
|
2877
|
+
if (vitePipelineCssAsset && shouldInjectVitePipelineCssIntoMain) recordViteProcessedCssAssetResult?.(file, tracedCss, {
|
|
2878
|
+
injectIntoMain: isAppOriginCssFile(file) ? false : shouldInjectVitePipelineCssIntoMain,
|
|
2879
|
+
outputFile
|
|
2880
|
+
});
|
|
1680
2881
|
metrics.css.elapsed += measureElapsed(start);
|
|
1681
2882
|
metrics.css.transformed++;
|
|
1682
2883
|
debug("css handle via tailwind v%s engine(%s): %s", runtimeState.twPatcher.majorVersion, generated.target, outputFile);
|
|
1683
|
-
return
|
|
2884
|
+
return tracedCss;
|
|
1684
2885
|
}
|
|
1685
2886
|
if (isWebGeneratorTarget) {
|
|
1686
2887
|
metrics.css.elapsed += measureElapsed(start);
|
|
1687
2888
|
metrics.css.transformed++;
|
|
1688
2889
|
debug("css preserve web target: %s", outputFile);
|
|
1689
|
-
return rawSource;
|
|
2890
|
+
return annotateCss(rawSource);
|
|
1690
2891
|
}
|
|
1691
2892
|
const { css } = await styleHandler(generatorRawSource, cssHandlerOptions);
|
|
1692
|
-
|
|
2893
|
+
const tracedCss = annotateCss(css);
|
|
2894
|
+
if (debugCssDiff) debug("css diff %s: %s", generatorSourceFile, summarizeStringDiff(generatorRawSource, tracedCss));
|
|
1693
2895
|
metrics.css.elapsed += measureElapsed(start);
|
|
1694
2896
|
metrics.css.transformed++;
|
|
1695
|
-
return
|
|
2897
|
+
return tracedCss;
|
|
1696
2898
|
};
|
|
1697
2899
|
const cssTask = cssSharedCacheKey ? sharedCssResultCache.get(cssSharedCacheKey) ?? runTransform() : runTransform();
|
|
1698
2900
|
if (cssSharedCacheKey && !sharedCssResultCache.has(cssSharedCacheKey)) sharedCssResultCache.set(cssSharedCacheKey, cssTask);
|
|
@@ -1765,9 +2967,10 @@ function createGenerateBundleHook(context) {
|
|
|
1765
2967
|
const factory = createUniAppXAssetTask(file, originalSource, outDir, {
|
|
1766
2968
|
cache,
|
|
1767
2969
|
hashKey: `${file}:js`,
|
|
1768
|
-
hashSalt: createJsHashSalt(runtimeSignature, useIncrementalMode ? createLinkedImpactSignature(file, snapshot.linkedImpactsByEntry, snapshot.sourceHashByFile) : void 0),
|
|
2970
|
+
hashSalt: createJsHashSalt(runtimeSignature, [UNI_APP_X_STYLE_PLACEHOLDER_VERSION, useIncrementalMode ? createLinkedImpactSignature(file, snapshot.linkedImpactsByEntry, snapshot.sourceHashByFile) : void 0].filter(Boolean).join(":")),
|
|
1769
2971
|
createHandlerOptions,
|
|
1770
2972
|
debug,
|
|
2973
|
+
getAssetSource: createUniAppXBundleAssetSourceGetter(bundle),
|
|
1771
2974
|
jsHandler,
|
|
1772
2975
|
onUpdate,
|
|
1773
2976
|
runtimeSet: transformRuntime,
|
|
@@ -1804,61 +3007,146 @@ function createGenerateBundleHook(context) {
|
|
|
1804
3007
|
});
|
|
1805
3008
|
}
|
|
1806
3009
|
}
|
|
1807
|
-
if (useIncrementalMode || isNativeAppStyleTarget)
|
|
1808
|
-
const
|
|
1809
|
-
const outputFile
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
const
|
|
1815
|
-
|
|
3010
|
+
if (useIncrementalMode || isNativeAppStyleTarget) {
|
|
3011
|
+
const rememberedReplayGroups = collectRememberedCssReplayGroups(getRememberedCssSources?.(), opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension);
|
|
3012
|
+
for (const [outputFile, rememberedGroup] of rememberedReplayGroups) {
|
|
3013
|
+
const refreshedRememberedGroup = await Promise.all(rememberedGroup.map(async (item) => ({
|
|
3014
|
+
key: item.key,
|
|
3015
|
+
remembered: await refreshRememberedCssSource?.(item.remembered) ?? item.remembered
|
|
3016
|
+
})));
|
|
3017
|
+
const rememberedCssSource = mergeRememberedCssSources(refreshedRememberedGroup.map((item) => item.remembered), outputFile);
|
|
3018
|
+
if (!rememberedCssSource) continue;
|
|
3019
|
+
const { rawSource, sourceFile } = rememberedCssSource;
|
|
3020
|
+
const outputCssHandlerOptions = getCssHandlerOptions(outputFile);
|
|
3021
|
+
const cssHandlerOptions = {
|
|
3022
|
+
...getCssHandlerOptions(sourceFile),
|
|
3023
|
+
isMainChunk: outputCssHandlerOptions.isMainChunk || isMainStyleEntryCssFile(sourceFile)
|
|
3024
|
+
};
|
|
3025
|
+
const scopedSourceCandidateGetter = createScopedSourceCandidateGetter(outputFile, cssHandlerOptions);
|
|
3026
|
+
const scopedSourceCandidateSourceGetter = createScopedSourceCandidateSourceGetter(outputFile, cssHandlerOptions);
|
|
3027
|
+
const sourceTraceTokenSources = scopedSourceCandidateSourceGetter ? createCssTokenSourceMap(scopedSourceCandidateSourceGetter(void 0), opts) : void 0;
|
|
3028
|
+
const annotateCss = (css) => annotateCssSourceTrace(css, {
|
|
1816
3029
|
opts,
|
|
1817
|
-
|
|
1818
|
-
runtime: generatorRuntime,
|
|
1819
|
-
rawSource,
|
|
1820
|
-
file: sourceFile,
|
|
1821
|
-
cssHandlerOptions,
|
|
1822
|
-
cssUserHandlerOptions: getCssUserHandlerOptions(outputFile),
|
|
1823
|
-
getSourceCandidatesForEntries,
|
|
1824
|
-
styleHandler,
|
|
1825
|
-
debug
|
|
1826
|
-
});
|
|
1827
|
-
const css = generated?.css ?? (await styleHandler(rawSource, cssHandlerOptions)).css;
|
|
1828
|
-
setRememberedCssSignature?.(key, rememberedCssRuntimeSignature);
|
|
1829
|
-
if (generated) {
|
|
1830
|
-
registerGeneratorDependencies$1({ addWatchFile }, generated.dependencies);
|
|
1831
|
-
recordCssAssetResult?.(outputFile, generated.css);
|
|
1832
|
-
recordViteProcessedCssAssetResult?.(sourceFile, generated.css, { injectIntoMain: cssHandlerOptions.isMainChunk });
|
|
1833
|
-
debug("css replay generated result: %s bytes=%d", outputFile, css.length);
|
|
1834
|
-
}
|
|
1835
|
-
const replayAsset = createReplayCssAsset(outputFile, css);
|
|
1836
|
-
if (typeof this.emitFile === "function") this.emitFile({
|
|
1837
|
-
type: "asset",
|
|
1838
|
-
fileName: outputFile,
|
|
1839
|
-
source: css
|
|
3030
|
+
tokenSources: sourceTraceTokenSources
|
|
1840
3031
|
});
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
3032
|
+
const scopedGeneratorRuntime = createScopedGeneratorRuntime(outputFile, cssHandlerOptions, generatorRuntime);
|
|
3033
|
+
const rememberedCssRuntimeSignature = createRememberedCssRuntimeSignature(createCssRuntimeSignature(createCandidateSignature(scopedGeneratorRuntime), await createScopedGeneratorCandidateSignature(rawSource, sourceFile, createCandidateSignature(scopedGeneratorRuntime), scopedSourceCandidateGetter, { includeFallbackSignature: cssHandlerOptions.isMainChunk })), cache.computeHash(createRuntimeAffectingSourceSignature(rawSource, "css")));
|
|
3034
|
+
const rememberedKeys = refreshedRememberedGroup.map((item) => item.key);
|
|
3035
|
+
const allRememberedSignaturesFresh = rememberedKeys.length > 0 && rememberedKeys.every((key) => getRememberedCssSignature?.(key) === rememberedCssRuntimeSignature);
|
|
3036
|
+
if (bundleFiles.includes(outputFile) || bundleFiles.includes(sourceFile) || allRememberedSignaturesFresh) continue;
|
|
3037
|
+
tasks.push(timeTask("css.replay", async () => {
|
|
3038
|
+
const start = performance.now();
|
|
3039
|
+
const generated = await generateCssByGenerator({
|
|
3040
|
+
opts,
|
|
3041
|
+
runtimeState,
|
|
3042
|
+
runtime: scopedGeneratorRuntime,
|
|
3043
|
+
rawSource,
|
|
3044
|
+
file: sourceFile,
|
|
3045
|
+
cssHandlerOptions,
|
|
3046
|
+
cssUserHandlerOptions: getCssUserHandlerOptions(sourceFile),
|
|
3047
|
+
getSourceCandidatesForEntries: scopedSourceCandidateGetter,
|
|
3048
|
+
styleHandler,
|
|
3049
|
+
debug
|
|
3050
|
+
});
|
|
3051
|
+
const css = annotateCss(generated?.css ?? (await styleHandler(rawSource, cssHandlerOptions)).css);
|
|
3052
|
+
for (const key of rememberedKeys) setRememberedCssSignature?.(key, rememberedCssRuntimeSignature);
|
|
3053
|
+
if (generated) {
|
|
3054
|
+
registerGeneratorDependencies$1({ addWatchFile }, generated.dependencies);
|
|
3055
|
+
recordCssAssetResult?.(outputFile, css);
|
|
3056
|
+
const shouldInjectReplayCssIntoMain = shouldInjectCssIntoMainFromOutput(outputFile, sourceFile, outputCssHandlerOptions);
|
|
3057
|
+
recordViteProcessedCssAssetResult?.(sourceFile, css, {
|
|
3058
|
+
injectIntoMain: isAppOriginCssFile(outputFile) ? false : shouldInjectReplayCssIntoMain,
|
|
3059
|
+
outputFile
|
|
3060
|
+
});
|
|
3061
|
+
debug("css replay generated result: %s bytes=%d", outputFile, css.length);
|
|
3062
|
+
}
|
|
3063
|
+
const replayAsset = createReplayCssAsset(outputFile, css);
|
|
3064
|
+
if (typeof this.emitFile === "function") this.emitFile({
|
|
3065
|
+
type: "asset",
|
|
3066
|
+
fileName: outputFile,
|
|
3067
|
+
source: css
|
|
3068
|
+
});
|
|
3069
|
+
else bundle[outputFile] = replayAsset;
|
|
3070
|
+
markCssAssetProcessed?.(replayAsset, outputFile);
|
|
3071
|
+
metrics.css.elapsed += measureElapsed(start);
|
|
3072
|
+
metrics.css.transformed++;
|
|
3073
|
+
onUpdate(outputFile, rawSource, css);
|
|
3074
|
+
debug("css replay handle: %s", outputFile);
|
|
3075
|
+
}));
|
|
3076
|
+
}
|
|
1848
3077
|
}
|
|
1849
3078
|
pushConcurrentTaskFactories(tasks, jsTaskFactories);
|
|
1850
3079
|
const tasksStart = performance.now();
|
|
1851
3080
|
await Promise.all(tasks);
|
|
1852
3081
|
recordTimingDetail("tasks", tasksStart);
|
|
1853
3082
|
for (const apply of pendingLinkedUpdates) apply();
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
3083
|
+
const applyStyleSources = collectUniAppXHarmonyApplyStyleSources(bundle);
|
|
3084
|
+
if (opts.appType === "uni-app-x" || isNativeAppStyleTarget || isHarmonyAppStyleTarget) {
|
|
3085
|
+
const getAssetSource = createUniAppXBundleAssetSourceGetter(bundle);
|
|
3086
|
+
const viteProcessedCssSources = [...getViteProcessedCssAssetResults?.() ?? []].map(([, record]) => typeof record === "string" ? record : record.css);
|
|
3087
|
+
const applyUtilities = collectUniAppXHarmonyApplyUtilities(bundle);
|
|
3088
|
+
const shouldInjectHarmonyBundleStyles = isHarmonyAppStyleTarget;
|
|
3089
|
+
if (shouldInjectHarmonyBundleStyles) {
|
|
3090
|
+
if (applyUtilities.size > 0 && applyStyleSources.length > 0) {
|
|
3091
|
+
const outputFile = "uni-app-x-harmony-apply.css";
|
|
3092
|
+
const cssHandlerOptions = getCssHandlerOptions(outputFile);
|
|
3093
|
+
const generated = await generateCssByGenerator({
|
|
3094
|
+
opts,
|
|
3095
|
+
runtimeState,
|
|
3096
|
+
runtime: new Set([...generatorRuntime, ...applyUtilities]),
|
|
3097
|
+
rawSource: createUniAppXHarmonyApplyGeneratorSource(applyStyleSources, applyUtilities),
|
|
3098
|
+
file: outputFile,
|
|
3099
|
+
cssHandlerOptions,
|
|
3100
|
+
cssUserHandlerOptions: {
|
|
3101
|
+
...cssHandlerOptions,
|
|
3102
|
+
isMainChunk: false
|
|
3103
|
+
},
|
|
3104
|
+
getSourceCandidatesForEntries,
|
|
3105
|
+
styleHandler,
|
|
3106
|
+
debug
|
|
3107
|
+
});
|
|
3108
|
+
if (generated?.css) viteProcessedCssSources.push(annotateCssSourceTrace(generated.css, {
|
|
3109
|
+
opts,
|
|
3110
|
+
tokenSources: getSourceCandidateSourcesForEntries ? createCssTokenSourceMap(getSourceCandidateSourcesForEntries(void 0), opts) : void 0
|
|
3111
|
+
}));
|
|
3112
|
+
}
|
|
3113
|
+
}
|
|
3114
|
+
if (shouldInjectHarmonyBundleStyles && injectUniAppXHarmonyBundleStyles(bundle, { cssSources: viteProcessedCssSources })) debug("uni-app-x harmony bundle styles inject");
|
|
3115
|
+
for (const [file, item] of Object.entries(bundle)) {
|
|
3116
|
+
if (item.type !== "asset" || !file.endsWith(".uvue.ts")) continue;
|
|
3117
|
+
const currentSource = String(item.source);
|
|
3118
|
+
const nextSource = injectUniAppXStylePlaceholder(file, currentSource, getAssetSource);
|
|
3119
|
+
if (nextSource !== currentSource) {
|
|
3120
|
+
item.source = nextSource;
|
|
3121
|
+
onUpdate(file, currentSource, nextSource);
|
|
3122
|
+
debug("uni-app-x style placeholder inject: %s", file);
|
|
3123
|
+
}
|
|
3124
|
+
}
|
|
3125
|
+
}
|
|
3126
|
+
const syncViteProcessedCssIntoMainCssAssets = () => {
|
|
3127
|
+
collectViteProcessedCssAssetResults(bundle, {
|
|
3128
|
+
opts,
|
|
3129
|
+
isViteProcessedCssAsset,
|
|
3130
|
+
markCssAssetProcessed,
|
|
3131
|
+
recordCssAssetResult,
|
|
3132
|
+
recordViteProcessedCssAssetResult,
|
|
3133
|
+
resolveViteProcessedCssOutputFile: (file) => resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension),
|
|
3134
|
+
debug
|
|
3135
|
+
});
|
|
3136
|
+
return injectViteProcessedCssIntoMainCssAssets(bundle, {
|
|
3137
|
+
opts,
|
|
3138
|
+
getViteProcessedCssAssetResults,
|
|
3139
|
+
markCssAssetProcessed,
|
|
3140
|
+
recordCssAssetResult,
|
|
3141
|
+
debug,
|
|
3142
|
+
onUpdate
|
|
3143
|
+
});
|
|
3144
|
+
};
|
|
3145
|
+
syncViteProcessedCssIntoMainCssAssets();
|
|
3146
|
+
if (isHarmonyAppStyleTarget && applyStyleSources.length > 0) {
|
|
3147
|
+
if (injectUniAppXHarmonyBundleStyles(bundle, { cssSources: [...getViteProcessedCssAssetResults?.() ?? []].map(([, record]) => typeof record === "string" ? record : record.css) })) debug("uni-app-x harmony bundle styles inject after css assets");
|
|
3148
|
+
syncViteProcessedCssIntoMainCssAssets();
|
|
3149
|
+
}
|
|
1862
3150
|
const stateUpdateStart = performance.now();
|
|
1863
3151
|
updateBundleBuildState(state, snapshot, useIncrementalMode ? linkedByEntry ?? /* @__PURE__ */ new Map() : /* @__PURE__ */ new Map(), { incremental: useIncrementalMode });
|
|
1864
3152
|
state.generatorCandidateSignature = generatorCandidateSignature;
|
|
@@ -1909,6 +3197,9 @@ function shouldGenerateCssByGenerator(opts, file, rawSource, processed) {
|
|
|
1909
3197
|
function shouldFinalizeProcessedCssAsset(opts, file) {
|
|
1910
3198
|
return opts.mainCssChunkMatcher(file, opts.appType);
|
|
1911
3199
|
}
|
|
3200
|
+
function collectViteProcessedCssSources(getViteProcessedCssAssetResults) {
|
|
3201
|
+
return [...getViteProcessedCssAssetResults?.() ?? []].map(([, record]) => typeof record === "string" ? record : record.css);
|
|
3202
|
+
}
|
|
1912
3203
|
function createViteCssFinalizerOutputPlugin(context) {
|
|
1913
3204
|
return {
|
|
1914
3205
|
name: "weapp-tailwindcss:adaptor:css-finalizer",
|
|
@@ -1916,29 +3207,34 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
1916
3207
|
generateBundle: {
|
|
1917
3208
|
order: "post",
|
|
1918
3209
|
async handler(_options, bundle) {
|
|
1919
|
-
const { opts, runtimeState, ensureRuntimeClassSet, isCssAssetProcessed, markCssAssetProcessed, debug, getResolvedConfig, recordCssAssetResult, recordViteProcessedCssAssetResult, getViteProcessedCssAssetResults, getRecordedGeneratorCandidates, getSourceCandidates, getSourceCandidatesForEntries, waitForSourceCandidateSyncs, rememberMainCssSource, getRememberedMainCssSource, isViteProcessedCssAsset } = context;
|
|
3210
|
+
const { opts, runtimeState, ensureRuntimeClassSet, isCssAssetProcessed, markCssAssetProcessed, debug, getResolvedConfig, recordCssAssetResult, recordViteProcessedCssAssetResult, getViteProcessedCssAssetResults, getRecordedGeneratorCandidates, getSourceCandidates, getSourceCandidatesForEntries, getSourceCandidateSourcesForEntries, waitForSourceCandidateSyncs, rememberMainCssSource, getRememberedMainCssSource, isViteProcessedCssAsset } = context;
|
|
1920
3211
|
const resolvedConfig = getResolvedConfig();
|
|
1921
|
-
if (resolvedConfig?.command !== "build") return;
|
|
1922
3212
|
const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(opts.generator);
|
|
1923
3213
|
const isWebGeneratorTarget = generatorOptions.target === "web";
|
|
1924
|
-
const
|
|
1925
|
-
const
|
|
1926
|
-
|
|
3214
|
+
const uniUtsPlatform = resolveUniUtsPlatform();
|
|
3215
|
+
const canInferHarmonyAppStyleTarget = !uniUtsPlatform.normalized || uniUtsPlatform.isApp;
|
|
3216
|
+
const isHarmonyAppStyleTarget = uniUtsPlatform.isAppHarmony || canInferHarmonyAppStyleTarget && (isUniAppXHarmonyBundle(bundle) || isUniAppXHarmonyOutDir(resolvedConfig?.build?.outDir));
|
|
3217
|
+
const isNativeAppStyleTarget = uniUtsPlatform.isApp || isHarmonyAppStyleTarget;
|
|
3218
|
+
if (resolvedConfig?.command !== "build" && !isNativeAppStyleTarget) return;
|
|
3219
|
+
const rootDir = resolvedConfig?.root ? path.resolve(resolvedConfig.root) : process$1.cwd();
|
|
3220
|
+
const sourceTraceTokenSources = getSourceCandidateSourcesForEntries ? createCssTokenSourceMap(getSourceCandidateSourcesForEntries(void 0), opts) : void 0;
|
|
3221
|
+
const annotateCss = (css) => annotateCssSourceTrace(css, {
|
|
1927
3222
|
opts,
|
|
1928
|
-
|
|
1929
|
-
markCssAssetProcessed,
|
|
1930
|
-
recordCssAssetResult,
|
|
1931
|
-
recordViteProcessedCssAssetResult,
|
|
1932
|
-
resolveViteProcessedCssOutputFile: (file) => resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget, isNativeAppStyleTarget),
|
|
1933
|
-
debug
|
|
3223
|
+
tokenSources: sourceTraceTokenSources
|
|
1934
3224
|
});
|
|
1935
|
-
const
|
|
1936
|
-
|
|
1937
|
-
|
|
3225
|
+
const collectViteProcessedCssAssets = () => {
|
|
3226
|
+
collectViteProcessedCssAssetResults(bundle, {
|
|
3227
|
+
opts,
|
|
3228
|
+
isViteProcessedCssAsset,
|
|
3229
|
+
markCssAssetProcessed,
|
|
3230
|
+
recordCssAssetResult,
|
|
3231
|
+
recordViteProcessedCssAssetResult,
|
|
3232
|
+
resolveViteProcessedCssOutputFile: (file) => resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget, isNativeAppStyleTarget),
|
|
3233
|
+
debug
|
|
3234
|
+
});
|
|
1938
3235
|
};
|
|
1939
|
-
const
|
|
1940
|
-
|
|
1941
|
-
injectViteProcessedCssIntoMainCssAssets(bundle, {
|
|
3236
|
+
const injectViteProcessedCssIntoMainCss = () => {
|
|
3237
|
+
return injectViteProcessedCssIntoMainCssAssets(bundle, {
|
|
1942
3238
|
opts,
|
|
1943
3239
|
getViteProcessedCssAssetResults,
|
|
1944
3240
|
markCssAssetProcessed,
|
|
@@ -1946,6 +3242,46 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
1946
3242
|
debug,
|
|
1947
3243
|
onUpdate: opts.onUpdate
|
|
1948
3244
|
});
|
|
3245
|
+
};
|
|
3246
|
+
collectViteProcessedCssAssets();
|
|
3247
|
+
const createHarmonyBundleStyleSources = async (runtime) => {
|
|
3248
|
+
const cssSources = collectViteProcessedCssSources(getViteProcessedCssAssetResults);
|
|
3249
|
+
const applyUtilities = collectUniAppXHarmonyApplyUtilities(bundle);
|
|
3250
|
+
const applyStyleSources = collectUniAppXHarmonyApplyStyleSources(bundle);
|
|
3251
|
+
if (applyUtilities.size === 0 || applyStyleSources.length === 0) return cssSources;
|
|
3252
|
+
const harmonyRuntime = new Set([...runtime, ...applyUtilities]);
|
|
3253
|
+
const harmonyCssHandlerOptions = createCssHandlerOptions(opts, runtimeState.twPatcher.majorVersion, "uni-app-x-harmony-apply.css");
|
|
3254
|
+
const generated = await generateCssByGenerator({
|
|
3255
|
+
opts,
|
|
3256
|
+
runtimeState,
|
|
3257
|
+
runtime: harmonyRuntime,
|
|
3258
|
+
rawSource: createUniAppXHarmonyApplyGeneratorSource(applyStyleSources, applyUtilities),
|
|
3259
|
+
file: "uni-app-x-harmony-apply.css",
|
|
3260
|
+
cssHandlerOptions: harmonyCssHandlerOptions,
|
|
3261
|
+
cssUserHandlerOptions: {
|
|
3262
|
+
...harmonyCssHandlerOptions,
|
|
3263
|
+
isMainChunk: false
|
|
3264
|
+
},
|
|
3265
|
+
getSourceCandidatesForEntries,
|
|
3266
|
+
styleHandler: opts.styleHandler,
|
|
3267
|
+
debug
|
|
3268
|
+
});
|
|
3269
|
+
if (generated?.css) cssSources.push(annotateCss(generated.css));
|
|
3270
|
+
return cssSources;
|
|
3271
|
+
};
|
|
3272
|
+
const injectHarmonyBundleStyles = async (runtime) => {
|
|
3273
|
+
if (!isHarmonyAppStyleTarget) return;
|
|
3274
|
+
if (injectUniAppXHarmonyBundleStyles(bundle, { cssSources: await createHarmonyBundleStyleSources(runtime) })) debug("uni-app-x harmony bundle styles inject");
|
|
3275
|
+
};
|
|
3276
|
+
const isCssOutputAssetEntry = (entry) => {
|
|
3277
|
+
const [, output] = entry;
|
|
3278
|
+
return output.type === "asset" && opts.cssMatcher(output.fileName) && !isCssAssetProcessed(output, output.fileName);
|
|
3279
|
+
};
|
|
3280
|
+
const entries = Object.entries(bundle).filter(isCssOutputAssetEntry);
|
|
3281
|
+
if (entries.length === 0) {
|
|
3282
|
+
await injectHarmonyBundleStyles(getRecordedGeneratorCandidates?.() ?? getSourceCandidates?.() ?? await ensureRuntimeClassSet());
|
|
3283
|
+
collectViteProcessedCssAssets();
|
|
3284
|
+
injectViteProcessedCssIntoMainCss();
|
|
1949
3285
|
return;
|
|
1950
3286
|
}
|
|
1951
3287
|
await runtimeState.readyPromise;
|
|
@@ -1957,7 +3293,7 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
1957
3293
|
const file = output.fileName || bundleFile;
|
|
1958
3294
|
const rawSource = output.source.toString();
|
|
1959
3295
|
if (isViteProcessedCssAsset?.(output, file)) {
|
|
1960
|
-
const nextCss = stripBundlerGeneratedCssMarkers(rawSource);
|
|
3296
|
+
const nextCss = annotateCss(stripBundlerGeneratedCssMarkers(rawSource));
|
|
1961
3297
|
output.source = nextCss;
|
|
1962
3298
|
markCssAssetProcessed(output, file);
|
|
1963
3299
|
recordCssAssetResult?.(file, nextCss);
|
|
@@ -1990,7 +3326,7 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
1990
3326
|
styleHandler: opts.styleHandler,
|
|
1991
3327
|
debug
|
|
1992
3328
|
}) : void 0;
|
|
1993
|
-
const nextCss = generated?.css ?? (generatorOptions.target === "web" ? rawSource : (await opts.styleHandler(rawSource, cssHandlerOptions)).css);
|
|
3329
|
+
const nextCss = annotateCss(generated?.css ?? (generatorOptions.target === "web" ? rawSource : (await opts.styleHandler(rawSource, cssHandlerOptions)).css));
|
|
1994
3330
|
if (generated) {
|
|
1995
3331
|
registerGeneratorDependencies(this, generated.dependencies);
|
|
1996
3332
|
debug("css finalizer generated result: %s bytes=%d", file, nextCss.length);
|
|
@@ -2002,14 +3338,9 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
2002
3338
|
opts.onUpdate(file, rawSource, nextCss);
|
|
2003
3339
|
debug("css finalizer handle: %s", file);
|
|
2004
3340
|
}));
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
markCssAssetProcessed,
|
|
2009
|
-
recordCssAssetResult,
|
|
2010
|
-
debug,
|
|
2011
|
-
onUpdate: opts.onUpdate
|
|
2012
|
-
});
|
|
3341
|
+
await injectHarmonyBundleStyles(generatorRuntime);
|
|
3342
|
+
collectViteProcessedCssAssets();
|
|
3343
|
+
injectViteProcessedCssIntoMainCss();
|
|
2013
3344
|
}
|
|
2014
3345
|
}
|
|
2015
3346
|
};
|
|
@@ -2261,8 +3592,14 @@ function createViteRuntimeClassSet(options) {
|
|
|
2261
3592
|
readyPromise: createTailwindRuntimeReadyPromise(initialTwPatcher),
|
|
2262
3593
|
refreshTailwindcssPatcher
|
|
2263
3594
|
};
|
|
2264
|
-
const bundleRuntimeClassSetManager = createBundleRuntimeClassSetManager({
|
|
2265
|
-
|
|
3595
|
+
const bundleRuntimeClassSetManager = createBundleRuntimeClassSetManager({
|
|
3596
|
+
bareArbitraryValues: opts.arbitraryValues?.bareArbitraryValues,
|
|
3597
|
+
escapeMap: opts.escapeMap
|
|
3598
|
+
});
|
|
3599
|
+
const transformRuntimeClassSetManager = createBundleRuntimeClassSetManager({
|
|
3600
|
+
bareArbitraryValues: opts.arbitraryValues?.bareArbitraryValues,
|
|
3601
|
+
escapeMap: opts.escapeMap
|
|
3602
|
+
});
|
|
2266
3603
|
let runtimeSet;
|
|
2267
3604
|
let runtimeSetPromise;
|
|
2268
3605
|
let runtimeRefreshSignature;
|
|
@@ -2490,6 +3827,7 @@ const weappTailwindcssPackageDir = resolvePackageDir("weapp-tailwindcss");
|
|
|
2490
3827
|
const weappTailwindcssDirPosix = slash(weappTailwindcssPackageDir);
|
|
2491
3828
|
const sourceCandidateScanSnapshotCache = /* @__PURE__ */ new Map();
|
|
2492
3829
|
const SFC_STYLE_BLOCK_RE = /<style\b[^>]*>([\s\S]*?)<\/style>/gi;
|
|
3830
|
+
const SFC_COMPONENT_FILE_RE = /\.(?:vue|uvue|nvue|svelte|mpx)$/i;
|
|
2493
3831
|
function normalizeSignaturePath(value) {
|
|
2494
3832
|
return slash(path.resolve(value));
|
|
2495
3833
|
}
|
|
@@ -2521,6 +3859,10 @@ function stripSourceHash(sourceFile) {
|
|
|
2521
3859
|
const hashIndex = sourceFile.indexOf("#");
|
|
2522
3860
|
return hashIndex === -1 ? sourceFile : sourceFile.slice(0, hashIndex);
|
|
2523
3861
|
}
|
|
3862
|
+
function isMainStyleEntryFile(file) {
|
|
3863
|
+
const name = path.basename(stripRequestQuery(cleanUrl(file))).replace(/\.[^.]+$/, "");
|
|
3864
|
+
return name === "app" || name === "main";
|
|
3865
|
+
}
|
|
2524
3866
|
function normalizeCssSourceIdentity(sourceFile) {
|
|
2525
3867
|
const cleanSourceFile = stripSourceHash(sourceFile);
|
|
2526
3868
|
const { filename, query } = parseVueRequest(cleanSourceFile);
|
|
@@ -2639,6 +3981,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
2639
3981
|
const viteProcessedCssAssetResults = /* @__PURE__ */ new Map();
|
|
2640
3982
|
const rememberedCssSources = /* @__PURE__ */ new Map();
|
|
2641
3983
|
const rememberedCssSignatureByFile = /* @__PURE__ */ new Map();
|
|
3984
|
+
const knownSfcSources = /* @__PURE__ */ new Map();
|
|
2642
3985
|
const tailwindRootCssModuleIds = /* @__PURE__ */ new Set();
|
|
2643
3986
|
const { runtimeState, refreshRuntimeState, ensureRuntimeClassSet, ensureBundleRuntimeClassSet } = createViteRuntimeClassSet({
|
|
2644
3987
|
opts,
|
|
@@ -2672,6 +4015,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
2672
4015
|
};
|
|
2673
4016
|
const getSourceCandidates = () => sourceCandidateCollector.values();
|
|
2674
4017
|
const getSourceCandidatesForEntries = (entries) => sourceCandidateCollector.valuesForEntries(entries);
|
|
4018
|
+
const getSourceCandidateSourcesForEntries = (entries, options) => sourceCandidateCollector.sourcesForEntries(entries, options);
|
|
2675
4019
|
const isWatchBuild = () => resolvedConfig?.command === "build" && resolvedConfig.build.watch != null;
|
|
2676
4020
|
const isWatchLikeBuild = () => isWatchBuild() || resolvedConfig?.command === "serve" || process$1.env["WEAPP_TW_WATCH_REGRESSION"] === "1" || process$1.env["WEAPP_TW_HMR_TIMING"] === "1";
|
|
2677
4021
|
const hasSourceCandidateScanState = () => sourceCandidateScanSignature !== void 0;
|
|
@@ -2779,19 +4123,18 @@ function WeappTailwindcss(options = {}) {
|
|
|
2779
4123
|
const syncChangedSourceCandidateFile = (id) => {
|
|
2780
4124
|
if (!shouldOwnTailwindGeneration || !isSourceCandidateRequest(id)) return Promise.resolve();
|
|
2781
4125
|
const file = cleanUrl(id);
|
|
2782
|
-
const refreshRememberedCssSourceTask = refreshRememberedCssSourceByCurrentFile(file);
|
|
2783
4126
|
if (isSourceScanDependency(file)) invalidateSourceCandidateScan();
|
|
2784
4127
|
if (sourceScanMatcher && !sourceScanMatcher(file)) {
|
|
2785
4128
|
sourceCandidateCollector.remove(file);
|
|
2786
4129
|
cacheCurrentSourceCandidateScan();
|
|
2787
|
-
return
|
|
4130
|
+
return refreshRememberedCssSourceByCurrentFile(file);
|
|
2788
4131
|
}
|
|
2789
4132
|
if (sourceScanExplicit && sourceScanEntries?.length === 0) {
|
|
2790
4133
|
cacheCurrentSourceCandidateScan();
|
|
2791
|
-
return
|
|
4134
|
+
return refreshRememberedCssSourceByCurrentFile(file);
|
|
2792
4135
|
}
|
|
2793
4136
|
const existingTask = pendingSourceCandidateSyncByFile.get(file);
|
|
2794
|
-
if (existingTask) return
|
|
4137
|
+
if (existingTask) return existingTask.then(() => refreshRememberedCssSourceByCurrentFile(file)).then(() => void 0);
|
|
2795
4138
|
const task = sourceCandidateCollector.syncCurrentFile(id).catch((error) => {
|
|
2796
4139
|
debug("source candidate watch sync failed: %s %O", id, error);
|
|
2797
4140
|
}).then(() => {
|
|
@@ -2802,18 +4145,37 @@ function WeappTailwindcss(options = {}) {
|
|
|
2802
4145
|
});
|
|
2803
4146
|
pendingSourceCandidateSyncs.add(task);
|
|
2804
4147
|
pendingSourceCandidateSyncByFile.set(file, task);
|
|
2805
|
-
return
|
|
4148
|
+
return task.then(() => refreshRememberedCssSourceByCurrentFile(file)).then(() => void 0);
|
|
2806
4149
|
};
|
|
2807
4150
|
const shouldCollectTransformedSourceCandidates = (id) => {
|
|
2808
4151
|
if (id.search(/[?#]/) < 0) return true;
|
|
2809
4152
|
const file = cleanUrl(id);
|
|
2810
|
-
return
|
|
4153
|
+
return !SFC_COMPONENT_FILE_RE.test(file);
|
|
4154
|
+
};
|
|
4155
|
+
const hasSfcStyleBlocks = (source) => {
|
|
4156
|
+
SFC_STYLE_BLOCK_RE.lastIndex = 0;
|
|
4157
|
+
return SFC_STYLE_BLOCK_RE.test(source);
|
|
4158
|
+
};
|
|
4159
|
+
const normalizeKnownSfcSourceKey = (file) => normalizeOutputPathKey(path.resolve(cleanUrl(file)));
|
|
4160
|
+
const rememberKnownSfcSource = (id, code) => {
|
|
4161
|
+
if (id.search(/[?#]/) >= 0) return;
|
|
4162
|
+
const file = cleanUrl(id);
|
|
4163
|
+
if (!SFC_COMPONENT_FILE_RE.test(file)) return;
|
|
4164
|
+
if (!hasSfcStyleBlocks(code)) return;
|
|
4165
|
+
knownSfcSources.set(normalizeKnownSfcSourceKey(file), code);
|
|
4166
|
+
};
|
|
4167
|
+
const getKnownSfcSource = (file) => {
|
|
4168
|
+
const scanSource = sourceCandidateCollector.source(file);
|
|
4169
|
+
if (scanSource && hasSfcStyleBlocks(scanSource)) return scanSource;
|
|
4170
|
+
return knownSfcSources.get(normalizeKnownSfcSourceKey(file));
|
|
2811
4171
|
};
|
|
2812
4172
|
const rememberCssSource = (entry, cssRuntimeSignature) => {
|
|
2813
|
-
const
|
|
4173
|
+
const outputKey = normalizeOutputPathKey(entry.outputFile);
|
|
4174
|
+
const normalizedSourceFile = normalizeCssSourceIdentity(entry.sourceFile);
|
|
4175
|
+
const previousOutputEntry = rememberedCssSources.get(outputKey);
|
|
4176
|
+
const key = previousOutputEntry != null && normalizeCssSourceIdentity(previousOutputEntry.sourceFile) !== normalizedSourceFile ? `${outputKey}\0${normalizedSourceFile}` : outputKey;
|
|
2814
4177
|
const previous = rememberedCssSources.get(key);
|
|
2815
4178
|
rememberedCssSources.set(key, entry);
|
|
2816
|
-
const normalizedSourceFile = normalizeCssSourceIdentity(entry.sourceFile);
|
|
2817
4179
|
for (const [rememberedKey, remembered] of rememberedCssSources) {
|
|
2818
4180
|
if (rememberedKey === key || normalizeCssSourceIdentity(remembered.sourceFile) !== normalizedSourceFile) continue;
|
|
2819
4181
|
rememberedCssSources.set(rememberedKey, {
|
|
@@ -2855,41 +4217,57 @@ function WeappTailwindcss(options = {}) {
|
|
|
2855
4217
|
match = SFC_STYLE_BLOCK_RE.exec(source);
|
|
2856
4218
|
}
|
|
2857
4219
|
};
|
|
4220
|
+
const extractSfcStyleSource = (source, index) => {
|
|
4221
|
+
if (index !== void 0) return extractSfcStyleBlock(source, index);
|
|
4222
|
+
const styleSources = [];
|
|
4223
|
+
SFC_STYLE_BLOCK_RE.lastIndex = 0;
|
|
4224
|
+
let match = SFC_STYLE_BLOCK_RE.exec(source);
|
|
4225
|
+
while (match !== null) {
|
|
4226
|
+
styleSources.push(match[1] ?? "");
|
|
4227
|
+
match = SFC_STYLE_BLOCK_RE.exec(source);
|
|
4228
|
+
}
|
|
4229
|
+
return styleSources.length > 0 ? styleSources.join("\n") : void 0;
|
|
4230
|
+
};
|
|
4231
|
+
const resolveCachedStyleSource = (sourceFile) => {
|
|
4232
|
+
const file = cleanUrl(stripRequestQuery(sourceFile));
|
|
4233
|
+
if (SFC_COMPONENT_FILE_RE.test(file)) return getKnownSfcSource(file);
|
|
4234
|
+
if (isSourceStyleRequest(file)) return sourceCandidateCollector.source(file);
|
|
4235
|
+
};
|
|
2858
4236
|
const refreshRememberedCssSourceByCurrentFile = async (sourceFile) => {
|
|
2859
4237
|
const file = cleanUrl(sourceFile);
|
|
2860
4238
|
const normalizedSourceFile = normalizeOutputPathKey(file);
|
|
2861
4239
|
const matchedRememberedSources = [...rememberedCssSources.values()].filter((remembered) => normalizeOutputPathKey(stripRequestQuery(cleanUrl(remembered.sourceFile))) === normalizedSourceFile);
|
|
2862
4240
|
if (matchedRememberedSources.length === 0) return;
|
|
2863
|
-
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
}
|
|
2871
|
-
|
|
4241
|
+
const source = resolveCachedStyleSource(file);
|
|
4242
|
+
if (source == null) {
|
|
4243
|
+
debug("refresh remembered css source skipped: missing cached source for %s", file);
|
|
4244
|
+
return;
|
|
4245
|
+
}
|
|
4246
|
+
if (SFC_COMPONENT_FILE_RE.test(file)) {
|
|
4247
|
+
for (const remembered of matchedRememberedSources) {
|
|
4248
|
+
const { query } = parseVueRequest(remembered.sourceFile);
|
|
4249
|
+
const styleSource = extractSfcStyleSource(source, query.type === "style" ? query.index : void 0);
|
|
4250
|
+
if (styleSource !== void 0) refreshRememberedCssSourceBySourceFile(remembered.sourceFile, styleSource);
|
|
2872
4251
|
}
|
|
2873
|
-
|
|
2874
|
-
} catch (error) {
|
|
2875
|
-
debug("refresh remembered css source failed: %s %O", file, error);
|
|
4252
|
+
return;
|
|
2876
4253
|
}
|
|
4254
|
+
if (isSourceStyleRequest(file)) refreshRememberedCssSourceBySourceFile(file, source);
|
|
2877
4255
|
};
|
|
2878
4256
|
const refreshRememberedCssSource = async (remembered) => {
|
|
2879
4257
|
const file = cleanUrl(stripRequestQuery(remembered.sourceFile));
|
|
2880
4258
|
const rememberedKey = [...rememberedCssSources.entries()].find(([, entry]) => entry === remembered)?.[0];
|
|
2881
4259
|
if (!rememberedKey || !path.isAbsolute(file)) return;
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
const styleSource = extractSfcStyleBlock(source, query.type === "style" ? query.index : void 0);
|
|
2887
|
-
return styleSource === void 0 ? void 0 : refreshRememberedCssSourceEntry(rememberedKey, remembered, remembered.sourceFile, styleSource);
|
|
2888
|
-
}
|
|
2889
|
-
if (isSourceStyleRequest(file)) return refreshRememberedCssSourceEntry(rememberedKey, remembered, remembered.sourceFile, source);
|
|
2890
|
-
} catch (error) {
|
|
2891
|
-
debug("refresh remembered css source before bundle replay failed: %s %O", file, error);
|
|
4260
|
+
const source = resolveCachedStyleSource(file);
|
|
4261
|
+
if (source == null) {
|
|
4262
|
+
debug("refresh remembered css source before bundle replay skipped: missing cached source for %s", file);
|
|
4263
|
+
return;
|
|
2892
4264
|
}
|
|
4265
|
+
if (SFC_COMPONENT_FILE_RE.test(file)) {
|
|
4266
|
+
const { query } = parseVueRequest(remembered.sourceFile);
|
|
4267
|
+
const styleSource = extractSfcStyleSource(source, query.type === "style" ? query.index : void 0);
|
|
4268
|
+
return styleSource === void 0 ? void 0 : refreshRememberedCssSourceEntry(rememberedKey, remembered, remembered.sourceFile, styleSource);
|
|
4269
|
+
}
|
|
4270
|
+
if (isSourceStyleRequest(file)) return refreshRememberedCssSourceEntry(rememberedKey, remembered, remembered.sourceFile, source);
|
|
2893
4271
|
};
|
|
2894
4272
|
const getRememberedCssSources = () => rememberedCssSources;
|
|
2895
4273
|
const getRememberedCssSourceEntry = (file) => rememberedCssSources.get(normalizeOutputPathKey(file));
|
|
@@ -2901,9 +4279,12 @@ function WeappTailwindcss(options = {}) {
|
|
|
2901
4279
|
viteGeneratedCssByFile.set(file, css);
|
|
2902
4280
|
};
|
|
2903
4281
|
const recordViteProcessedCssAssetResult = (file, css, options = {}) => {
|
|
2904
|
-
|
|
4282
|
+
const key = normalizeOutputPathKey(file);
|
|
4283
|
+
const previous = viteProcessedCssAssetResults.get(key);
|
|
4284
|
+
viteProcessedCssAssetResults.set(key, {
|
|
2905
4285
|
css,
|
|
2906
|
-
injectIntoMain: options.injectIntoMain
|
|
4286
|
+
injectIntoMain: options.injectIntoMain ?? previous?.injectIntoMain,
|
|
4287
|
+
outputFile: options.outputFile ?? previous?.outputFile
|
|
2907
4288
|
});
|
|
2908
4289
|
};
|
|
2909
4290
|
const getViteProcessedCssAssetResults = () => viteProcessedCssAssetResults.entries();
|
|
@@ -2958,6 +4339,10 @@ function WeappTailwindcss(options = {}) {
|
|
|
2958
4339
|
const isUniViteProject = () => {
|
|
2959
4340
|
return resolvedConfig?.plugins?.some((plugin) => plugin.name.includes("uni")) ?? false;
|
|
2960
4341
|
};
|
|
4342
|
+
const isHarmonyAppBuildTarget = () => {
|
|
4343
|
+
if (resolveUniUtsPlatform().isAppHarmony) return true;
|
|
4344
|
+
return isUniAppXHarmonyOutDir(resolvedConfig?.build?.outDir);
|
|
4345
|
+
};
|
|
2961
4346
|
const sendSupplementalCssHotUpdates = (ctx, cssModules) => {
|
|
2962
4347
|
const updates = cssModules.filter((mod) => !includesHotModule(ctx.modules, mod)).map((mod) => {
|
|
2963
4348
|
const hotUrl = resolveModuleHotUrl(mod);
|
|
@@ -3011,10 +4396,16 @@ function WeappTailwindcss(options = {}) {
|
|
|
3011
4396
|
await waitForSourceCandidateSyncs();
|
|
3012
4397
|
const file = cleanUrl(id);
|
|
3013
4398
|
const rootDir = resolvedConfig?.root ? path.resolve(resolvedConfig.root) : process$1.cwd();
|
|
3014
|
-
const
|
|
4399
|
+
const isHarmonyAppStyleTarget = isHarmonyAppBuildTarget();
|
|
4400
|
+
const isNativeAppStyleTarget = resolveUniUtsPlatform().isApp || isHarmonyAppStyleTarget;
|
|
3015
4401
|
const outputFile = resolveViteCssPipelineOutputFile(file, opts, rootDir, generatorOptions.target === "web", isNativeAppStyleTarget);
|
|
3016
4402
|
const runtime = getRecordedGeneratorCandidates() ?? getSourceCandidates() ?? await ensureRuntimeClassSet();
|
|
3017
|
-
const
|
|
4403
|
+
const outputCssHandlerOptions = transformCssHandlerOptions.getCssHandlerOptions(outputFile);
|
|
4404
|
+
const cssHandlerOptions = {
|
|
4405
|
+
...transformCssHandlerOptions.getCssHandlerOptions(file),
|
|
4406
|
+
isMainChunk: outputCssHandlerOptions.isMainChunk || isMainStyleEntryFile(file)
|
|
4407
|
+
};
|
|
4408
|
+
const shouldDeferEmptyScopedCssSource = !(opts.appType === "uni-app-x" && !cssHandlerOptions.isMainChunk && hasTailwindApplyDirective(code));
|
|
3018
4409
|
const generated = await generateCssByGenerator({
|
|
3019
4410
|
opts,
|
|
3020
4411
|
runtimeState,
|
|
@@ -3022,21 +4413,33 @@ function WeappTailwindcss(options = {}) {
|
|
|
3022
4413
|
rawSource: code,
|
|
3023
4414
|
file,
|
|
3024
4415
|
cssHandlerOptions,
|
|
3025
|
-
cssUserHandlerOptions: transformCssHandlerOptions.getCssUserHandlerOptions(
|
|
4416
|
+
cssUserHandlerOptions: transformCssHandlerOptions.getCssUserHandlerOptions(file),
|
|
3026
4417
|
getSourceCandidatesForEntries,
|
|
3027
4418
|
styleHandler,
|
|
3028
4419
|
debug,
|
|
3029
4420
|
previousCss: viteGeneratedCssByFile.get(file),
|
|
3030
|
-
deferEmptyScopedCssSource:
|
|
4421
|
+
deferEmptyScopedCssSource: shouldDeferEmptyScopedCssSource
|
|
3031
4422
|
});
|
|
3032
4423
|
if (!generated) return;
|
|
4424
|
+
const tracedCss = annotateCssSourceTrace(generated.css, {
|
|
4425
|
+
opts,
|
|
4426
|
+
tokenSources: createCssTokenSourceMap(getSourceCandidateSourcesForEntries(void 0), opts)
|
|
4427
|
+
});
|
|
3033
4428
|
for (const dependency of generated.dependencies) hookContext?.addWatchFile?.(dependency);
|
|
3034
|
-
viteGeneratedCssByFile.set(file,
|
|
3035
|
-
|
|
4429
|
+
viteGeneratedCssByFile.set(file, tracedCss);
|
|
4430
|
+
const shouldInjectGeneratedCssIntoMain = isMainStyleEntryFile(file) || mainCssChunkMatcher(outputFile, opts.appType);
|
|
4431
|
+
recordViteProcessedCssAssetResult(file, tracedCss, {
|
|
4432
|
+
injectIntoMain: shouldInjectGeneratedCssIntoMain,
|
|
4433
|
+
outputFile
|
|
4434
|
+
});
|
|
4435
|
+
if (tracedCss.includes("weapp-tailwindcss layer components start")) recordViteProcessedCssAssetResult(file, tracedCss, {
|
|
4436
|
+
injectIntoMain: shouldInjectGeneratedCssIntoMain,
|
|
4437
|
+
outputFile
|
|
4438
|
+
});
|
|
3036
4439
|
if (isNativeAppStyleTarget && outputFile.endsWith(".css")) hookContext?.emitFile?.({
|
|
3037
4440
|
type: "asset",
|
|
3038
4441
|
fileName: outputFile,
|
|
3039
|
-
source:
|
|
4442
|
+
source: tracedCss
|
|
3040
4443
|
});
|
|
3041
4444
|
markViteProcessedCssSource(file);
|
|
3042
4445
|
rememberTailwindRootCssModule(id);
|
|
@@ -3046,8 +4449,8 @@ function WeappTailwindcss(options = {}) {
|
|
|
3046
4449
|
rawSource: code,
|
|
3047
4450
|
sourceFile: id
|
|
3048
4451
|
});
|
|
3049
|
-
debug("css generated for vite postcss pipeline: %s bytes=%d", file,
|
|
3050
|
-
return `${createBundlerGeneratedCssMarker("vite", normalizeViteProcessedCssFile(file))}\n${
|
|
4452
|
+
debug("css generated for vite postcss pipeline: %s bytes=%d", file, tracedCss.length);
|
|
4453
|
+
return `${createBundlerGeneratedCssMarker("vite", normalizeViteProcessedCssFile(file))}\n${tracedCss}`;
|
|
3051
4454
|
};
|
|
3052
4455
|
const rewritePlugins = createRewriteCssImportsPlugins({
|
|
3053
4456
|
getAppType: () => opts.appType,
|
|
@@ -3077,12 +4480,14 @@ function WeappTailwindcss(options = {}) {
|
|
|
3077
4480
|
getViteProcessedCssAssetResult,
|
|
3078
4481
|
getSourceCandidates,
|
|
3079
4482
|
getSourceCandidatesForEntries,
|
|
4483
|
+
getSourceCandidateSourcesForEntries,
|
|
3080
4484
|
waitForSourceCandidateSyncs,
|
|
3081
4485
|
rememberCssSource,
|
|
3082
4486
|
refreshRememberedCssSource,
|
|
3083
4487
|
getRememberedCssSources,
|
|
3084
4488
|
getRememberedCssSignature,
|
|
3085
4489
|
setRememberedCssSignature,
|
|
4490
|
+
getKnownSfcSource,
|
|
3086
4491
|
recordGeneratorCandidates,
|
|
3087
4492
|
hmrTimingRecorder
|
|
3088
4493
|
});
|
|
@@ -3101,6 +4506,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
3101
4506
|
getRecordedGeneratorCandidates,
|
|
3102
4507
|
getSourceCandidates,
|
|
3103
4508
|
getSourceCandidatesForEntries,
|
|
4509
|
+
getSourceCandidateSourcesForEntries,
|
|
3104
4510
|
waitForSourceCandidateSyncs,
|
|
3105
4511
|
rememberMainCssSource: (file, rawSource) => rememberCssSource({
|
|
3106
4512
|
outputFile: file,
|
|
@@ -3134,6 +4540,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
3134
4540
|
name: `${vitePluginName}:source-candidates`,
|
|
3135
4541
|
enforce: "pre",
|
|
3136
4542
|
async transform(code, id) {
|
|
4543
|
+
if (shouldOwnTailwindGeneration) rememberKnownSfcSource(id, code);
|
|
3137
4544
|
if (!shouldOwnTailwindGeneration || !isSourceCandidateRequest(id) || !shouldCollectTransformedSourceCandidates(id)) return;
|
|
3138
4545
|
return hmrTimingRecorder.measure("sourceCandidates.transform", async () => {
|
|
3139
4546
|
invalidateRecordedGeneratorCandidates();
|
|
@@ -3259,11 +4666,14 @@ function WeappTailwindcss(options = {}) {
|
|
|
3259
4666
|
}
|
|
3260
4667
|
}, { emit: false });
|
|
3261
4668
|
},
|
|
3262
|
-
generateBundle:
|
|
3263
|
-
|
|
3264
|
-
|
|
4669
|
+
generateBundle: {
|
|
4670
|
+
order: "post",
|
|
4671
|
+
handler: generateBundleHook
|
|
4672
|
+
}
|
|
4673
|
+
}
|
|
3265
4674
|
];
|
|
3266
4675
|
if (uniAppXPlugins) plugins.push(...uniAppXPlugins);
|
|
4676
|
+
plugins.push(cssFinalizerOutputPlugin);
|
|
3267
4677
|
return plugins;
|
|
3268
4678
|
}
|
|
3269
4679
|
//#endregion
|