weapp-tailwindcss 5.1.4 → 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/generation-helpers.d.ts +8 -2
- package/dist/bundlers/shared/generator-css/source-resolver/metadata.d.ts +5 -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/generate-bundle/tailwind-v4-css-source.d.ts +6 -3
- package/dist/bundlers/vite/hot-css-modules.d.ts +1 -0
- package/dist/bundlers/vite/processed-css-assets.d.ts +7 -0
- package/dist/bundlers/vite/source-scan/css-entries.d.ts +1 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers.d.ts +2 -1
- package/dist/cli.js +18 -3
- package/dist/cli.mjs +16 -1
- package/dist/{context-Bkpmt3ja.mjs → context-3GGqW9vw.mjs} +20 -5
- package/dist/{context-DCVMkTRj.js → context-BCSk_YnL.js} +23 -8
- package/dist/core.js +1 -1
- package/dist/core.mjs +1 -1
- package/dist/css-macro/index.d.ts +2 -1
- package/dist/{defaults-BhE26nSw.mjs → defaults-9B6aMyZb.mjs} +2 -2
- package/dist/{defaults-DQhgnnn-.js → defaults-nsf4VNMX.js} +2 -2
- package/dist/defaults.d.ts +1 -1
- package/dist/defaults.js +1 -1
- package/dist/defaults.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-0RsqkF_d.mjs → gulp-Bss4wJ8t.mjs} +4 -4
- package/dist/{gulp-Bogfnoki.js → gulp-hXE1U4Cu.js} +4 -4
- package/dist/gulp.js +1 -1
- package/dist/gulp.mjs +1 -1
- package/dist/{hmr-timing-BRNaz8Od.mjs → hmr-timing-Cfu-4Bnf.mjs} +229 -576
- package/dist/{hmr-timing-BV6nFPoT.js → hmr-timing-Df4203aI.js} +253 -630
- package/dist/index.js +4 -4
- package/dist/index.mjs +4 -4
- package/dist/js/js-string-escape.d.ts +1 -0
- 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-CaDT0gkj.js → source-candidate-scan-signature-5Uk6U72B.js} +168 -5
- package/dist/{source-candidate-scan-signature-BB1hvW68.mjs → source-candidate-scan-signature-BbCmW975.mjs} +157 -6
- package/dist/style-injector/internal.d.ts +7 -0
- package/dist/style-injector/options.d.ts +25 -0
- package/dist/tailwindcss/v4/preflight.d.ts +4 -0
- package/dist/{tailwindcss-D0JF0fuZ.mjs → tailwindcss-Bjr3aphG.mjs} +62 -15
- package/dist/{tailwindcss-D2xs4OEu.js → tailwindcss-DYJ3HZD2.js} +67 -14
- package/dist/{transform-BP86eSZp.mjs → transform--155BmeJ.mjs} +1 -1
- package/dist/{transform-CXCQ28Tc.js → transform-B6_y_yCB.js} +1 -1
- package/dist/typedoc.export.d.ts +1 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/user-defined-options/general.d.ts +2 -0
- 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-BYgT1ir9.js → vite-Baw9qNrc.js} +652 -140
- package/dist/{vite-B1SlBmqO.mjs → vite-PdxjaqhO.mjs} +653 -141
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/weapp-tw-css-import-rewrite-loader.js +2981 -2752
- package/dist/{webpack-Bg6pefpb.mjs → webpack-BffTDmod.mjs} +69 -26
- package/dist/{webpack-khSwkXP5.js → webpack-C9u7mfGE.js} +74 -31
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +16 -5
|
@@ -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, 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));
|
|
@@ -1922,8 +1922,14 @@ function resolveSourceStyleSourceFromOutputFile(outputFile, snapshot, outputRoot
|
|
|
1922
1922
|
//#endregion
|
|
1923
1923
|
//#region src/bundlers/vite/generate-bundle/subpackages.ts
|
|
1924
1924
|
function readBundleAssetSource(output) {
|
|
1925
|
-
if (output.type !== "asset") return;
|
|
1926
|
-
|
|
1925
|
+
if ("type" in output && output.type !== "asset") return;
|
|
1926
|
+
const source = output.source;
|
|
1927
|
+
if (typeof source === "string") return source;
|
|
1928
|
+
if (typeof source === "function") {
|
|
1929
|
+
const value = source.call(output);
|
|
1930
|
+
return typeof value === "string" ? value : value?.toString();
|
|
1931
|
+
}
|
|
1932
|
+
if (source != null && typeof source.toString === "function") return source.toString();
|
|
1927
1933
|
}
|
|
1928
1934
|
function normalizePackageRoot(root) {
|
|
1929
1935
|
return normalizeOutputPathKey(root).replace(/\/+$/, "");
|
|
@@ -2008,6 +2014,21 @@ function appendCss$1(baseCss, css) {
|
|
|
2008
2014
|
if (css.length === 0) return baseCss;
|
|
2009
2015
|
return `${baseCss}\n${css}`;
|
|
2010
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
|
+
}
|
|
2011
2032
|
function removeTailwindSourceMediaWrappers(css) {
|
|
2012
2033
|
if (!css.includes("@media source(")) return css;
|
|
2013
2034
|
try {
|
|
@@ -2084,6 +2105,183 @@ function collectRootStyleBundleCssSources(bundle, excludedFile) {
|
|
|
2084
2105
|
}
|
|
2085
2106
|
return sources;
|
|
2086
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
|
+
}
|
|
2087
2285
|
function collectSingleViteGeneratedCssMarkerFile(rawSource) {
|
|
2088
2286
|
const blocks = parseBundlerGeneratedCssMarkerBlocks(rawSource).filter((block) => block.bundler === "vite");
|
|
2089
2287
|
if (blocks.length !== 1) return;
|
|
@@ -2096,7 +2294,9 @@ function shouldFilterRootGeneratedCssMarkerForScopedAsset(targetFile, markerFile
|
|
|
2096
2294
|
return !isMatchingGeneratedCssMarkerFile(targetFile, markerFile, resolveViteProcessedCssOutputFile);
|
|
2097
2295
|
}
|
|
2098
2296
|
function removeCssCoveredByRootStyleBundleSources(bundle, file, css) {
|
|
2099
|
-
|
|
2297
|
+
const rootSources = collectRootStyleBundleCssSources(bundle, file);
|
|
2298
|
+
const nextCss = removeScopedCssCoveredByRootStyleSources(removeDanglingCssSourceTraceComments(removeCssCoveredByImportedViteResults(css, rootSources)), rootSources);
|
|
2299
|
+
return hasNonCommentCss(nextCss) ? nextCss : "";
|
|
2100
2300
|
}
|
|
2101
2301
|
function removeDanglingCssSourceTraceComments(css) {
|
|
2102
2302
|
if (!css.includes("/* tokens:")) return css;
|
|
@@ -2120,8 +2320,11 @@ function removeCssCoveredByRootStyleAssets(bundle, options) {
|
|
|
2120
2320
|
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2121
2321
|
if (output.type !== "asset") continue;
|
|
2122
2322
|
const file = getAssetFile$1(bundleFile, output);
|
|
2123
|
-
if (!options.cssMatcher(file) || isRootStyleOutputFile(file) || options.isViteProcessedCssAsset?.(output, file) === true || options.subpackageRoots != null && isSubpackageOutputFile(file, options.subpackageRoots)) continue;
|
|
2124
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;
|
|
2125
2328
|
const nextCss = removeCssCoveredByRootStyleBundleSources(bundle, file, rawSource);
|
|
2126
2329
|
if (nextCss === rawSource) continue;
|
|
2127
2330
|
output.source = nextCss;
|
|
@@ -2174,6 +2377,12 @@ function shouldUseCssAssetAsMainInjectionTarget(opts, file, records) {
|
|
|
2174
2377
|
const fileKey = normalizeOutputPathKey(file);
|
|
2175
2378
|
if (!isRootStyleOutputFile(file) && records.some((record) => typeof record.outputFile === "string" && normalizeOutputPathKey(record.outputFile) === fileKey)) return true;
|
|
2176
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);
|
|
2177
2386
|
if (records.some((record) => {
|
|
2178
2387
|
if (record.injectIntoMain !== true) return false;
|
|
2179
2388
|
return isRootStyleOutputFile(file) || typeof record.outputFile === "string" && normalizeOutputPathKey(record.outputFile) === fileKey;
|
|
@@ -2194,6 +2403,33 @@ function isViteProcessedCssResultCoveredByImportedBundleAsset(record, importedSt
|
|
|
2194
2403
|
}
|
|
2195
2404
|
return false;
|
|
2196
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
|
+
}
|
|
2197
2433
|
function removeCssCoveredByImportedViteResults(css, importedCssSources) {
|
|
2198
2434
|
if (importedCssSources.length === 0) return css;
|
|
2199
2435
|
const importedCss = importedCssSources.map((source) => stripBundlerGeneratedCssMarkers(source).trim()).filter(Boolean).join("\n");
|
|
@@ -2220,6 +2456,38 @@ function collectBundleAssetFiles(bundle) {
|
|
|
2220
2456
|
}
|
|
2221
2457
|
return files;
|
|
2222
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
|
+
}
|
|
2223
2491
|
function findBundleAssetByOutputFile(bundle, file) {
|
|
2224
2492
|
const fileKey = normalizeOutputPathKey(file);
|
|
2225
2493
|
return Object.entries(bundle).find(([bundleFile, output]) => {
|
|
@@ -2273,6 +2541,8 @@ function collectViteProcessedCssAssetResults(bundle, options) {
|
|
|
2273
2541
|
options.markCssAssetProcessed?.(output, file);
|
|
2274
2542
|
options.recordCssAssetResult?.(file, nextCss);
|
|
2275
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;
|
|
2276
2546
|
if (singleMarkerFile && normalizeOutputPathKey(resolvedOutputFile) !== normalizeOutputPathKey(file) && !isRootStyleOutputFile(resolvedOutputFile) && existingAssetFiles.has(normalizeOutputPathKey(resolvedOutputFile))) {
|
|
2277
2547
|
const targetAsset = findBundleAssetByOutputFile(bundle, resolvedOutputFile);
|
|
2278
2548
|
if (targetAsset) {
|
|
@@ -2292,24 +2562,24 @@ function collectViteProcessedCssAssetResults(bundle, options) {
|
|
|
2292
2562
|
continue;
|
|
2293
2563
|
}
|
|
2294
2564
|
}
|
|
2295
|
-
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));
|
|
2296
2566
|
options.recordViteProcessedCssAssetResult?.(file, nextCss, {
|
|
2297
2567
|
injectIntoMain: shouldReplayIntoMainCss || void 0,
|
|
2298
|
-
outputFile:
|
|
2568
|
+
outputFile: recordOutputFile
|
|
2299
2569
|
});
|
|
2300
|
-
if (normalizeOutputPathKey(
|
|
2570
|
+
if (normalizeOutputPathKey(recordOutputFile) !== normalizeOutputPathKey(file)) options.recordViteProcessedCssAssetResult?.(recordOutputFile, nextCss, {
|
|
2301
2571
|
injectIntoMain: shouldReplayIntoMainCss || void 0,
|
|
2302
|
-
outputFile:
|
|
2572
|
+
outputFile: recordOutputFile
|
|
2303
2573
|
});
|
|
2304
2574
|
for (const markerFile of collectMatchingGeneratedCssMarkerFiles(file, rawSource, options.resolveViteProcessedCssOutputFile)) {
|
|
2305
2575
|
if (normalizeOutputPathKey(markerFile) === normalizeOutputPathKey(file)) continue;
|
|
2306
2576
|
options.recordViteProcessedCssAssetResult?.(markerFile, nextCss, {
|
|
2307
2577
|
injectIntoMain: shouldReplayIntoMainCss || void 0,
|
|
2308
|
-
outputFile:
|
|
2578
|
+
outputFile: recordOutputFile
|
|
2309
2579
|
});
|
|
2310
|
-
if (normalizeOutputPathKey(
|
|
2580
|
+
if (normalizeOutputPathKey(recordOutputFile) !== normalizeOutputPathKey(markerFile) && normalizeOutputPathKey(recordOutputFile) !== normalizeOutputPathKey(file)) options.recordViteProcessedCssAssetResult?.(recordOutputFile, nextCss, {
|
|
2311
2581
|
injectIntoMain: shouldReplayIntoMainCss || void 0,
|
|
2312
|
-
outputFile:
|
|
2582
|
+
outputFile: recordOutputFile
|
|
2313
2583
|
});
|
|
2314
2584
|
}
|
|
2315
2585
|
if (isCoveredViteGeneratedSourceAsset(file, existingAssetFiles, options.resolveViteProcessedCssOutputFile)) {
|
|
@@ -2324,7 +2594,8 @@ function collectViteProcessedCssAssetResults(bundle, options) {
|
|
|
2324
2594
|
return collected;
|
|
2325
2595
|
}
|
|
2326
2596
|
function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
2327
|
-
const
|
|
2597
|
+
const transformCss = (css, file) => options.transformCss?.(css, file) ?? css;
|
|
2598
|
+
const viteCssResults = dedupeViteCssResults([...options.getViteProcessedCssAssetResults?.() ?? []].map(([file, record]) => {
|
|
2328
2599
|
return typeof record === "string" ? {
|
|
2329
2600
|
file,
|
|
2330
2601
|
css: record,
|
|
@@ -2335,10 +2606,14 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
2335
2606
|
injectIntoMain: record.injectIntoMain,
|
|
2336
2607
|
outputFile: record.outputFile
|
|
2337
2608
|
};
|
|
2338
|
-
}).
|
|
2609
|
+
})).map((record) => ({
|
|
2610
|
+
...record,
|
|
2611
|
+
css: transformCss(record.css, record.outputFile ?? record.file)
|
|
2612
|
+
})).filter((record) => record.css.length > 0);
|
|
2339
2613
|
let injected = 0;
|
|
2340
2614
|
for (const [bundleFile, bundleOutput] of Object.entries(bundle)) {
|
|
2341
2615
|
let output = bundleOutput;
|
|
2616
|
+
if (bundle[bundleFile] !== bundleOutput) continue;
|
|
2342
2617
|
if (output.type !== "asset") continue;
|
|
2343
2618
|
let file = getAssetFile$1(bundleFile, output);
|
|
2344
2619
|
if (!options.opts.cssMatcher(file) || !shouldUseCssAssetAsMainInjectionTarget(options.opts, file, viteCssResults)) continue;
|
|
@@ -2360,7 +2635,7 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
2360
2635
|
}
|
|
2361
2636
|
const fileKey = normalizeOutputPathKey(file);
|
|
2362
2637
|
const mainFileKey = normalizeOutputPathKey(file);
|
|
2363
|
-
let nextCss = removeTailwindEntryDirectivesFromCss(originalSource);
|
|
2638
|
+
let nextCss = transformCss(removeTailwindEntryDirectivesFromCss(originalSource), file);
|
|
2364
2639
|
const importedStyleFiles = collectImportedStyleFiles(nextCss, file);
|
|
2365
2640
|
const importedBundleCssSources = collectImportedBundleCssSources(bundle, importedStyleFiles);
|
|
2366
2641
|
nextCss = removeCssCoveredByImportedViteResults(nextCss, importedBundleCssSources);
|
|
@@ -2369,12 +2644,14 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
2369
2644
|
const uncoveredImportedViteCssResults = importedViteCssResults.filter((record) => !isViteProcessedCssResultCoveredByImportedBundleAsset(record, importedStyleFiles, bundleAssetFiles));
|
|
2370
2645
|
const importedCssSources = [...importedBundleCssSources, ...uncoveredImportedViteCssResults.map((record) => record.css)];
|
|
2371
2646
|
nextCss = removeCssCoveredByImportedViteResults(nextCss, uncoveredImportedViteCssResults.map((record) => record.css));
|
|
2647
|
+
const targetViteCssResults = [];
|
|
2372
2648
|
for (const record of viteCssResults) {
|
|
2373
2649
|
if (!isRootStyleOutputFile(file)) {
|
|
2374
2650
|
if (typeof record.outputFile !== "string" || normalizeOutputPathKey(record.outputFile) !== fileKey) continue;
|
|
2375
2651
|
}
|
|
2376
2652
|
if (!shouldInjectViteProcessedCssResult(options.opts, mainFileKey, record.file, record)) continue;
|
|
2377
2653
|
if (isViteProcessedCssResultImported(record, importedStyleFiles)) continue;
|
|
2654
|
+
targetViteCssResults.push(record);
|
|
2378
2655
|
let css = stripBundlerGeneratedCssMarkers(record.css).trim();
|
|
2379
2656
|
css = removeCssCoveredByImportedViteResults(css, importedCssSources).trim();
|
|
2380
2657
|
if (css.length === 0) continue;
|
|
@@ -2405,29 +2682,19 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
2405
2682
|
if (css.length === 0) continue;
|
|
2406
2683
|
}
|
|
2407
2684
|
const missingCss = filterExistingCssRules(nextCss, css);
|
|
2408
|
-
if (missingCss.length === 0 || containsCssAfterMinify(nextCss, missingCss)) continue;
|
|
2685
|
+
if (missingCss.length === 0 || !hasNonCommentCss(missingCss) || containsCssAfterMinify(nextCss, missingCss)) continue;
|
|
2409
2686
|
nextCss = appendCss$1(nextCss, missingCss);
|
|
2410
2687
|
}
|
|
2411
|
-
|
|
2412
|
-
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2417
|
-
|
|
2418
|
-
if (!options.shouldRemoveInjectedSourceAsset?.(file, record)) continue;
|
|
2419
|
-
const recordFileKey = normalizeOutputPathKey(record.file);
|
|
2420
|
-
for (const [candidateFile, candidateOutput] of Object.entries(bundle)) {
|
|
2421
|
-
if (candidateOutput.type !== "asset") continue;
|
|
2422
|
-
const candidateKey = normalizeOutputPathKey(getAssetFile$1(candidateFile, candidateOutput));
|
|
2423
|
-
const isRecordFile = candidateKey === recordFileKey;
|
|
2424
|
-
const candidateSource = readAssetSource$2(candidateOutput).trim();
|
|
2425
|
-
const isProcessedSource = candidateSource === record.css.trim() || candidateSource.length > 0 && containsCssAfterMinify(nextCss, candidateSource);
|
|
2426
|
-
if (!isRecordFile && !isProcessedSource || candidateKey === normalizeOutputPathKey(file)) continue;
|
|
2427
|
-
clearAssetSource(candidateOutput);
|
|
2428
|
-
options.debug?.("remove injected vite-processed source css asset: %s -> %s", candidateKey, file);
|
|
2429
|
-
}
|
|
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);
|
|
2430
2695
|
}
|
|
2696
|
+
const removedSources = removeCoveredInjectedSourceAssets(bundle, file, nextCss, targetViteCssResults, options);
|
|
2697
|
+
if (nextCss === originalSource && removedSources === 0) continue;
|
|
2431
2698
|
injected++;
|
|
2432
2699
|
}
|
|
2433
2700
|
return injected;
|
|
@@ -2699,9 +2966,34 @@ function pruneLastCssResults(resultByFile, sourceHashByFile, activeFiles) {
|
|
|
2699
2966
|
function readAssetSource(asset) {
|
|
2700
2967
|
return typeof asset.source === "string" ? asset.source : asset.source.toString();
|
|
2701
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
|
+
}
|
|
2702
2976
|
function getAssetFile(bundleFile, asset) {
|
|
2703
2977
|
return asset.fileName || bundleFile;
|
|
2704
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
|
+
}
|
|
2705
2997
|
function isRootMiniProgramStyleOutputFile(file) {
|
|
2706
2998
|
const normalized = normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
2707
2999
|
return !normalized.includes("/") && /\.(?:wxss|acss|ttss|qss|jxss|tyss)$/i.test(normalized);
|
|
@@ -2770,7 +3062,7 @@ function normalizeTaroRootImportShellAssets(bundle, options) {
|
|
|
2770
3062
|
return updated;
|
|
2771
3063
|
}
|
|
2772
3064
|
async function finalizeGenerateBundle(options) {
|
|
2773
|
-
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;
|
|
2774
3066
|
const tasksStart = performance.now();
|
|
2775
3067
|
if (cssTaskFactories.length > 0) {
|
|
2776
3068
|
const cssTask = runWithConcurrency(cssTaskFactories, resolveViteCssTaskConcurrency(useIncrementalMode, runtimeState.tailwindRuntime.majorVersion)).then(() => void 0);
|
|
@@ -2805,6 +3097,7 @@ async function finalizeGenerateBundle(options) {
|
|
|
2805
3097
|
recordViteProcessedCssAssetResult,
|
|
2806
3098
|
resolveViteProcessedCssOutputFile: (file) => resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension, sourceRoot, defaultStyleOutputExtension, bundleFiles),
|
|
2807
3099
|
subpackageRoots: collectMiniProgramSubpackageRoots(bundle),
|
|
3100
|
+
transformCss: transformWebTargetCss,
|
|
2808
3101
|
debug
|
|
2809
3102
|
});
|
|
2810
3103
|
return injectViteProcessedCssIntoMainCssAssets(bundle, {
|
|
@@ -2812,6 +3105,7 @@ async function finalizeGenerateBundle(options) {
|
|
|
2812
3105
|
getViteProcessedCssAssetResults,
|
|
2813
3106
|
markCssAssetProcessed,
|
|
2814
3107
|
recordCssAssetResult,
|
|
3108
|
+
transformCss: transformWebTargetCss,
|
|
2815
3109
|
shouldRemoveInjectedSourceAsset: (targetFile, record) => {
|
|
2816
3110
|
if (record.injectIntoMain === false) return false;
|
|
2817
3111
|
const targetFileKey = normalizeOutputPathKey(targetFile);
|
|
@@ -2837,11 +3131,13 @@ async function finalizeGenerateBundle(options) {
|
|
|
2837
3131
|
removeCssCoveredByRootStyleAssets(bundle, {
|
|
2838
3132
|
cssMatcher: opts.cssMatcher,
|
|
2839
3133
|
debug,
|
|
3134
|
+
includeTailwindGeneratedCssAssets: opts.appType === "uni-app-vite" && isWebGeneratorTarget && isUniAppViteWebviewAppBundle(bundleFiles),
|
|
2840
3135
|
isViteProcessedCssAsset,
|
|
2841
3136
|
onUpdate,
|
|
2842
3137
|
recordCssAssetResult,
|
|
2843
3138
|
subpackageRoots: collectMiniProgramSubpackageRoots(bundle)
|
|
2844
3139
|
});
|
|
3140
|
+
if (opts.appType === "uni-app-vite" && isWebGeneratorTarget && isUniAppViteWebviewAppBundle(Object.keys(bundle))) removeDuplicateUnlinkedRootCssAssetsReferencedByHtml(bundle, { debug });
|
|
2845
3141
|
await finalizeMiniProgramCssAssets(bundle, {
|
|
2846
3142
|
cssMatcher: opts.cssMatcher,
|
|
2847
3143
|
debug,
|
|
@@ -2852,6 +3148,12 @@ async function finalizeGenerateBundle(options) {
|
|
|
2852
3148
|
recordCssAssetResult,
|
|
2853
3149
|
styleHandler
|
|
2854
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
|
+
});
|
|
2855
3157
|
const stateUpdateStart = performance.now();
|
|
2856
3158
|
updateBundleBuildState(state, snapshot, useIncrementalMode ? linkedByEntry ?? /* @__PURE__ */ new Map() : /* @__PURE__ */ new Map(), { incremental: useIncrementalMode });
|
|
2857
3159
|
state.generatorCandidateSignature = generatorCandidateSignature;
|
|
@@ -3208,13 +3510,15 @@ function createRememberedCssRuntimeSignature(cssRuntimeSignature, cssRuntimeAffe
|
|
|
3208
3510
|
function normalizeRememberedSourceIdentity(file) {
|
|
3209
3511
|
return normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
3210
3512
|
}
|
|
3211
|
-
function selectBestRememberedCssSourceMatches(sources, outputFile, outputRoot, sourceRoot) {
|
|
3212
|
-
|
|
3513
|
+
function selectBestRememberedCssSourceMatches(sources, outputFile, outputRoot, sourceRoot, options = {}) {
|
|
3514
|
+
const minimumScore = options.minimumScore ?? (options.requirePositiveScore ? 1 : 0);
|
|
3213
3515
|
const scoredMatches = sources.map((remembered) => ({
|
|
3214
3516
|
remembered,
|
|
3215
3517
|
score: Math.max(scoreMatchingStyleFileBase(outputFile, remembered.sourceFile, outputRoot, sourceRoot), scoreMatchingStyleFileBase(outputFile, remembered.outputFile, outputRoot, sourceRoot))
|
|
3216
|
-
})).filter((match) => match.score > 0).sort((a, b) => b.score - a.score);
|
|
3518
|
+
})).filter((match) => match.score >= minimumScore && match.score > 0).sort((a, b) => b.score - a.score);
|
|
3217
3519
|
const bestScore = scoredMatches[0]?.score;
|
|
3520
|
+
if (!bestScore && minimumScore > 0) return [];
|
|
3521
|
+
if (sources.length <= 1) return sources;
|
|
3218
3522
|
return bestScore ? scoredMatches.filter((match) => match.score === bestScore).map((match) => match.remembered) : sources;
|
|
3219
3523
|
}
|
|
3220
3524
|
function findRememberedCssSources(sources, outputFile, file, originalSource, outputRoot, sourceRoot) {
|
|
@@ -3232,11 +3536,16 @@ function findRememberedCssSources(sources, outputFile, file, originalSource, out
|
|
|
3232
3536
|
...originalSource.originalFileNames ?? []
|
|
3233
3537
|
].filter((item) => typeof item === "string" && item.length > 0);
|
|
3234
3538
|
const sourceMatched = rememberedSources.filter((remembered) => originalFiles.some((originalFile) => normalizeRememberedSourceIdentity(remembered.sourceFile) === normalizeRememberedSourceIdentity(originalFile)));
|
|
3235
|
-
if (sourceMatched.length > 0)
|
|
3539
|
+
if (sourceMatched.length > 0) {
|
|
3540
|
+
const scoredSourceMatched = selectBestRememberedCssSourceMatches(sourceMatched, outputFile, outputRoot, sourceRoot, { requirePositiveScore: true });
|
|
3541
|
+
if (scoredSourceMatched.length > 0) return scoredSourceMatched;
|
|
3542
|
+
}
|
|
3236
3543
|
const outputMatched = rememberedSources.filter((remembered) => normalizeOutputPathKey(remembered.outputFile) === normalizeOutputPathKey(outputFile));
|
|
3237
3544
|
if (outputMatched.length > 0) return outputMatched;
|
|
3238
3545
|
if (!hasBundlerGeneratedCssMarker(source) && !hasTailwindGenerationSource(source)) return [];
|
|
3239
3546
|
const scoredMatches = selectBestRememberedCssSourceMatches(rememberedSources, outputFile, outputRoot, sourceRoot);
|
|
3547
|
+
const strongScoredMatches = selectBestRememberedCssSourceMatches(rememberedSources, outputFile, outputRoot, sourceRoot, { minimumScore: 1e5 });
|
|
3548
|
+
if (strongScoredMatches.length > 0 && strongScoredMatches.length < rememberedSources.length) return strongScoredMatches;
|
|
3240
3549
|
return scoredMatches.length === rememberedSources.length ? [] : scoredMatches;
|
|
3241
3550
|
}
|
|
3242
3551
|
function mergeRememberedCssSources(sources, outputFile) {
|
|
@@ -3259,7 +3568,9 @@ function collectRememberedCssReplayGroups(sources, opts, rootDir, isWebGenerator
|
|
|
3259
3568
|
const groups = /* @__PURE__ */ new Map();
|
|
3260
3569
|
for (const [key, remembered] of sources ?? []) {
|
|
3261
3570
|
const cleanSourceFile = remembered.sourceFile.replace(/[?#].*$/, "");
|
|
3262
|
-
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);
|
|
3263
3574
|
const group = groups.get(outputKey) ?? [];
|
|
3264
3575
|
group.push({
|
|
3265
3576
|
key,
|
|
@@ -3272,7 +3583,7 @@ function collectRememberedCssReplayGroups(sources, opts, rootDir, isWebGenerator
|
|
|
3272
3583
|
//#endregion
|
|
3273
3584
|
//#region src/bundlers/vite/generate-bundle/remembered-css-replay.ts
|
|
3274
3585
|
async function processRememberedCssReplay(options) {
|
|
3275
|
-
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;
|
|
3276
3587
|
const rememberedReplayGroups = collectRememberedCssReplayGroups(getRememberedCssSources?.(), opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension, sourceRoot, defaultStyleOutputExtension, bundleFiles);
|
|
3277
3588
|
for (const [outputFile, rememberedGroup] of rememberedReplayGroups) {
|
|
3278
3589
|
if (isHTMLRequest(outputFile) || options.opts.htmlMatcher(outputFile)) continue;
|
|
@@ -3323,6 +3634,7 @@ async function processRememberedCssReplay(options) {
|
|
|
3323
3634
|
cssHandlerOptions,
|
|
3324
3635
|
cssUserHandlerOptions: getCssUserHandlerOptions(sourceFile),
|
|
3325
3636
|
getSourceCandidatesForEntries: scopedSourceCandidateGetter,
|
|
3637
|
+
generatorPlatform,
|
|
3326
3638
|
styleHandler,
|
|
3327
3639
|
debug,
|
|
3328
3640
|
previousCss
|
|
@@ -3638,16 +3950,24 @@ function scoreConfiguredTailwindV4SourceForRawSource(rawSource, entrySource) {
|
|
|
3638
3950
|
for (const token of entryTokens) if (rawTokens.has(token)) score += token.startsWith("config:") ? 100 : 1;
|
|
3639
3951
|
return score;
|
|
3640
3952
|
}
|
|
3641
|
-
function
|
|
3642
|
-
if (!file || !subpackageRoots) return;
|
|
3643
|
-
return [...subpackageRoots].find((root) => isSubpackageOutputFile(file, /* @__PURE__ */ new Set([root])));
|
|
3644
|
-
}
|
|
3645
|
-
function isSameSubpackageScope(outputFile, sourceFile, subpackageRoots) {
|
|
3646
|
-
return resolveSubpackageRootForFile(outputFile, subpackageRoots) === resolveSubpackageRootForFile(sourceFile, subpackageRoots);
|
|
3647
|
-
}
|
|
3648
|
-
function selectTailwindV4GenerationCssSourceForOutput(outputFile, entries, rawSource, subpackageRoots) {
|
|
3953
|
+
function selectTailwindV4GenerationCssSourceForOutput(outputFile, entries, rawSource, options = {}) {
|
|
3649
3954
|
const generationSources = entries.filter((entry) => hasTailwindGenerationSource(entry.source));
|
|
3650
3955
|
if (generationSources.length <= 1) return generationSources[0];
|
|
3956
|
+
const canMatchByOutputPath = Boolean(options.cwd || options.outputRoot || options.projectRoot);
|
|
3957
|
+
const selectByOutputPath = (candidates) => {
|
|
3958
|
+
if (!canMatchByOutputPath) return;
|
|
3959
|
+
const scoredSources = candidates.map((entry) => ({
|
|
3960
|
+
entry,
|
|
3961
|
+
score: scoreTailwindV4CssSourceFileMatch(outputFile, entry.file, {
|
|
3962
|
+
cwd: options.cwd,
|
|
3963
|
+
outputRoot: options.outputRoot,
|
|
3964
|
+
projectRoot: options.projectRoot
|
|
3965
|
+
})
|
|
3966
|
+
})).filter((item) => item.score > 0).sort((a, b) => b.score - a.score);
|
|
3967
|
+
const bestScore = scoredSources[0]?.score;
|
|
3968
|
+
const bestSources = bestScore ? scoredSources.filter((item) => item.score === bestScore) : [];
|
|
3969
|
+
return bestSources.length === 1 ? bestSources[0]?.entry : void 0;
|
|
3970
|
+
};
|
|
3651
3971
|
const selectByRawSourceFingerprint = (candidates) => {
|
|
3652
3972
|
const scoredSources = candidates.map((entry) => ({
|
|
3653
3973
|
entry,
|
|
@@ -3659,14 +3979,10 @@ function selectTailwindV4GenerationCssSourceForOutput(outputFile, entries, rawSo
|
|
|
3659
3979
|
};
|
|
3660
3980
|
const rawSourceMatched = selectByRawSourceFingerprint(generationSources);
|
|
3661
3981
|
if (rawSourceMatched) return rawSourceMatched;
|
|
3662
|
-
const
|
|
3663
|
-
|
|
3664
|
-
|
|
3665
|
-
|
|
3666
|
-
return sourceMatchesSubpackage && [...subpackageRoots].some((root) => isSubpackageOutputFile(outputFile, /* @__PURE__ */ new Set([root])) && isSubpackageOutputFile(entry.file, /* @__PURE__ */ new Set([root])));
|
|
3667
|
-
}) : generationSources;
|
|
3668
|
-
const explicitSources = scopedSources.filter((entry) => /@(?:config|source|plugin|custom-variant|theme|utility|variant|apply)\b/.test(entry.source));
|
|
3669
|
-
const candidates = explicitSources.length === 1 ? explicitSources : scopedSources;
|
|
3982
|
+
const explicitSources = generationSources.filter((entry) => /@(?:config|source|plugin|custom-variant|theme|utility|variant|apply)\b/.test(entry.source));
|
|
3983
|
+
const candidates = explicitSources.length === 1 ? explicitSources : generationSources;
|
|
3984
|
+
const outputPathMatched = selectByOutputPath(candidates);
|
|
3985
|
+
if (outputPathMatched) return outputPathMatched;
|
|
3670
3986
|
if (candidates.length === 1) return candidates[0];
|
|
3671
3987
|
return selectByRawSourceFingerprint(candidates);
|
|
3672
3988
|
}
|
|
@@ -3900,6 +4216,16 @@ function resolveSourceRootFromBundleGraph(config, bundle) {
|
|
|
3900
4216
|
}
|
|
3901
4217
|
//#endregion
|
|
3902
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
|
+
}
|
|
3903
4229
|
function createGenerateBundleHook(context) {
|
|
3904
4230
|
const state = createBundleBuildState();
|
|
3905
4231
|
const lastCssResultByFile = /* @__PURE__ */ new Map();
|
|
@@ -3929,23 +4255,32 @@ function createGenerateBundleHook(context) {
|
|
|
3929
4255
|
const { cache, onEnd, onStart, onUpdate, styleHandler, templateHandler, jsHandler, uniAppX } = opts;
|
|
3930
4256
|
const resolvedConfig = getResolvedConfig();
|
|
3931
4257
|
const uniUtsPlatform = resolveUniUtsPlatform();
|
|
3932
|
-
const
|
|
4258
|
+
const generatorPlatform = opts.cssOptions?.platform ?? opts.platform ?? inferPlatformFromViteOutDir$1(resolvedConfig?.build?.outDir);
|
|
4259
|
+
const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(opts.generator, {
|
|
3933
4260
|
appType: opts.appType,
|
|
3934
|
-
platform:
|
|
4261
|
+
platform: generatorPlatform,
|
|
3935
4262
|
tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
3936
4263
|
uniAppX,
|
|
3937
4264
|
uniUtsPlatform
|
|
3938
|
-
})
|
|
4265
|
+
});
|
|
4266
|
+
const generatorBranch = resolveGeneratorRuntimeBranch(generatorOptions, {
|
|
3939
4267
|
appType: opts.appType,
|
|
3940
|
-
platform:
|
|
4268
|
+
platform: generatorPlatform,
|
|
3941
4269
|
tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
3942
4270
|
uniAppX,
|
|
3943
4271
|
uniUtsPlatform
|
|
3944
4272
|
});
|
|
3945
4273
|
const isWebGeneratorTarget = generatorBranch.isWeb;
|
|
3946
|
-
const
|
|
3947
|
-
const
|
|
3948
|
-
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)));
|
|
3949
4284
|
const shouldPreserveAppCssExtension = isNativeAppStyleTarget || isHarmonyAppStyleTarget;
|
|
3950
4285
|
const shouldGenerateWebCssByGenerator = isWebGeneratorTarget;
|
|
3951
4286
|
const { getCssHandlerOptions, getCssUserHandlerOptions } = cssHandlerOptions;
|
|
@@ -3967,6 +4302,7 @@ function createGenerateBundleHook(context) {
|
|
|
3967
4302
|
recordViteProcessedCssAssetResult,
|
|
3968
4303
|
resolveViteProcessedCssOutputFile: (file) => resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension, sourceRoot, defaultStyleOutputExtension, Object.keys(bundle)),
|
|
3969
4304
|
subpackageRoots: currentSubpackageRoots,
|
|
4305
|
+
transformCss: transformWebTargetCss,
|
|
3970
4306
|
debug
|
|
3971
4307
|
});
|
|
3972
4308
|
const hmrTimingStartedAt = performance.now();
|
|
@@ -4010,7 +4346,47 @@ function createGenerateBundleHook(context) {
|
|
|
4010
4346
|
const snapshotStart = performance.now();
|
|
4011
4347
|
const snapshot = buildBundleSnapshot(bundle, opts, outDir, state, envFlags.disableDirtyOptimization || !useIncrementalMode, { hasOmittedKnownFiles });
|
|
4012
4348
|
const configuredTailwindV4CssSourceEntriesForScope = getConfiguredTailwindV4CssSourceEntries();
|
|
4013
|
-
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
|
+
};
|
|
4014
4390
|
const { createScopedSourceCandidateGetter, createScopedSourceCandidateSourceGetter, shouldExcludeSubpackageSourceCandidates, shouldInjectCssIntoMainFromOutput } = createSubpackageSourceCandidateScope({
|
|
4015
4391
|
cssSourceFiles: configuredTailwindV4CssSourceEntriesForScope.map((entry) => entry.file),
|
|
4016
4392
|
getSourceCandidateSourcesForEntries,
|
|
@@ -4166,10 +4542,14 @@ function createGenerateBundleHook(context) {
|
|
|
4166
4542
|
onUpdate,
|
|
4167
4543
|
debug
|
|
4168
4544
|
});
|
|
4169
|
-
const
|
|
4545
|
+
const createBaseHandlerOptions = createJsHandlerOptionsFactory({
|
|
4170
4546
|
getMajorVersion: () => runtimeState.tailwindRuntime.majorVersion,
|
|
4171
4547
|
moduleGraph: moduleGraphOptions
|
|
4172
4548
|
});
|
|
4549
|
+
const createHandlerOptions = (absoluteFilename, extra) => createBaseHandlerOptions(absoluteFilename, shouldApplyWebviewSafeSelectors ? {
|
|
4550
|
+
needEscaped: true,
|
|
4551
|
+
...extra
|
|
4552
|
+
} : extra);
|
|
4173
4553
|
const linkedByEntry = useIncrementalMode ? /* @__PURE__ */ new Map() : void 0;
|
|
4174
4554
|
const sharedCssResultCache = /* @__PURE__ */ new Map();
|
|
4175
4555
|
const activeProcessCacheKeys = /* @__PURE__ */ new Set();
|
|
@@ -4283,6 +4663,11 @@ function createGenerateBundleHook(context) {
|
|
|
4283
4663
|
if (rememberedCssSources.length > 0) rememberedCssSources = await Promise.all(rememberedCssSources.map(async (remembered) => {
|
|
4284
4664
|
return await refreshRememberedCssSource?.(remembered) ?? remembered;
|
|
4285
4665
|
}));
|
|
4666
|
+
rememberedCssSources = rememberedCssSources.filter((remembered) => {
|
|
4667
|
+
if (!configuredTailwindV4CssSourceFileKeysForScope.has(normalizeConfiguredTailwindV4CssEntryFileKey(remembered.sourceFile))) return true;
|
|
4668
|
+
const matchedOutputFile = resolveMatchedOutputFileForCurrentAsset(remembered.sourceFile);
|
|
4669
|
+
return !matchedOutputFile || normalizeOutputPathKey(matchedOutputFile) === normalizeOutputPathKey(outputFile);
|
|
4670
|
+
});
|
|
4286
4671
|
let hasUsableRememberedTailwindSource = rememberedCssSources.some((remembered) => hasTailwindGenerationSource(remembered.rawSource) && normalizeOutputPathKey(remembered.sourceFile.replace(/[?#].*$/, "")) !== normalizeOutputPathKey(file));
|
|
4287
4672
|
const inferredSfcStyleSource = await resolveSfcStyleSourceFromOutputFile(outputFile, snapshot, outDir, opts.tailwindcssBasedir, opts.cssMatcher, getSfcSource, debug);
|
|
4288
4673
|
if (inferredSfcStyleSource) {
|
|
@@ -4290,15 +4675,11 @@ function createGenerateBundleHook(context) {
|
|
|
4290
4675
|
const rememberedSourcesBelongToInferredSfc = rememberedCssSources.length > 0 && rememberedCssSources.every((remembered) => normalizeSfcSourceFileForCompare(remembered.sourceFile) === inferredSourceFile);
|
|
4291
4676
|
if (!hasUsableRememberedTailwindSource || rememberedSourcesBelongToInferredSfc) rememberedCssSources = [inferredSfcStyleSource];
|
|
4292
4677
|
}
|
|
4293
|
-
if (isTemporaryCssAssetFile(outputFile) && rememberedCssSources.some((remembered) => configuredTailwindV4CssSourceFileKeysForScope.has(
|
|
4678
|
+
if (isTemporaryCssAssetFile(outputFile) && rememberedCssSources.some((remembered) => configuredTailwindV4CssSourceFileKeysForScope.has(normalizeConfiguredTailwindV4CssEntryFileKey(remembered.sourceFile)))) {
|
|
4294
4679
|
rememberedCssSources = [];
|
|
4295
4680
|
hasUsableRememberedTailwindSource = false;
|
|
4296
4681
|
}
|
|
4297
4682
|
let outputCssHandlerOptions = getCssHandlerOptions(outputFile);
|
|
4298
|
-
if (currentSubpackageRoots && rememberedCssSources.length > 0 && rememberedCssSources.some((remembered) => configuredTailwindV4CssSourceFileKeysForScope.has(normalizeOutputPathKey(remembered.sourceFile.replace(/[?#].*$/, ""))) && !isSameSubpackageScope(outputFile, remembered.sourceFile, currentSubpackageRoots))) {
|
|
4299
|
-
rememberedCssSources = [];
|
|
4300
|
-
hasUsableRememberedTailwindSource = false;
|
|
4301
|
-
}
|
|
4302
4683
|
if (isTemporaryCssAssetFile(outputFile) && hasTailwindGenerationSource(rawSource)) {
|
|
4303
4684
|
const resolvedTemporarySource = temporaryCssAssetSourceResolver.resolve(outputFile, rawSource);
|
|
4304
4685
|
if (resolvedTemporarySource) {
|
|
@@ -4322,7 +4703,14 @@ function createGenerateBundleHook(context) {
|
|
|
4322
4703
|
}
|
|
4323
4704
|
if (!hasUsableRememberedTailwindSource) {
|
|
4324
4705
|
const configuredTailwindV4CssSourceEntries = getConfiguredTailwindV4CssSourceEntries();
|
|
4325
|
-
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;
|
|
4326
4714
|
if (inferredOriginalSourceStyle) {
|
|
4327
4715
|
outputFile = resolveMatchedOutputFileForCurrentAsset(inferredOriginalSourceStyle.sourceFile) ?? outputFile;
|
|
4328
4716
|
activeViteCssCacheFiles.add(normalizeViteCssCacheKey(outputFile));
|
|
@@ -4352,7 +4740,11 @@ function createGenerateBundleHook(context) {
|
|
|
4352
4740
|
}
|
|
4353
4741
|
} else if (hasTailwindGenerationSource(rawSource) && (originalSource.originalFileNames?.length ?? 0) === 0) {
|
|
4354
4742
|
const availableConfiguredTailwindV4CssSourceEntries = configuredTailwindV4CssSourceEntries.filter((entry) => !usedConfiguredTailwindV4CssSourceFiles.has(normalizeOutputPathKey(entry.file)));
|
|
4355
|
-
const configuredGenerationSource = selectTailwindV4GenerationCssSourceForOutput(outputFile, availableConfiguredTailwindV4CssSourceEntries, rawSource,
|
|
4743
|
+
const configuredGenerationSource = selectTailwindV4GenerationCssSourceForOutput(outputFile, availableConfiguredTailwindV4CssSourceEntries, rawSource, {
|
|
4744
|
+
cwd: opts.tailwindcssBasedir,
|
|
4745
|
+
outputRoot: outDir,
|
|
4746
|
+
projectRoot: sourceRoot ?? rootDir
|
|
4747
|
+
});
|
|
4356
4748
|
if (configuredGenerationSource && !hasViteProcessedCssResultForSource(configuredGenerationSource.file, getViteProcessedCssAssetResults)) {
|
|
4357
4749
|
outputFile = resolveMatchedOutputFileForCurrentAsset(configuredGenerationSource.file) ?? outputFile;
|
|
4358
4750
|
activeViteCssCacheFiles.add(normalizeViteCssCacheKey(outputFile));
|
|
@@ -4368,7 +4760,7 @@ function createGenerateBundleHook(context) {
|
|
|
4368
4760
|
}
|
|
4369
4761
|
}
|
|
4370
4762
|
let rememberedCssSource = mergeRememberedCssSources(rememberedCssSources, outputFile);
|
|
4371
|
-
if (rememberedCssSource && viteProcessedCssAsset && outputCssHandlerOptions.isMainChunk !== true && configuredTailwindV4CssSourceFileKeysForScope.has(
|
|
4763
|
+
if (rememberedCssSource && viteProcessedCssAsset && outputCssHandlerOptions.isMainChunk !== true && configuredTailwindV4CssSourceFileKeysForScope.has(normalizeConfiguredTailwindV4CssEntryFileKey(rememberedCssSource.sourceFile))) {
|
|
4372
4764
|
const matchedOutputFile = resolveMatchedOutputFileForCurrentAsset(rememberedCssSource.sourceFile);
|
|
4373
4765
|
if (matchedOutputFile && normalizeOutputPathKey(matchedOutputFile) !== normalizeOutputPathKey(outputFile)) {
|
|
4374
4766
|
outputFile = matchedOutputFile;
|
|
@@ -4397,11 +4789,12 @@ function createGenerateBundleHook(context) {
|
|
|
4397
4789
|
}
|
|
4398
4790
|
const hasRememberedApplyDirective = rememberedCssSource != null && hasTailwindApplyDirective(rememberedCssSource.rawSource);
|
|
4399
4791
|
const hasRememberedTailwindGenerationSource = rememberedCssSource != null && hasTailwindGenerationSource(rememberedCssSource.rawSource);
|
|
4400
|
-
const usesConfiguredTailwindV4FallbackSource = rememberedCssSource != null && normalizeOutputPathKey(rememberedCssSource.outputFile) === normalizeOutputPathKey(outputFile) && normalizeOutputPathKey(rememberedCssSource.sourceFile.replace(/[?#].*$/, "")) !== normalizeOutputPathKey(file);
|
|
4401
4792
|
const hasSameOutputRememberedTailwindGenerationSource = hasRememberedTailwindGenerationSource && rememberedCssSource != null && normalizeOutputPathKey(rememberedCssSource.outputFile) === normalizeOutputPathKey(outputFile);
|
|
4402
4793
|
const hasStaleViteProcessedCssSource = vitePipelineCssAsset && hasDifferentRememberedCssSource && (hasCurrentTailwindGenerationDirective || hasRememberedApplyDirective || hasRememberedTailwindGenerationSource);
|
|
4403
4794
|
const generatorSourceFile = vitePipelineCssAsset ? rememberedCssSource?.sourceFile ?? assetSourceFile : assetSourceFile;
|
|
4404
|
-
|
|
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))) {
|
|
4405
4798
|
usedConfiguredTailwindV4CssSourceFiles.add(normalizeOutputPathKey(generatorSourceFile));
|
|
4406
4799
|
temporaryCssAssetSourceResolver.markUsed(generatorSourceFile);
|
|
4407
4800
|
}
|
|
@@ -4409,12 +4802,13 @@ function createGenerateBundleHook(context) {
|
|
|
4409
4802
|
...getCssHandlerOptions(generatorSourceFile),
|
|
4410
4803
|
isMainChunk: resolvedFromTemporaryCssAsset ? false : outputCssHandlerOptions.isMainChunk
|
|
4411
4804
|
} : getCssHandlerOptions(file);
|
|
4805
|
+
const generatorCssEntries = configuredTailwindV4ExplicitCssEntryFileKeysForScope.has(normalizeConfiguredTailwindV4CssEntryFileKey(generatorSourceFile)) ? [generatorSourceFile] : opts.cssEntries;
|
|
4412
4806
|
const generatorCssHandlerOptions = {
|
|
4413
4807
|
...cssHandlerOptions,
|
|
4414
4808
|
sourceOptions: {
|
|
4415
4809
|
...cssHandlerOptions.sourceOptions ?? {},
|
|
4416
4810
|
sourceFile: generatorSourceFile,
|
|
4417
|
-
cssEntries:
|
|
4811
|
+
cssEntries: generatorCssEntries
|
|
4418
4812
|
}
|
|
4419
4813
|
};
|
|
4420
4814
|
const scopedSourceCandidateGetter = createScopedSourceCandidateGetter(outputFile, generatorCssHandlerOptions);
|
|
@@ -4426,6 +4820,10 @@ function createGenerateBundleHook(context) {
|
|
|
4426
4820
|
opts,
|
|
4427
4821
|
tokenSources: sourceTraceTokenSources
|
|
4428
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
|
+
};
|
|
4429
4827
|
const shouldRegenerateMainPackageCssWithScopedCandidates = vitePipelineCssAsset && shouldExcludeSubpackageSourceCandidates(outputFile, generatorCssHandlerOptions);
|
|
4430
4828
|
const generatorCssUserHandlerOptions = getCssUserHandlerOptions(generatorSourceFile);
|
|
4431
4829
|
const cssRuntimeAffectingSignature = vitePipelineCssAsset ? createRuntimeAffectingSourceSignature(generatorRawSource, "css") : snapshot.runtimeAffectingSignatureByFile.get(file) ?? createRuntimeAffectingSourceSignature(generatorRawSource, "css");
|
|
@@ -4433,19 +4831,30 @@ function createGenerateBundleHook(context) {
|
|
|
4433
4831
|
const cssShareScope = createCssTransformShareScopeKey(opts, outputFile, generatorRawSource);
|
|
4434
4832
|
const shouldRegenerateCollectedViteCss = viteProcessedCssAsset && useIncrementalMode && state.generatorCandidateSignature !== void 0 && generatorCandidatesChanged && (hasTailwindGenerationSource(generatorRawSource) || hasBundlerGeneratedCssMarker(rawSource) || rememberedCssSource != null && hasTailwindGenerationSource(rememberedCssSource.rawSource));
|
|
4435
4833
|
const shouldRefreshViteProcessedCssByCandidates = viteProcessedCssAsset && useIncrementalMode && state.generatorCandidateSignature !== void 0 && generatorCandidatesChanged;
|
|
4436
|
-
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));
|
|
4437
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));
|
|
4438
4838
|
const shouldPreserveCollectedViteCssAsset = !shouldRegenerateCollectedViteCss && (state.generatorCandidateSignature === void 0 || !generatorCandidatesChanged) && (collectedBundlerGeneratedCssFiles.has(file) || hasBundlerGeneratedCssMarker(rawSource));
|
|
4439
4839
|
const strippedViteProcessedCss = stripBundlerGeneratedCssMarkers(rawSource);
|
|
4440
4840
|
const shouldPreserveStaleGeneratedCssAsset = hasStaleViteProcessedCssSource && shouldPreserveCollectedViteCssAsset && strippedViteProcessedCss.trim().length > 0 && !strippedViteProcessedCss.includes("weapp-tailwindcss generator-placeholder") && !strippedViteProcessedCss.includes("vite-placeholder") && !hasTailwindGenerationSource(strippedViteProcessedCss) && !hasTailwindApplyDirective(strippedViteProcessedCss);
|
|
4441
4841
|
if (alreadyProcessedCssAsset && !shouldRefreshViteProcessedCssByCandidates && (!hasStaleViteProcessedCssSource || shouldPreserveStaleGeneratedCssAsset) && !hasRememberedApplySource && !shouldRegenerateMainPackageCssWithScopedCandidates && (!shouldTrackGeneratorRuntime || shouldPreserveCollectedViteCssAsset)) {
|
|
4442
|
-
const nextCss = strippedViteProcessedCss;
|
|
4842
|
+
const nextCss = removeRootCoveredCssFromScopedAsset(strippedViteProcessedCss);
|
|
4443
4843
|
applyCssResult(nextCss);
|
|
4444
4844
|
markCssAssetProcessed?.(originalSource, outputFile);
|
|
4445
4845
|
recordCssAssetResult?.(outputFile, nextCss);
|
|
4446
|
-
|
|
4846
|
+
if (vitePipelineCssAsset && rememberedCssSource) rememberCssSource?.({
|
|
4847
|
+
outputFile: vitePipelineCssInjectionOutputFile,
|
|
4848
|
+
rawSource: generatorRawSource,
|
|
4849
|
+
sourceFile: generatorSourceFile
|
|
4850
|
+
});
|
|
4851
|
+
if (shouldRecordVitePipelineCssByOutput) recordViteProcessedCssAssetResult?.(vitePipelineCssInjectionOutputFile, nextCss, {
|
|
4447
4852
|
injectIntoMain: outputCssHandlerOptions.isMainChunk ? false : shouldInjectVitePipelineCssIntoMain,
|
|
4448
|
-
outputFile
|
|
4853
|
+
outputFile: vitePipelineCssInjectionOutputFile
|
|
4854
|
+
});
|
|
4855
|
+
if (vitePipelineCssAsset && shouldInjectVitePipelineCssIntoMain) recordViteProcessedCssAssetResult?.(file, nextCss, {
|
|
4856
|
+
injectIntoMain: shouldInjectVitePipelineCssIntoMain,
|
|
4857
|
+
outputFile: vitePipelineCssInjectionOutputFile
|
|
4449
4858
|
});
|
|
4450
4859
|
onUpdate(outputFile, rawSource, nextCss);
|
|
4451
4860
|
debug("css skip vite-processed asset: %s", outputFile);
|
|
@@ -4483,7 +4892,7 @@ function createGenerateBundleHook(context) {
|
|
|
4483
4892
|
rememberLastCssResult(lastCssResultByFile, lastCssSourceHashByFile, outputFile, source, cssRuntimeAffectingHash);
|
|
4484
4893
|
markCssAssetProcessed?.(originalSource, outputFile);
|
|
4485
4894
|
if (rememberedCssSources.length <= 1) rememberCssSource?.({
|
|
4486
|
-
outputFile,
|
|
4895
|
+
outputFile: vitePipelineCssInjectionOutputFile,
|
|
4487
4896
|
rawSource: generatorRawSource,
|
|
4488
4897
|
sourceFile: generatorSourceFile
|
|
4489
4898
|
}, rememberedCssRuntimeSignature);
|
|
@@ -4518,6 +4927,7 @@ function createGenerateBundleHook(context) {
|
|
|
4518
4927
|
cssUserHandlerOptions: generatorCssUserHandlerOptions,
|
|
4519
4928
|
getSourceCandidatesForEntries: scopedSourceCandidateGetter,
|
|
4520
4929
|
sourceCandidates: scopedGeneratorRuntime,
|
|
4930
|
+
generatorPlatform,
|
|
4521
4931
|
styleHandler,
|
|
4522
4932
|
debug,
|
|
4523
4933
|
previousCss,
|
|
@@ -4525,19 +4935,19 @@ function createGenerateBundleHook(context) {
|
|
|
4525
4935
|
...usesConfiguredTailwindV4FallbackSource ? { restoreLocalCssImports: false } : {}
|
|
4526
4936
|
}) : void 0;
|
|
4527
4937
|
if (generated) {
|
|
4528
|
-
const tracedCss = annotateCss(generated.css);
|
|
4938
|
+
const tracedCss = removeRootCoveredCssFromScopedAsset(annotateCss(transformWebTargetCss(generated.css)));
|
|
4529
4939
|
registerGeneratorDependencies$1({ addWatchFile }, generated.dependencies);
|
|
4530
4940
|
if (envFlags.debugCssDiff) debug("css diff %s: %s", generatorSourceFile, summarizeStringDiff(generatorRawSource, tracedCss));
|
|
4531
4941
|
debug("css generated result: %s bytes=%d", file, tracedCss.length);
|
|
4532
4942
|
for (const candidate of generated.classSet ?? []) transformRuntime.add(candidate);
|
|
4533
4943
|
recordCssAssetResult?.(outputFile, tracedCss);
|
|
4534
|
-
recordViteProcessedCssAssetResult?.(
|
|
4944
|
+
if (shouldRecordVitePipelineCssByOutput) recordViteProcessedCssAssetResult?.(vitePipelineCssInjectionOutputFile, tracedCss, {
|
|
4535
4945
|
injectIntoMain: outputCssHandlerOptions.isMainChunk ? false : shouldInjectVitePipelineCssIntoMain,
|
|
4536
|
-
outputFile
|
|
4946
|
+
outputFile: vitePipelineCssInjectionOutputFile
|
|
4537
4947
|
});
|
|
4538
4948
|
if (vitePipelineCssAsset && shouldInjectVitePipelineCssIntoMain) recordViteProcessedCssAssetResult?.(file, tracedCss, {
|
|
4539
4949
|
injectIntoMain: shouldInjectVitePipelineCssIntoMain,
|
|
4540
|
-
outputFile
|
|
4950
|
+
outputFile: vitePipelineCssInjectionOutputFile
|
|
4541
4951
|
});
|
|
4542
4952
|
metrics.css.elapsed += measureElapsed(start);
|
|
4543
4953
|
metrics.css.transformed++;
|
|
@@ -4545,10 +4955,11 @@ function createGenerateBundleHook(context) {
|
|
|
4545
4955
|
return tracedCss;
|
|
4546
4956
|
}
|
|
4547
4957
|
if (isWebGeneratorTarget) {
|
|
4958
|
+
const outputCss = transformWebTargetCss(rawSource);
|
|
4548
4959
|
metrics.css.elapsed += measureElapsed(start);
|
|
4549
4960
|
metrics.css.transformed++;
|
|
4550
4961
|
debug("css preserve web target: %s", outputFile);
|
|
4551
|
-
return annotateCss(
|
|
4962
|
+
return annotateCss(outputCss);
|
|
4552
4963
|
}
|
|
4553
4964
|
const { css } = await styleHandler(generatorRawSource, cssHandlerOptions);
|
|
4554
4965
|
const tracedCss = annotateCss(css);
|
|
@@ -4568,7 +4979,7 @@ function createGenerateBundleHook(context) {
|
|
|
4568
4979
|
continue;
|
|
4569
4980
|
}
|
|
4570
4981
|
if (type !== "js") continue;
|
|
4571
|
-
if (isWebGeneratorTarget) {
|
|
4982
|
+
if (isWebGeneratorTarget && !shouldApplyWebviewSafeSelectors) {
|
|
4572
4983
|
debug("js skip web target: %s", file);
|
|
4573
4984
|
continue;
|
|
4574
4985
|
}
|
|
@@ -4614,6 +5025,7 @@ function createGenerateBundleHook(context) {
|
|
|
4614
5025
|
debug,
|
|
4615
5026
|
defaultStyleOutputExtension,
|
|
4616
5027
|
emitOrReplayCssAsset,
|
|
5028
|
+
generatorPlatform,
|
|
4617
5029
|
generatorRuntime,
|
|
4618
5030
|
getCssHandlerOptions,
|
|
4619
5031
|
getCssUserHandlerOptions,
|
|
@@ -4693,12 +5105,19 @@ function createGenerateBundleHook(context) {
|
|
|
4693
5105
|
tasks,
|
|
4694
5106
|
timingDetails,
|
|
4695
5107
|
transformRuntime,
|
|
5108
|
+
transformWebTargetCss,
|
|
4696
5109
|
useIncrementalMode
|
|
4697
5110
|
});
|
|
4698
5111
|
};
|
|
4699
5112
|
}
|
|
4700
5113
|
//#endregion
|
|
4701
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
|
+
}
|
|
4702
5121
|
function isAddWatchFileInvalidRollupPhaseError(error) {
|
|
4703
5122
|
const candidate = error;
|
|
4704
5123
|
return candidate?.code === "INVALID_ROLLUP_PHASE" || candidate?.pluginCode === "INVALID_ROLLUP_PHASE" || candidate?.message?.includes("Cannot call \"addWatchFile\" after the build has finished.") === true;
|
|
@@ -4742,8 +5161,13 @@ function shouldFinalizeProcessedCssAsset(opts, file) {
|
|
|
4742
5161
|
function collectViteProcessedCssSources(getViteProcessedCssAssetResults) {
|
|
4743
5162
|
return [...getViteProcessedCssAssetResults?.() ?? []].map(([, record]) => typeof record === "string" ? record : record.css);
|
|
4744
5163
|
}
|
|
4745
|
-
function
|
|
4746
|
-
|
|
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;
|
|
4747
5171
|
}
|
|
4748
5172
|
function createViteCssFinalizerOutputPlugin(context) {
|
|
4749
5173
|
return {
|
|
@@ -4755,24 +5179,27 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
4755
5179
|
const { opts, runtimeState, ensureRuntimeClassSet, isCssAssetProcessed, markCssAssetProcessed, debug, getResolvedConfig, recordCssAssetResult, recordViteProcessedCssAssetResult, getViteProcessedCssAssetResults, getRecordedGeneratorCandidates, getSourceCandidates, getSourceCandidatesForEntries, getSourceCandidateSourcesForEntries, waitForSourceCandidateSyncs, rememberMainCssSource, getRememberedMainCssSource, isViteProcessedCssAsset } = context;
|
|
4756
5180
|
const resolvedConfig = getResolvedConfig();
|
|
4757
5181
|
const uniUtsPlatform = resolveUniUtsPlatform();
|
|
5182
|
+
const generatorPlatform = opts.cssOptions?.platform ?? opts.platform ?? inferPlatformFromViteOutDir(resolvedConfig?.build?.outDir);
|
|
4758
5183
|
const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(opts.generator, {
|
|
4759
5184
|
appType: opts.appType,
|
|
4760
|
-
platform:
|
|
5185
|
+
platform: generatorPlatform,
|
|
4761
5186
|
tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
4762
5187
|
uniAppX: opts.uniAppX,
|
|
4763
5188
|
uniUtsPlatform
|
|
4764
5189
|
});
|
|
4765
5190
|
const generatorBranch = resolveGeneratorRuntimeBranch(generatorOptions, {
|
|
4766
5191
|
appType: opts.appType,
|
|
4767
|
-
platform:
|
|
5192
|
+
platform: generatorPlatform,
|
|
4768
5193
|
tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
4769
5194
|
uniAppX: opts.uniAppX,
|
|
4770
5195
|
uniUtsPlatform
|
|
4771
5196
|
});
|
|
4772
5197
|
const isWebGeneratorTarget = generatorBranch.isWeb;
|
|
4773
|
-
const
|
|
4774
|
-
const
|
|
4775
|
-
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);
|
|
4776
5203
|
if (resolvedConfig?.command !== "build" && !isNativeAppStyleTarget) return;
|
|
4777
5204
|
const rootDir = resolvedConfig?.root ? path.resolve(resolvedConfig.root) : process$1.cwd();
|
|
4778
5205
|
const sourceRoot = resolveWeappViteSourceRoot(resolvedConfig, opts.appType) ?? resolveSourceRootFromBundleGraph(resolvedConfig, bundle);
|
|
@@ -4789,7 +5216,10 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
4789
5216
|
recordCssAssetResult,
|
|
4790
5217
|
recordViteProcessedCssAssetResult,
|
|
4791
5218
|
resolveViteProcessedCssOutputFile: (file) => resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget, isNativeAppStyleTarget, sourceRoot, resolveMiniProgramStyleOutputExtension({ files: Object.keys(bundle) }), Object.keys(bundle)),
|
|
4792
|
-
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
|
+
}),
|
|
4793
5223
|
debug
|
|
4794
5224
|
});
|
|
4795
5225
|
};
|
|
@@ -4799,6 +5229,10 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
4799
5229
|
getViteProcessedCssAssetResults,
|
|
4800
5230
|
markCssAssetProcessed,
|
|
4801
5231
|
recordCssAssetResult,
|
|
5232
|
+
transformCss: (css) => finalizeWebCss(css, generatorBranch.isWeb, generatorOptions.webCompat, {
|
|
5233
|
+
escapeMap: opts.escapeMap,
|
|
5234
|
+
safeSelectors: shouldApplyWebviewSafeSelectors
|
|
5235
|
+
}),
|
|
4802
5236
|
debug,
|
|
4803
5237
|
onUpdate: opts.onUpdate
|
|
4804
5238
|
});
|
|
@@ -4824,6 +5258,7 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
4824
5258
|
isMainChunk: false
|
|
4825
5259
|
},
|
|
4826
5260
|
getSourceCandidatesForEntries,
|
|
5261
|
+
generatorPlatform,
|
|
4827
5262
|
styleHandler: opts.styleHandler,
|
|
4828
5263
|
debug
|
|
4829
5264
|
});
|
|
@@ -4862,7 +5297,10 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
4862
5297
|
const file = output.fileName || bundleFile;
|
|
4863
5298
|
const rawSource = output.source.toString();
|
|
4864
5299
|
if (isViteProcessedCssAsset?.(output, file)) {
|
|
4865
|
-
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
|
+
}));
|
|
4866
5304
|
output.source = nextCss;
|
|
4867
5305
|
markCssAssetProcessed(output, file);
|
|
4868
5306
|
recordCssAssetResult?.(file, nextCss);
|
|
@@ -4893,10 +5331,14 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
4893
5331
|
cssHandlerOptions: generatorCssHandlerOptions,
|
|
4894
5332
|
cssUserHandlerOptions: generatorCssUserHandlerOptions,
|
|
4895
5333
|
getSourceCandidatesForEntries,
|
|
5334
|
+
generatorPlatform,
|
|
4896
5335
|
styleHandler: opts.styleHandler,
|
|
4897
5336
|
debug
|
|
4898
5337
|
}) : void 0;
|
|
4899
|
-
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));
|
|
4900
5342
|
if (generated) {
|
|
4901
5343
|
registerGeneratorDependencies(this, generated.dependencies);
|
|
4902
5344
|
debug("css finalizer generated result: %s bytes=%d", file, nextCss.length);
|
|
@@ -5045,6 +5487,7 @@ function createViteCssMemory(options) {
|
|
|
5045
5487
|
for (const [rememberedKey, remembered] of relatedRememberedEntries) {
|
|
5046
5488
|
touchMapEntry(rememberedCssSources, rememberedKey, {
|
|
5047
5489
|
...remembered,
|
|
5490
|
+
outputFile: entry.outputFile,
|
|
5048
5491
|
rawSource: entry.rawSource,
|
|
5049
5492
|
sourceFile: entry.sourceFile
|
|
5050
5493
|
});
|
|
@@ -5199,6 +5642,22 @@ function resolveHotTailwindCssModules(ctx, tailwindRootCssModuleIds) {
|
|
|
5199
5642
|
}
|
|
5200
5643
|
return modules;
|
|
5201
5644
|
}
|
|
5645
|
+
function resolveHotSourceModules(ctx) {
|
|
5646
|
+
const modules = [];
|
|
5647
|
+
const seenModules = /* @__PURE__ */ new Set();
|
|
5648
|
+
const collectModule = (mod) => {
|
|
5649
|
+
if (mod == null || seenModules.has(mod)) return;
|
|
5650
|
+
if (isSourceStyleRequest(mod.id ?? mod.url)) return;
|
|
5651
|
+
seenModules.add(mod);
|
|
5652
|
+
modules.push(mod);
|
|
5653
|
+
};
|
|
5654
|
+
for (const mod of ctx.modules) collectModule(mod);
|
|
5655
|
+
for (const mod of ctx.server.moduleGraph.getModulesByFile(ctx.file) ?? []) collectModule(mod);
|
|
5656
|
+
for (const mod of ctx.server.moduleGraph.getModulesByFile(cleanUrl(ctx.file)) ?? []) collectModule(mod);
|
|
5657
|
+
collectModule(ctx.server.moduleGraph.getModuleById?.(ctx.file));
|
|
5658
|
+
collectModule(ctx.server.moduleGraph.getModuleById?.(cleanUrl(ctx.file)));
|
|
5659
|
+
return modules;
|
|
5660
|
+
}
|
|
5202
5661
|
function resolveModuleHotUrl(mod) {
|
|
5203
5662
|
if (typeof mod.url === "string" && mod.url.length > 0) return mod.url;
|
|
5204
5663
|
if (typeof mod.id === "string" && mod.id.startsWith("/")) return mod.id;
|
|
@@ -5679,6 +6138,15 @@ function sameStringList(first, second) {
|
|
|
5679
6138
|
if (!first || !second || first.length !== second.length) return false;
|
|
5680
6139
|
return first.every((item, index) => item === second[index]);
|
|
5681
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
|
+
}
|
|
5682
6150
|
function normalizeViteStylePlatform(value, appType) {
|
|
5683
6151
|
return normalizeFrameworkStylePlatform(value, appType);
|
|
5684
6152
|
}
|
|
@@ -5691,6 +6159,13 @@ function inferPlatformFromOutDir(outDir) {
|
|
|
5691
6159
|
function isWebOrNativeAppPlatform(platform) {
|
|
5692
6160
|
return platform === "h5" || platform === "web" || platform?.startsWith("web-") === true || platform === "app" || platform === "app-plus" || platform?.startsWith("app-") === true;
|
|
5693
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
|
+
}
|
|
5694
6169
|
/**
|
|
5695
6170
|
* @name WeappTailwindcss
|
|
5696
6171
|
* @description uni-app vite / uni-app-x 版本插件
|
|
@@ -5699,7 +6174,7 @@ function isWebOrNativeAppPlatform(platform) {
|
|
|
5699
6174
|
function WeappTailwindcss(options = {}) {
|
|
5700
6175
|
const hasExplicitAppType = typeof options.appType === "string" && options.appType.trim().length > 0;
|
|
5701
6176
|
const hasExplicitTailwindcssBasedir = typeof options.tailwindcssBasedir === "string" && options.tailwindcssBasedir.trim().length > 0;
|
|
5702
|
-
const rawCssEntries =
|
|
6177
|
+
const rawCssEntries = collectConfiguredCssEntries(options);
|
|
5703
6178
|
const opts = getCompilerContext({
|
|
5704
6179
|
...options,
|
|
5705
6180
|
__internalDeferMissingCssEntriesWarning: true
|
|
@@ -5718,7 +6193,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
5718
6193
|
return changed;
|
|
5719
6194
|
};
|
|
5720
6195
|
syncCssEntriesFromAnchor(opts.tailwindcssBasedir);
|
|
5721
|
-
const { disabled, customAttributes, onLoad, mainCssChunkMatcher, styleHandler, jsHandler, tailwindRuntime, refreshTailwindcssRuntime, uniAppX, disabledDefaultTemplateHandler } = opts;
|
|
6196
|
+
const { disabled, customAttributes, onLoad, mainCssChunkMatcher, styleHandler, jsHandler, tailwindRuntime, refreshTailwindcssRuntime, uniAppX, disabledDefaultTemplateHandler, styleInjector } = opts;
|
|
5722
6197
|
const initialTailwindRuntime = tailwindRuntime;
|
|
5723
6198
|
const refreshTailwindRuntime = refreshTailwindcssRuntime;
|
|
5724
6199
|
const uniAppXEnabled = isUniAppXEnabled(uniAppX);
|
|
@@ -5727,18 +6202,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
5727
6202
|
if (!disabledOptions.plugin && tailwindcssMajorVersion !== 4) throw new Error("weapp-tailwindcss/vite 新生成管线仅支持 Tailwind CSS v4,请升级 tailwindcss 或停留在旧版 weapp-tailwindcss。");
|
|
5728
6203
|
const shouldOwnTailwindGeneration = !disabledOptions.plugin;
|
|
5729
6204
|
const shouldRewriteCssImports = opts.rewriteCssImports === true;
|
|
5730
|
-
|
|
5731
|
-
appType: opts.appType,
|
|
5732
|
-
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
5733
|
-
tailwindcssMajorVersion,
|
|
5734
|
-
uniAppX
|
|
5735
|
-
});
|
|
5736
|
-
const generatorBranch = resolveGeneratorRuntimeBranch(generatorOptions, {
|
|
5737
|
-
appType: opts.appType,
|
|
5738
|
-
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
5739
|
-
tailwindcssMajorVersion,
|
|
5740
|
-
uniAppX
|
|
5741
|
-
});
|
|
6205
|
+
let resolvedConfig;
|
|
5742
6206
|
const resolveViteStylePlatform = () => {
|
|
5743
6207
|
const explicit = normalizeViteStylePlatform(opts.cssOptions?.platform ?? opts.platform, opts.appType);
|
|
5744
6208
|
if (explicit) return explicit;
|
|
@@ -5748,9 +6212,23 @@ function WeappTailwindcss(options = {}) {
|
|
|
5748
6212
|
}
|
|
5749
6213
|
return inferPlatformFromOutDir(resolvedConfig?.build?.outDir);
|
|
5750
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();
|
|
5751
6229
|
const transformEarlyMiniProgramCss = (code) => {
|
|
5752
6230
|
const platform = resolveViteStylePlatform();
|
|
5753
|
-
if (!shouldOwnTailwindGeneration || (platform ? isWebOrNativeAppPlatform(platform) :
|
|
6231
|
+
if (!shouldOwnTailwindGeneration || (platform ? isWebOrNativeAppPlatform(platform) : resolveCurrentGeneratorBranch().isWeb)) return code;
|
|
5754
6232
|
let transformedCode = code;
|
|
5755
6233
|
if (transformedCode.includes("#if")) transformedCode = compileCssMacroConditionalComments(transformedCode, { platform: resolveViteStylePlatform() });
|
|
5756
6234
|
if (transformedCode.includes("@layer")) transformedCode = unwrapUnsupportedCascadeLayers(transformedCode);
|
|
@@ -5758,10 +6236,10 @@ function WeappTailwindcss(options = {}) {
|
|
|
5758
6236
|
};
|
|
5759
6237
|
const finalizeViteMiniProgramCss = (css) => {
|
|
5760
6238
|
const platform = resolveViteStylePlatform();
|
|
5761
|
-
if (!shouldOwnTailwindGeneration || (platform ? isWebOrNativeAppPlatform(platform) :
|
|
6239
|
+
if (!shouldOwnTailwindGeneration || (platform ? isWebOrNativeAppPlatform(platform) : resolveCurrentGeneratorBranch().isWeb)) return css;
|
|
5762
6240
|
return unwrapUnsupportedCascadeLayers(css);
|
|
5763
6241
|
};
|
|
5764
|
-
const shouldInferAppType = !hasExplicitAppType && !
|
|
6242
|
+
const shouldInferAppType = !hasExplicitAppType && !initialGeneratorBranch.isWeb;
|
|
5765
6243
|
const hasInitialTailwindCssRoots = hasConfiguredTailwindV4CssRoots({
|
|
5766
6244
|
...options,
|
|
5767
6245
|
cssEntries: opts.cssEntries ?? options.cssEntries
|
|
@@ -5841,7 +6319,6 @@ function WeappTailwindcss(options = {}) {
|
|
|
5841
6319
|
await refreshRuntimeStateForAutoCssSources?.(true);
|
|
5842
6320
|
};
|
|
5843
6321
|
const customAttributesEntities = toCustomAttributesEntities(customAttributes);
|
|
5844
|
-
let resolvedConfig;
|
|
5845
6322
|
let recordedGeneratorCandidates;
|
|
5846
6323
|
const sourceCandidateCollector = createSourceCandidateCollector({ bareArbitraryValues: opts.arbitraryValues?.bareArbitraryValues });
|
|
5847
6324
|
const sourceCandidateScanCache = new LRUCache({ max: SOURCE_CANDIDATE_SCAN_CACHE_MAX });
|
|
@@ -5897,6 +6374,15 @@ function WeappTailwindcss(options = {}) {
|
|
|
5897
6374
|
const getSourceCandidateSourcesForEntries = (entries, options) => sourceCandidateCollector.sourcesForEntries(entries, options);
|
|
5898
6375
|
const isWatchBuild = () => resolvedConfig?.command === "build" && resolvedConfig.build.watch != null;
|
|
5899
6376
|
const isWatchLikeBuild = () => isWatchBuild() || resolvedConfig?.command === "serve" || process$1.env["WEAPP_TW_WATCH_REGRESSION"] === "1" || process$1.env["WEAPP_TW_HMR_TIMING"] === "1";
|
|
6377
|
+
const isCurrentWebLikeStylePlatform = () => {
|
|
6378
|
+
const platform = resolveViteStylePlatform();
|
|
6379
|
+
return platform ? isWebOrNativeAppPlatform(platform) : resolveCurrentGeneratorBranch().isWeb;
|
|
6380
|
+
};
|
|
6381
|
+
const isNuxtPageMacroHotModule = (id) => {
|
|
6382
|
+
if (typeof id !== "string" || !/[?&]macro=true(?:&|$)/.test(id)) return false;
|
|
6383
|
+
const cleanId = cleanUrl(id);
|
|
6384
|
+
return cleanId.includes("/pages/") && /\.(?:vue|tsx?|jsx?)$/.test(cleanId);
|
|
6385
|
+
};
|
|
5900
6386
|
const hasSourceCandidateScanState = () => sourceCandidateScanSignature !== void 0;
|
|
5901
6387
|
const normalizeSourceScanDependency = (file) => path.normalize(path.resolve(cleanUrl(file)));
|
|
5902
6388
|
const isSourceScanDependency = (file) => sourceScanDependencies.has(normalizeSourceScanDependency(file));
|
|
@@ -6110,47 +6596,58 @@ function WeappTailwindcss(options = {}) {
|
|
|
6110
6596
|
const file = cleanUrl(id);
|
|
6111
6597
|
const requestFile = isCSSRequest(id) ? id : file;
|
|
6112
6598
|
if (!isCSSRequest(requestFile) || opts.htmlMatcher(file) || isHTMLRequest(file)) return;
|
|
6599
|
+
const generatorCode = normalizeEmptyTailwindCustomVariants(code);
|
|
6113
6600
|
const rootDir = resolvedConfig?.root ? path.resolve(resolvedConfig.root) : process$1.cwd();
|
|
6114
6601
|
const isHarmonyAppStyleTarget = isHarmonyAppBuildTarget();
|
|
6115
|
-
const isNativeAppStyleTarget = resolveUniUtsPlatform().isApp || isHarmonyAppStyleTarget;
|
|
6602
|
+
const isNativeAppStyleTarget = opts.appType === "uni-app-x" && (resolveUniUtsPlatform().isApp || isHarmonyAppStyleTarget);
|
|
6116
6603
|
const sourceRoot = resolveWeappViteSourceRoot(resolvedConfig, opts.appType);
|
|
6117
|
-
const
|
|
6604
|
+
const currentGeneratorOptions = resolveCurrentGeneratorOptions();
|
|
6605
|
+
const currentGeneratorBranch = resolveCurrentGeneratorBranch();
|
|
6606
|
+
const outputFile = resolveViteCssPipelineOutputFile(requestFile, opts, rootDir, currentGeneratorBranch.isWeb, isNativeAppStyleTarget, sourceRoot);
|
|
6118
6607
|
const runtime = getRecordedGeneratorCandidates() ?? getSourceCandidates() ?? await ensureRuntimeClassSet();
|
|
6119
6608
|
const outputCssHandlerOptions = transformCssHandlerOptions.getCssHandlerOptions(outputFile);
|
|
6120
6609
|
const cssHandlerOptions = {
|
|
6121
6610
|
...transformCssHandlerOptions.getCssHandlerOptions(file),
|
|
6122
6611
|
isMainChunk: outputCssHandlerOptions.isMainChunk
|
|
6123
6612
|
};
|
|
6124
|
-
const transientCssSource = transientAutoCssSources.get(file) ?? (hasTailwindRootDirectives(
|
|
6613
|
+
const transientCssSource = transientAutoCssSources.get(file) ?? (hasTailwindRootDirectives(generatorCode, { importFallback: currentGeneratorOptions.importFallback }) || hasTailwindSourceDirectives(generatorCode, { importFallback: currentGeneratorOptions.importFallback }) || hasTailwindApplyDirective(generatorCode) ? {
|
|
6125
6614
|
base: path.dirname(path.resolve(file)),
|
|
6126
|
-
css:
|
|
6615
|
+
css: generatorCode,
|
|
6127
6616
|
file: path.resolve(file)
|
|
6128
6617
|
} : void 0);
|
|
6129
|
-
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));
|
|
6130
6619
|
const generated = await generateTailwindV4Css({
|
|
6131
6620
|
opts,
|
|
6132
6621
|
runtimeState,
|
|
6133
6622
|
runtime,
|
|
6134
|
-
rawSource:
|
|
6623
|
+
rawSource: generatorCode,
|
|
6135
6624
|
file,
|
|
6136
6625
|
outputFile,
|
|
6137
6626
|
cssHandlerOptions,
|
|
6138
6627
|
cssUserHandlerOptions: transformCssHandlerOptions.getCssUserHandlerOptions(file),
|
|
6139
6628
|
cssSources: transientCssSource ? [transientCssSource] : void 0,
|
|
6140
6629
|
getSourceCandidatesForEntries,
|
|
6630
|
+
generatorPlatform: resolveGeneratorPlatform(),
|
|
6141
6631
|
styleHandler,
|
|
6142
6632
|
debug,
|
|
6143
6633
|
previousCss: viteGeneratedCssByFile.get(file),
|
|
6144
|
-
deferEmptyScopedCssSource: shouldDeferEmptyScopedCssSource
|
|
6634
|
+
deferEmptyScopedCssSource: shouldDeferEmptyScopedCssSource,
|
|
6635
|
+
restoreLocalCssImports: !currentGeneratorBranch.isWeb
|
|
6145
6636
|
});
|
|
6146
6637
|
if (!generated) return;
|
|
6147
|
-
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), {
|
|
6148
6645
|
opts,
|
|
6149
6646
|
tokenSources: createCssTokenSourceMap(getSourceCandidateSourcesForEntries(void 0), opts)
|
|
6150
6647
|
});
|
|
6151
6648
|
for (const dependency of generated.dependencies) hookContext?.addWatchFile?.(dependency);
|
|
6152
6649
|
viteGeneratedCssByFile.set(file, tracedCss);
|
|
6153
|
-
const shouldInjectGeneratedCssIntoMain = mainCssChunkMatcher(outputFile, opts.appType) || hasTailwindRootDirectives(
|
|
6650
|
+
const shouldInjectGeneratedCssIntoMain = mainCssChunkMatcher(outputFile, opts.appType) || hasTailwindRootDirectives(generatorCode, { importFallback: currentGeneratorOptions.importFallback }) && !normalizeOutputPathKey(outputFile).includes("/");
|
|
6154
6651
|
recordViteProcessedCssAssetResult(file, tracedCss, {
|
|
6155
6652
|
injectIntoMain: shouldInjectGeneratedCssIntoMain,
|
|
6156
6653
|
outputFile
|
|
@@ -6182,7 +6679,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
6182
6679
|
onTailwindRootCss: (id, code) => registerAutoCssSource(id, code),
|
|
6183
6680
|
onCssSourceTransform: (id, code) => cssMemory.refreshRememberedCssSourceBySourceFile(id, code),
|
|
6184
6681
|
shouldGenerateCss: (_id, code) => hasVitePipelineTailwindGenerationDirective(code),
|
|
6185
|
-
shouldDeferGeneration: (_id, code) => !shouldRewriteCssImports && hasTailwindRootDirectives(code, { importFallback:
|
|
6682
|
+
shouldDeferGeneration: (_id, code) => !shouldRewriteCssImports && hasTailwindRootDirectives(code, { importFallback: resolveCurrentGeneratorOptions().importFallback }),
|
|
6186
6683
|
shouldOwnTailwindGeneration,
|
|
6187
6684
|
shouldRewrite: shouldRewriteCssImports,
|
|
6188
6685
|
weappTailwindcssDirPosix
|
|
@@ -6281,7 +6778,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
6281
6778
|
order: "pre",
|
|
6282
6779
|
async handler(code, id) {
|
|
6283
6780
|
let transformedCode = code;
|
|
6284
|
-
if (shouldOwnTailwindGeneration && !
|
|
6781
|
+
if (shouldOwnTailwindGeneration && !resolveCurrentGeneratorBranch().isWeb && isCSSRequest(id)) transformedCode = transformEarlyMiniProgramCss(code);
|
|
6285
6782
|
const shouldReturnTransformedCode = transformedCode !== code;
|
|
6286
6783
|
if (shouldOwnTailwindGeneration) cssMemory.rememberKnownSfcSource(id, transformedCode);
|
|
6287
6784
|
if (!shouldOwnTailwindGeneration || !isSourceCandidateRequest(id) || !shouldCollectTransformedSourceCandidates(id)) {
|
|
@@ -6324,13 +6821,27 @@ function WeappTailwindcss(options = {}) {
|
|
|
6324
6821
|
return hmrTimingRecorder.measure("sourceCandidates.handleHotUpdate", async () => {
|
|
6325
6822
|
const isSourceCandidateHotUpdate = shouldOwnTailwindGeneration && isSourceCandidateRequest(ctx.file);
|
|
6326
6823
|
await syncChangedSourceCandidateFile(ctx.file);
|
|
6327
|
-
|
|
6824
|
+
const isWebLikeHotUpdate = isCurrentWebLikeStylePlatform();
|
|
6825
|
+
if (isSourceCandidateHotUpdate) {
|
|
6826
|
+
invalidateRecordedGeneratorCandidates();
|
|
6827
|
+
if (isWebLikeHotUpdate) {
|
|
6828
|
+
await refreshRuntimeStateForAutoCssSources?.(true);
|
|
6829
|
+
await syncSourceCandidateScan({ force: true });
|
|
6830
|
+
}
|
|
6831
|
+
}
|
|
6328
6832
|
const cssModules = resolveHotTailwindCssModules(ctx, tailwindRootCssModuleIds);
|
|
6329
|
-
|
|
6833
|
+
const sourceModules = isSourceCandidateHotUpdate && !isSourceStyleRequest(ctx.file) ? resolveHotSourceModules(ctx) : ctx.modules;
|
|
6834
|
+
if (isSourceCandidateHotUpdate && !isSourceStyleRequest(ctx.file) && !isWebLikeHotUpdate && (!hasSelfAcceptingNonStyleHotModule(sourceModules) && cssModules.length === 0 || cssModules.length > 0 && isUniViteProject())) {
|
|
6835
|
+
sendFullReloadForUnresolvedHotUpdate(ctx);
|
|
6836
|
+
return [];
|
|
6837
|
+
}
|
|
6838
|
+
if (isWebLikeHotUpdate && isSourceCandidateHotUpdate && !isSourceStyleRequest(ctx.file) && ctx.modules.some((mod) => isNuxtPageMacroHotModule(mod.id ?? mod.url))) {
|
|
6330
6839
|
sendFullReloadForUnresolvedHotUpdate(ctx);
|
|
6331
6840
|
return [];
|
|
6332
6841
|
}
|
|
6333
6842
|
sendSupplementalCssHotUpdates(ctx, cssModules);
|
|
6843
|
+
if (isWebLikeHotUpdate && isSourceCandidateHotUpdate && !isSourceStyleRequest(ctx.file)) return;
|
|
6844
|
+
if (isSourceCandidateHotUpdate && !isSourceStyleRequest(ctx.file) && cssModules.length > 0) return [...sourceModules, ...cssModules];
|
|
6334
6845
|
return cssModules.length > 0 ? [...ctx.modules, ...cssModules] : void 0;
|
|
6335
6846
|
}, { emit: false });
|
|
6336
6847
|
},
|
|
@@ -6347,10 +6858,10 @@ function WeappTailwindcss(options = {}) {
|
|
|
6347
6858
|
shouldGenerate: () => shouldOwnTailwindGeneration
|
|
6348
6859
|
}),
|
|
6349
6860
|
createViteServeJsTransformPlugin({
|
|
6350
|
-
createHandlerOptions: serveJsHandlerOptions,
|
|
6861
|
+
createHandlerOptions: (file) => serveJsHandlerOptions(file, opts.appType === "uni-app-vite" && isUniAppViteWebviewStylePlatform(resolveViteStylePlatform()) ? { needEscaped: true } : void 0),
|
|
6351
6862
|
getCommand: () => resolvedConfig?.command,
|
|
6352
6863
|
jsHandler,
|
|
6353
|
-
shouldTransform: () => shouldOwnTailwindGeneration && !
|
|
6864
|
+
shouldTransform: () => shouldOwnTailwindGeneration && (!resolveCurrentGeneratorBranch().isWeb || opts.appType === "uni-app-vite" && isUniAppViteWebviewStylePlatform(resolveViteStylePlatform())),
|
|
6354
6865
|
transformRuntime: ensureRuntimeClassSet
|
|
6355
6866
|
}),
|
|
6356
6867
|
{
|
|
@@ -6427,6 +6938,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
6427
6938
|
];
|
|
6428
6939
|
if (uniAppXPlugins) plugins.push(...uniAppXPlugins);
|
|
6429
6940
|
plugins.push(cssFinalizerOutputPlugin);
|
|
6941
|
+
plugins.push(...createBuiltinViteStyleInjectorPlugins(styleInjector, () => opts.appType));
|
|
6430
6942
|
return plugins;
|
|
6431
6943
|
}
|
|
6432
6944
|
//#endregion
|