weapp-tailwindcss 5.1.5 → 5.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +1 -1
- package/README.md +1 -1
- package/dist/bundlers/shared/generator-css/types.d.ts +1 -0
- package/dist/bundlers/shared/generator-css/user-css.d.ts +4 -1
- package/dist/bundlers/vite/generate-bundle/finalize.d.ts +1 -0
- package/dist/bundlers/vite/generate-bundle/remembered-css-replay.d.ts +1 -0
- package/dist/bundlers/vite/processed-css-assets.d.ts +7 -0
- package/dist/{context-rrYZuUBU.mjs → context-3GGqW9vw.mjs} +3 -3
- package/dist/{context-BziwyWy1.js → context-BCSk_YnL.js} +3 -3
- package/dist/core.js +1 -1
- package/dist/core.mjs +1 -1
- package/dist/{generator-24-HgU9F.mjs → generator-CoT5vu9w.mjs} +2 -2
- package/dist/{generator-CilgHtxb.js → generator-CqWzj2Z1.js} +2 -2
- package/dist/generator.js +2 -2
- package/dist/generator.mjs +2 -2
- package/dist/{gulp-ygWfmOqh.mjs → gulp-Bss4wJ8t.mjs} +4 -4
- package/dist/{gulp-CuVsZdO9.js → gulp-hXE1U4Cu.js} +4 -4
- package/dist/gulp.js +1 -1
- package/dist/gulp.mjs +1 -1
- package/dist/{hmr-timing-Dh_nn3w5.mjs → hmr-timing-Cfu-4Bnf.mjs} +24 -511
- package/dist/{hmr-timing-BKdCeIrn.js → hmr-timing-Df4203aI.js} +48 -565
- package/dist/index.js +4 -4
- package/dist/index.mjs +4 -4
- package/dist/postcss.js +2 -2
- package/dist/postcss.mjs +2 -2
- package/dist/presets.js +6 -3
- package/dist/presets.mjs +6 -3
- package/dist/rspack.js +1 -1
- package/dist/rspack.mjs +1 -1
- package/dist/runtime-branch/generator-target-env.d.ts +1 -0
- package/dist/{source-candidate-scan-signature-DIj9m4wB.js → source-candidate-scan-signature-5Uk6U72B.js} +3 -3
- package/dist/{source-candidate-scan-signature-DATRnS1X.mjs → source-candidate-scan-signature-BbCmW975.mjs} +3 -3
- package/dist/{tailwindcss-C-uM4rB8.mjs → tailwindcss-Bjr3aphG.mjs} +15 -2
- package/dist/{tailwindcss-BwoNQ3t8.js → tailwindcss-DYJ3HZD2.js} +15 -2
- package/dist/{transform-DHLemtaX.mjs → transform--155BmeJ.mjs} +1 -1
- package/dist/{transform-KLD1tJdb.js → transform-B6_y_yCB.js} +1 -1
- package/dist/{v4-engine-CKtsdKxK.js → v4-engine-C9cmNlP8.js} +610 -3
- package/dist/{v4-engine-BuuYDXt1.mjs → v4-engine-DRQaCFMm.mjs} +529 -6
- package/dist/{vite-Yp14HNyS.js → vite-Baw9qNrc.js} +560 -112
- package/dist/{vite-cH0tTMHc.mjs → vite-PdxjaqhO.mjs} +561 -113
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/weapp-tw-css-import-rewrite-loader.js +2994 -2958
- package/dist/{webpack-DBhmJ-_P.mjs → webpack-BffTDmod.mjs} +12 -13
- package/dist/{webpack-DN3tgLbF.js → webpack-C9u7mfGE.js} +18 -19
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +3 -3
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { resolveImplicitAppTypeFromViteRoot } from "./framework.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import { a as resolveGeneratorRuntimeBranch, c as shouldUseNativeAppCssBranch, i as normalizeWeappTailwindcssGeneratorOptions, s as shouldUseMiniProgramCssBranch } from "./generator-
|
|
2
|
+
import { $ as hasTailwindGeneratedCssMarkers, B as hasTailwindNonRootGenerationDirectives, Et as omitUndefined, G as normalizeTailwindSourceForGenerator, H as hasTailwindSourceDirectives, K as parseImportRequest, L as stripMiniProgramCssSpecificityPlaceholders, P as hasMiniProgramCssSpecificityPlaceholders, R as hasLocalCssImport, Tt as filterUnsupportedMiniProgramTailwindV4Candidates, U as normalizeTailwindConfigDirectives, V as hasTailwindRootDirectives, _ as resolveTailwindcssOptions, a as filterTailwindV4CssSourceRoots, d as normalizeCssEntries, f as findNearestPackageRoot, lt as getTailwindV4IncrementalGenerateCacheStats, o as hasConfiguredTailwindV4CssRoots, q as removeTailwindSourceDirectives, s as upsertTailwindV4CssSource, u as isTailwindV4CssEntry, w as normalizeEmptyTailwindCustomVariants, xt as resolveTailwindV4CssSourceBase, z as hasTailwindApplyDirective } from "./v4-engine-DRQaCFMm.mjs";
|
|
3
|
+
import { a as resolveGeneratorRuntimeBranch, c as shouldUseNativeAppCssBranch, i as normalizeWeappTailwindcssGeneratorOptions, s as shouldUseMiniProgramCssBranch } from "./generator-CoT5vu9w.mjs";
|
|
4
4
|
import { o as resolveUniUtsPlatform } from "./utils-DodxWHGz.mjs";
|
|
5
|
-
import { C as normalizeFrameworkStylePlatform, S as createDebug, _ as toCustomAttributesEntities, a as vitePluginName, l as shouldSkipJsTransform, m as replaceWxml, n as normalizeStyleHandlerMajorVersion, t as getCompilerContext, v as collectRuntimeClassSet, x as refreshTailwindRuntimeState, y as createTailwindRuntimeReadyPromise } from "./context-
|
|
6
|
-
import { _ as resolveViteTailwindV4CssDependencies, a as findTailwindConfig, f as createViteSourceScanMatcher, g as resolveTailwindV4EntriesFromCssCached, i as resolveUniAppXOptions, l as getRuntimeClassSetSignature, m as discoverTailwindV4CssEntries, p as resolveViteSourceScanEntries, r as isUniAppXEnabled } from "./tailwindcss-
|
|
7
|
-
import {
|
|
8
|
-
import { A as isSourceStyleRequest, C as resolvePluginDisabledState, D as isHTMLRequest, E as isCSSRequest, F as createBuiltinViteStyleInjectorPlugins, M as normalizeOutputPathKey, O as normalizePath, P as toAbsoluteOutputPath, S as resolvePackageDir, T as formatPostcssSourceMap, _ as generateTailwindV4Css, a as createJsHashSalt, b as parseBundlerGeneratedCssMarkerBlocks, c as hasRuntimeAffectingSourceChanges, f as createBundleBuildState, g as createBundleModuleGraphOptions, h as applyLinkedResults, i as createCandidateSignature, j as stripRequestQuery, k as slash, l as summarizeStringDiff, m as createRuntimeAffectingSourceSignature, n as createScopedGeneratorCandidateSignature, o as createLinkedImpactSignature, p as updateBundleBuildState, r as createScopedGeneratorRuntime, s as getSnapshotHash, t as createSourceCandidateScanSignature, u as buildBundleSnapshot, v as createBundlerGeneratedCssMarker, w as cleanUrl, x as stripBundlerGeneratedCssMarkers, y as hasBundlerGeneratedCssMarker } from "./source-candidate-scan-signature-
|
|
5
|
+
import { C as normalizeFrameworkStylePlatform, S as createDebug, _ as toCustomAttributesEntities, a as vitePluginName, l as shouldSkipJsTransform, m as replaceWxml, n as normalizeStyleHandlerMajorVersion, t as getCompilerContext, v as collectRuntimeClassSet, x as refreshTailwindRuntimeState, y as createTailwindRuntimeReadyPromise } from "./context-3GGqW9vw.mjs";
|
|
6
|
+
import { _ as resolveViteTailwindV4CssDependencies, a as findTailwindConfig, f as createViteSourceScanMatcher, g as resolveTailwindV4EntriesFromCssCached, i as resolveUniAppXOptions, l as getRuntimeClassSetSignature, m as discoverTailwindV4CssEntries, p as resolveViteSourceScanEntries, r as isUniAppXEnabled } from "./tailwindcss-Bjr3aphG.mjs";
|
|
7
|
+
import { E as createCssTokenSourceMap, O as processCachedTask, T as createCssSourceTraceCacheSignature, _ as isPureLocalCssImportWrapper, a as isSourceCandidateRequest, b as scoreTailwindV4CssSourceFileMatch, d as validateCandidatesByGenerator, g as mergeMarkedUserLayerComponentsCss, h as extractMarkedUserLayerComponentsCss, m as runWithConcurrency, r as createSourceCandidateCollector, s as createBundleRuntimeClassSetManager, t as createHmrTimingRecorder, w as annotateCssSourceTrace } from "./hmr-timing-Cfu-4Bnf.mjs";
|
|
8
|
+
import { A as isSourceStyleRequest, C as resolvePluginDisabledState, D as isHTMLRequest, E as isCSSRequest, F as createBuiltinViteStyleInjectorPlugins, M as normalizeOutputPathKey, O as normalizePath, P as toAbsoluteOutputPath, S as resolvePackageDir, T as formatPostcssSourceMap, _ as generateTailwindV4Css, a as createJsHashSalt, b as parseBundlerGeneratedCssMarkerBlocks, c as hasRuntimeAffectingSourceChanges, f as createBundleBuildState, g as createBundleModuleGraphOptions, h as applyLinkedResults, i as createCandidateSignature, j as stripRequestQuery, k as slash, l as summarizeStringDiff, m as createRuntimeAffectingSourceSignature, n as createScopedGeneratorCandidateSignature, o as createLinkedImpactSignature, p as updateBundleBuildState, r as createScopedGeneratorRuntime, s as getSnapshotHash, t as createSourceCandidateScanSignature, u as buildBundleSnapshot, v as createBundlerGeneratedCssMarker, w as cleanUrl, x as stripBundlerGeneratedCssMarkers, y as hasBundlerGeneratedCssMarker } from "./source-candidate-scan-signature-BbCmW975.mjs";
|
|
9
9
|
import { t as logger$1 } from "./logger-BNzxZbZj.mjs";
|
|
10
10
|
import fs, { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
11
11
|
import path from "node:path";
|
|
12
12
|
import process$1 from "node:process";
|
|
13
13
|
import { splitCandidateTokens } from "@tailwindcss-mangle/engine";
|
|
14
|
-
import { compileCssMacroConditionalComments, containsCssAfterMinify, filterExistingCssRules, mergeCoveredCssRuleDeclarations, mergeMiniProgramPreflightRuleDeclarations, mergeMiniProgramThemeScopeRuleDeclarations, postcss, removeTailwindPostcssPlugins, resolveFilteredPostcssConfig, transformWebCssCompat, unwrapUnsupportedCascadeLayers } from "@weapp-tailwindcss/postcss";
|
|
14
|
+
import { compileCssMacroConditionalComments, containsCssAfterMinify, filterExistingCssRules, mergeCoveredCssRuleDeclarations, mergeMiniProgramPreflightRuleDeclarations, mergeMiniProgramThemeScopeRuleDeclarations, postcss, removeTailwindPostcssPlugins, resolveFilteredPostcssConfig, transformWebCssCompat, transformWebCssSafeSelectors, unwrapUnsupportedCascadeLayers } from "@weapp-tailwindcss/postcss";
|
|
15
15
|
import { LRUCache } from "lru-cache";
|
|
16
16
|
import { readFile } from "node:fs/promises";
|
|
17
17
|
import micromatch from "micromatch";
|
|
@@ -509,7 +509,7 @@ function resolveUniAppXStyleIsolationEnabled(root) {
|
|
|
509
509
|
//#region src/uni-app-x/vite.ts
|
|
510
510
|
let transformUVuePromise;
|
|
511
511
|
function loadTransformUVue() {
|
|
512
|
-
transformUVuePromise ?? (transformUVuePromise = import("./transform
|
|
512
|
+
transformUVuePromise ?? (transformUVuePromise = import("./transform--155BmeJ.mjs").then((mod) => mod.transformUVue));
|
|
513
513
|
return transformUVuePromise;
|
|
514
514
|
}
|
|
515
515
|
const preprocessorLangs = /* @__PURE__ */ new Set([
|
|
@@ -1055,7 +1055,7 @@ function normalizeMatchedCssSourcePath(file) {
|
|
|
1055
1055
|
if (!file || !path.isAbsolute(file)) return;
|
|
1056
1056
|
return path.resolve(file.replace(/[?#].*$/, ""));
|
|
1057
1057
|
}
|
|
1058
|
-
function collectConfiguredCssEntries(opts) {
|
|
1058
|
+
function collectConfiguredCssEntries$1(opts) {
|
|
1059
1059
|
const runtimeCssEntries = opts.tailwindcssRuntimeOptions?.tailwindcss?.v4?.cssEntries ?? [];
|
|
1060
1060
|
return [
|
|
1061
1061
|
...opts.cssEntries ?? [],
|
|
@@ -1078,7 +1078,7 @@ function collectCssConfigBaseCandidates(source, file, outputRoot, opts) {
|
|
|
1078
1078
|
const runtimeProjectRoot = typeof opts.tailwindcssRuntimeOptions?.projectRoot === "string" ? opts.tailwindcssRuntimeOptions.projectRoot : void 0;
|
|
1079
1079
|
const sourceBaseFallback = opts.tailwindcss?.v4?.base ?? runtimeProjectRoot ?? opts.tailwindcssBasedir ?? outputRoot;
|
|
1080
1080
|
const sourceRoot = opts.tailwindcssBasedir ?? runtimeProjectRoot;
|
|
1081
|
-
const configuredCssEntries = collectConfiguredCssEntries(opts);
|
|
1081
|
+
const configuredCssEntries = collectConfiguredCssEntries$1(opts);
|
|
1082
1082
|
for (const cssEntry of configuredCssEntries) {
|
|
1083
1083
|
const resolvedCssEntry = path.resolve(cssEntry);
|
|
1084
1084
|
if (configuredCssEntries.length === 1 || isMatchingCssSourceFile(file, resolvedCssEntry, outputRoot) || hasMatchingStyleFileBase(file, resolvedCssEntry, outputRoot, sourceRoot)) addCandidate(path.dirname(resolvedCssEntry));
|
|
@@ -2014,6 +2014,21 @@ function appendCss$1(baseCss, css) {
|
|
|
2014
2014
|
if (css.length === 0) return baseCss;
|
|
2015
2015
|
return `${baseCss}\n${css}`;
|
|
2016
2016
|
}
|
|
2017
|
+
function normalizeCssRecordIdentity(css) {
|
|
2018
|
+
return css.trim();
|
|
2019
|
+
}
|
|
2020
|
+
function hasNonCommentCss(css) {
|
|
2021
|
+
return css.replace(/\/\*[\s\S]*?\*\//g, "").trim().length > 0;
|
|
2022
|
+
}
|
|
2023
|
+
function dedupeViteCssResults(records) {
|
|
2024
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2025
|
+
return records.filter((record) => {
|
|
2026
|
+
const key = `${normalizeOutputPathKey(record.outputFile ?? "")}\0${normalizeCssRecordIdentity(record.css)}`;
|
|
2027
|
+
if (seen.has(key)) return false;
|
|
2028
|
+
seen.add(key);
|
|
2029
|
+
return true;
|
|
2030
|
+
});
|
|
2031
|
+
}
|
|
2017
2032
|
function removeTailwindSourceMediaWrappers(css) {
|
|
2018
2033
|
if (!css.includes("@media source(")) return css;
|
|
2019
2034
|
try {
|
|
@@ -2090,6 +2105,183 @@ function collectRootStyleBundleCssSources(bundle, excludedFile) {
|
|
|
2090
2105
|
}
|
|
2091
2106
|
return sources;
|
|
2092
2107
|
}
|
|
2108
|
+
function isHtmlOutputFile(file) {
|
|
2109
|
+
return /\.html(?:$|[?#])/i.test(file);
|
|
2110
|
+
}
|
|
2111
|
+
function stripQueryAndHash(file) {
|
|
2112
|
+
return file.replace(/[?#].*$/, "");
|
|
2113
|
+
}
|
|
2114
|
+
function resolveHtmlLinkedStyleFile(htmlFile, request) {
|
|
2115
|
+
if (!isStyleImportRequest(request)) return;
|
|
2116
|
+
const cleanRequest = stripQueryAndHash(request);
|
|
2117
|
+
if (cleanRequest.startsWith("/")) return normalizeOutputPathKey(cleanRequest.slice(1));
|
|
2118
|
+
const htmlDir = posix.posix.dirname(normalizeOutputPathKey(stripQueryAndHash(htmlFile)));
|
|
2119
|
+
return normalizeOutputPathKey(posix.posix.join(htmlDir === "." ? "" : htmlDir, cleanRequest));
|
|
2120
|
+
}
|
|
2121
|
+
function collectHtmlLinkedStyleFiles(bundle) {
|
|
2122
|
+
const linkedFiles = /* @__PURE__ */ new Set();
|
|
2123
|
+
const linkedBasenames = /* @__PURE__ */ new Set();
|
|
2124
|
+
const linkHrefRE = /<link\s[^>]*href\s*=\s*(["'])([^"']+)\1[^>]*>/gi;
|
|
2125
|
+
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2126
|
+
if (output.type !== "asset") continue;
|
|
2127
|
+
const htmlFile = getAssetFile$1(bundleFile, output);
|
|
2128
|
+
if (!isHtmlOutputFile(htmlFile)) continue;
|
|
2129
|
+
const html = readAssetSource$2(output);
|
|
2130
|
+
for (const match of html.matchAll(linkHrefRE)) {
|
|
2131
|
+
const href = match[2];
|
|
2132
|
+
if (!href) continue;
|
|
2133
|
+
const linkedFile = resolveHtmlLinkedStyleFile(htmlFile, href);
|
|
2134
|
+
if (!linkedFile || !isRootStyleOutputFile(linkedFile)) continue;
|
|
2135
|
+
linkedFiles.add(linkedFile);
|
|
2136
|
+
linkedBasenames.add(posix.posix.basename(linkedFile));
|
|
2137
|
+
}
|
|
2138
|
+
}
|
|
2139
|
+
return {
|
|
2140
|
+
linkedBasenames,
|
|
2141
|
+
linkedFiles
|
|
2142
|
+
};
|
|
2143
|
+
}
|
|
2144
|
+
function isLinkedStyleFile(file, linked) {
|
|
2145
|
+
const fileKey = normalizeOutputPathKey(stripQueryAndHash(file));
|
|
2146
|
+
return linked.linkedFiles.has(fileKey) || isRootStyleOutputFile(fileKey) && linked.linkedBasenames.has(posix.posix.basename(fileKey));
|
|
2147
|
+
}
|
|
2148
|
+
function removeDuplicateUnlinkedRootCssAssetsReferencedByHtml(bundle, options = {}) {
|
|
2149
|
+
const linked = collectHtmlLinkedStyleFiles(bundle);
|
|
2150
|
+
if (linked.linkedFiles.size === 0 && linked.linkedBasenames.size === 0) return 0;
|
|
2151
|
+
const linkedSources = /* @__PURE__ */ new Set();
|
|
2152
|
+
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2153
|
+
if (output.type !== "asset") continue;
|
|
2154
|
+
const file = getAssetFile$1(bundleFile, output);
|
|
2155
|
+
if (!isCssOutputFile(file) || isMiniProgramStyleOutputFile(file) || !isLinkedStyleFile(file, linked)) continue;
|
|
2156
|
+
const source = stripBundlerGeneratedCssMarkers(readAssetSource$2(output)).trim();
|
|
2157
|
+
if (source.length > 0) linkedSources.add(source);
|
|
2158
|
+
}
|
|
2159
|
+
if (linkedSources.size === 0) return 0;
|
|
2160
|
+
let removed = 0;
|
|
2161
|
+
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2162
|
+
if (output.type !== "asset") continue;
|
|
2163
|
+
const file = getAssetFile$1(bundleFile, output);
|
|
2164
|
+
if (!isRootStyleOutputFile(file) || isMiniProgramStyleOutputFile(file) || isLinkedStyleFile(file, linked)) continue;
|
|
2165
|
+
const source = stripBundlerGeneratedCssMarkers(readAssetSource$2(output)).trim();
|
|
2166
|
+
if (!linkedSources.has(source)) continue;
|
|
2167
|
+
delete bundle[bundleFile];
|
|
2168
|
+
options.debug?.("remove duplicate unlinked root css asset referenced by html: %s", file);
|
|
2169
|
+
removed++;
|
|
2170
|
+
}
|
|
2171
|
+
return removed;
|
|
2172
|
+
}
|
|
2173
|
+
const VUE_SCOPED_ATTR_RE = /\[data-v-[^\]]+\]/gi;
|
|
2174
|
+
function hasVueScopedAttr(value) {
|
|
2175
|
+
VUE_SCOPED_ATTR_RE.lastIndex = 0;
|
|
2176
|
+
const matched = VUE_SCOPED_ATTR_RE.test(value);
|
|
2177
|
+
VUE_SCOPED_ATTR_RE.lastIndex = 0;
|
|
2178
|
+
return matched;
|
|
2179
|
+
}
|
|
2180
|
+
function normalizeCssSignatureValue(value) {
|
|
2181
|
+
return value.replace(VUE_SCOPED_ATTR_RE, "").replace(/\s+/g, " ").replace(/\s*([>+~])\s*/g, "$1").replace(/\(\s+/g, "(").replace(/\s+\)/g, ")").trim();
|
|
2182
|
+
}
|
|
2183
|
+
function createDeclarationSignature(rule) {
|
|
2184
|
+
return createDeclarationKeys(rule).sort().join(";");
|
|
2185
|
+
}
|
|
2186
|
+
function createRuleCoverageKey(selector, declarations) {
|
|
2187
|
+
return `${normalizeCssSignatureValue(selector)}\0${declarations}`;
|
|
2188
|
+
}
|
|
2189
|
+
function createDeclarationKeys(rule) {
|
|
2190
|
+
return (rule.nodes ?? []).filter((node) => node.type === "decl").map((node) => `${node.prop}:${normalizeCssSignatureValue(node.value)}${node.important ? "!important" : ""}`);
|
|
2191
|
+
}
|
|
2192
|
+
function createAtRuleCoverageKey(atRule) {
|
|
2193
|
+
return `${atRule.name}\0${normalizeCssSignatureValue(atRule.params)}\0${normalizeCssSignatureValue(atRule.toString())}`;
|
|
2194
|
+
}
|
|
2195
|
+
function hasClassSelector(selector) {
|
|
2196
|
+
return /(?:^|[^\\])\.[_a-z\u00A0-\uFFFF-]/i.test(normalizeCssSignatureValue(selector));
|
|
2197
|
+
}
|
|
2198
|
+
function isLikelyTailwindGlobalSelector(selector) {
|
|
2199
|
+
const normalized = normalizeCssSignatureValue(selector);
|
|
2200
|
+
return normalized === "*" || normalized.startsWith("::") || normalized.startsWith(":root") || normalized.startsWith(":host") || /^(?:html|body|hr|abbr|h1|h2|h3|h4|h5|h6|a|b|strong|code|kbd|samp|small|sub|sup|table|button|input|select|optgroup|textarea|summary|blockquote|dl|dd|fieldset|legend|ol|ul|menu|dialog|progress|video|audio|canvas|embed|iframe|img|object|svg|details|template|[uo]ni-progress)(?:$|[:,[\s>+~.#])/.test(normalized);
|
|
2201
|
+
}
|
|
2202
|
+
function isLikelyTailwindGlobalRule(rule) {
|
|
2203
|
+
return (rule.selectors ?? [rule.selector]).every((selector) => !hasClassSelector(selector) && isLikelyTailwindGlobalSelector(selector));
|
|
2204
|
+
}
|
|
2205
|
+
function isLikelyTailwindPropertyAtRule(atRule) {
|
|
2206
|
+
return atRule.name.toLowerCase() === "property" && normalizeCssSignatureValue(atRule.params).startsWith("--tw-");
|
|
2207
|
+
}
|
|
2208
|
+
function collectRootScopedComparableCssCoverage(cssSources) {
|
|
2209
|
+
const rules = /* @__PURE__ */ new Set();
|
|
2210
|
+
const atRules = /* @__PURE__ */ new Set();
|
|
2211
|
+
const declarationsBySelector = /* @__PURE__ */ new Map();
|
|
2212
|
+
for (const source of cssSources) try {
|
|
2213
|
+
const root = postcss.parse(source);
|
|
2214
|
+
root.walkRules((rule) => {
|
|
2215
|
+
const declarations = createDeclarationSignature(rule);
|
|
2216
|
+
if (declarations.length === 0) return;
|
|
2217
|
+
for (const selector of rule.selectors ?? [rule.selector]) {
|
|
2218
|
+
const normalizedSelector = normalizeCssSignatureValue(selector);
|
|
2219
|
+
rules.add(`${normalizedSelector}\0${declarations}`);
|
|
2220
|
+
const selectorDeclarations = declarationsBySelector.get(normalizedSelector) ?? /* @__PURE__ */ new Set();
|
|
2221
|
+
for (const declaration of createDeclarationKeys(rule)) selectorDeclarations.add(declaration);
|
|
2222
|
+
declarationsBySelector.set(normalizedSelector, selectorDeclarations);
|
|
2223
|
+
}
|
|
2224
|
+
});
|
|
2225
|
+
root.walkAtRules((atRule) => {
|
|
2226
|
+
atRules.add(createAtRuleCoverageKey(atRule));
|
|
2227
|
+
});
|
|
2228
|
+
} catch {}
|
|
2229
|
+
return {
|
|
2230
|
+
rules,
|
|
2231
|
+
atRules,
|
|
2232
|
+
declarationsBySelector
|
|
2233
|
+
};
|
|
2234
|
+
}
|
|
2235
|
+
function isRuleCoveredByRootCss(rule, coverage) {
|
|
2236
|
+
const declarations = createDeclarationSignature(rule);
|
|
2237
|
+
if (declarations.length === 0) return false;
|
|
2238
|
+
const selectors = rule.selectors ?? [rule.selector];
|
|
2239
|
+
if (selectors.every((selector) => coverage.rules.has(createRuleCoverageKey(selector, declarations)))) return true;
|
|
2240
|
+
const declarationKeys = createDeclarationKeys(rule);
|
|
2241
|
+
return declarationKeys.length > 0 && selectors.every((selector) => {
|
|
2242
|
+
const rootDeclarations = coverage.declarationsBySelector.get(normalizeCssSignatureValue(selector));
|
|
2243
|
+
return rootDeclarations != null && declarationKeys.every((declaration) => rootDeclarations.has(declaration));
|
|
2244
|
+
}) || selectors.every((selector) => coverage.declarationsBySelector.has(normalizeCssSignatureValue(selector)));
|
|
2245
|
+
}
|
|
2246
|
+
function removeScopedCssCoveredByRootStyleSources(css, rootSources) {
|
|
2247
|
+
if (!hasVueScopedAttr(css)) return css;
|
|
2248
|
+
const hasScopedTailwindGeneratedCss = /tailwindcss v\d/i.test(css);
|
|
2249
|
+
const coverage = collectRootScopedComparableCssCoverage(rootSources);
|
|
2250
|
+
if (coverage.rules.size === 0 && coverage.atRules.size === 0 && !hasScopedTailwindGeneratedCss) return css;
|
|
2251
|
+
try {
|
|
2252
|
+
const root = postcss.parse(css);
|
|
2253
|
+
let changed = false;
|
|
2254
|
+
root.walkComments((comment) => {
|
|
2255
|
+
if (/tailwindcss v\d/i.test(comment.text)) {
|
|
2256
|
+
comment.remove();
|
|
2257
|
+
changed = true;
|
|
2258
|
+
}
|
|
2259
|
+
});
|
|
2260
|
+
root.walkRules((rule) => {
|
|
2261
|
+
if (isRuleCoveredByRootCss(rule, coverage) || hasScopedTailwindGeneratedCss && isLikelyTailwindGlobalRule(rule)) {
|
|
2262
|
+
rule.remove();
|
|
2263
|
+
changed = true;
|
|
2264
|
+
}
|
|
2265
|
+
});
|
|
2266
|
+
root.walkAtRules((atRule) => {
|
|
2267
|
+
if (coverage.atRules.has(createAtRuleCoverageKey(atRule)) || hasScopedTailwindGeneratedCss && isLikelyTailwindPropertyAtRule(atRule)) {
|
|
2268
|
+
atRule.remove();
|
|
2269
|
+
changed = true;
|
|
2270
|
+
return;
|
|
2271
|
+
}
|
|
2272
|
+
if (atRule.nodes !== void 0 && atRule.nodes.length === 0) {
|
|
2273
|
+
atRule.remove();
|
|
2274
|
+
changed = true;
|
|
2275
|
+
}
|
|
2276
|
+
});
|
|
2277
|
+
return changed ? removeDanglingCssSourceTraceComments(root.toString()).trim() : css;
|
|
2278
|
+
} catch {
|
|
2279
|
+
return css;
|
|
2280
|
+
}
|
|
2281
|
+
}
|
|
2282
|
+
function removeScopedTailwindPreflightCss(css) {
|
|
2283
|
+
return removeScopedCssCoveredByRootStyleSources(css, []);
|
|
2284
|
+
}
|
|
2093
2285
|
function collectSingleViteGeneratedCssMarkerFile(rawSource) {
|
|
2094
2286
|
const blocks = parseBundlerGeneratedCssMarkerBlocks(rawSource).filter((block) => block.bundler === "vite");
|
|
2095
2287
|
if (blocks.length !== 1) return;
|
|
@@ -2102,7 +2294,9 @@ function shouldFilterRootGeneratedCssMarkerForScopedAsset(targetFile, markerFile
|
|
|
2102
2294
|
return !isMatchingGeneratedCssMarkerFile(targetFile, markerFile, resolveViteProcessedCssOutputFile);
|
|
2103
2295
|
}
|
|
2104
2296
|
function removeCssCoveredByRootStyleBundleSources(bundle, file, css) {
|
|
2105
|
-
|
|
2297
|
+
const rootSources = collectRootStyleBundleCssSources(bundle, file);
|
|
2298
|
+
const nextCss = removeScopedCssCoveredByRootStyleSources(removeDanglingCssSourceTraceComments(removeCssCoveredByImportedViteResults(css, rootSources)), rootSources);
|
|
2299
|
+
return hasNonCommentCss(nextCss) ? nextCss : "";
|
|
2106
2300
|
}
|
|
2107
2301
|
function removeDanglingCssSourceTraceComments(css) {
|
|
2108
2302
|
if (!css.includes("/* tokens:")) return css;
|
|
@@ -2126,8 +2320,11 @@ function removeCssCoveredByRootStyleAssets(bundle, options) {
|
|
|
2126
2320
|
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2127
2321
|
if (output.type !== "asset") continue;
|
|
2128
2322
|
const file = getAssetFile$1(bundleFile, output);
|
|
2129
|
-
if (!options.cssMatcher(file) || isRootStyleOutputFile(file) || options.isViteProcessedCssAsset?.(output, file) === true || options.subpackageRoots != null && isSubpackageOutputFile(file, options.subpackageRoots)) continue;
|
|
2130
2323
|
const rawSource = readAssetSource$2(output);
|
|
2324
|
+
const hasScopedCss = hasVueScopedAttr(rawSource);
|
|
2325
|
+
const hasTailwindGeneratedCss = /tailwindcss v\d/i.test(rawSource);
|
|
2326
|
+
const shouldIncludeTailwindGeneratedCssAsset = options.includeTailwindGeneratedCssAssets === true && hasTailwindGeneratedCss && isCssOutputFile(file) && !isMiniProgramStyleOutputFile(file);
|
|
2327
|
+
if (!(options.cssMatcher(file) || hasScopedCss && isCssOutputFile(file) || shouldIncludeTailwindGeneratedCssAsset) || isRootStyleOutputFile(file) || options.isViteProcessedCssAsset?.(output, file) === true && !hasScopedCss && !shouldIncludeTailwindGeneratedCssAsset || options.subpackageRoots != null && isSubpackageOutputFile(file, options.subpackageRoots)) continue;
|
|
2131
2328
|
const nextCss = removeCssCoveredByRootStyleBundleSources(bundle, file, rawSource);
|
|
2132
2329
|
if (nextCss === rawSource) continue;
|
|
2133
2330
|
output.source = nextCss;
|
|
@@ -2180,6 +2377,12 @@ function shouldUseCssAssetAsMainInjectionTarget(opts, file, records) {
|
|
|
2180
2377
|
const fileKey = normalizeOutputPathKey(file);
|
|
2181
2378
|
if (!isRootStyleOutputFile(file) && records.some((record) => typeof record.outputFile === "string" && normalizeOutputPathKey(record.outputFile) === fileKey)) return true;
|
|
2182
2379
|
if (!isRootStyleOutputFile(file)) return records.some((record) => record.injectIntoMain === true && typeof record.outputFile === "string" && normalizeOutputPathKey(record.outputFile) === fileKey);
|
|
2380
|
+
const matchedRootWebOutputTargets = records.map((record) => typeof record.outputFile === "string" ? normalizeOutputPathKey(record.outputFile) : void 0).filter((outputFile) => typeof outputFile === "string" && isRootStyleOutputFile(outputFile) && !isMiniProgramStyleOutputFile(outputFile)).filter((outputFile) => opts.mainCssChunkMatcher(outputFile, opts.appType));
|
|
2381
|
+
if (opts.appType === "uni-app-vite" && !isMiniProgramStyleOutputFile(file) && matchedRootWebOutputTargets.length > 0) return matchedRootWebOutputTargets.includes(fileKey);
|
|
2382
|
+
const explicitRootTargets = records.filter((record) => record.injectIntoMain === true).map((record) => typeof record.outputFile === "string" ? normalizeOutputPathKey(record.outputFile) : void 0).filter((outputFile) => typeof outputFile === "string" && isRootStyleOutputFile(outputFile) && !isMiniProgramStyleOutputFile(outputFile));
|
|
2383
|
+
const explicitWebCssTargets = records.filter((record) => record.injectIntoMain === true).map((record) => typeof record.outputFile === "string" ? normalizeOutputPathKey(record.outputFile) : void 0).filter((outputFile) => typeof outputFile === "string" && isCssOutputFile(outputFile) && !isMiniProgramStyleOutputFile(outputFile));
|
|
2384
|
+
if (opts.appType === "uni-app-vite" && !isMiniProgramStyleOutputFile(file) && explicitWebCssTargets.length > 0) return explicitRootTargets.includes(fileKey);
|
|
2385
|
+
if (explicitRootTargets.length > 0) return explicitRootTargets.includes(fileKey);
|
|
2183
2386
|
if (records.some((record) => {
|
|
2184
2387
|
if (record.injectIntoMain !== true) return false;
|
|
2185
2388
|
return isRootStyleOutputFile(file) || typeof record.outputFile === "string" && normalizeOutputPathKey(record.outputFile) === fileKey;
|
|
@@ -2200,6 +2403,33 @@ function isViteProcessedCssResultCoveredByImportedBundleAsset(record, importedSt
|
|
|
2200
2403
|
}
|
|
2201
2404
|
return false;
|
|
2202
2405
|
}
|
|
2406
|
+
function removeCoveredInjectedSourceAssets(bundle, targetFile, targetCss, records, options) {
|
|
2407
|
+
let removed = 0;
|
|
2408
|
+
const targetFileKey = normalizeOutputPathKey(targetFile);
|
|
2409
|
+
const targetIsRootWebStyle = isRootStyleOutputFile(targetFileKey) && !isMiniProgramStyleOutputFile(targetFileKey);
|
|
2410
|
+
for (const record of records) {
|
|
2411
|
+
if (!options.shouldRemoveInjectedSourceAsset?.(targetFile, record)) continue;
|
|
2412
|
+
const recordFileKey = normalizeOutputPathKey(record.file);
|
|
2413
|
+
for (const [candidateFile, candidateOutput] of Object.entries(bundle)) {
|
|
2414
|
+
if (candidateOutput.type !== "asset") continue;
|
|
2415
|
+
const candidateKey = normalizeOutputPathKey(getAssetFile$1(candidateFile, candidateOutput));
|
|
2416
|
+
if (candidateKey === targetFileKey) continue;
|
|
2417
|
+
const isRecordFile = candidateKey === recordFileKey;
|
|
2418
|
+
const candidateIsRootWebStyle = isRootStyleOutputFile(candidateKey) && !isMiniProgramStyleOutputFile(candidateKey);
|
|
2419
|
+
const candidateSource = readAssetSource$2(candidateOutput).trim();
|
|
2420
|
+
const uncoveredCandidateSource = candidateSource.length > 0 ? filterExistingCssRules(targetCss, candidateSource).trim() : candidateSource;
|
|
2421
|
+
const isProcessedSource = candidateSource === record.css.trim() || candidateSource.length > 0 && containsCssAfterMinify(targetCss, candidateSource) || targetIsRootWebStyle && candidateIsRootWebStyle && candidateSource.length > 0 && !hasNonCommentCss(uncoveredCandidateSource);
|
|
2422
|
+
if (!isRecordFile && !isProcessedSource) continue;
|
|
2423
|
+
if (candidateIsRootWebStyle && !targetIsRootWebStyle) continue;
|
|
2424
|
+
if (candidateIsRootWebStyle && !isRecordFile) continue;
|
|
2425
|
+
if (candidateIsRootWebStyle) delete bundle[candidateFile];
|
|
2426
|
+
else clearAssetSource(candidateOutput);
|
|
2427
|
+
options.debug?.("remove injected vite-processed source css asset: %s -> %s", candidateKey, targetFile);
|
|
2428
|
+
removed++;
|
|
2429
|
+
}
|
|
2430
|
+
}
|
|
2431
|
+
return removed;
|
|
2432
|
+
}
|
|
2203
2433
|
function removeCssCoveredByImportedViteResults(css, importedCssSources) {
|
|
2204
2434
|
if (importedCssSources.length === 0) return css;
|
|
2205
2435
|
const importedCss = importedCssSources.map((source) => stripBundlerGeneratedCssMarkers(source).trim()).filter(Boolean).join("\n");
|
|
@@ -2226,6 +2456,38 @@ function collectBundleAssetFiles(bundle) {
|
|
|
2226
2456
|
}
|
|
2227
2457
|
return files;
|
|
2228
2458
|
}
|
|
2459
|
+
function normalizeComparableStyleFile(file) {
|
|
2460
|
+
return normalizeOutputPathKey(posix.normalize(file.replace(/[?#].*$/, "")));
|
|
2461
|
+
}
|
|
2462
|
+
function collectConfiguredTailwindV4CssEntryFiles(opts) {
|
|
2463
|
+
const runtimeCssEntries = opts.tailwindRuntime?.options?.tailwindcss?.v4?.cssEntries;
|
|
2464
|
+
return [
|
|
2465
|
+
...Array.isArray(opts.cssEntries) ? opts.cssEntries : [],
|
|
2466
|
+
...Array.isArray(opts.tailwindcss?.v4?.cssEntries) ? opts.tailwindcss.v4.cssEntries : [],
|
|
2467
|
+
...Array.isArray(opts.tailwindcssRuntimeOptions?.tailwindcss?.v4?.cssEntries) ? opts.tailwindcssRuntimeOptions.tailwindcss.v4.cssEntries : [],
|
|
2468
|
+
...Array.isArray(runtimeCssEntries) ? runtimeCssEntries : []
|
|
2469
|
+
].filter((file) => typeof file === "string" && file.length > 0);
|
|
2470
|
+
}
|
|
2471
|
+
function isConfiguredTailwindV4CssEntryFile(opts, file) {
|
|
2472
|
+
if (typeof file !== "string" || file.length === 0) return false;
|
|
2473
|
+
const fileKey = normalizeComparableStyleFile(file);
|
|
2474
|
+
return collectConfiguredTailwindV4CssEntryFiles(opts).some((entry) => normalizeComparableStyleFile(entry) === fileKey);
|
|
2475
|
+
}
|
|
2476
|
+
function resolveUniAppViteWebviewRootCssInjectionTarget(bundle, opts, sourceFile, outputFile) {
|
|
2477
|
+
if (opts.appType !== "uni-app-vite" || isMiniProgramStyleOutputFile(outputFile) || !isConfiguredTailwindV4CssEntryFile(opts, sourceFile)) return;
|
|
2478
|
+
const rootCssFiles = [];
|
|
2479
|
+
const matchedRootCssFiles = [];
|
|
2480
|
+
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2481
|
+
if (output.type !== "asset") continue;
|
|
2482
|
+
const file = getAssetFile$1(bundleFile, output);
|
|
2483
|
+
if (!opts.cssMatcher(file) || !isRootStyleOutputFile(file) || isMiniProgramStyleOutputFile(file)) continue;
|
|
2484
|
+
rootCssFiles.push(file);
|
|
2485
|
+
if (opts.mainCssChunkMatcher(file, opts.appType)) matchedRootCssFiles.push(file);
|
|
2486
|
+
}
|
|
2487
|
+
if (matchedRootCssFiles.length === 1) return matchedRootCssFiles[0];
|
|
2488
|
+
if (matchedRootCssFiles.length > 1) return;
|
|
2489
|
+
return rootCssFiles.length === 1 ? rootCssFiles[0] : void 0;
|
|
2490
|
+
}
|
|
2229
2491
|
function findBundleAssetByOutputFile(bundle, file) {
|
|
2230
2492
|
const fileKey = normalizeOutputPathKey(file);
|
|
2231
2493
|
return Object.entries(bundle).find(([bundleFile, output]) => {
|
|
@@ -2279,6 +2541,8 @@ function collectViteProcessedCssAssetResults(bundle, options) {
|
|
|
2279
2541
|
options.markCssAssetProcessed?.(output, file);
|
|
2280
2542
|
options.recordCssAssetResult?.(file, nextCss);
|
|
2281
2543
|
const resolvedOutputFile = resolveViteGeneratedCssMarkerOutputFile(file, singleMarkerFile, existingAssetFiles, options.resolveViteProcessedCssOutputFile);
|
|
2544
|
+
const webviewRootCssInjectionTarget = options.opts ? resolveUniAppViteWebviewRootCssInjectionTarget(bundle, options.opts, singleMarkerFile ?? file, resolvedOutputFile) : void 0;
|
|
2545
|
+
const recordOutputFile = webviewRootCssInjectionTarget ?? resolvedOutputFile;
|
|
2282
2546
|
if (singleMarkerFile && normalizeOutputPathKey(resolvedOutputFile) !== normalizeOutputPathKey(file) && !isRootStyleOutputFile(resolvedOutputFile) && existingAssetFiles.has(normalizeOutputPathKey(resolvedOutputFile))) {
|
|
2283
2547
|
const targetAsset = findBundleAssetByOutputFile(bundle, resolvedOutputFile);
|
|
2284
2548
|
if (targetAsset) {
|
|
@@ -2298,24 +2562,24 @@ function collectViteProcessedCssAssetResults(bundle, options) {
|
|
|
2298
2562
|
continue;
|
|
2299
2563
|
}
|
|
2300
2564
|
}
|
|
2301
|
-
const shouldReplayIntoMainCss = options.opts != null && shouldReplayViteProcessedCssIntoMainCss(options.opts, file, singleMarkerFile, resolvedOutputFile, options.subpackageRoots);
|
|
2565
|
+
const shouldReplayIntoMainCss = options.opts != null && (webviewRootCssInjectionTarget != null || shouldReplayViteProcessedCssIntoMainCss(options.opts, file, singleMarkerFile, resolvedOutputFile, options.subpackageRoots));
|
|
2302
2566
|
options.recordViteProcessedCssAssetResult?.(file, nextCss, {
|
|
2303
2567
|
injectIntoMain: shouldReplayIntoMainCss || void 0,
|
|
2304
|
-
outputFile:
|
|
2568
|
+
outputFile: recordOutputFile
|
|
2305
2569
|
});
|
|
2306
|
-
if (normalizeOutputPathKey(
|
|
2570
|
+
if (normalizeOutputPathKey(recordOutputFile) !== normalizeOutputPathKey(file)) options.recordViteProcessedCssAssetResult?.(recordOutputFile, nextCss, {
|
|
2307
2571
|
injectIntoMain: shouldReplayIntoMainCss || void 0,
|
|
2308
|
-
outputFile:
|
|
2572
|
+
outputFile: recordOutputFile
|
|
2309
2573
|
});
|
|
2310
2574
|
for (const markerFile of collectMatchingGeneratedCssMarkerFiles(file, rawSource, options.resolveViteProcessedCssOutputFile)) {
|
|
2311
2575
|
if (normalizeOutputPathKey(markerFile) === normalizeOutputPathKey(file)) continue;
|
|
2312
2576
|
options.recordViteProcessedCssAssetResult?.(markerFile, nextCss, {
|
|
2313
2577
|
injectIntoMain: shouldReplayIntoMainCss || void 0,
|
|
2314
|
-
outputFile:
|
|
2578
|
+
outputFile: recordOutputFile
|
|
2315
2579
|
});
|
|
2316
|
-
if (normalizeOutputPathKey(
|
|
2580
|
+
if (normalizeOutputPathKey(recordOutputFile) !== normalizeOutputPathKey(markerFile) && normalizeOutputPathKey(recordOutputFile) !== normalizeOutputPathKey(file)) options.recordViteProcessedCssAssetResult?.(recordOutputFile, nextCss, {
|
|
2317
2581
|
injectIntoMain: shouldReplayIntoMainCss || void 0,
|
|
2318
|
-
outputFile:
|
|
2582
|
+
outputFile: recordOutputFile
|
|
2319
2583
|
});
|
|
2320
2584
|
}
|
|
2321
2585
|
if (isCoveredViteGeneratedSourceAsset(file, existingAssetFiles, options.resolveViteProcessedCssOutputFile)) {
|
|
@@ -2330,7 +2594,8 @@ function collectViteProcessedCssAssetResults(bundle, options) {
|
|
|
2330
2594
|
return collected;
|
|
2331
2595
|
}
|
|
2332
2596
|
function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
2333
|
-
const
|
|
2597
|
+
const transformCss = (css, file) => options.transformCss?.(css, file) ?? css;
|
|
2598
|
+
const viteCssResults = dedupeViteCssResults([...options.getViteProcessedCssAssetResults?.() ?? []].map(([file, record]) => {
|
|
2334
2599
|
return typeof record === "string" ? {
|
|
2335
2600
|
file,
|
|
2336
2601
|
css: record,
|
|
@@ -2341,10 +2606,14 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
2341
2606
|
injectIntoMain: record.injectIntoMain,
|
|
2342
2607
|
outputFile: record.outputFile
|
|
2343
2608
|
};
|
|
2344
|
-
}).
|
|
2609
|
+
})).map((record) => ({
|
|
2610
|
+
...record,
|
|
2611
|
+
css: transformCss(record.css, record.outputFile ?? record.file)
|
|
2612
|
+
})).filter((record) => record.css.length > 0);
|
|
2345
2613
|
let injected = 0;
|
|
2346
2614
|
for (const [bundleFile, bundleOutput] of Object.entries(bundle)) {
|
|
2347
2615
|
let output = bundleOutput;
|
|
2616
|
+
if (bundle[bundleFile] !== bundleOutput) continue;
|
|
2348
2617
|
if (output.type !== "asset") continue;
|
|
2349
2618
|
let file = getAssetFile$1(bundleFile, output);
|
|
2350
2619
|
if (!options.opts.cssMatcher(file) || !shouldUseCssAssetAsMainInjectionTarget(options.opts, file, viteCssResults)) continue;
|
|
@@ -2366,7 +2635,7 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
2366
2635
|
}
|
|
2367
2636
|
const fileKey = normalizeOutputPathKey(file);
|
|
2368
2637
|
const mainFileKey = normalizeOutputPathKey(file);
|
|
2369
|
-
let nextCss = removeTailwindEntryDirectivesFromCss(originalSource);
|
|
2638
|
+
let nextCss = transformCss(removeTailwindEntryDirectivesFromCss(originalSource), file);
|
|
2370
2639
|
const importedStyleFiles = collectImportedStyleFiles(nextCss, file);
|
|
2371
2640
|
const importedBundleCssSources = collectImportedBundleCssSources(bundle, importedStyleFiles);
|
|
2372
2641
|
nextCss = removeCssCoveredByImportedViteResults(nextCss, importedBundleCssSources);
|
|
@@ -2375,12 +2644,14 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
2375
2644
|
const uncoveredImportedViteCssResults = importedViteCssResults.filter((record) => !isViteProcessedCssResultCoveredByImportedBundleAsset(record, importedStyleFiles, bundleAssetFiles));
|
|
2376
2645
|
const importedCssSources = [...importedBundleCssSources, ...uncoveredImportedViteCssResults.map((record) => record.css)];
|
|
2377
2646
|
nextCss = removeCssCoveredByImportedViteResults(nextCss, uncoveredImportedViteCssResults.map((record) => record.css));
|
|
2647
|
+
const targetViteCssResults = [];
|
|
2378
2648
|
for (const record of viteCssResults) {
|
|
2379
2649
|
if (!isRootStyleOutputFile(file)) {
|
|
2380
2650
|
if (typeof record.outputFile !== "string" || normalizeOutputPathKey(record.outputFile) !== fileKey) continue;
|
|
2381
2651
|
}
|
|
2382
2652
|
if (!shouldInjectViteProcessedCssResult(options.opts, mainFileKey, record.file, record)) continue;
|
|
2383
2653
|
if (isViteProcessedCssResultImported(record, importedStyleFiles)) continue;
|
|
2654
|
+
targetViteCssResults.push(record);
|
|
2384
2655
|
let css = stripBundlerGeneratedCssMarkers(record.css).trim();
|
|
2385
2656
|
css = removeCssCoveredByImportedViteResults(css, importedCssSources).trim();
|
|
2386
2657
|
if (css.length === 0) continue;
|
|
@@ -2411,29 +2682,19 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
2411
2682
|
if (css.length === 0) continue;
|
|
2412
2683
|
}
|
|
2413
2684
|
const missingCss = filterExistingCssRules(nextCss, css);
|
|
2414
|
-
if (missingCss.length === 0 || containsCssAfterMinify(nextCss, missingCss)) continue;
|
|
2685
|
+
if (missingCss.length === 0 || !hasNonCommentCss(missingCss) || containsCssAfterMinify(nextCss, missingCss)) continue;
|
|
2415
2686
|
nextCss = appendCss$1(nextCss, missingCss);
|
|
2416
2687
|
}
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
if (!options.shouldRemoveInjectedSourceAsset?.(file, record)) continue;
|
|
2425
|
-
const recordFileKey = normalizeOutputPathKey(record.file);
|
|
2426
|
-
for (const [candidateFile, candidateOutput] of Object.entries(bundle)) {
|
|
2427
|
-
if (candidateOutput.type !== "asset") continue;
|
|
2428
|
-
const candidateKey = normalizeOutputPathKey(getAssetFile$1(candidateFile, candidateOutput));
|
|
2429
|
-
const isRecordFile = candidateKey === recordFileKey;
|
|
2430
|
-
const candidateSource = readAssetSource$2(candidateOutput).trim();
|
|
2431
|
-
const isProcessedSource = candidateSource === record.css.trim() || candidateSource.length > 0 && containsCssAfterMinify(nextCss, candidateSource);
|
|
2432
|
-
if (!isRecordFile && !isProcessedSource || candidateKey === normalizeOutputPathKey(file)) continue;
|
|
2433
|
-
clearAssetSource(candidateOutput);
|
|
2434
|
-
options.debug?.("remove injected vite-processed source css asset: %s -> %s", candidateKey, file);
|
|
2435
|
-
}
|
|
2688
|
+
nextCss = transformCss(nextCss, file);
|
|
2689
|
+
if (nextCss !== originalSource) {
|
|
2690
|
+
output.source = nextCss;
|
|
2691
|
+
options.markCssAssetProcessed?.(output, file);
|
|
2692
|
+
options.recordCssAssetResult?.(file, nextCss);
|
|
2693
|
+
options.onUpdate?.(file, originalSource, nextCss);
|
|
2694
|
+
options.debug?.("inject vite-processed css into main css asset: %s bytes=%d", file, nextCss.length);
|
|
2436
2695
|
}
|
|
2696
|
+
const removedSources = removeCoveredInjectedSourceAssets(bundle, file, nextCss, targetViteCssResults, options);
|
|
2697
|
+
if (nextCss === originalSource && removedSources === 0) continue;
|
|
2437
2698
|
injected++;
|
|
2438
2699
|
}
|
|
2439
2700
|
return injected;
|
|
@@ -2705,9 +2966,34 @@ function pruneLastCssResults(resultByFile, sourceHashByFile, activeFiles) {
|
|
|
2705
2966
|
function readAssetSource(asset) {
|
|
2706
2967
|
return typeof asset.source === "string" ? asset.source : asset.source.toString();
|
|
2707
2968
|
}
|
|
2969
|
+
function isUniAppViteWebviewAppBundle(bundleFiles) {
|
|
2970
|
+
return bundleFiles.some((file) => path.basename(file.replace(/[?#].*$/, "")) === "app-service.js");
|
|
2971
|
+
}
|
|
2972
|
+
function isUniAppViteWebviewOutDir$2(outDir) {
|
|
2973
|
+
const normalized = outDir ? path.basename(path.normalize(outDir)).trim().toLowerCase() : void 0;
|
|
2974
|
+
return normalized === "app" || normalized === "app-plus";
|
|
2975
|
+
}
|
|
2708
2976
|
function getAssetFile(bundleFile, asset) {
|
|
2709
2977
|
return asset.fileName || bundleFile;
|
|
2710
2978
|
}
|
|
2979
|
+
function finalizeUniAppViteWebviewCssCompat(bundle, options) {
|
|
2980
|
+
if (options.opts.generator?.webCompat === false) return 0;
|
|
2981
|
+
let transformed = 0;
|
|
2982
|
+
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2983
|
+
if (output.type !== "asset") continue;
|
|
2984
|
+
const file = getAssetFile(bundleFile, output);
|
|
2985
|
+
if (!options.opts.cssMatcher(file) || !/\.css(?:$|[?#])/i.test(file)) continue;
|
|
2986
|
+
const rawSource = readAssetSource(output);
|
|
2987
|
+
const nextCss = transformWebCssSafeSelectors(transformWebCssCompat(rawSource, options.opts.generator?.webCompat ?? true), { escapeMap: options.opts.escapeMap });
|
|
2988
|
+
if (nextCss === rawSource) continue;
|
|
2989
|
+
output.source = nextCss;
|
|
2990
|
+
options.recordCssAssetResult?.(file, nextCss);
|
|
2991
|
+
options.onUpdate(file, rawSource, nextCss);
|
|
2992
|
+
options.debug("finalize uni-app vite webview css compat: %s bytes=%d", file, nextCss.length);
|
|
2993
|
+
transformed++;
|
|
2994
|
+
}
|
|
2995
|
+
return transformed;
|
|
2996
|
+
}
|
|
2711
2997
|
function isRootMiniProgramStyleOutputFile(file) {
|
|
2712
2998
|
const normalized = normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
2713
2999
|
return !normalized.includes("/") && /\.(?:wxss|acss|ttss|qss|jxss|tyss)$/i.test(normalized);
|
|
@@ -2776,7 +3062,7 @@ function normalizeTaroRootImportShellAssets(bundle, options) {
|
|
|
2776
3062
|
return updated;
|
|
2777
3063
|
}
|
|
2778
3064
|
async function finalizeGenerateBundle(options) {
|
|
2779
|
-
const { activeProcessCacheKeys, activeProcessHashKeys, activeViteCssCacheFiles, bundle, bundleFiles, cache, cssTaskFactories, debug, defaultStyleOutputExtension, formatIteration, generatorCandidateSignature, generatorRuntime, getCssHandlerOptions, getSourceCandidateSourcesForEntries, getSourceCandidatesForEntries, getViteCssCacheStats, getViteProcessedCssAssetResults, hmrTimingRecorder, hmrTimingStartedAt, isHarmonyAppStyleTarget, isNativeAppStyleTarget, isViteProcessedCssAsset, isWebGeneratorTarget, jsAfterCss, jsTaskFactories, lastCssResultByFile, lastCssSourceHashByFile, linkedByEntry, markCssAssetProcessed, metrics, onEnd, onUpdate, opts, pendingLinkedUpdates, pruneViteCssCaches, recordCssAssetResult, recordTimingDetail, recordViteProcessedCssAssetResult, rootDir, runtime, runtimeState, shouldPreserveAppCssExtension, snapshot, sourceCandidates, sourceRoot, state, styleHandler, tasks, timingDetails, transformRuntime, useIncrementalMode } = options;
|
|
3065
|
+
const { activeProcessCacheKeys, activeProcessHashKeys, activeViteCssCacheFiles, bundle, bundleFiles, cache, cssTaskFactories, debug, defaultStyleOutputExtension, formatIteration, generatorCandidateSignature, generatorRuntime, getCssHandlerOptions, getSourceCandidateSourcesForEntries, getSourceCandidatesForEntries, getViteCssCacheStats, getViteProcessedCssAssetResults, hmrTimingRecorder, hmrTimingStartedAt, isHarmonyAppStyleTarget, isNativeAppStyleTarget, isViteProcessedCssAsset, isWebGeneratorTarget, jsAfterCss, jsTaskFactories, lastCssResultByFile, lastCssSourceHashByFile, linkedByEntry, markCssAssetProcessed, metrics, onEnd, onUpdate, opts, outDir, pendingLinkedUpdates, pruneViteCssCaches, recordCssAssetResult, recordTimingDetail, recordViteProcessedCssAssetResult, rootDir, runtime, runtimeState, shouldPreserveAppCssExtension, snapshot, sourceCandidates, sourceRoot, state, styleHandler, tasks, timingDetails, transformRuntime, transformWebTargetCss, useIncrementalMode } = options;
|
|
2780
3066
|
const tasksStart = performance.now();
|
|
2781
3067
|
if (cssTaskFactories.length > 0) {
|
|
2782
3068
|
const cssTask = runWithConcurrency(cssTaskFactories, resolveViteCssTaskConcurrency(useIncrementalMode, runtimeState.tailwindRuntime.majorVersion)).then(() => void 0);
|
|
@@ -2811,6 +3097,7 @@ async function finalizeGenerateBundle(options) {
|
|
|
2811
3097
|
recordViteProcessedCssAssetResult,
|
|
2812
3098
|
resolveViteProcessedCssOutputFile: (file) => resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension, sourceRoot, defaultStyleOutputExtension, bundleFiles),
|
|
2813
3099
|
subpackageRoots: collectMiniProgramSubpackageRoots(bundle),
|
|
3100
|
+
transformCss: transformWebTargetCss,
|
|
2814
3101
|
debug
|
|
2815
3102
|
});
|
|
2816
3103
|
return injectViteProcessedCssIntoMainCssAssets(bundle, {
|
|
@@ -2818,6 +3105,7 @@ async function finalizeGenerateBundle(options) {
|
|
|
2818
3105
|
getViteProcessedCssAssetResults,
|
|
2819
3106
|
markCssAssetProcessed,
|
|
2820
3107
|
recordCssAssetResult,
|
|
3108
|
+
transformCss: transformWebTargetCss,
|
|
2821
3109
|
shouldRemoveInjectedSourceAsset: (targetFile, record) => {
|
|
2822
3110
|
if (record.injectIntoMain === false) return false;
|
|
2823
3111
|
const targetFileKey = normalizeOutputPathKey(targetFile);
|
|
@@ -2843,11 +3131,13 @@ async function finalizeGenerateBundle(options) {
|
|
|
2843
3131
|
removeCssCoveredByRootStyleAssets(bundle, {
|
|
2844
3132
|
cssMatcher: opts.cssMatcher,
|
|
2845
3133
|
debug,
|
|
3134
|
+
includeTailwindGeneratedCssAssets: opts.appType === "uni-app-vite" && isWebGeneratorTarget && isUniAppViteWebviewAppBundle(bundleFiles),
|
|
2846
3135
|
isViteProcessedCssAsset,
|
|
2847
3136
|
onUpdate,
|
|
2848
3137
|
recordCssAssetResult,
|
|
2849
3138
|
subpackageRoots: collectMiniProgramSubpackageRoots(bundle)
|
|
2850
3139
|
});
|
|
3140
|
+
if (opts.appType === "uni-app-vite" && isWebGeneratorTarget && isUniAppViteWebviewAppBundle(Object.keys(bundle))) removeDuplicateUnlinkedRootCssAssetsReferencedByHtml(bundle, { debug });
|
|
2851
3141
|
await finalizeMiniProgramCssAssets(bundle, {
|
|
2852
3142
|
cssMatcher: opts.cssMatcher,
|
|
2853
3143
|
debug,
|
|
@@ -2858,6 +3148,12 @@ async function finalizeGenerateBundle(options) {
|
|
|
2858
3148
|
recordCssAssetResult,
|
|
2859
3149
|
styleHandler
|
|
2860
3150
|
});
|
|
3151
|
+
if (opts.appType === "uni-app-vite" && (isWebGeneratorTarget || isUniAppViteWebviewAppBundle(Object.keys(bundle)) || isUniAppViteWebviewOutDir$2(outDir))) finalizeUniAppViteWebviewCssCompat(bundle, {
|
|
3152
|
+
debug,
|
|
3153
|
+
onUpdate,
|
|
3154
|
+
opts,
|
|
3155
|
+
recordCssAssetResult
|
|
3156
|
+
});
|
|
2861
3157
|
const stateUpdateStart = performance.now();
|
|
2862
3158
|
updateBundleBuildState(state, snapshot, useIncrementalMode ? linkedByEntry ?? /* @__PURE__ */ new Map() : /* @__PURE__ */ new Map(), { incremental: useIncrementalMode });
|
|
2863
3159
|
state.generatorCandidateSignature = generatorCandidateSignature;
|
|
@@ -3272,7 +3568,9 @@ function collectRememberedCssReplayGroups(sources, opts, rootDir, isWebGenerator
|
|
|
3272
3568
|
const groups = /* @__PURE__ */ new Map();
|
|
3273
3569
|
for (const [key, remembered] of sources ?? []) {
|
|
3274
3570
|
const cleanSourceFile = remembered.sourceFile.replace(/[?#].*$/, "");
|
|
3275
|
-
const
|
|
3571
|
+
const resolvedOutputFile = CSS_SOURCE_OUTPUT_EXT_RE.test(cleanSourceFile) ? resolveViteCssPipelineOutputFileFromSourceFile(remembered.sourceFile, opts, rootDir, isWebGeneratorTarget, preserveCssExtension, sourceRoot, styleOutputExtension, styleOutputFiles) : resolveViteCssPipelineOutputFileFromSourceFile(remembered.outputFile, opts, rootDir, isWebGeneratorTarget, preserveCssExtension, sourceRoot, styleOutputExtension, styleOutputFiles);
|
|
3572
|
+
const rememberedOutputFile = remembered.outputFile.replace(/[?#].*$/, "");
|
|
3573
|
+
const outputKey = normalizeOutputPathKey(opts.cssMatcher(rememberedOutputFile) && !normalizeOutputPathKey(rememberedOutputFile).includes("/") && normalizeOutputPathKey(rememberedOutputFile) !== normalizeOutputPathKey(resolvedOutputFile.replace(/[?#].*$/, "")) ? remembered.outputFile : resolvedOutputFile);
|
|
3276
3574
|
const group = groups.get(outputKey) ?? [];
|
|
3277
3575
|
group.push({
|
|
3278
3576
|
key,
|
|
@@ -3285,7 +3583,7 @@ function collectRememberedCssReplayGroups(sources, opts, rootDir, isWebGenerator
|
|
|
3285
3583
|
//#endregion
|
|
3286
3584
|
//#region src/bundlers/vite/generate-bundle/remembered-css-replay.ts
|
|
3287
3585
|
async function processRememberedCssReplay(options) {
|
|
3288
|
-
const { addWatchFile, activeViteCssCacheFiles, bundleFiles, cache, createScopedGeneratorRuntime, createScopedSourceCandidateGetter, createScopedSourceCandidateSourceGetter, cssTaskFactories, debug, defaultStyleOutputExtension, emitOrReplayCssAsset, generatorRuntime, getCssHandlerOptions, getCssUserHandlerOptions, getRememberedCssSignature, getRememberedCssSources, isNativeAppStyleTarget, isWebGeneratorTarget, lastCssResultByFile, lastCssSourceHashByFile, markCssAssetProcessed, metrics, normalizeViteCssCacheKey, onUpdate, opts, recordCssAssetResult, recordViteProcessedCssAssetResult, refreshRememberedCssSource, rootDir, runtimeState, setRememberedCssSignature, shouldInjectCssIntoMainFromOutput, shouldPreserveAppCssExtension, sourceRoot, styleHandler, timeTask, useIncrementalMode } = options;
|
|
3586
|
+
const { addWatchFile, activeViteCssCacheFiles, bundleFiles, cache, createScopedGeneratorRuntime, createScopedSourceCandidateGetter, createScopedSourceCandidateSourceGetter, cssTaskFactories, debug, defaultStyleOutputExtension, emitOrReplayCssAsset, generatorRuntime, generatorPlatform, getCssHandlerOptions, getCssUserHandlerOptions, getRememberedCssSignature, getRememberedCssSources, isNativeAppStyleTarget, isWebGeneratorTarget, lastCssResultByFile, lastCssSourceHashByFile, markCssAssetProcessed, metrics, normalizeViteCssCacheKey, onUpdate, opts, recordCssAssetResult, recordViteProcessedCssAssetResult, refreshRememberedCssSource, rootDir, runtimeState, setRememberedCssSignature, shouldInjectCssIntoMainFromOutput, shouldPreserveAppCssExtension, sourceRoot, styleHandler, timeTask, useIncrementalMode } = options;
|
|
3289
3587
|
const rememberedReplayGroups = collectRememberedCssReplayGroups(getRememberedCssSources?.(), opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension, sourceRoot, defaultStyleOutputExtension, bundleFiles);
|
|
3290
3588
|
for (const [outputFile, rememberedGroup] of rememberedReplayGroups) {
|
|
3291
3589
|
if (isHTMLRequest(outputFile) || options.opts.htmlMatcher(outputFile)) continue;
|
|
@@ -3336,6 +3634,7 @@ async function processRememberedCssReplay(options) {
|
|
|
3336
3634
|
cssHandlerOptions,
|
|
3337
3635
|
cssUserHandlerOptions: getCssUserHandlerOptions(sourceFile),
|
|
3338
3636
|
getSourceCandidatesForEntries: scopedSourceCandidateGetter,
|
|
3637
|
+
generatorPlatform,
|
|
3339
3638
|
styleHandler,
|
|
3340
3639
|
debug,
|
|
3341
3640
|
previousCss
|
|
@@ -3917,6 +4216,16 @@ function resolveSourceRootFromBundleGraph(config, bundle) {
|
|
|
3917
4216
|
}
|
|
3918
4217
|
//#endregion
|
|
3919
4218
|
//#region src/bundlers/vite/generate-bundle.ts
|
|
4219
|
+
function inferPlatformFromViteOutDir$1(outDir) {
|
|
4220
|
+
const segment = outDir ? path.basename(path.normalize(outDir)) : void 0;
|
|
4221
|
+
if (!segment) return;
|
|
4222
|
+
const normalized = segment.trim().toLowerCase();
|
|
4223
|
+
if (normalized === "h5" || normalized === "web" || normalized === "app" || normalized === "app-plus" || normalized.startsWith("app-") || normalized.startsWith("mp-") || normalized.startsWith("quickapp-webview")) return normalized;
|
|
4224
|
+
}
|
|
4225
|
+
function isUniAppViteWebviewOutDir$1(outDir) {
|
|
4226
|
+
const normalized = outDir ? path.basename(path.normalize(outDir)).trim().toLowerCase() : void 0;
|
|
4227
|
+
return normalized === "app" || normalized === "app-plus";
|
|
4228
|
+
}
|
|
3920
4229
|
function createGenerateBundleHook(context) {
|
|
3921
4230
|
const state = createBundleBuildState();
|
|
3922
4231
|
const lastCssResultByFile = /* @__PURE__ */ new Map();
|
|
@@ -3946,23 +4255,32 @@ function createGenerateBundleHook(context) {
|
|
|
3946
4255
|
const { cache, onEnd, onStart, onUpdate, styleHandler, templateHandler, jsHandler, uniAppX } = opts;
|
|
3947
4256
|
const resolvedConfig = getResolvedConfig();
|
|
3948
4257
|
const uniUtsPlatform = resolveUniUtsPlatform();
|
|
3949
|
-
const
|
|
4258
|
+
const generatorPlatform = opts.cssOptions?.platform ?? opts.platform ?? inferPlatformFromViteOutDir$1(resolvedConfig?.build?.outDir);
|
|
4259
|
+
const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(opts.generator, {
|
|
3950
4260
|
appType: opts.appType,
|
|
3951
|
-
platform:
|
|
4261
|
+
platform: generatorPlatform,
|
|
3952
4262
|
tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
3953
4263
|
uniAppX,
|
|
3954
4264
|
uniUtsPlatform
|
|
3955
|
-
})
|
|
4265
|
+
});
|
|
4266
|
+
const generatorBranch = resolveGeneratorRuntimeBranch(generatorOptions, {
|
|
3956
4267
|
appType: opts.appType,
|
|
3957
|
-
platform:
|
|
4268
|
+
platform: generatorPlatform,
|
|
3958
4269
|
tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
3959
4270
|
uniAppX,
|
|
3960
4271
|
uniUtsPlatform
|
|
3961
4272
|
});
|
|
3962
4273
|
const isWebGeneratorTarget = generatorBranch.isWeb;
|
|
3963
|
-
const
|
|
3964
|
-
const
|
|
3965
|
-
const
|
|
4274
|
+
const shouldApplyWebviewSafeSelectors = opts.appType === "uni-app-vite" && isUniAppViteWebviewOutDir$1(resolvedConfig?.build?.outDir);
|
|
4275
|
+
const shouldApplyWebviewCssCompat = isWebGeneratorTarget || shouldApplyWebviewSafeSelectors;
|
|
4276
|
+
const transformWebTargetCss = (css) => {
|
|
4277
|
+
const compatCss = isWebGeneratorTarget ? transformWebCssCompat(css, generatorOptions.webCompat) : shouldApplyWebviewCssCompat ? transformWebCssCompat(css, generatorOptions.webCompat ?? true) : css;
|
|
4278
|
+
return shouldApplyWebviewSafeSelectors ? transformWebCssSafeSelectors(compatCss, { escapeMap: opts.escapeMap }) : compatCss;
|
|
4279
|
+
};
|
|
4280
|
+
const isUniAppXStyleTarget = opts.appType === "uni-app-x";
|
|
4281
|
+
const isNativeAppStyleTarget = isUniAppXStyleTarget && uniUtsPlatform.isApp;
|
|
4282
|
+
const canInferHarmonyAppStyleTarget = isUniAppXStyleTarget && (!uniUtsPlatform.normalized || uniUtsPlatform.isApp);
|
|
4283
|
+
const isHarmonyAppStyleTarget = isUniAppXStyleTarget && (uniUtsPlatform.isAppHarmony || canInferHarmonyAppStyleTarget && (isUniAppXHarmonyBundle(bundle) || isUniAppXHarmonyOutDir(resolvedConfig?.build?.outDir)));
|
|
3966
4284
|
const shouldPreserveAppCssExtension = isNativeAppStyleTarget || isHarmonyAppStyleTarget;
|
|
3967
4285
|
const shouldGenerateWebCssByGenerator = isWebGeneratorTarget;
|
|
3968
4286
|
const { getCssHandlerOptions, getCssUserHandlerOptions } = cssHandlerOptions;
|
|
@@ -3984,6 +4302,7 @@ function createGenerateBundleHook(context) {
|
|
|
3984
4302
|
recordViteProcessedCssAssetResult,
|
|
3985
4303
|
resolveViteProcessedCssOutputFile: (file) => resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension, sourceRoot, defaultStyleOutputExtension, Object.keys(bundle)),
|
|
3986
4304
|
subpackageRoots: currentSubpackageRoots,
|
|
4305
|
+
transformCss: transformWebTargetCss,
|
|
3987
4306
|
debug
|
|
3988
4307
|
});
|
|
3989
4308
|
const hmrTimingStartedAt = performance.now();
|
|
@@ -4027,7 +4346,47 @@ function createGenerateBundleHook(context) {
|
|
|
4027
4346
|
const snapshotStart = performance.now();
|
|
4028
4347
|
const snapshot = buildBundleSnapshot(bundle, opts, outDir, state, envFlags.disableDirtyOptimization || !useIncrementalMode, { hasOmittedKnownFiles });
|
|
4029
4348
|
const configuredTailwindV4CssSourceEntriesForScope = getConfiguredTailwindV4CssSourceEntries();
|
|
4030
|
-
const
|
|
4349
|
+
const normalizeSystemAliasPathKey = (file) => file.startsWith("/private/var/") ? file.slice(8) : file;
|
|
4350
|
+
const normalizeConfiguredTailwindV4CssEntryFileKey = (file) => {
|
|
4351
|
+
const cleanFile = file.replace(/[?#].*$/, "");
|
|
4352
|
+
return normalizeSystemAliasPathKey(normalizeOutputPathKey(path.isAbsolute(cleanFile) ? path.resolve(cleanFile) : path.resolve(opts.tailwindcssBasedir ?? rootDir, cleanFile)));
|
|
4353
|
+
};
|
|
4354
|
+
const runtimeTailwindcssOptions = resolveTailwindcssOptions(opts.tailwindcssRuntimeOptions);
|
|
4355
|
+
const tailwindRuntimeOptions = resolveTailwindcssOptions(runtimeState.tailwindRuntime.options);
|
|
4356
|
+
const configuredTailwindV4CssSourceFileKeysForScope = new Set(configuredTailwindV4CssSourceEntriesForScope.map((entry) => normalizeConfiguredTailwindV4CssEntryFileKey(entry.file)));
|
|
4357
|
+
const configuredTailwindV4ExplicitCssEntryFileKeysForScope = new Set([
|
|
4358
|
+
...Array.isArray(opts.cssEntries) ? opts.cssEntries : [],
|
|
4359
|
+
...Array.isArray(opts.tailwindcss?.v4?.cssEntries) ? opts.tailwindcss.v4.cssEntries : [],
|
|
4360
|
+
...Array.isArray(runtimeTailwindcssOptions?.v4?.cssEntries) ? runtimeTailwindcssOptions.v4.cssEntries : [],
|
|
4361
|
+
...Array.isArray(tailwindRuntimeOptions?.v4?.cssEntries) ? tailwindRuntimeOptions.v4.cssEntries : []
|
|
4362
|
+
].filter((file) => typeof file === "string" && file.length > 0).map(normalizeConfiguredTailwindV4CssEntryFileKey));
|
|
4363
|
+
const resolveUniAppViteWebviewRootCssInjectionTarget = (sourceFile, outputFile) => {
|
|
4364
|
+
if (opts.appType !== "uni-app-vite" || !outputFile.replace(/[?#].*$/, "").endsWith(".css") || typeof sourceFile !== "string" || !configuredTailwindV4ExplicitCssEntryFileKeysForScope.has(normalizeConfiguredTailwindV4CssEntryFileKey(sourceFile))) return;
|
|
4365
|
+
const rootCssFiles = bundleFiles.filter((file) => {
|
|
4366
|
+
const normalized = normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
4367
|
+
return opts.cssMatcher(file) && normalized.endsWith(".css") && !normalized.includes("/");
|
|
4368
|
+
});
|
|
4369
|
+
const matchedRootCssFiles = rootCssFiles.filter((file) => getCssHandlerOptions(file).isMainChunk);
|
|
4370
|
+
if (matchedRootCssFiles.length === 1) return matchedRootCssFiles[0];
|
|
4371
|
+
if (matchedRootCssFiles.length > 1) return;
|
|
4372
|
+
return rootCssFiles.length === 1 ? rootCssFiles[0] : void 0;
|
|
4373
|
+
};
|
|
4374
|
+
const resolveConfiguredTailwindV4CssEntryOutputFile = (sourceFile) => resolveViteCssPipelineOutputFile(sourceFile, opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension, sourceRoot, defaultStyleOutputExtension, bundleFiles);
|
|
4375
|
+
const selectUniAppViteWebviewRootCssSourceEntry = (outputFile, entries) => {
|
|
4376
|
+
if (opts.appType !== "uni-app-vite" || !isWebGeneratorTarget || !opts.cssMatcher(outputFile) || normalizeOutputPathKey(outputFile.replace(/[?#].*$/, "")).includes("/")) return;
|
|
4377
|
+
const generationEntries = entries.filter((entry) => hasTailwindGenerationSource(entry.source));
|
|
4378
|
+
if (generationEntries.length <= 1) return generationEntries[0];
|
|
4379
|
+
const rootOutputEntries = generationEntries.filter((entry) => {
|
|
4380
|
+
return !normalizeOutputPathKey(resolveConfiguredTailwindV4CssEntryOutputFile(entry.file).replace(/[?#].*$/, "")).includes("/");
|
|
4381
|
+
});
|
|
4382
|
+
if (rootOutputEntries.length === 1) return rootOutputEntries[0];
|
|
4383
|
+
if (currentSubpackageRoots) {
|
|
4384
|
+
const mainPackageEntries = generationEntries.filter((entry) => {
|
|
4385
|
+
return !isSubpackageOutputFile(resolveConfiguredTailwindV4CssEntryOutputFile(entry.file), currentSubpackageRoots);
|
|
4386
|
+
});
|
|
4387
|
+
if (mainPackageEntries.length === 1) return mainPackageEntries[0];
|
|
4388
|
+
}
|
|
4389
|
+
};
|
|
4031
4390
|
const { createScopedSourceCandidateGetter, createScopedSourceCandidateSourceGetter, shouldExcludeSubpackageSourceCandidates, shouldInjectCssIntoMainFromOutput } = createSubpackageSourceCandidateScope({
|
|
4032
4391
|
cssSourceFiles: configuredTailwindV4CssSourceEntriesForScope.map((entry) => entry.file),
|
|
4033
4392
|
getSourceCandidateSourcesForEntries,
|
|
@@ -4183,10 +4542,14 @@ function createGenerateBundleHook(context) {
|
|
|
4183
4542
|
onUpdate,
|
|
4184
4543
|
debug
|
|
4185
4544
|
});
|
|
4186
|
-
const
|
|
4545
|
+
const createBaseHandlerOptions = createJsHandlerOptionsFactory({
|
|
4187
4546
|
getMajorVersion: () => runtimeState.tailwindRuntime.majorVersion,
|
|
4188
4547
|
moduleGraph: moduleGraphOptions
|
|
4189
4548
|
});
|
|
4549
|
+
const createHandlerOptions = (absoluteFilename, extra) => createBaseHandlerOptions(absoluteFilename, shouldApplyWebviewSafeSelectors ? {
|
|
4550
|
+
needEscaped: true,
|
|
4551
|
+
...extra
|
|
4552
|
+
} : extra);
|
|
4190
4553
|
const linkedByEntry = useIncrementalMode ? /* @__PURE__ */ new Map() : void 0;
|
|
4191
4554
|
const sharedCssResultCache = /* @__PURE__ */ new Map();
|
|
4192
4555
|
const activeProcessCacheKeys = /* @__PURE__ */ new Set();
|
|
@@ -4301,7 +4664,7 @@ function createGenerateBundleHook(context) {
|
|
|
4301
4664
|
return await refreshRememberedCssSource?.(remembered) ?? remembered;
|
|
4302
4665
|
}));
|
|
4303
4666
|
rememberedCssSources = rememberedCssSources.filter((remembered) => {
|
|
4304
|
-
if (!configuredTailwindV4CssSourceFileKeysForScope.has(
|
|
4667
|
+
if (!configuredTailwindV4CssSourceFileKeysForScope.has(normalizeConfiguredTailwindV4CssEntryFileKey(remembered.sourceFile))) return true;
|
|
4305
4668
|
const matchedOutputFile = resolveMatchedOutputFileForCurrentAsset(remembered.sourceFile);
|
|
4306
4669
|
return !matchedOutputFile || normalizeOutputPathKey(matchedOutputFile) === normalizeOutputPathKey(outputFile);
|
|
4307
4670
|
});
|
|
@@ -4312,7 +4675,7 @@ function createGenerateBundleHook(context) {
|
|
|
4312
4675
|
const rememberedSourcesBelongToInferredSfc = rememberedCssSources.length > 0 && rememberedCssSources.every((remembered) => normalizeSfcSourceFileForCompare(remembered.sourceFile) === inferredSourceFile);
|
|
4313
4676
|
if (!hasUsableRememberedTailwindSource || rememberedSourcesBelongToInferredSfc) rememberedCssSources = [inferredSfcStyleSource];
|
|
4314
4677
|
}
|
|
4315
|
-
if (isTemporaryCssAssetFile(outputFile) && rememberedCssSources.some((remembered) => configuredTailwindV4CssSourceFileKeysForScope.has(
|
|
4678
|
+
if (isTemporaryCssAssetFile(outputFile) && rememberedCssSources.some((remembered) => configuredTailwindV4CssSourceFileKeysForScope.has(normalizeConfiguredTailwindV4CssEntryFileKey(remembered.sourceFile)))) {
|
|
4316
4679
|
rememberedCssSources = [];
|
|
4317
4680
|
hasUsableRememberedTailwindSource = false;
|
|
4318
4681
|
}
|
|
@@ -4340,7 +4703,14 @@ function createGenerateBundleHook(context) {
|
|
|
4340
4703
|
}
|
|
4341
4704
|
if (!hasUsableRememberedTailwindSource) {
|
|
4342
4705
|
const configuredTailwindV4CssSourceEntries = getConfiguredTailwindV4CssSourceEntries();
|
|
4343
|
-
const
|
|
4706
|
+
const inferredSourceStyle = resolveSourceStyleSourceFromOutputFile(outputFile, snapshot, outDir, sourceRoot, getCssSource, getSourceCandidateSources, configuredTailwindV4CssSourceEntries.map((entry) => [entry.file, entry.source]), debug);
|
|
4707
|
+
const inferredWebviewRootSourceEntry = inferredSourceStyle ? void 0 : selectUniAppViteWebviewRootCssSourceEntry(outputFile, configuredTailwindV4CssSourceEntries);
|
|
4708
|
+
const inferredWebviewRootSourceStyle = inferredWebviewRootSourceEntry ? {
|
|
4709
|
+
outputFile,
|
|
4710
|
+
rawSource: inferredWebviewRootSourceEntry.source,
|
|
4711
|
+
sourceFile: inferredWebviewRootSourceEntry.file
|
|
4712
|
+
} : void 0;
|
|
4713
|
+
const inferredOriginalSourceStyle = inferredSourceStyle ?? (outputFile === file ? void 0 : resolveSourceStyleSourceFromOutputFile(file, snapshot, outDir, sourceRoot, getCssSource, getSourceCandidateSources, configuredTailwindV4CssSourceEntries.map((entry) => [entry.file, entry.source]), debug)) ?? inferredWebviewRootSourceStyle;
|
|
4344
4714
|
if (inferredOriginalSourceStyle) {
|
|
4345
4715
|
outputFile = resolveMatchedOutputFileForCurrentAsset(inferredOriginalSourceStyle.sourceFile) ?? outputFile;
|
|
4346
4716
|
activeViteCssCacheFiles.add(normalizeViteCssCacheKey(outputFile));
|
|
@@ -4390,7 +4760,7 @@ function createGenerateBundleHook(context) {
|
|
|
4390
4760
|
}
|
|
4391
4761
|
}
|
|
4392
4762
|
let rememberedCssSource = mergeRememberedCssSources(rememberedCssSources, outputFile);
|
|
4393
|
-
if (rememberedCssSource && viteProcessedCssAsset && outputCssHandlerOptions.isMainChunk !== true && configuredTailwindV4CssSourceFileKeysForScope.has(
|
|
4763
|
+
if (rememberedCssSource && viteProcessedCssAsset && outputCssHandlerOptions.isMainChunk !== true && configuredTailwindV4CssSourceFileKeysForScope.has(normalizeConfiguredTailwindV4CssEntryFileKey(rememberedCssSource.sourceFile))) {
|
|
4394
4764
|
const matchedOutputFile = resolveMatchedOutputFileForCurrentAsset(rememberedCssSource.sourceFile);
|
|
4395
4765
|
if (matchedOutputFile && normalizeOutputPathKey(matchedOutputFile) !== normalizeOutputPathKey(outputFile)) {
|
|
4396
4766
|
outputFile = matchedOutputFile;
|
|
@@ -4419,11 +4789,12 @@ function createGenerateBundleHook(context) {
|
|
|
4419
4789
|
}
|
|
4420
4790
|
const hasRememberedApplyDirective = rememberedCssSource != null && hasTailwindApplyDirective(rememberedCssSource.rawSource);
|
|
4421
4791
|
const hasRememberedTailwindGenerationSource = rememberedCssSource != null && hasTailwindGenerationSource(rememberedCssSource.rawSource);
|
|
4422
|
-
const usesConfiguredTailwindV4FallbackSource = rememberedCssSource != null && normalizeOutputPathKey(rememberedCssSource.outputFile) === normalizeOutputPathKey(outputFile) && normalizeOutputPathKey(rememberedCssSource.sourceFile.replace(/[?#].*$/, "")) !== normalizeOutputPathKey(file);
|
|
4423
4792
|
const hasSameOutputRememberedTailwindGenerationSource = hasRememberedTailwindGenerationSource && rememberedCssSource != null && normalizeOutputPathKey(rememberedCssSource.outputFile) === normalizeOutputPathKey(outputFile);
|
|
4424
4793
|
const hasStaleViteProcessedCssSource = vitePipelineCssAsset && hasDifferentRememberedCssSource && (hasCurrentTailwindGenerationDirective || hasRememberedApplyDirective || hasRememberedTailwindGenerationSource);
|
|
4425
4794
|
const generatorSourceFile = vitePipelineCssAsset ? rememberedCssSource?.sourceFile ?? assetSourceFile : assetSourceFile;
|
|
4426
|
-
|
|
4795
|
+
const webviewRootCssInjectionTarget = vitePipelineCssAsset ? resolveUniAppViteWebviewRootCssInjectionTarget(generatorSourceFile, outputFile) : void 0;
|
|
4796
|
+
const usesConfiguredTailwindV4FallbackSource = rememberedCssSource != null && normalizeOutputPathKey(rememberedCssSource.outputFile) === normalizeOutputPathKey(outputFile) && normalizeOutputPathKey(rememberedCssSource.sourceFile.replace(/[?#].*$/, "")) !== normalizeOutputPathKey(file);
|
|
4797
|
+
if (vitePipelineCssAsset && outputCssHandlerOptions.isMainChunk !== true && configuredTailwindV4CssSourceFileKeysForScope.has(normalizeConfiguredTailwindV4CssEntryFileKey(generatorSourceFile))) {
|
|
4427
4798
|
usedConfiguredTailwindV4CssSourceFiles.add(normalizeOutputPathKey(generatorSourceFile));
|
|
4428
4799
|
temporaryCssAssetSourceResolver.markUsed(generatorSourceFile);
|
|
4429
4800
|
}
|
|
@@ -4431,7 +4802,7 @@ function createGenerateBundleHook(context) {
|
|
|
4431
4802
|
...getCssHandlerOptions(generatorSourceFile),
|
|
4432
4803
|
isMainChunk: resolvedFromTemporaryCssAsset ? false : outputCssHandlerOptions.isMainChunk
|
|
4433
4804
|
} : getCssHandlerOptions(file);
|
|
4434
|
-
const generatorCssEntries =
|
|
4805
|
+
const generatorCssEntries = configuredTailwindV4ExplicitCssEntryFileKeysForScope.has(normalizeConfiguredTailwindV4CssEntryFileKey(generatorSourceFile)) ? [generatorSourceFile] : opts.cssEntries;
|
|
4435
4806
|
const generatorCssHandlerOptions = {
|
|
4436
4807
|
...cssHandlerOptions,
|
|
4437
4808
|
sourceOptions: {
|
|
@@ -4449,6 +4820,10 @@ function createGenerateBundleHook(context) {
|
|
|
4449
4820
|
opts,
|
|
4450
4821
|
tokenSources: sourceTraceTokenSources
|
|
4451
4822
|
});
|
|
4823
|
+
const removeRootCoveredCssFromScopedAsset = (css) => {
|
|
4824
|
+
const normalizedOutputFile = normalizeOutputPathKey(outputFile.replace(/[?#].*$/, ""));
|
|
4825
|
+
return !normalizedOutputFile.includes("/") || currentSubpackageRoots != null && isSubpackageOutputFile(normalizedOutputFile, currentSubpackageRoots) ? css : removeCssCoveredByRootStyleBundleSources(bundle, outputFile, css);
|
|
4826
|
+
};
|
|
4452
4827
|
const shouldRegenerateMainPackageCssWithScopedCandidates = vitePipelineCssAsset && shouldExcludeSubpackageSourceCandidates(outputFile, generatorCssHandlerOptions);
|
|
4453
4828
|
const generatorCssUserHandlerOptions = getCssUserHandlerOptions(generatorSourceFile);
|
|
4454
4829
|
const cssRuntimeAffectingSignature = vitePipelineCssAsset ? createRuntimeAffectingSourceSignature(generatorRawSource, "css") : snapshot.runtimeAffectingSignatureByFile.get(file) ?? createRuntimeAffectingSourceSignature(generatorRawSource, "css");
|
|
@@ -4456,19 +4831,30 @@ function createGenerateBundleHook(context) {
|
|
|
4456
4831
|
const cssShareScope = createCssTransformShareScopeKey(opts, outputFile, generatorRawSource);
|
|
4457
4832
|
const shouldRegenerateCollectedViteCss = viteProcessedCssAsset && useIncrementalMode && state.generatorCandidateSignature !== void 0 && generatorCandidatesChanged && (hasTailwindGenerationSource(generatorRawSource) || hasBundlerGeneratedCssMarker(rawSource) || rememberedCssSource != null && hasTailwindGenerationSource(rememberedCssSource.rawSource));
|
|
4458
4833
|
const shouldRefreshViteProcessedCssByCandidates = viteProcessedCssAsset && useIncrementalMode && state.generatorCandidateSignature !== void 0 && generatorCandidatesChanged;
|
|
4459
|
-
const
|
|
4834
|
+
const vitePipelineCssInjectionOutputFile = webviewRootCssInjectionTarget ?? outputFile;
|
|
4835
|
+
const shouldRecordVitePipelineCssByOutput = normalizeOutputPathKey(vitePipelineCssInjectionOutputFile) === normalizeOutputPathKey(outputFile);
|
|
4836
|
+
const shouldInjectVitePipelineCssIntoMain = vitePipelineCssAsset && outputCssHandlerOptions.isMainChunk !== true && (webviewRootCssInjectionTarget != null || shouldInjectCssIntoMainFromOutput(outputFile, generatorSourceFile, outputCssHandlerOptions));
|
|
4460
4837
|
const shouldTrackGeneratorRuntime = hasStaleViteProcessedCssSource || shouldRegenerateMainPackageCssWithScopedCandidates || hasCurrentTailwindGenerationDirective || hasSameOutputRememberedTailwindGenerationSource || shouldProcessTailwindGeneration && (!useIncrementalMode || cssHandlerOptions.isMainChunk || processFiles.css.has(file) || runtimeLinkedCssFiles.has(file) || runtimeLinkedCssFiles.has(outputFile) || shouldRegenerateCollectedViteCss || hasRuntimeAffectingChanges && (alreadyProcessedCssAsset || vitePipelineCssAsset));
|
|
4461
4838
|
const shouldPreserveCollectedViteCssAsset = !shouldRegenerateCollectedViteCss && (state.generatorCandidateSignature === void 0 || !generatorCandidatesChanged) && (collectedBundlerGeneratedCssFiles.has(file) || hasBundlerGeneratedCssMarker(rawSource));
|
|
4462
4839
|
const strippedViteProcessedCss = stripBundlerGeneratedCssMarkers(rawSource);
|
|
4463
4840
|
const shouldPreserveStaleGeneratedCssAsset = hasStaleViteProcessedCssSource && shouldPreserveCollectedViteCssAsset && strippedViteProcessedCss.trim().length > 0 && !strippedViteProcessedCss.includes("weapp-tailwindcss generator-placeholder") && !strippedViteProcessedCss.includes("vite-placeholder") && !hasTailwindGenerationSource(strippedViteProcessedCss) && !hasTailwindApplyDirective(strippedViteProcessedCss);
|
|
4464
4841
|
if (alreadyProcessedCssAsset && !shouldRefreshViteProcessedCssByCandidates && (!hasStaleViteProcessedCssSource || shouldPreserveStaleGeneratedCssAsset) && !hasRememberedApplySource && !shouldRegenerateMainPackageCssWithScopedCandidates && (!shouldTrackGeneratorRuntime || shouldPreserveCollectedViteCssAsset)) {
|
|
4465
|
-
const nextCss = strippedViteProcessedCss;
|
|
4842
|
+
const nextCss = removeRootCoveredCssFromScopedAsset(strippedViteProcessedCss);
|
|
4466
4843
|
applyCssResult(nextCss);
|
|
4467
4844
|
markCssAssetProcessed?.(originalSource, outputFile);
|
|
4468
4845
|
recordCssAssetResult?.(outputFile, nextCss);
|
|
4469
|
-
|
|
4846
|
+
if (vitePipelineCssAsset && rememberedCssSource) rememberCssSource?.({
|
|
4847
|
+
outputFile: vitePipelineCssInjectionOutputFile,
|
|
4848
|
+
rawSource: generatorRawSource,
|
|
4849
|
+
sourceFile: generatorSourceFile
|
|
4850
|
+
});
|
|
4851
|
+
if (shouldRecordVitePipelineCssByOutput) recordViteProcessedCssAssetResult?.(vitePipelineCssInjectionOutputFile, nextCss, {
|
|
4470
4852
|
injectIntoMain: outputCssHandlerOptions.isMainChunk ? false : shouldInjectVitePipelineCssIntoMain,
|
|
4471
|
-
outputFile
|
|
4853
|
+
outputFile: vitePipelineCssInjectionOutputFile
|
|
4854
|
+
});
|
|
4855
|
+
if (vitePipelineCssAsset && shouldInjectVitePipelineCssIntoMain) recordViteProcessedCssAssetResult?.(file, nextCss, {
|
|
4856
|
+
injectIntoMain: shouldInjectVitePipelineCssIntoMain,
|
|
4857
|
+
outputFile: vitePipelineCssInjectionOutputFile
|
|
4472
4858
|
});
|
|
4473
4859
|
onUpdate(outputFile, rawSource, nextCss);
|
|
4474
4860
|
debug("css skip vite-processed asset: %s", outputFile);
|
|
@@ -4506,7 +4892,7 @@ function createGenerateBundleHook(context) {
|
|
|
4506
4892
|
rememberLastCssResult(lastCssResultByFile, lastCssSourceHashByFile, outputFile, source, cssRuntimeAffectingHash);
|
|
4507
4893
|
markCssAssetProcessed?.(originalSource, outputFile);
|
|
4508
4894
|
if (rememberedCssSources.length <= 1) rememberCssSource?.({
|
|
4509
|
-
outputFile,
|
|
4895
|
+
outputFile: vitePipelineCssInjectionOutputFile,
|
|
4510
4896
|
rawSource: generatorRawSource,
|
|
4511
4897
|
sourceFile: generatorSourceFile
|
|
4512
4898
|
}, rememberedCssRuntimeSignature);
|
|
@@ -4541,6 +4927,7 @@ function createGenerateBundleHook(context) {
|
|
|
4541
4927
|
cssUserHandlerOptions: generatorCssUserHandlerOptions,
|
|
4542
4928
|
getSourceCandidatesForEntries: scopedSourceCandidateGetter,
|
|
4543
4929
|
sourceCandidates: scopedGeneratorRuntime,
|
|
4930
|
+
generatorPlatform,
|
|
4544
4931
|
styleHandler,
|
|
4545
4932
|
debug,
|
|
4546
4933
|
previousCss,
|
|
@@ -4548,19 +4935,19 @@ function createGenerateBundleHook(context) {
|
|
|
4548
4935
|
...usesConfiguredTailwindV4FallbackSource ? { restoreLocalCssImports: false } : {}
|
|
4549
4936
|
}) : void 0;
|
|
4550
4937
|
if (generated) {
|
|
4551
|
-
const tracedCss = annotateCss(generated.css);
|
|
4938
|
+
const tracedCss = removeRootCoveredCssFromScopedAsset(annotateCss(transformWebTargetCss(generated.css)));
|
|
4552
4939
|
registerGeneratorDependencies$1({ addWatchFile }, generated.dependencies);
|
|
4553
4940
|
if (envFlags.debugCssDiff) debug("css diff %s: %s", generatorSourceFile, summarizeStringDiff(generatorRawSource, tracedCss));
|
|
4554
4941
|
debug("css generated result: %s bytes=%d", file, tracedCss.length);
|
|
4555
4942
|
for (const candidate of generated.classSet ?? []) transformRuntime.add(candidate);
|
|
4556
4943
|
recordCssAssetResult?.(outputFile, tracedCss);
|
|
4557
|
-
recordViteProcessedCssAssetResult?.(
|
|
4944
|
+
if (shouldRecordVitePipelineCssByOutput) recordViteProcessedCssAssetResult?.(vitePipelineCssInjectionOutputFile, tracedCss, {
|
|
4558
4945
|
injectIntoMain: outputCssHandlerOptions.isMainChunk ? false : shouldInjectVitePipelineCssIntoMain,
|
|
4559
|
-
outputFile
|
|
4946
|
+
outputFile: vitePipelineCssInjectionOutputFile
|
|
4560
4947
|
});
|
|
4561
4948
|
if (vitePipelineCssAsset && shouldInjectVitePipelineCssIntoMain) recordViteProcessedCssAssetResult?.(file, tracedCss, {
|
|
4562
4949
|
injectIntoMain: shouldInjectVitePipelineCssIntoMain,
|
|
4563
|
-
outputFile
|
|
4950
|
+
outputFile: vitePipelineCssInjectionOutputFile
|
|
4564
4951
|
});
|
|
4565
4952
|
metrics.css.elapsed += measureElapsed(start);
|
|
4566
4953
|
metrics.css.transformed++;
|
|
@@ -4568,10 +4955,11 @@ function createGenerateBundleHook(context) {
|
|
|
4568
4955
|
return tracedCss;
|
|
4569
4956
|
}
|
|
4570
4957
|
if (isWebGeneratorTarget) {
|
|
4958
|
+
const outputCss = transformWebTargetCss(rawSource);
|
|
4571
4959
|
metrics.css.elapsed += measureElapsed(start);
|
|
4572
4960
|
metrics.css.transformed++;
|
|
4573
4961
|
debug("css preserve web target: %s", outputFile);
|
|
4574
|
-
return annotateCss(
|
|
4962
|
+
return annotateCss(outputCss);
|
|
4575
4963
|
}
|
|
4576
4964
|
const { css } = await styleHandler(generatorRawSource, cssHandlerOptions);
|
|
4577
4965
|
const tracedCss = annotateCss(css);
|
|
@@ -4591,7 +4979,7 @@ function createGenerateBundleHook(context) {
|
|
|
4591
4979
|
continue;
|
|
4592
4980
|
}
|
|
4593
4981
|
if (type !== "js") continue;
|
|
4594
|
-
if (isWebGeneratorTarget) {
|
|
4982
|
+
if (isWebGeneratorTarget && !shouldApplyWebviewSafeSelectors) {
|
|
4595
4983
|
debug("js skip web target: %s", file);
|
|
4596
4984
|
continue;
|
|
4597
4985
|
}
|
|
@@ -4637,6 +5025,7 @@ function createGenerateBundleHook(context) {
|
|
|
4637
5025
|
debug,
|
|
4638
5026
|
defaultStyleOutputExtension,
|
|
4639
5027
|
emitOrReplayCssAsset,
|
|
5028
|
+
generatorPlatform,
|
|
4640
5029
|
generatorRuntime,
|
|
4641
5030
|
getCssHandlerOptions,
|
|
4642
5031
|
getCssUserHandlerOptions,
|
|
@@ -4716,12 +5105,19 @@ function createGenerateBundleHook(context) {
|
|
|
4716
5105
|
tasks,
|
|
4717
5106
|
timingDetails,
|
|
4718
5107
|
transformRuntime,
|
|
5108
|
+
transformWebTargetCss,
|
|
4719
5109
|
useIncrementalMode
|
|
4720
5110
|
});
|
|
4721
5111
|
};
|
|
4722
5112
|
}
|
|
4723
5113
|
//#endregion
|
|
4724
5114
|
//#region src/bundlers/vite/css-finalizer.ts
|
|
5115
|
+
function inferPlatformFromViteOutDir(outDir) {
|
|
5116
|
+
const segment = outDir ? path.basename(path.normalize(outDir)) : void 0;
|
|
5117
|
+
if (!segment) return;
|
|
5118
|
+
const normalized = segment.trim().toLowerCase();
|
|
5119
|
+
if (normalized === "h5" || normalized === "web" || normalized === "app" || normalized === "app-plus" || normalized.startsWith("app-") || normalized.startsWith("mp-") || normalized.startsWith("quickapp-webview")) return normalized;
|
|
5120
|
+
}
|
|
4725
5121
|
function isAddWatchFileInvalidRollupPhaseError(error) {
|
|
4726
5122
|
const candidate = error;
|
|
4727
5123
|
return candidate?.code === "INVALID_ROLLUP_PHASE" || candidate?.pluginCode === "INVALID_ROLLUP_PHASE" || candidate?.message?.includes("Cannot call \"addWatchFile\" after the build has finished.") === true;
|
|
@@ -4765,8 +5161,13 @@ function shouldFinalizeProcessedCssAsset(opts, file) {
|
|
|
4765
5161
|
function collectViteProcessedCssSources(getViteProcessedCssAssetResults) {
|
|
4766
5162
|
return [...getViteProcessedCssAssetResults?.() ?? []].map(([, record]) => typeof record === "string" ? record : record.css);
|
|
4767
5163
|
}
|
|
4768
|
-
function
|
|
4769
|
-
|
|
5164
|
+
function isUniAppViteWebviewOutDir(outDir) {
|
|
5165
|
+
const normalized = outDir ? path.basename(path.normalize(outDir)).trim().toLowerCase() : void 0;
|
|
5166
|
+
return normalized === "app" || normalized === "app-plus";
|
|
5167
|
+
}
|
|
5168
|
+
function finalizeWebCss(css, enabled, webCompat, options = {}) {
|
|
5169
|
+
const compatCss = enabled ? transformWebCssCompat(css, webCompat) : css;
|
|
5170
|
+
return options.safeSelectors ? transformWebCssSafeSelectors(compatCss, { escapeMap: options.escapeMap }) : compatCss;
|
|
4770
5171
|
}
|
|
4771
5172
|
function createViteCssFinalizerOutputPlugin(context) {
|
|
4772
5173
|
return {
|
|
@@ -4778,24 +5179,27 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
4778
5179
|
const { opts, runtimeState, ensureRuntimeClassSet, isCssAssetProcessed, markCssAssetProcessed, debug, getResolvedConfig, recordCssAssetResult, recordViteProcessedCssAssetResult, getViteProcessedCssAssetResults, getRecordedGeneratorCandidates, getSourceCandidates, getSourceCandidatesForEntries, getSourceCandidateSourcesForEntries, waitForSourceCandidateSyncs, rememberMainCssSource, getRememberedMainCssSource, isViteProcessedCssAsset } = context;
|
|
4779
5180
|
const resolvedConfig = getResolvedConfig();
|
|
4780
5181
|
const uniUtsPlatform = resolveUniUtsPlatform();
|
|
5182
|
+
const generatorPlatform = opts.cssOptions?.platform ?? opts.platform ?? inferPlatformFromViteOutDir(resolvedConfig?.build?.outDir);
|
|
4781
5183
|
const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(opts.generator, {
|
|
4782
5184
|
appType: opts.appType,
|
|
4783
|
-
platform:
|
|
5185
|
+
platform: generatorPlatform,
|
|
4784
5186
|
tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
4785
5187
|
uniAppX: opts.uniAppX,
|
|
4786
5188
|
uniUtsPlatform
|
|
4787
5189
|
});
|
|
4788
5190
|
const generatorBranch = resolveGeneratorRuntimeBranch(generatorOptions, {
|
|
4789
5191
|
appType: opts.appType,
|
|
4790
|
-
platform:
|
|
5192
|
+
platform: generatorPlatform,
|
|
4791
5193
|
tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
4792
5194
|
uniAppX: opts.uniAppX,
|
|
4793
5195
|
uniUtsPlatform
|
|
4794
5196
|
});
|
|
4795
5197
|
const isWebGeneratorTarget = generatorBranch.isWeb;
|
|
4796
|
-
const
|
|
4797
|
-
const
|
|
4798
|
-
const
|
|
5198
|
+
const shouldApplyWebviewSafeSelectors = opts.appType === "uni-app-vite" && isUniAppViteWebviewOutDir(resolvedConfig?.build?.outDir);
|
|
5199
|
+
const isUniAppXStyleTarget = opts.appType === "uni-app-x";
|
|
5200
|
+
const canInferHarmonyAppStyleTarget = isUniAppXStyleTarget && (!uniUtsPlatform.normalized || uniUtsPlatform.isApp);
|
|
5201
|
+
const isHarmonyAppStyleTarget = isUniAppXStyleTarget && (uniUtsPlatform.isAppHarmony || canInferHarmonyAppStyleTarget && (isUniAppXHarmonyBundle(bundle) || isUniAppXHarmonyOutDir(resolvedConfig?.build?.outDir)));
|
|
5202
|
+
const isNativeAppStyleTarget = isUniAppXStyleTarget && (uniUtsPlatform.isApp || isHarmonyAppStyleTarget);
|
|
4799
5203
|
if (resolvedConfig?.command !== "build" && !isNativeAppStyleTarget) return;
|
|
4800
5204
|
const rootDir = resolvedConfig?.root ? path.resolve(resolvedConfig.root) : process$1.cwd();
|
|
4801
5205
|
const sourceRoot = resolveWeappViteSourceRoot(resolvedConfig, opts.appType) ?? resolveSourceRootFromBundleGraph(resolvedConfig, bundle);
|
|
@@ -4812,7 +5216,10 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
4812
5216
|
recordCssAssetResult,
|
|
4813
5217
|
recordViteProcessedCssAssetResult,
|
|
4814
5218
|
resolveViteProcessedCssOutputFile: (file) => resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget, isNativeAppStyleTarget, sourceRoot, resolveMiniProgramStyleOutputExtension({ files: Object.keys(bundle) }), Object.keys(bundle)),
|
|
4815
|
-
transformCss: (css) => finalizeWebCss(css, generatorBranch.isWeb, generatorOptions.webCompat
|
|
5219
|
+
transformCss: (css) => finalizeWebCss(css, generatorBranch.isWeb, generatorOptions.webCompat, {
|
|
5220
|
+
escapeMap: opts.escapeMap,
|
|
5221
|
+
safeSelectors: shouldApplyWebviewSafeSelectors
|
|
5222
|
+
}),
|
|
4816
5223
|
debug
|
|
4817
5224
|
});
|
|
4818
5225
|
};
|
|
@@ -4822,6 +5229,10 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
4822
5229
|
getViteProcessedCssAssetResults,
|
|
4823
5230
|
markCssAssetProcessed,
|
|
4824
5231
|
recordCssAssetResult,
|
|
5232
|
+
transformCss: (css) => finalizeWebCss(css, generatorBranch.isWeb, generatorOptions.webCompat, {
|
|
5233
|
+
escapeMap: opts.escapeMap,
|
|
5234
|
+
safeSelectors: shouldApplyWebviewSafeSelectors
|
|
5235
|
+
}),
|
|
4825
5236
|
debug,
|
|
4826
5237
|
onUpdate: opts.onUpdate
|
|
4827
5238
|
});
|
|
@@ -4847,6 +5258,7 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
4847
5258
|
isMainChunk: false
|
|
4848
5259
|
},
|
|
4849
5260
|
getSourceCandidatesForEntries,
|
|
5261
|
+
generatorPlatform,
|
|
4850
5262
|
styleHandler: opts.styleHandler,
|
|
4851
5263
|
debug
|
|
4852
5264
|
});
|
|
@@ -4885,7 +5297,10 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
4885
5297
|
const file = output.fileName || bundleFile;
|
|
4886
5298
|
const rawSource = output.source.toString();
|
|
4887
5299
|
if (isViteProcessedCssAsset?.(output, file)) {
|
|
4888
|
-
const nextCss = annotateCss(finalizeWebCss(stripBundlerGeneratedCssMarkers(rawSource), generatorBranch.isWeb, generatorOptions.webCompat
|
|
5300
|
+
const nextCss = annotateCss(finalizeWebCss(stripBundlerGeneratedCssMarkers(rawSource), generatorBranch.isWeb, generatorOptions.webCompat, {
|
|
5301
|
+
escapeMap: opts.escapeMap,
|
|
5302
|
+
safeSelectors: shouldApplyWebviewSafeSelectors
|
|
5303
|
+
}));
|
|
4889
5304
|
output.source = nextCss;
|
|
4890
5305
|
markCssAssetProcessed(output, file);
|
|
4891
5306
|
recordCssAssetResult?.(file, nextCss);
|
|
@@ -4916,10 +5331,14 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
4916
5331
|
cssHandlerOptions: generatorCssHandlerOptions,
|
|
4917
5332
|
cssUserHandlerOptions: generatorCssUserHandlerOptions,
|
|
4918
5333
|
getSourceCandidatesForEntries,
|
|
5334
|
+
generatorPlatform,
|
|
4919
5335
|
styleHandler: opts.styleHandler,
|
|
4920
5336
|
debug
|
|
4921
5337
|
}) : void 0;
|
|
4922
|
-
const nextCss = annotateCss(generated?.css ?? (generatorBranch.isWeb ? finalizeWebCss(rawSource, true, generatorOptions.webCompat
|
|
5338
|
+
const nextCss = annotateCss(generated?.css ?? (generatorBranch.isWeb ? finalizeWebCss(rawSource, true, generatorOptions.webCompat, {
|
|
5339
|
+
escapeMap: opts.escapeMap,
|
|
5340
|
+
safeSelectors: shouldApplyWebviewSafeSelectors
|
|
5341
|
+
}) : (await opts.styleHandler(rawSource, cssHandlerOptions)).css));
|
|
4923
5342
|
if (generated) {
|
|
4924
5343
|
registerGeneratorDependencies(this, generated.dependencies);
|
|
4925
5344
|
debug("css finalizer generated result: %s bytes=%d", file, nextCss.length);
|
|
@@ -5068,6 +5487,7 @@ function createViteCssMemory(options) {
|
|
|
5068
5487
|
for (const [rememberedKey, remembered] of relatedRememberedEntries) {
|
|
5069
5488
|
touchMapEntry(rememberedCssSources, rememberedKey, {
|
|
5070
5489
|
...remembered,
|
|
5490
|
+
outputFile: entry.outputFile,
|
|
5071
5491
|
rawSource: entry.rawSource,
|
|
5072
5492
|
sourceFile: entry.sourceFile
|
|
5073
5493
|
});
|
|
@@ -5718,6 +6138,15 @@ function sameStringList(first, second) {
|
|
|
5718
6138
|
if (!first || !second || first.length !== second.length) return false;
|
|
5719
6139
|
return first.every((item, index) => item === second[index]);
|
|
5720
6140
|
}
|
|
6141
|
+
function collectConfiguredCssEntries(options) {
|
|
6142
|
+
const runtimeCssEntries = options.tailwindcssRuntimeOptions?.tailwindcss?.v4?.cssEntries;
|
|
6143
|
+
const entries = [
|
|
6144
|
+
...Array.isArray(options.cssEntries) ? options.cssEntries : [],
|
|
6145
|
+
...Array.isArray(options.tailwindcss?.v4?.cssEntries) ? options.tailwindcss.v4.cssEntries : [],
|
|
6146
|
+
...Array.isArray(runtimeCssEntries) ? runtimeCssEntries : []
|
|
6147
|
+
].filter((item) => typeof item === "string" && item.length > 0);
|
|
6148
|
+
return entries.length > 0 ? [...new Set(entries)] : void 0;
|
|
6149
|
+
}
|
|
5721
6150
|
function normalizeViteStylePlatform(value, appType) {
|
|
5722
6151
|
return normalizeFrameworkStylePlatform(value, appType);
|
|
5723
6152
|
}
|
|
@@ -5730,6 +6159,13 @@ function inferPlatformFromOutDir(outDir) {
|
|
|
5730
6159
|
function isWebOrNativeAppPlatform(platform) {
|
|
5731
6160
|
return platform === "h5" || platform === "web" || platform?.startsWith("web-") === true || platform === "app" || platform === "app-plus" || platform?.startsWith("app-") === true;
|
|
5732
6161
|
}
|
|
6162
|
+
function isUniAppViteWebviewStylePlatform(platform) {
|
|
6163
|
+
return platform === "app" || platform === "app-plus";
|
|
6164
|
+
}
|
|
6165
|
+
function applyUniAppViteWebviewCssCompat(css, options) {
|
|
6166
|
+
const compatCss = transformWebCssCompat(css, options.compat);
|
|
6167
|
+
return options.safeSelectors ? transformWebCssSafeSelectors(compatCss, { escapeMap: options.escapeMap }) : compatCss;
|
|
6168
|
+
}
|
|
5733
6169
|
/**
|
|
5734
6170
|
* @name WeappTailwindcss
|
|
5735
6171
|
* @description uni-app vite / uni-app-x 版本插件
|
|
@@ -5738,7 +6174,7 @@ function isWebOrNativeAppPlatform(platform) {
|
|
|
5738
6174
|
function WeappTailwindcss(options = {}) {
|
|
5739
6175
|
const hasExplicitAppType = typeof options.appType === "string" && options.appType.trim().length > 0;
|
|
5740
6176
|
const hasExplicitTailwindcssBasedir = typeof options.tailwindcssBasedir === "string" && options.tailwindcssBasedir.trim().length > 0;
|
|
5741
|
-
const rawCssEntries =
|
|
6177
|
+
const rawCssEntries = collectConfiguredCssEntries(options);
|
|
5742
6178
|
const opts = getCompilerContext({
|
|
5743
6179
|
...options,
|
|
5744
6180
|
__internalDeferMissingCssEntriesWarning: true
|
|
@@ -5766,18 +6202,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
5766
6202
|
if (!disabledOptions.plugin && tailwindcssMajorVersion !== 4) throw new Error("weapp-tailwindcss/vite 新生成管线仅支持 Tailwind CSS v4,请升级 tailwindcss 或停留在旧版 weapp-tailwindcss。");
|
|
5767
6203
|
const shouldOwnTailwindGeneration = !disabledOptions.plugin;
|
|
5768
6204
|
const shouldRewriteCssImports = opts.rewriteCssImports === true;
|
|
5769
|
-
|
|
5770
|
-
appType: opts.appType,
|
|
5771
|
-
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
5772
|
-
tailwindcssMajorVersion,
|
|
5773
|
-
uniAppX
|
|
5774
|
-
});
|
|
5775
|
-
const generatorBranch = resolveGeneratorRuntimeBranch(generatorOptions, {
|
|
5776
|
-
appType: opts.appType,
|
|
5777
|
-
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
5778
|
-
tailwindcssMajorVersion,
|
|
5779
|
-
uniAppX
|
|
5780
|
-
});
|
|
6205
|
+
let resolvedConfig;
|
|
5781
6206
|
const resolveViteStylePlatform = () => {
|
|
5782
6207
|
const explicit = normalizeViteStylePlatform(opts.cssOptions?.platform ?? opts.platform, opts.appType);
|
|
5783
6208
|
if (explicit) return explicit;
|
|
@@ -5787,9 +6212,23 @@ function WeappTailwindcss(options = {}) {
|
|
|
5787
6212
|
}
|
|
5788
6213
|
return inferPlatformFromOutDir(resolvedConfig?.build?.outDir);
|
|
5789
6214
|
};
|
|
6215
|
+
const resolveGeneratorPlatform = () => opts.cssOptions?.platform ?? opts.platform ?? resolveViteStylePlatform();
|
|
6216
|
+
const resolveCurrentGeneratorOptions = () => normalizeWeappTailwindcssGeneratorOptions(opts.generator, {
|
|
6217
|
+
appType: opts.appType,
|
|
6218
|
+
platform: resolveGeneratorPlatform(),
|
|
6219
|
+
tailwindcssMajorVersion,
|
|
6220
|
+
uniAppX
|
|
6221
|
+
});
|
|
6222
|
+
const resolveCurrentGeneratorBranch = () => resolveGeneratorRuntimeBranch(resolveCurrentGeneratorOptions(), {
|
|
6223
|
+
appType: opts.appType,
|
|
6224
|
+
platform: resolveGeneratorPlatform(),
|
|
6225
|
+
tailwindcssMajorVersion,
|
|
6226
|
+
uniAppX
|
|
6227
|
+
});
|
|
6228
|
+
const initialGeneratorBranch = resolveCurrentGeneratorBranch();
|
|
5790
6229
|
const transformEarlyMiniProgramCss = (code) => {
|
|
5791
6230
|
const platform = resolveViteStylePlatform();
|
|
5792
|
-
if (!shouldOwnTailwindGeneration || (platform ? isWebOrNativeAppPlatform(platform) :
|
|
6231
|
+
if (!shouldOwnTailwindGeneration || (platform ? isWebOrNativeAppPlatform(platform) : resolveCurrentGeneratorBranch().isWeb)) return code;
|
|
5793
6232
|
let transformedCode = code;
|
|
5794
6233
|
if (transformedCode.includes("#if")) transformedCode = compileCssMacroConditionalComments(transformedCode, { platform: resolveViteStylePlatform() });
|
|
5795
6234
|
if (transformedCode.includes("@layer")) transformedCode = unwrapUnsupportedCascadeLayers(transformedCode);
|
|
@@ -5797,10 +6236,10 @@ function WeappTailwindcss(options = {}) {
|
|
|
5797
6236
|
};
|
|
5798
6237
|
const finalizeViteMiniProgramCss = (css) => {
|
|
5799
6238
|
const platform = resolveViteStylePlatform();
|
|
5800
|
-
if (!shouldOwnTailwindGeneration || (platform ? isWebOrNativeAppPlatform(platform) :
|
|
6239
|
+
if (!shouldOwnTailwindGeneration || (platform ? isWebOrNativeAppPlatform(platform) : resolveCurrentGeneratorBranch().isWeb)) return css;
|
|
5801
6240
|
return unwrapUnsupportedCascadeLayers(css);
|
|
5802
6241
|
};
|
|
5803
|
-
const shouldInferAppType = !hasExplicitAppType && !
|
|
6242
|
+
const shouldInferAppType = !hasExplicitAppType && !initialGeneratorBranch.isWeb;
|
|
5804
6243
|
const hasInitialTailwindCssRoots = hasConfiguredTailwindV4CssRoots({
|
|
5805
6244
|
...options,
|
|
5806
6245
|
cssEntries: opts.cssEntries ?? options.cssEntries
|
|
@@ -5880,7 +6319,6 @@ function WeappTailwindcss(options = {}) {
|
|
|
5880
6319
|
await refreshRuntimeStateForAutoCssSources?.(true);
|
|
5881
6320
|
};
|
|
5882
6321
|
const customAttributesEntities = toCustomAttributesEntities(customAttributes);
|
|
5883
|
-
let resolvedConfig;
|
|
5884
6322
|
let recordedGeneratorCandidates;
|
|
5885
6323
|
const sourceCandidateCollector = createSourceCandidateCollector({ bareArbitraryValues: opts.arbitraryValues?.bareArbitraryValues });
|
|
5886
6324
|
const sourceCandidateScanCache = new LRUCache({ max: SOURCE_CANDIDATE_SCAN_CACHE_MAX });
|
|
@@ -5938,7 +6376,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
5938
6376
|
const isWatchLikeBuild = () => isWatchBuild() || resolvedConfig?.command === "serve" || process$1.env["WEAPP_TW_WATCH_REGRESSION"] === "1" || process$1.env["WEAPP_TW_HMR_TIMING"] === "1";
|
|
5939
6377
|
const isCurrentWebLikeStylePlatform = () => {
|
|
5940
6378
|
const platform = resolveViteStylePlatform();
|
|
5941
|
-
return platform ? isWebOrNativeAppPlatform(platform) :
|
|
6379
|
+
return platform ? isWebOrNativeAppPlatform(platform) : resolveCurrentGeneratorBranch().isWeb;
|
|
5942
6380
|
};
|
|
5943
6381
|
const isNuxtPageMacroHotModule = (id) => {
|
|
5944
6382
|
if (typeof id !== "string" || !/[?&]macro=true(?:&|$)/.test(id)) return false;
|
|
@@ -6158,48 +6596,58 @@ function WeappTailwindcss(options = {}) {
|
|
|
6158
6596
|
const file = cleanUrl(id);
|
|
6159
6597
|
const requestFile = isCSSRequest(id) ? id : file;
|
|
6160
6598
|
if (!isCSSRequest(requestFile) || opts.htmlMatcher(file) || isHTMLRequest(file)) return;
|
|
6599
|
+
const generatorCode = normalizeEmptyTailwindCustomVariants(code);
|
|
6161
6600
|
const rootDir = resolvedConfig?.root ? path.resolve(resolvedConfig.root) : process$1.cwd();
|
|
6162
6601
|
const isHarmonyAppStyleTarget = isHarmonyAppBuildTarget();
|
|
6163
|
-
const isNativeAppStyleTarget = resolveUniUtsPlatform().isApp || isHarmonyAppStyleTarget;
|
|
6602
|
+
const isNativeAppStyleTarget = opts.appType === "uni-app-x" && (resolveUniUtsPlatform().isApp || isHarmonyAppStyleTarget);
|
|
6164
6603
|
const sourceRoot = resolveWeappViteSourceRoot(resolvedConfig, opts.appType);
|
|
6165
|
-
const
|
|
6604
|
+
const currentGeneratorOptions = resolveCurrentGeneratorOptions();
|
|
6605
|
+
const currentGeneratorBranch = resolveCurrentGeneratorBranch();
|
|
6606
|
+
const outputFile = resolveViteCssPipelineOutputFile(requestFile, opts, rootDir, currentGeneratorBranch.isWeb, isNativeAppStyleTarget, sourceRoot);
|
|
6166
6607
|
const runtime = getRecordedGeneratorCandidates() ?? getSourceCandidates() ?? await ensureRuntimeClassSet();
|
|
6167
6608
|
const outputCssHandlerOptions = transformCssHandlerOptions.getCssHandlerOptions(outputFile);
|
|
6168
6609
|
const cssHandlerOptions = {
|
|
6169
6610
|
...transformCssHandlerOptions.getCssHandlerOptions(file),
|
|
6170
6611
|
isMainChunk: outputCssHandlerOptions.isMainChunk
|
|
6171
6612
|
};
|
|
6172
|
-
const transientCssSource = transientAutoCssSources.get(file) ?? (hasTailwindRootDirectives(
|
|
6613
|
+
const transientCssSource = transientAutoCssSources.get(file) ?? (hasTailwindRootDirectives(generatorCode, { importFallback: currentGeneratorOptions.importFallback }) || hasTailwindSourceDirectives(generatorCode, { importFallback: currentGeneratorOptions.importFallback }) || hasTailwindApplyDirective(generatorCode) ? {
|
|
6173
6614
|
base: path.dirname(path.resolve(file)),
|
|
6174
|
-
css:
|
|
6615
|
+
css: generatorCode,
|
|
6175
6616
|
file: path.resolve(file)
|
|
6176
6617
|
} : void 0);
|
|
6177
|
-
const shouldDeferEmptyScopedCssSource = transientCssSource == null && !(opts.appType === "uni-app-x" && !cssHandlerOptions.isMainChunk && hasTailwindApplyDirective(
|
|
6618
|
+
const shouldDeferEmptyScopedCssSource = transientCssSource == null && !(opts.appType === "uni-app-x" && !cssHandlerOptions.isMainChunk && hasTailwindApplyDirective(generatorCode));
|
|
6178
6619
|
const generated = await generateTailwindV4Css({
|
|
6179
6620
|
opts,
|
|
6180
6621
|
runtimeState,
|
|
6181
6622
|
runtime,
|
|
6182
|
-
rawSource:
|
|
6623
|
+
rawSource: generatorCode,
|
|
6183
6624
|
file,
|
|
6184
6625
|
outputFile,
|
|
6185
6626
|
cssHandlerOptions,
|
|
6186
6627
|
cssUserHandlerOptions: transformCssHandlerOptions.getCssUserHandlerOptions(file),
|
|
6187
6628
|
cssSources: transientCssSource ? [transientCssSource] : void 0,
|
|
6188
6629
|
getSourceCandidatesForEntries,
|
|
6630
|
+
generatorPlatform: resolveGeneratorPlatform(),
|
|
6189
6631
|
styleHandler,
|
|
6190
6632
|
debug,
|
|
6191
6633
|
previousCss: viteGeneratedCssByFile.get(file),
|
|
6192
6634
|
deferEmptyScopedCssSource: shouldDeferEmptyScopedCssSource,
|
|
6193
|
-
restoreLocalCssImports: !
|
|
6635
|
+
restoreLocalCssImports: !currentGeneratorBranch.isWeb
|
|
6194
6636
|
});
|
|
6195
6637
|
if (!generated) return;
|
|
6196
|
-
const
|
|
6638
|
+
const finalizedCss = finalizeViteMiniProgramCss(generated.css);
|
|
6639
|
+
const isUniAppViteWebviewPlatform = opts.appType === "uni-app-vite" && isUniAppViteWebviewStylePlatform(resolveViteStylePlatform());
|
|
6640
|
+
const tracedCss = annotateCssSourceTrace(removeScopedTailwindPreflightCss(currentGeneratorBranch.isWeb || isUniAppViteWebviewPlatform ? applyUniAppViteWebviewCssCompat(finalizedCss, {
|
|
6641
|
+
compat: currentGeneratorOptions.webCompat ?? true,
|
|
6642
|
+
escapeMap: opts.escapeMap,
|
|
6643
|
+
safeSelectors: isUniAppViteWebviewPlatform
|
|
6644
|
+
}) : finalizedCss), {
|
|
6197
6645
|
opts,
|
|
6198
6646
|
tokenSources: createCssTokenSourceMap(getSourceCandidateSourcesForEntries(void 0), opts)
|
|
6199
6647
|
});
|
|
6200
6648
|
for (const dependency of generated.dependencies) hookContext?.addWatchFile?.(dependency);
|
|
6201
6649
|
viteGeneratedCssByFile.set(file, tracedCss);
|
|
6202
|
-
const shouldInjectGeneratedCssIntoMain = mainCssChunkMatcher(outputFile, opts.appType) || hasTailwindRootDirectives(
|
|
6650
|
+
const shouldInjectGeneratedCssIntoMain = mainCssChunkMatcher(outputFile, opts.appType) || hasTailwindRootDirectives(generatorCode, { importFallback: currentGeneratorOptions.importFallback }) && !normalizeOutputPathKey(outputFile).includes("/");
|
|
6203
6651
|
recordViteProcessedCssAssetResult(file, tracedCss, {
|
|
6204
6652
|
injectIntoMain: shouldInjectGeneratedCssIntoMain,
|
|
6205
6653
|
outputFile
|
|
@@ -6231,7 +6679,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
6231
6679
|
onTailwindRootCss: (id, code) => registerAutoCssSource(id, code),
|
|
6232
6680
|
onCssSourceTransform: (id, code) => cssMemory.refreshRememberedCssSourceBySourceFile(id, code),
|
|
6233
6681
|
shouldGenerateCss: (_id, code) => hasVitePipelineTailwindGenerationDirective(code),
|
|
6234
|
-
shouldDeferGeneration: (_id, code) => !shouldRewriteCssImports && hasTailwindRootDirectives(code, { importFallback:
|
|
6682
|
+
shouldDeferGeneration: (_id, code) => !shouldRewriteCssImports && hasTailwindRootDirectives(code, { importFallback: resolveCurrentGeneratorOptions().importFallback }),
|
|
6235
6683
|
shouldOwnTailwindGeneration,
|
|
6236
6684
|
shouldRewrite: shouldRewriteCssImports,
|
|
6237
6685
|
weappTailwindcssDirPosix
|
|
@@ -6330,7 +6778,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
6330
6778
|
order: "pre",
|
|
6331
6779
|
async handler(code, id) {
|
|
6332
6780
|
let transformedCode = code;
|
|
6333
|
-
if (shouldOwnTailwindGeneration && !
|
|
6781
|
+
if (shouldOwnTailwindGeneration && !resolveCurrentGeneratorBranch().isWeb && isCSSRequest(id)) transformedCode = transformEarlyMiniProgramCss(code);
|
|
6334
6782
|
const shouldReturnTransformedCode = transformedCode !== code;
|
|
6335
6783
|
if (shouldOwnTailwindGeneration) cssMemory.rememberKnownSfcSource(id, transformedCode);
|
|
6336
6784
|
if (!shouldOwnTailwindGeneration || !isSourceCandidateRequest(id) || !shouldCollectTransformedSourceCandidates(id)) {
|
|
@@ -6410,10 +6858,10 @@ function WeappTailwindcss(options = {}) {
|
|
|
6410
6858
|
shouldGenerate: () => shouldOwnTailwindGeneration
|
|
6411
6859
|
}),
|
|
6412
6860
|
createViteServeJsTransformPlugin({
|
|
6413
|
-
createHandlerOptions: serveJsHandlerOptions,
|
|
6861
|
+
createHandlerOptions: (file) => serveJsHandlerOptions(file, opts.appType === "uni-app-vite" && isUniAppViteWebviewStylePlatform(resolveViteStylePlatform()) ? { needEscaped: true } : void 0),
|
|
6414
6862
|
getCommand: () => resolvedConfig?.command,
|
|
6415
6863
|
jsHandler,
|
|
6416
|
-
shouldTransform: () => shouldOwnTailwindGeneration && !
|
|
6864
|
+
shouldTransform: () => shouldOwnTailwindGeneration && (!resolveCurrentGeneratorBranch().isWeb || opts.appType === "uni-app-vite" && isUniAppViteWebviewStylePlatform(resolveViteStylePlatform())),
|
|
6417
6865
|
transformRuntime: ensureRuntimeClassSet
|
|
6418
6866
|
}),
|
|
6419
6867
|
{
|