weapp-tailwindcss 5.1.5 → 5.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +1 -1
- package/README.md +1 -1
- package/dist/bundlers/shared/generator-css/types.d.ts +1 -0
- package/dist/bundlers/shared/generator-css/user-css.d.ts +4 -1
- package/dist/bundlers/vite/generate-bundle/finalize.d.ts +1 -0
- package/dist/bundlers/vite/generate-bundle/remembered-css-replay.d.ts +1 -0
- package/dist/bundlers/vite/processed-css-assets.d.ts +7 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers.d.ts +10 -0
- package/dist/{context-rrYZuUBU.mjs → context-BqeDu1Ha.mjs} +5 -4
- package/dist/{context-BziwyWy1.js → context-C7KTDlrG.js} +5 -4
- package/dist/core.js +1 -1
- package/dist/core.mjs +1 -1
- package/dist/{generator-24-HgU9F.mjs → generator-BOt2Tvx3.mjs} +2 -2
- package/dist/{generator-CilgHtxb.js → generator-DASZwC6t.js} +2 -2
- package/dist/generator.js +2 -2
- package/dist/generator.mjs +2 -2
- package/dist/{gulp-CuVsZdO9.js → gulp-D6hsaTLM.js} +4 -4
- package/dist/{gulp-ygWfmOqh.mjs → gulp-alDZryyB.mjs} +4 -4
- package/dist/gulp.js +1 -1
- package/dist/gulp.mjs +1 -1
- package/dist/{hmr-timing-BKdCeIrn.js → hmr-timing-BIr_CiPW.js} +55 -566
- package/dist/{hmr-timing-Dh_nn3w5.mjs → hmr-timing-CYwVMRol.mjs} +32 -513
- package/dist/index.js +4 -4
- package/dist/index.mjs +4 -4
- package/dist/postcss.js +2 -2
- package/dist/postcss.mjs +2 -2
- package/dist/presets.js +6 -3
- package/dist/presets.mjs +6 -3
- package/dist/rspack.js +1 -1
- package/dist/rspack.mjs +1 -1
- package/dist/runtime-branch/generator-target-env.d.ts +1 -0
- package/dist/{source-candidate-scan-signature-DATRnS1X.mjs → source-candidate-scan-signature-D97ZEXcj.mjs} +3 -3
- package/dist/{source-candidate-scan-signature-DIj9m4wB.js → source-candidate-scan-signature-Djr2Hw8y.js} +3 -3
- package/dist/{tailwindcss-C-uM4rB8.mjs → tailwindcss-DDGD90w7.mjs} +15 -2
- package/dist/{tailwindcss-BwoNQ3t8.js → tailwindcss-DPxJpRVP.js} +15 -2
- package/dist/{transform-KLD1tJdb.js → transform-CvqqZBuq.js} +1 -1
- package/dist/{transform-DHLemtaX.mjs → transform-DPPr79r2.mjs} +1 -1
- package/dist/uni-app-x/web-preflight-reset.d.ts +3 -0
- package/dist/{v4-engine-CKtsdKxK.js → v4-engine-3UmJkAY7.js} +641 -3
- package/dist/{v4-engine-BuuYDXt1.mjs → v4-engine-CYSrDVNp.mjs} +560 -6
- package/dist/{vite-Yp14HNyS.js → vite-BJRlG835.js} +636 -114
- package/dist/{vite-cH0tTMHc.mjs → vite-XxJh7Xtu.mjs} +637 -115
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/weapp-tw-css-import-rewrite-loader.js +3078 -2907
- package/dist/{webpack-DN3tgLbF.js → webpack-BxBOMUtY.js} +286 -47
- package/dist/{webpack-DBhmJ-_P.mjs → webpack-eN8WzIT-.mjs} +280 -41
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +3 -3
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { resolveImplicitAppTypeFromViteRoot } from "./framework.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import { a as resolveGeneratorRuntimeBranch, c as shouldUseNativeAppCssBranch, i as normalizeWeappTailwindcssGeneratorOptions, s as shouldUseMiniProgramCssBranch } from "./generator-
|
|
2
|
+
import { $ as hasTailwindGeneratedCssMarkers, B as hasTailwindNonRootGenerationDirectives, Et as omitUndefined, G as normalizeTailwindSourceForGenerator, H as hasTailwindSourceDirectives, K as parseImportRequest, L as stripMiniProgramCssSpecificityPlaceholders, P as hasMiniProgramCssSpecificityPlaceholders, R as hasLocalCssImport, Tt as filterUnsupportedMiniProgramTailwindV4Candidates, U as normalizeTailwindConfigDirectives, V as hasTailwindRootDirectives, _ as resolveTailwindcssOptions, a as filterTailwindV4CssSourceRoots, d as normalizeCssEntries, f as findNearestPackageRoot, lt as getTailwindV4IncrementalGenerateCacheStats, o as hasConfiguredTailwindV4CssRoots, q as removeTailwindSourceDirectives, s as upsertTailwindV4CssSource, u as isTailwindV4CssEntry, w as normalizeEmptyTailwindCustomVariants, xt as resolveTailwindV4CssSourceBase, z as hasTailwindApplyDirective } from "./v4-engine-CYSrDVNp.mjs";
|
|
3
|
+
import { a as resolveGeneratorRuntimeBranch, c as shouldUseNativeAppCssBranch, i as normalizeWeappTailwindcssGeneratorOptions, s as shouldUseMiniProgramCssBranch } from "./generator-BOt2Tvx3.mjs";
|
|
4
4
|
import { o as resolveUniUtsPlatform } from "./utils-DodxWHGz.mjs";
|
|
5
|
-
import { C as normalizeFrameworkStylePlatform, S as createDebug, _ as toCustomAttributesEntities, a as vitePluginName, l as shouldSkipJsTransform, m as replaceWxml, n as normalizeStyleHandlerMajorVersion, t as getCompilerContext, v as collectRuntimeClassSet, x as refreshTailwindRuntimeState, y as createTailwindRuntimeReadyPromise } from "./context-
|
|
6
|
-
import { _ as resolveViteTailwindV4CssDependencies, a as findTailwindConfig, f as createViteSourceScanMatcher, g as resolveTailwindV4EntriesFromCssCached, i as resolveUniAppXOptions, l as getRuntimeClassSetSignature, m as discoverTailwindV4CssEntries, p as resolveViteSourceScanEntries, r as isUniAppXEnabled } from "./tailwindcss-
|
|
7
|
-
import {
|
|
8
|
-
import { A as isSourceStyleRequest, C as resolvePluginDisabledState, D as isHTMLRequest, E as isCSSRequest, F as createBuiltinViteStyleInjectorPlugins, M as normalizeOutputPathKey, O as normalizePath, P as toAbsoluteOutputPath, S as resolvePackageDir, T as formatPostcssSourceMap, _ as generateTailwindV4Css, a as createJsHashSalt, b as parseBundlerGeneratedCssMarkerBlocks, c as hasRuntimeAffectingSourceChanges, f as createBundleBuildState, g as createBundleModuleGraphOptions, h as applyLinkedResults, i as createCandidateSignature, j as stripRequestQuery, k as slash, l as summarizeStringDiff, m as createRuntimeAffectingSourceSignature, n as createScopedGeneratorCandidateSignature, o as createLinkedImpactSignature, p as updateBundleBuildState, r as createScopedGeneratorRuntime, s as getSnapshotHash, t as createSourceCandidateScanSignature, u as buildBundleSnapshot, v as createBundlerGeneratedCssMarker, w as cleanUrl, x as stripBundlerGeneratedCssMarkers, y as hasBundlerGeneratedCssMarker } from "./source-candidate-scan-signature-
|
|
5
|
+
import { C as normalizeFrameworkStylePlatform, S as createDebug, _ as toCustomAttributesEntities, a as vitePluginName, l as shouldSkipJsTransform, m as replaceWxml, n as normalizeStyleHandlerMajorVersion, t as getCompilerContext, v as collectRuntimeClassSet, x as refreshTailwindRuntimeState, y as createTailwindRuntimeReadyPromise } from "./context-BqeDu1Ha.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-DDGD90w7.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-CYwVMRol.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-D97ZEXcj.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-DPPr79r2.mjs").then((mod) => mod.transformUVue));
|
|
513
513
|
return transformUVuePromise;
|
|
514
514
|
}
|
|
515
515
|
const preprocessorLangs = /* @__PURE__ */ new Set([
|
|
@@ -743,6 +743,68 @@ function createUniAppXAssetTask(file, originalSource, outDir, options) {
|
|
|
743
743
|
});
|
|
744
744
|
};
|
|
745
745
|
}
|
|
746
|
+
const UNI_APP_X_WEB_PREFLIGHT_RESET_CSS = [`/* weapp-tailwindcss uni-app-x web preflight reset */`, `${[
|
|
747
|
+
"uni-ad-draw",
|
|
748
|
+
"uni-ad-fullscreen-video",
|
|
749
|
+
"uni-ad-interactive",
|
|
750
|
+
"uni-ad-interstitial",
|
|
751
|
+
"uni-ad-rewarded-video",
|
|
752
|
+
"uni-ad",
|
|
753
|
+
"uni-animation-view",
|
|
754
|
+
"uni-audio",
|
|
755
|
+
"uni-block",
|
|
756
|
+
"uni-button",
|
|
757
|
+
"uni-camera",
|
|
758
|
+
"uni-canvas",
|
|
759
|
+
"uni-checkbox-group",
|
|
760
|
+
"uni-checkbox",
|
|
761
|
+
"uni-cover-image",
|
|
762
|
+
"uni-cover-view",
|
|
763
|
+
"uni-custom-tab-bar",
|
|
764
|
+
"uni-editor",
|
|
765
|
+
"uni-form",
|
|
766
|
+
"uni-icon",
|
|
767
|
+
"uni-image",
|
|
768
|
+
"uni-input",
|
|
769
|
+
"uni-label",
|
|
770
|
+
"uni-list-item",
|
|
771
|
+
"uni-list-view",
|
|
772
|
+
"uni-live-player",
|
|
773
|
+
"uni-live-pusher",
|
|
774
|
+
"uni-map",
|
|
775
|
+
"uni-match-media",
|
|
776
|
+
"uni-movable-area",
|
|
777
|
+
"uni-movable-view",
|
|
778
|
+
"uni-navigation-bar",
|
|
779
|
+
"uni-navigator",
|
|
780
|
+
"uni-open-data",
|
|
781
|
+
"uni-page-meta",
|
|
782
|
+
"uni-picker-view",
|
|
783
|
+
"uni-picker",
|
|
784
|
+
"uni-progress",
|
|
785
|
+
"uni-radio-group",
|
|
786
|
+
"uni-radio",
|
|
787
|
+
"uni-rich-text",
|
|
788
|
+
"uni-scroll-view",
|
|
789
|
+
"uni-slider",
|
|
790
|
+
"uni-sticky-header",
|
|
791
|
+
"uni-sticky-section",
|
|
792
|
+
"uni-swiper-item",
|
|
793
|
+
"uni-swiper",
|
|
794
|
+
"uni-switch",
|
|
795
|
+
"uni-template",
|
|
796
|
+
"uni-text",
|
|
797
|
+
"uni-textarea",
|
|
798
|
+
"uni-unicloud-db",
|
|
799
|
+
"uni-video",
|
|
800
|
+
"uni-view",
|
|
801
|
+
"uni-web-view"
|
|
802
|
+
].map((tag) => `uni-app ${tag}`).join(", ")}{border-width:0;}`].join("\n");
|
|
803
|
+
const TAILWIND_PREFLIGHT_BORDER_RE = /\bborder\s*:\s*0(?:px)?\s+solid\b/;
|
|
804
|
+
function withUniAppXWebPreflightReset(css, enabled) {
|
|
805
|
+
if (!enabled || css.includes("weapp-tailwindcss uni-app-x web preflight reset") || !TAILWIND_PREFLIGHT_BORDER_RE.test(css)) return css;
|
|
806
|
+
return css.length > 0 ? `${UNI_APP_X_WEB_PREFLIGHT_RESET_CSS}\n${css}` : UNI_APP_X_WEB_PREFLIGHT_RESET_CSS;
|
|
807
|
+
}
|
|
746
808
|
//#endregion
|
|
747
809
|
//#region src/bundlers/vite/generate-bundle/configured-css-sources.ts
|
|
748
810
|
function collectConfiguredTailwindV4CssSources(opts) {
|
|
@@ -1055,7 +1117,7 @@ function normalizeMatchedCssSourcePath(file) {
|
|
|
1055
1117
|
if (!file || !path.isAbsolute(file)) return;
|
|
1056
1118
|
return path.resolve(file.replace(/[?#].*$/, ""));
|
|
1057
1119
|
}
|
|
1058
|
-
function collectConfiguredCssEntries(opts) {
|
|
1120
|
+
function collectConfiguredCssEntries$1(opts) {
|
|
1059
1121
|
const runtimeCssEntries = opts.tailwindcssRuntimeOptions?.tailwindcss?.v4?.cssEntries ?? [];
|
|
1060
1122
|
return [
|
|
1061
1123
|
...opts.cssEntries ?? [],
|
|
@@ -1078,7 +1140,7 @@ function collectCssConfigBaseCandidates(source, file, outputRoot, opts) {
|
|
|
1078
1140
|
const runtimeProjectRoot = typeof opts.tailwindcssRuntimeOptions?.projectRoot === "string" ? opts.tailwindcssRuntimeOptions.projectRoot : void 0;
|
|
1079
1141
|
const sourceBaseFallback = opts.tailwindcss?.v4?.base ?? runtimeProjectRoot ?? opts.tailwindcssBasedir ?? outputRoot;
|
|
1080
1142
|
const sourceRoot = opts.tailwindcssBasedir ?? runtimeProjectRoot;
|
|
1081
|
-
const configuredCssEntries = collectConfiguredCssEntries(opts);
|
|
1143
|
+
const configuredCssEntries = collectConfiguredCssEntries$1(opts);
|
|
1082
1144
|
for (const cssEntry of configuredCssEntries) {
|
|
1083
1145
|
const resolvedCssEntry = path.resolve(cssEntry);
|
|
1084
1146
|
if (configuredCssEntries.length === 1 || isMatchingCssSourceFile(file, resolvedCssEntry, outputRoot) || hasMatchingStyleFileBase(file, resolvedCssEntry, outputRoot, sourceRoot)) addCandidate(path.dirname(resolvedCssEntry));
|
|
@@ -2014,6 +2076,21 @@ function appendCss$1(baseCss, css) {
|
|
|
2014
2076
|
if (css.length === 0) return baseCss;
|
|
2015
2077
|
return `${baseCss}\n${css}`;
|
|
2016
2078
|
}
|
|
2079
|
+
function normalizeCssRecordIdentity(css) {
|
|
2080
|
+
return css.trim();
|
|
2081
|
+
}
|
|
2082
|
+
function hasNonCommentCss(css) {
|
|
2083
|
+
return css.replace(/\/\*[\s\S]*?\*\//g, "").trim().length > 0;
|
|
2084
|
+
}
|
|
2085
|
+
function dedupeViteCssResults(records) {
|
|
2086
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2087
|
+
return records.filter((record) => {
|
|
2088
|
+
const key = `${normalizeOutputPathKey(record.outputFile ?? "")}\0${normalizeCssRecordIdentity(record.css)}`;
|
|
2089
|
+
if (seen.has(key)) return false;
|
|
2090
|
+
seen.add(key);
|
|
2091
|
+
return true;
|
|
2092
|
+
});
|
|
2093
|
+
}
|
|
2017
2094
|
function removeTailwindSourceMediaWrappers(css) {
|
|
2018
2095
|
if (!css.includes("@media source(")) return css;
|
|
2019
2096
|
try {
|
|
@@ -2090,6 +2167,183 @@ function collectRootStyleBundleCssSources(bundle, excludedFile) {
|
|
|
2090
2167
|
}
|
|
2091
2168
|
return sources;
|
|
2092
2169
|
}
|
|
2170
|
+
function isHtmlOutputFile(file) {
|
|
2171
|
+
return /\.html(?:$|[?#])/i.test(file);
|
|
2172
|
+
}
|
|
2173
|
+
function stripQueryAndHash(file) {
|
|
2174
|
+
return file.replace(/[?#].*$/, "");
|
|
2175
|
+
}
|
|
2176
|
+
function resolveHtmlLinkedStyleFile(htmlFile, request) {
|
|
2177
|
+
if (!isStyleImportRequest(request)) return;
|
|
2178
|
+
const cleanRequest = stripQueryAndHash(request);
|
|
2179
|
+
if (cleanRequest.startsWith("/")) return normalizeOutputPathKey(cleanRequest.slice(1));
|
|
2180
|
+
const htmlDir = posix.posix.dirname(normalizeOutputPathKey(stripQueryAndHash(htmlFile)));
|
|
2181
|
+
return normalizeOutputPathKey(posix.posix.join(htmlDir === "." ? "" : htmlDir, cleanRequest));
|
|
2182
|
+
}
|
|
2183
|
+
function collectHtmlLinkedStyleFiles(bundle) {
|
|
2184
|
+
const linkedFiles = /* @__PURE__ */ new Set();
|
|
2185
|
+
const linkedBasenames = /* @__PURE__ */ new Set();
|
|
2186
|
+
const linkHrefRE = /<link\s[^>]*href\s*=\s*(["'])([^"']+)\1[^>]*>/gi;
|
|
2187
|
+
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2188
|
+
if (output.type !== "asset") continue;
|
|
2189
|
+
const htmlFile = getAssetFile$1(bundleFile, output);
|
|
2190
|
+
if (!isHtmlOutputFile(htmlFile)) continue;
|
|
2191
|
+
const html = readAssetSource$2(output);
|
|
2192
|
+
for (const match of html.matchAll(linkHrefRE)) {
|
|
2193
|
+
const href = match[2];
|
|
2194
|
+
if (!href) continue;
|
|
2195
|
+
const linkedFile = resolveHtmlLinkedStyleFile(htmlFile, href);
|
|
2196
|
+
if (!linkedFile || !isRootStyleOutputFile(linkedFile)) continue;
|
|
2197
|
+
linkedFiles.add(linkedFile);
|
|
2198
|
+
linkedBasenames.add(posix.posix.basename(linkedFile));
|
|
2199
|
+
}
|
|
2200
|
+
}
|
|
2201
|
+
return {
|
|
2202
|
+
linkedBasenames,
|
|
2203
|
+
linkedFiles
|
|
2204
|
+
};
|
|
2205
|
+
}
|
|
2206
|
+
function isLinkedStyleFile(file, linked) {
|
|
2207
|
+
const fileKey = normalizeOutputPathKey(stripQueryAndHash(file));
|
|
2208
|
+
return linked.linkedFiles.has(fileKey) || isRootStyleOutputFile(fileKey) && linked.linkedBasenames.has(posix.posix.basename(fileKey));
|
|
2209
|
+
}
|
|
2210
|
+
function removeDuplicateUnlinkedRootCssAssetsReferencedByHtml(bundle, options = {}) {
|
|
2211
|
+
const linked = collectHtmlLinkedStyleFiles(bundle);
|
|
2212
|
+
if (linked.linkedFiles.size === 0 && linked.linkedBasenames.size === 0) return 0;
|
|
2213
|
+
const linkedSources = /* @__PURE__ */ new Set();
|
|
2214
|
+
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2215
|
+
if (output.type !== "asset") continue;
|
|
2216
|
+
const file = getAssetFile$1(bundleFile, output);
|
|
2217
|
+
if (!isCssOutputFile(file) || isMiniProgramStyleOutputFile(file) || !isLinkedStyleFile(file, linked)) continue;
|
|
2218
|
+
const source = stripBundlerGeneratedCssMarkers(readAssetSource$2(output)).trim();
|
|
2219
|
+
if (source.length > 0) linkedSources.add(source);
|
|
2220
|
+
}
|
|
2221
|
+
if (linkedSources.size === 0) return 0;
|
|
2222
|
+
let removed = 0;
|
|
2223
|
+
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2224
|
+
if (output.type !== "asset") continue;
|
|
2225
|
+
const file = getAssetFile$1(bundleFile, output);
|
|
2226
|
+
if (!isRootStyleOutputFile(file) || isMiniProgramStyleOutputFile(file) || isLinkedStyleFile(file, linked)) continue;
|
|
2227
|
+
const source = stripBundlerGeneratedCssMarkers(readAssetSource$2(output)).trim();
|
|
2228
|
+
if (!linkedSources.has(source)) continue;
|
|
2229
|
+
delete bundle[bundleFile];
|
|
2230
|
+
options.debug?.("remove duplicate unlinked root css asset referenced by html: %s", file);
|
|
2231
|
+
removed++;
|
|
2232
|
+
}
|
|
2233
|
+
return removed;
|
|
2234
|
+
}
|
|
2235
|
+
const VUE_SCOPED_ATTR_RE = /\[data-v-[^\]]+\]/gi;
|
|
2236
|
+
function hasVueScopedAttr(value) {
|
|
2237
|
+
VUE_SCOPED_ATTR_RE.lastIndex = 0;
|
|
2238
|
+
const matched = VUE_SCOPED_ATTR_RE.test(value);
|
|
2239
|
+
VUE_SCOPED_ATTR_RE.lastIndex = 0;
|
|
2240
|
+
return matched;
|
|
2241
|
+
}
|
|
2242
|
+
function normalizeCssSignatureValue(value) {
|
|
2243
|
+
return value.replace(VUE_SCOPED_ATTR_RE, "").replace(/\s+/g, " ").replace(/\s*([>+~])\s*/g, "$1").replace(/\(\s+/g, "(").replace(/\s+\)/g, ")").trim();
|
|
2244
|
+
}
|
|
2245
|
+
function createDeclarationSignature(rule) {
|
|
2246
|
+
return createDeclarationKeys(rule).sort().join(";");
|
|
2247
|
+
}
|
|
2248
|
+
function createRuleCoverageKey(selector, declarations) {
|
|
2249
|
+
return `${normalizeCssSignatureValue(selector)}\0${declarations}`;
|
|
2250
|
+
}
|
|
2251
|
+
function createDeclarationKeys(rule) {
|
|
2252
|
+
return (rule.nodes ?? []).filter((node) => node.type === "decl").map((node) => `${node.prop}:${normalizeCssSignatureValue(node.value)}${node.important ? "!important" : ""}`);
|
|
2253
|
+
}
|
|
2254
|
+
function createAtRuleCoverageKey(atRule) {
|
|
2255
|
+
return `${atRule.name}\0${normalizeCssSignatureValue(atRule.params)}\0${normalizeCssSignatureValue(atRule.toString())}`;
|
|
2256
|
+
}
|
|
2257
|
+
function hasClassSelector(selector) {
|
|
2258
|
+
return /(?:^|[^\\])\.[_a-z\u00A0-\uFFFF-]/i.test(normalizeCssSignatureValue(selector));
|
|
2259
|
+
}
|
|
2260
|
+
function isLikelyTailwindGlobalSelector(selector) {
|
|
2261
|
+
const normalized = normalizeCssSignatureValue(selector);
|
|
2262
|
+
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);
|
|
2263
|
+
}
|
|
2264
|
+
function isLikelyTailwindGlobalRule(rule) {
|
|
2265
|
+
return (rule.selectors ?? [rule.selector]).every((selector) => !hasClassSelector(selector) && isLikelyTailwindGlobalSelector(selector));
|
|
2266
|
+
}
|
|
2267
|
+
function isLikelyTailwindPropertyAtRule(atRule) {
|
|
2268
|
+
return atRule.name.toLowerCase() === "property" && normalizeCssSignatureValue(atRule.params).startsWith("--tw-");
|
|
2269
|
+
}
|
|
2270
|
+
function collectRootScopedComparableCssCoverage(cssSources) {
|
|
2271
|
+
const rules = /* @__PURE__ */ new Set();
|
|
2272
|
+
const atRules = /* @__PURE__ */ new Set();
|
|
2273
|
+
const declarationsBySelector = /* @__PURE__ */ new Map();
|
|
2274
|
+
for (const source of cssSources) try {
|
|
2275
|
+
const root = postcss.parse(source);
|
|
2276
|
+
root.walkRules((rule) => {
|
|
2277
|
+
const declarations = createDeclarationSignature(rule);
|
|
2278
|
+
if (declarations.length === 0) return;
|
|
2279
|
+
for (const selector of rule.selectors ?? [rule.selector]) {
|
|
2280
|
+
const normalizedSelector = normalizeCssSignatureValue(selector);
|
|
2281
|
+
rules.add(`${normalizedSelector}\0${declarations}`);
|
|
2282
|
+
const selectorDeclarations = declarationsBySelector.get(normalizedSelector) ?? /* @__PURE__ */ new Set();
|
|
2283
|
+
for (const declaration of createDeclarationKeys(rule)) selectorDeclarations.add(declaration);
|
|
2284
|
+
declarationsBySelector.set(normalizedSelector, selectorDeclarations);
|
|
2285
|
+
}
|
|
2286
|
+
});
|
|
2287
|
+
root.walkAtRules((atRule) => {
|
|
2288
|
+
atRules.add(createAtRuleCoverageKey(atRule));
|
|
2289
|
+
});
|
|
2290
|
+
} catch {}
|
|
2291
|
+
return {
|
|
2292
|
+
rules,
|
|
2293
|
+
atRules,
|
|
2294
|
+
declarationsBySelector
|
|
2295
|
+
};
|
|
2296
|
+
}
|
|
2297
|
+
function isRuleCoveredByRootCss(rule, coverage) {
|
|
2298
|
+
const declarations = createDeclarationSignature(rule);
|
|
2299
|
+
if (declarations.length === 0) return false;
|
|
2300
|
+
const selectors = rule.selectors ?? [rule.selector];
|
|
2301
|
+
if (selectors.every((selector) => coverage.rules.has(createRuleCoverageKey(selector, declarations)))) return true;
|
|
2302
|
+
const declarationKeys = createDeclarationKeys(rule);
|
|
2303
|
+
return declarationKeys.length > 0 && selectors.every((selector) => {
|
|
2304
|
+
const rootDeclarations = coverage.declarationsBySelector.get(normalizeCssSignatureValue(selector));
|
|
2305
|
+
return rootDeclarations != null && declarationKeys.every((declaration) => rootDeclarations.has(declaration));
|
|
2306
|
+
}) || selectors.every((selector) => coverage.declarationsBySelector.has(normalizeCssSignatureValue(selector)));
|
|
2307
|
+
}
|
|
2308
|
+
function removeScopedCssCoveredByRootStyleSources(css, rootSources) {
|
|
2309
|
+
if (!hasVueScopedAttr(css)) return css;
|
|
2310
|
+
const hasScopedTailwindGeneratedCss = /tailwindcss v\d/i.test(css);
|
|
2311
|
+
const coverage = collectRootScopedComparableCssCoverage(rootSources);
|
|
2312
|
+
if (coverage.rules.size === 0 && coverage.atRules.size === 0 && !hasScopedTailwindGeneratedCss) return css;
|
|
2313
|
+
try {
|
|
2314
|
+
const root = postcss.parse(css);
|
|
2315
|
+
let changed = false;
|
|
2316
|
+
root.walkComments((comment) => {
|
|
2317
|
+
if (/tailwindcss v\d/i.test(comment.text)) {
|
|
2318
|
+
comment.remove();
|
|
2319
|
+
changed = true;
|
|
2320
|
+
}
|
|
2321
|
+
});
|
|
2322
|
+
root.walkRules((rule) => {
|
|
2323
|
+
if (isRuleCoveredByRootCss(rule, coverage) || hasScopedTailwindGeneratedCss && isLikelyTailwindGlobalRule(rule)) {
|
|
2324
|
+
rule.remove();
|
|
2325
|
+
changed = true;
|
|
2326
|
+
}
|
|
2327
|
+
});
|
|
2328
|
+
root.walkAtRules((atRule) => {
|
|
2329
|
+
if (coverage.atRules.has(createAtRuleCoverageKey(atRule)) || hasScopedTailwindGeneratedCss && isLikelyTailwindPropertyAtRule(atRule)) {
|
|
2330
|
+
atRule.remove();
|
|
2331
|
+
changed = true;
|
|
2332
|
+
return;
|
|
2333
|
+
}
|
|
2334
|
+
if (atRule.nodes !== void 0 && atRule.nodes.length === 0) {
|
|
2335
|
+
atRule.remove();
|
|
2336
|
+
changed = true;
|
|
2337
|
+
}
|
|
2338
|
+
});
|
|
2339
|
+
return changed ? removeDanglingCssSourceTraceComments(root.toString()).trim() : css;
|
|
2340
|
+
} catch {
|
|
2341
|
+
return css;
|
|
2342
|
+
}
|
|
2343
|
+
}
|
|
2344
|
+
function removeScopedTailwindPreflightCss(css) {
|
|
2345
|
+
return removeScopedCssCoveredByRootStyleSources(css, []);
|
|
2346
|
+
}
|
|
2093
2347
|
function collectSingleViteGeneratedCssMarkerFile(rawSource) {
|
|
2094
2348
|
const blocks = parseBundlerGeneratedCssMarkerBlocks(rawSource).filter((block) => block.bundler === "vite");
|
|
2095
2349
|
if (blocks.length !== 1) return;
|
|
@@ -2102,7 +2356,9 @@ function shouldFilterRootGeneratedCssMarkerForScopedAsset(targetFile, markerFile
|
|
|
2102
2356
|
return !isMatchingGeneratedCssMarkerFile(targetFile, markerFile, resolveViteProcessedCssOutputFile);
|
|
2103
2357
|
}
|
|
2104
2358
|
function removeCssCoveredByRootStyleBundleSources(bundle, file, css) {
|
|
2105
|
-
|
|
2359
|
+
const rootSources = collectRootStyleBundleCssSources(bundle, file);
|
|
2360
|
+
const nextCss = removeScopedCssCoveredByRootStyleSources(removeDanglingCssSourceTraceComments(removeCssCoveredByImportedViteResults(css, rootSources)), rootSources);
|
|
2361
|
+
return hasNonCommentCss(nextCss) ? nextCss : "";
|
|
2106
2362
|
}
|
|
2107
2363
|
function removeDanglingCssSourceTraceComments(css) {
|
|
2108
2364
|
if (!css.includes("/* tokens:")) return css;
|
|
@@ -2126,8 +2382,11 @@ function removeCssCoveredByRootStyleAssets(bundle, options) {
|
|
|
2126
2382
|
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2127
2383
|
if (output.type !== "asset") continue;
|
|
2128
2384
|
const file = getAssetFile$1(bundleFile, output);
|
|
2129
|
-
if (!options.cssMatcher(file) || isRootStyleOutputFile(file) || options.isViteProcessedCssAsset?.(output, file) === true || options.subpackageRoots != null && isSubpackageOutputFile(file, options.subpackageRoots)) continue;
|
|
2130
2385
|
const rawSource = readAssetSource$2(output);
|
|
2386
|
+
const hasScopedCss = hasVueScopedAttr(rawSource);
|
|
2387
|
+
const hasTailwindGeneratedCss = /tailwindcss v\d/i.test(rawSource);
|
|
2388
|
+
const shouldIncludeTailwindGeneratedCssAsset = options.includeTailwindGeneratedCssAssets === true && hasTailwindGeneratedCss && isCssOutputFile(file) && !isMiniProgramStyleOutputFile(file);
|
|
2389
|
+
if (!(options.cssMatcher(file) || hasScopedCss && isCssOutputFile(file) || shouldIncludeTailwindGeneratedCssAsset) || isRootStyleOutputFile(file) || options.isViteProcessedCssAsset?.(output, file) === true && !hasScopedCss && !shouldIncludeTailwindGeneratedCssAsset || options.subpackageRoots != null && isSubpackageOutputFile(file, options.subpackageRoots)) continue;
|
|
2131
2390
|
const nextCss = removeCssCoveredByRootStyleBundleSources(bundle, file, rawSource);
|
|
2132
2391
|
if (nextCss === rawSource) continue;
|
|
2133
2392
|
output.source = nextCss;
|
|
@@ -2180,6 +2439,12 @@ function shouldUseCssAssetAsMainInjectionTarget(opts, file, records) {
|
|
|
2180
2439
|
const fileKey = normalizeOutputPathKey(file);
|
|
2181
2440
|
if (!isRootStyleOutputFile(file) && records.some((record) => typeof record.outputFile === "string" && normalizeOutputPathKey(record.outputFile) === fileKey)) return true;
|
|
2182
2441
|
if (!isRootStyleOutputFile(file)) return records.some((record) => record.injectIntoMain === true && typeof record.outputFile === "string" && normalizeOutputPathKey(record.outputFile) === fileKey);
|
|
2442
|
+
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));
|
|
2443
|
+
if (opts.appType === "uni-app-vite" && !isMiniProgramStyleOutputFile(file) && matchedRootWebOutputTargets.length > 0) return matchedRootWebOutputTargets.includes(fileKey);
|
|
2444
|
+
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));
|
|
2445
|
+
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));
|
|
2446
|
+
if (opts.appType === "uni-app-vite" && !isMiniProgramStyleOutputFile(file) && explicitWebCssTargets.length > 0) return explicitRootTargets.includes(fileKey);
|
|
2447
|
+
if (explicitRootTargets.length > 0) return explicitRootTargets.includes(fileKey);
|
|
2183
2448
|
if (records.some((record) => {
|
|
2184
2449
|
if (record.injectIntoMain !== true) return false;
|
|
2185
2450
|
return isRootStyleOutputFile(file) || typeof record.outputFile === "string" && normalizeOutputPathKey(record.outputFile) === fileKey;
|
|
@@ -2200,6 +2465,33 @@ function isViteProcessedCssResultCoveredByImportedBundleAsset(record, importedSt
|
|
|
2200
2465
|
}
|
|
2201
2466
|
return false;
|
|
2202
2467
|
}
|
|
2468
|
+
function removeCoveredInjectedSourceAssets(bundle, targetFile, targetCss, records, options) {
|
|
2469
|
+
let removed = 0;
|
|
2470
|
+
const targetFileKey = normalizeOutputPathKey(targetFile);
|
|
2471
|
+
const targetIsRootWebStyle = isRootStyleOutputFile(targetFileKey) && !isMiniProgramStyleOutputFile(targetFileKey);
|
|
2472
|
+
for (const record of records) {
|
|
2473
|
+
if (!options.shouldRemoveInjectedSourceAsset?.(targetFile, record)) continue;
|
|
2474
|
+
const recordFileKey = normalizeOutputPathKey(record.file);
|
|
2475
|
+
for (const [candidateFile, candidateOutput] of Object.entries(bundle)) {
|
|
2476
|
+
if (candidateOutput.type !== "asset") continue;
|
|
2477
|
+
const candidateKey = normalizeOutputPathKey(getAssetFile$1(candidateFile, candidateOutput));
|
|
2478
|
+
if (candidateKey === targetFileKey) continue;
|
|
2479
|
+
const isRecordFile = candidateKey === recordFileKey;
|
|
2480
|
+
const candidateIsRootWebStyle = isRootStyleOutputFile(candidateKey) && !isMiniProgramStyleOutputFile(candidateKey);
|
|
2481
|
+
const candidateSource = readAssetSource$2(candidateOutput).trim();
|
|
2482
|
+
const uncoveredCandidateSource = candidateSource.length > 0 ? filterExistingCssRules(targetCss, candidateSource).trim() : candidateSource;
|
|
2483
|
+
const isProcessedSource = candidateSource === record.css.trim() || candidateSource.length > 0 && containsCssAfterMinify(targetCss, candidateSource) || targetIsRootWebStyle && candidateIsRootWebStyle && candidateSource.length > 0 && !hasNonCommentCss(uncoveredCandidateSource);
|
|
2484
|
+
if (!isRecordFile && !isProcessedSource) continue;
|
|
2485
|
+
if (candidateIsRootWebStyle && !targetIsRootWebStyle) continue;
|
|
2486
|
+
if (candidateIsRootWebStyle && !isRecordFile) continue;
|
|
2487
|
+
if (candidateIsRootWebStyle) delete bundle[candidateFile];
|
|
2488
|
+
else clearAssetSource(candidateOutput);
|
|
2489
|
+
options.debug?.("remove injected vite-processed source css asset: %s -> %s", candidateKey, targetFile);
|
|
2490
|
+
removed++;
|
|
2491
|
+
}
|
|
2492
|
+
}
|
|
2493
|
+
return removed;
|
|
2494
|
+
}
|
|
2203
2495
|
function removeCssCoveredByImportedViteResults(css, importedCssSources) {
|
|
2204
2496
|
if (importedCssSources.length === 0) return css;
|
|
2205
2497
|
const importedCss = importedCssSources.map((source) => stripBundlerGeneratedCssMarkers(source).trim()).filter(Boolean).join("\n");
|
|
@@ -2226,6 +2518,38 @@ function collectBundleAssetFiles(bundle) {
|
|
|
2226
2518
|
}
|
|
2227
2519
|
return files;
|
|
2228
2520
|
}
|
|
2521
|
+
function normalizeComparableStyleFile(file) {
|
|
2522
|
+
return normalizeOutputPathKey(posix.normalize(file.replace(/[?#].*$/, "")));
|
|
2523
|
+
}
|
|
2524
|
+
function collectConfiguredTailwindV4CssEntryFiles(opts) {
|
|
2525
|
+
const runtimeCssEntries = opts.tailwindRuntime?.options?.tailwindcss?.v4?.cssEntries;
|
|
2526
|
+
return [
|
|
2527
|
+
...Array.isArray(opts.cssEntries) ? opts.cssEntries : [],
|
|
2528
|
+
...Array.isArray(opts.tailwindcss?.v4?.cssEntries) ? opts.tailwindcss.v4.cssEntries : [],
|
|
2529
|
+
...Array.isArray(opts.tailwindcssRuntimeOptions?.tailwindcss?.v4?.cssEntries) ? opts.tailwindcssRuntimeOptions.tailwindcss.v4.cssEntries : [],
|
|
2530
|
+
...Array.isArray(runtimeCssEntries) ? runtimeCssEntries : []
|
|
2531
|
+
].filter((file) => typeof file === "string" && file.length > 0);
|
|
2532
|
+
}
|
|
2533
|
+
function isConfiguredTailwindV4CssEntryFile(opts, file) {
|
|
2534
|
+
if (typeof file !== "string" || file.length === 0) return false;
|
|
2535
|
+
const fileKey = normalizeComparableStyleFile(file);
|
|
2536
|
+
return collectConfiguredTailwindV4CssEntryFiles(opts).some((entry) => normalizeComparableStyleFile(entry) === fileKey);
|
|
2537
|
+
}
|
|
2538
|
+
function resolveUniAppViteWebviewRootCssInjectionTarget(bundle, opts, sourceFile, outputFile) {
|
|
2539
|
+
if (opts.appType !== "uni-app-vite" || isMiniProgramStyleOutputFile(outputFile) || !isConfiguredTailwindV4CssEntryFile(opts, sourceFile)) return;
|
|
2540
|
+
const rootCssFiles = [];
|
|
2541
|
+
const matchedRootCssFiles = [];
|
|
2542
|
+
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2543
|
+
if (output.type !== "asset") continue;
|
|
2544
|
+
const file = getAssetFile$1(bundleFile, output);
|
|
2545
|
+
if (!opts.cssMatcher(file) || !isRootStyleOutputFile(file) || isMiniProgramStyleOutputFile(file)) continue;
|
|
2546
|
+
rootCssFiles.push(file);
|
|
2547
|
+
if (opts.mainCssChunkMatcher(file, opts.appType)) matchedRootCssFiles.push(file);
|
|
2548
|
+
}
|
|
2549
|
+
if (matchedRootCssFiles.length === 1) return matchedRootCssFiles[0];
|
|
2550
|
+
if (matchedRootCssFiles.length > 1) return;
|
|
2551
|
+
return rootCssFiles.length === 1 ? rootCssFiles[0] : void 0;
|
|
2552
|
+
}
|
|
2229
2553
|
function findBundleAssetByOutputFile(bundle, file) {
|
|
2230
2554
|
const fileKey = normalizeOutputPathKey(file);
|
|
2231
2555
|
return Object.entries(bundle).find(([bundleFile, output]) => {
|
|
@@ -2279,6 +2603,8 @@ function collectViteProcessedCssAssetResults(bundle, options) {
|
|
|
2279
2603
|
options.markCssAssetProcessed?.(output, file);
|
|
2280
2604
|
options.recordCssAssetResult?.(file, nextCss);
|
|
2281
2605
|
const resolvedOutputFile = resolveViteGeneratedCssMarkerOutputFile(file, singleMarkerFile, existingAssetFiles, options.resolveViteProcessedCssOutputFile);
|
|
2606
|
+
const webviewRootCssInjectionTarget = options.opts ? resolveUniAppViteWebviewRootCssInjectionTarget(bundle, options.opts, singleMarkerFile ?? file, resolvedOutputFile) : void 0;
|
|
2607
|
+
const recordOutputFile = webviewRootCssInjectionTarget ?? resolvedOutputFile;
|
|
2282
2608
|
if (singleMarkerFile && normalizeOutputPathKey(resolvedOutputFile) !== normalizeOutputPathKey(file) && !isRootStyleOutputFile(resolvedOutputFile) && existingAssetFiles.has(normalizeOutputPathKey(resolvedOutputFile))) {
|
|
2283
2609
|
const targetAsset = findBundleAssetByOutputFile(bundle, resolvedOutputFile);
|
|
2284
2610
|
if (targetAsset) {
|
|
@@ -2298,24 +2624,24 @@ function collectViteProcessedCssAssetResults(bundle, options) {
|
|
|
2298
2624
|
continue;
|
|
2299
2625
|
}
|
|
2300
2626
|
}
|
|
2301
|
-
const shouldReplayIntoMainCss = options.opts != null && shouldReplayViteProcessedCssIntoMainCss(options.opts, file, singleMarkerFile, resolvedOutputFile, options.subpackageRoots);
|
|
2627
|
+
const shouldReplayIntoMainCss = options.opts != null && (webviewRootCssInjectionTarget != null || shouldReplayViteProcessedCssIntoMainCss(options.opts, file, singleMarkerFile, resolvedOutputFile, options.subpackageRoots));
|
|
2302
2628
|
options.recordViteProcessedCssAssetResult?.(file, nextCss, {
|
|
2303
2629
|
injectIntoMain: shouldReplayIntoMainCss || void 0,
|
|
2304
|
-
outputFile:
|
|
2630
|
+
outputFile: recordOutputFile
|
|
2305
2631
|
});
|
|
2306
|
-
if (normalizeOutputPathKey(
|
|
2632
|
+
if (normalizeOutputPathKey(recordOutputFile) !== normalizeOutputPathKey(file)) options.recordViteProcessedCssAssetResult?.(recordOutputFile, nextCss, {
|
|
2307
2633
|
injectIntoMain: shouldReplayIntoMainCss || void 0,
|
|
2308
|
-
outputFile:
|
|
2634
|
+
outputFile: recordOutputFile
|
|
2309
2635
|
});
|
|
2310
2636
|
for (const markerFile of collectMatchingGeneratedCssMarkerFiles(file, rawSource, options.resolveViteProcessedCssOutputFile)) {
|
|
2311
2637
|
if (normalizeOutputPathKey(markerFile) === normalizeOutputPathKey(file)) continue;
|
|
2312
2638
|
options.recordViteProcessedCssAssetResult?.(markerFile, nextCss, {
|
|
2313
2639
|
injectIntoMain: shouldReplayIntoMainCss || void 0,
|
|
2314
|
-
outputFile:
|
|
2640
|
+
outputFile: recordOutputFile
|
|
2315
2641
|
});
|
|
2316
|
-
if (normalizeOutputPathKey(
|
|
2642
|
+
if (normalizeOutputPathKey(recordOutputFile) !== normalizeOutputPathKey(markerFile) && normalizeOutputPathKey(recordOutputFile) !== normalizeOutputPathKey(file)) options.recordViteProcessedCssAssetResult?.(recordOutputFile, nextCss, {
|
|
2317
2643
|
injectIntoMain: shouldReplayIntoMainCss || void 0,
|
|
2318
|
-
outputFile:
|
|
2644
|
+
outputFile: recordOutputFile
|
|
2319
2645
|
});
|
|
2320
2646
|
}
|
|
2321
2647
|
if (isCoveredViteGeneratedSourceAsset(file, existingAssetFiles, options.resolveViteProcessedCssOutputFile)) {
|
|
@@ -2330,7 +2656,8 @@ function collectViteProcessedCssAssetResults(bundle, options) {
|
|
|
2330
2656
|
return collected;
|
|
2331
2657
|
}
|
|
2332
2658
|
function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
2333
|
-
const
|
|
2659
|
+
const transformCss = (css, file) => options.transformCss?.(css, file) ?? css;
|
|
2660
|
+
const viteCssResults = dedupeViteCssResults([...options.getViteProcessedCssAssetResults?.() ?? []].map(([file, record]) => {
|
|
2334
2661
|
return typeof record === "string" ? {
|
|
2335
2662
|
file,
|
|
2336
2663
|
css: record,
|
|
@@ -2341,10 +2668,14 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
2341
2668
|
injectIntoMain: record.injectIntoMain,
|
|
2342
2669
|
outputFile: record.outputFile
|
|
2343
2670
|
};
|
|
2344
|
-
}).
|
|
2671
|
+
})).map((record) => ({
|
|
2672
|
+
...record,
|
|
2673
|
+
css: transformCss(record.css, record.outputFile ?? record.file)
|
|
2674
|
+
})).filter((record) => record.css.length > 0);
|
|
2345
2675
|
let injected = 0;
|
|
2346
2676
|
for (const [bundleFile, bundleOutput] of Object.entries(bundle)) {
|
|
2347
2677
|
let output = bundleOutput;
|
|
2678
|
+
if (bundle[bundleFile] !== bundleOutput) continue;
|
|
2348
2679
|
if (output.type !== "asset") continue;
|
|
2349
2680
|
let file = getAssetFile$1(bundleFile, output);
|
|
2350
2681
|
if (!options.opts.cssMatcher(file) || !shouldUseCssAssetAsMainInjectionTarget(options.opts, file, viteCssResults)) continue;
|
|
@@ -2366,7 +2697,7 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
2366
2697
|
}
|
|
2367
2698
|
const fileKey = normalizeOutputPathKey(file);
|
|
2368
2699
|
const mainFileKey = normalizeOutputPathKey(file);
|
|
2369
|
-
let nextCss = removeTailwindEntryDirectivesFromCss(originalSource);
|
|
2700
|
+
let nextCss = transformCss(removeTailwindEntryDirectivesFromCss(originalSource), file);
|
|
2370
2701
|
const importedStyleFiles = collectImportedStyleFiles(nextCss, file);
|
|
2371
2702
|
const importedBundleCssSources = collectImportedBundleCssSources(bundle, importedStyleFiles);
|
|
2372
2703
|
nextCss = removeCssCoveredByImportedViteResults(nextCss, importedBundleCssSources);
|
|
@@ -2375,12 +2706,14 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
2375
2706
|
const uncoveredImportedViteCssResults = importedViteCssResults.filter((record) => !isViteProcessedCssResultCoveredByImportedBundleAsset(record, importedStyleFiles, bundleAssetFiles));
|
|
2376
2707
|
const importedCssSources = [...importedBundleCssSources, ...uncoveredImportedViteCssResults.map((record) => record.css)];
|
|
2377
2708
|
nextCss = removeCssCoveredByImportedViteResults(nextCss, uncoveredImportedViteCssResults.map((record) => record.css));
|
|
2709
|
+
const targetViteCssResults = [];
|
|
2378
2710
|
for (const record of viteCssResults) {
|
|
2379
2711
|
if (!isRootStyleOutputFile(file)) {
|
|
2380
2712
|
if (typeof record.outputFile !== "string" || normalizeOutputPathKey(record.outputFile) !== fileKey) continue;
|
|
2381
2713
|
}
|
|
2382
2714
|
if (!shouldInjectViteProcessedCssResult(options.opts, mainFileKey, record.file, record)) continue;
|
|
2383
2715
|
if (isViteProcessedCssResultImported(record, importedStyleFiles)) continue;
|
|
2716
|
+
targetViteCssResults.push(record);
|
|
2384
2717
|
let css = stripBundlerGeneratedCssMarkers(record.css).trim();
|
|
2385
2718
|
css = removeCssCoveredByImportedViteResults(css, importedCssSources).trim();
|
|
2386
2719
|
if (css.length === 0) continue;
|
|
@@ -2411,29 +2744,19 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
2411
2744
|
if (css.length === 0) continue;
|
|
2412
2745
|
}
|
|
2413
2746
|
const missingCss = filterExistingCssRules(nextCss, css);
|
|
2414
|
-
if (missingCss.length === 0 || containsCssAfterMinify(nextCss, missingCss)) continue;
|
|
2747
|
+
if (missingCss.length === 0 || !hasNonCommentCss(missingCss) || containsCssAfterMinify(nextCss, missingCss)) continue;
|
|
2415
2748
|
nextCss = appendCss$1(nextCss, missingCss);
|
|
2416
2749
|
}
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
if (!options.shouldRemoveInjectedSourceAsset?.(file, record)) continue;
|
|
2425
|
-
const recordFileKey = normalizeOutputPathKey(record.file);
|
|
2426
|
-
for (const [candidateFile, candidateOutput] of Object.entries(bundle)) {
|
|
2427
|
-
if (candidateOutput.type !== "asset") continue;
|
|
2428
|
-
const candidateKey = normalizeOutputPathKey(getAssetFile$1(candidateFile, candidateOutput));
|
|
2429
|
-
const isRecordFile = candidateKey === recordFileKey;
|
|
2430
|
-
const candidateSource = readAssetSource$2(candidateOutput).trim();
|
|
2431
|
-
const isProcessedSource = candidateSource === record.css.trim() || candidateSource.length > 0 && containsCssAfterMinify(nextCss, candidateSource);
|
|
2432
|
-
if (!isRecordFile && !isProcessedSource || candidateKey === normalizeOutputPathKey(file)) continue;
|
|
2433
|
-
clearAssetSource(candidateOutput);
|
|
2434
|
-
options.debug?.("remove injected vite-processed source css asset: %s -> %s", candidateKey, file);
|
|
2435
|
-
}
|
|
2750
|
+
nextCss = transformCss(nextCss, file);
|
|
2751
|
+
if (nextCss !== originalSource) {
|
|
2752
|
+
output.source = nextCss;
|
|
2753
|
+
options.markCssAssetProcessed?.(output, file);
|
|
2754
|
+
options.recordCssAssetResult?.(file, nextCss);
|
|
2755
|
+
options.onUpdate?.(file, originalSource, nextCss);
|
|
2756
|
+
options.debug?.("inject vite-processed css into main css asset: %s bytes=%d", file, nextCss.length);
|
|
2436
2757
|
}
|
|
2758
|
+
const removedSources = removeCoveredInjectedSourceAssets(bundle, file, nextCss, targetViteCssResults, options);
|
|
2759
|
+
if (nextCss === originalSource && removedSources === 0) continue;
|
|
2437
2760
|
injected++;
|
|
2438
2761
|
}
|
|
2439
2762
|
return injected;
|
|
@@ -2705,9 +3028,34 @@ function pruneLastCssResults(resultByFile, sourceHashByFile, activeFiles) {
|
|
|
2705
3028
|
function readAssetSource(asset) {
|
|
2706
3029
|
return typeof asset.source === "string" ? asset.source : asset.source.toString();
|
|
2707
3030
|
}
|
|
3031
|
+
function isUniAppViteWebviewAppBundle(bundleFiles) {
|
|
3032
|
+
return bundleFiles.some((file) => path.basename(file.replace(/[?#].*$/, "")) === "app-service.js");
|
|
3033
|
+
}
|
|
3034
|
+
function isUniAppViteWebviewOutDir$2(outDir) {
|
|
3035
|
+
const normalized = outDir ? path.basename(path.normalize(outDir)).trim().toLowerCase() : void 0;
|
|
3036
|
+
return normalized === "app" || normalized === "app-plus";
|
|
3037
|
+
}
|
|
2708
3038
|
function getAssetFile(bundleFile, asset) {
|
|
2709
3039
|
return asset.fileName || bundleFile;
|
|
2710
3040
|
}
|
|
3041
|
+
function finalizeUniAppViteWebviewCssCompat(bundle, options) {
|
|
3042
|
+
if (options.opts.generator?.webCompat === false) return 0;
|
|
3043
|
+
let transformed = 0;
|
|
3044
|
+
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
3045
|
+
if (output.type !== "asset") continue;
|
|
3046
|
+
const file = getAssetFile(bundleFile, output);
|
|
3047
|
+
if (!options.opts.cssMatcher(file) || !/\.css(?:$|[?#])/i.test(file)) continue;
|
|
3048
|
+
const rawSource = readAssetSource(output);
|
|
3049
|
+
const nextCss = transformWebCssSafeSelectors(transformWebCssCompat(rawSource, options.opts.generator?.webCompat ?? true), { escapeMap: options.opts.escapeMap });
|
|
3050
|
+
if (nextCss === rawSource) continue;
|
|
3051
|
+
output.source = nextCss;
|
|
3052
|
+
options.recordCssAssetResult?.(file, nextCss);
|
|
3053
|
+
options.onUpdate(file, rawSource, nextCss);
|
|
3054
|
+
options.debug("finalize uni-app vite webview css compat: %s bytes=%d", file, nextCss.length);
|
|
3055
|
+
transformed++;
|
|
3056
|
+
}
|
|
3057
|
+
return transformed;
|
|
3058
|
+
}
|
|
2711
3059
|
function isRootMiniProgramStyleOutputFile(file) {
|
|
2712
3060
|
const normalized = normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
2713
3061
|
return !normalized.includes("/") && /\.(?:wxss|acss|ttss|qss|jxss|tyss)$/i.test(normalized);
|
|
@@ -2776,7 +3124,7 @@ function normalizeTaroRootImportShellAssets(bundle, options) {
|
|
|
2776
3124
|
return updated;
|
|
2777
3125
|
}
|
|
2778
3126
|
async function finalizeGenerateBundle(options) {
|
|
2779
|
-
const { activeProcessCacheKeys, activeProcessHashKeys, activeViteCssCacheFiles, bundle, bundleFiles, cache, cssTaskFactories, debug, defaultStyleOutputExtension, formatIteration, generatorCandidateSignature, generatorRuntime, getCssHandlerOptions, getSourceCandidateSourcesForEntries, getSourceCandidatesForEntries, getViteCssCacheStats, getViteProcessedCssAssetResults, hmrTimingRecorder, hmrTimingStartedAt, isHarmonyAppStyleTarget, isNativeAppStyleTarget, isViteProcessedCssAsset, isWebGeneratorTarget, jsAfterCss, jsTaskFactories, lastCssResultByFile, lastCssSourceHashByFile, linkedByEntry, markCssAssetProcessed, metrics, onEnd, onUpdate, opts, pendingLinkedUpdates, pruneViteCssCaches, recordCssAssetResult, recordTimingDetail, recordViteProcessedCssAssetResult, rootDir, runtime, runtimeState, shouldPreserveAppCssExtension, snapshot, sourceCandidates, sourceRoot, state, styleHandler, tasks, timingDetails, transformRuntime, useIncrementalMode } = options;
|
|
3127
|
+
const { activeProcessCacheKeys, activeProcessHashKeys, activeViteCssCacheFiles, bundle, bundleFiles, cache, cssTaskFactories, debug, defaultStyleOutputExtension, formatIteration, generatorCandidateSignature, generatorRuntime, getCssHandlerOptions, getSourceCandidateSourcesForEntries, getSourceCandidatesForEntries, getViteCssCacheStats, getViteProcessedCssAssetResults, hmrTimingRecorder, hmrTimingStartedAt, isHarmonyAppStyleTarget, isNativeAppStyleTarget, isViteProcessedCssAsset, isWebGeneratorTarget, jsAfterCss, jsTaskFactories, lastCssResultByFile, lastCssSourceHashByFile, linkedByEntry, markCssAssetProcessed, metrics, onEnd, onUpdate, opts, outDir, pendingLinkedUpdates, pruneViteCssCaches, recordCssAssetResult, recordTimingDetail, recordViteProcessedCssAssetResult, rootDir, runtime, runtimeState, shouldPreserveAppCssExtension, snapshot, sourceCandidates, sourceRoot, state, styleHandler, tasks, timingDetails, transformRuntime, transformWebTargetCss, useIncrementalMode } = options;
|
|
2780
3128
|
const tasksStart = performance.now();
|
|
2781
3129
|
if (cssTaskFactories.length > 0) {
|
|
2782
3130
|
const cssTask = runWithConcurrency(cssTaskFactories, resolveViteCssTaskConcurrency(useIncrementalMode, runtimeState.tailwindRuntime.majorVersion)).then(() => void 0);
|
|
@@ -2811,6 +3159,7 @@ async function finalizeGenerateBundle(options) {
|
|
|
2811
3159
|
recordViteProcessedCssAssetResult,
|
|
2812
3160
|
resolveViteProcessedCssOutputFile: (file) => resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension, sourceRoot, defaultStyleOutputExtension, bundleFiles),
|
|
2813
3161
|
subpackageRoots: collectMiniProgramSubpackageRoots(bundle),
|
|
3162
|
+
transformCss: transformWebTargetCss,
|
|
2814
3163
|
debug
|
|
2815
3164
|
});
|
|
2816
3165
|
return injectViteProcessedCssIntoMainCssAssets(bundle, {
|
|
@@ -2818,6 +3167,7 @@ async function finalizeGenerateBundle(options) {
|
|
|
2818
3167
|
getViteProcessedCssAssetResults,
|
|
2819
3168
|
markCssAssetProcessed,
|
|
2820
3169
|
recordCssAssetResult,
|
|
3170
|
+
transformCss: transformWebTargetCss,
|
|
2821
3171
|
shouldRemoveInjectedSourceAsset: (targetFile, record) => {
|
|
2822
3172
|
if (record.injectIntoMain === false) return false;
|
|
2823
3173
|
const targetFileKey = normalizeOutputPathKey(targetFile);
|
|
@@ -2843,11 +3193,13 @@ async function finalizeGenerateBundle(options) {
|
|
|
2843
3193
|
removeCssCoveredByRootStyleAssets(bundle, {
|
|
2844
3194
|
cssMatcher: opts.cssMatcher,
|
|
2845
3195
|
debug,
|
|
3196
|
+
includeTailwindGeneratedCssAssets: opts.appType === "uni-app-vite" && isWebGeneratorTarget && isUniAppViteWebviewAppBundle(bundleFiles),
|
|
2846
3197
|
isViteProcessedCssAsset,
|
|
2847
3198
|
onUpdate,
|
|
2848
3199
|
recordCssAssetResult,
|
|
2849
3200
|
subpackageRoots: collectMiniProgramSubpackageRoots(bundle)
|
|
2850
3201
|
});
|
|
3202
|
+
if (opts.appType === "uni-app-vite" && isWebGeneratorTarget && isUniAppViteWebviewAppBundle(Object.keys(bundle))) removeDuplicateUnlinkedRootCssAssetsReferencedByHtml(bundle, { debug });
|
|
2851
3203
|
await finalizeMiniProgramCssAssets(bundle, {
|
|
2852
3204
|
cssMatcher: opts.cssMatcher,
|
|
2853
3205
|
debug,
|
|
@@ -2858,6 +3210,12 @@ async function finalizeGenerateBundle(options) {
|
|
|
2858
3210
|
recordCssAssetResult,
|
|
2859
3211
|
styleHandler
|
|
2860
3212
|
});
|
|
3213
|
+
if (opts.appType === "uni-app-vite" && (isWebGeneratorTarget || isUniAppViteWebviewAppBundle(Object.keys(bundle)) || isUniAppViteWebviewOutDir$2(outDir))) finalizeUniAppViteWebviewCssCompat(bundle, {
|
|
3214
|
+
debug,
|
|
3215
|
+
onUpdate,
|
|
3216
|
+
opts,
|
|
3217
|
+
recordCssAssetResult
|
|
3218
|
+
});
|
|
2861
3219
|
const stateUpdateStart = performance.now();
|
|
2862
3220
|
updateBundleBuildState(state, snapshot, useIncrementalMode ? linkedByEntry ?? /* @__PURE__ */ new Map() : /* @__PURE__ */ new Map(), { incremental: useIncrementalMode });
|
|
2863
3221
|
state.generatorCandidateSignature = generatorCandidateSignature;
|
|
@@ -3272,7 +3630,9 @@ function collectRememberedCssReplayGroups(sources, opts, rootDir, isWebGenerator
|
|
|
3272
3630
|
const groups = /* @__PURE__ */ new Map();
|
|
3273
3631
|
for (const [key, remembered] of sources ?? []) {
|
|
3274
3632
|
const cleanSourceFile = remembered.sourceFile.replace(/[?#].*$/, "");
|
|
3275
|
-
const
|
|
3633
|
+
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);
|
|
3634
|
+
const rememberedOutputFile = remembered.outputFile.replace(/[?#].*$/, "");
|
|
3635
|
+
const outputKey = normalizeOutputPathKey(opts.cssMatcher(rememberedOutputFile) && !normalizeOutputPathKey(rememberedOutputFile).includes("/") && normalizeOutputPathKey(rememberedOutputFile) !== normalizeOutputPathKey(resolvedOutputFile.replace(/[?#].*$/, "")) ? remembered.outputFile : resolvedOutputFile);
|
|
3276
3636
|
const group = groups.get(outputKey) ?? [];
|
|
3277
3637
|
group.push({
|
|
3278
3638
|
key,
|
|
@@ -3285,7 +3645,7 @@ function collectRememberedCssReplayGroups(sources, opts, rootDir, isWebGenerator
|
|
|
3285
3645
|
//#endregion
|
|
3286
3646
|
//#region src/bundlers/vite/generate-bundle/remembered-css-replay.ts
|
|
3287
3647
|
async function processRememberedCssReplay(options) {
|
|
3288
|
-
const { addWatchFile, activeViteCssCacheFiles, bundleFiles, cache, createScopedGeneratorRuntime, createScopedSourceCandidateGetter, createScopedSourceCandidateSourceGetter, cssTaskFactories, debug, defaultStyleOutputExtension, emitOrReplayCssAsset, generatorRuntime, getCssHandlerOptions, getCssUserHandlerOptions, getRememberedCssSignature, getRememberedCssSources, isNativeAppStyleTarget, isWebGeneratorTarget, lastCssResultByFile, lastCssSourceHashByFile, markCssAssetProcessed, metrics, normalizeViteCssCacheKey, onUpdate, opts, recordCssAssetResult, recordViteProcessedCssAssetResult, refreshRememberedCssSource, rootDir, runtimeState, setRememberedCssSignature, shouldInjectCssIntoMainFromOutput, shouldPreserveAppCssExtension, sourceRoot, styleHandler, timeTask, useIncrementalMode } = options;
|
|
3648
|
+
const { addWatchFile, activeViteCssCacheFiles, bundleFiles, cache, createScopedGeneratorRuntime, createScopedSourceCandidateGetter, createScopedSourceCandidateSourceGetter, cssTaskFactories, debug, defaultStyleOutputExtension, emitOrReplayCssAsset, generatorRuntime, generatorPlatform, getCssHandlerOptions, getCssUserHandlerOptions, getRememberedCssSignature, getRememberedCssSources, isNativeAppStyleTarget, isWebGeneratorTarget, lastCssResultByFile, lastCssSourceHashByFile, markCssAssetProcessed, metrics, normalizeViteCssCacheKey, onUpdate, opts, recordCssAssetResult, recordViteProcessedCssAssetResult, refreshRememberedCssSource, rootDir, runtimeState, setRememberedCssSignature, shouldInjectCssIntoMainFromOutput, shouldPreserveAppCssExtension, sourceRoot, styleHandler, timeTask, useIncrementalMode } = options;
|
|
3289
3649
|
const rememberedReplayGroups = collectRememberedCssReplayGroups(getRememberedCssSources?.(), opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension, sourceRoot, defaultStyleOutputExtension, bundleFiles);
|
|
3290
3650
|
for (const [outputFile, rememberedGroup] of rememberedReplayGroups) {
|
|
3291
3651
|
if (isHTMLRequest(outputFile) || options.opts.htmlMatcher(outputFile)) continue;
|
|
@@ -3336,6 +3696,7 @@ async function processRememberedCssReplay(options) {
|
|
|
3336
3696
|
cssHandlerOptions,
|
|
3337
3697
|
cssUserHandlerOptions: getCssUserHandlerOptions(sourceFile),
|
|
3338
3698
|
getSourceCandidatesForEntries: scopedSourceCandidateGetter,
|
|
3699
|
+
generatorPlatform,
|
|
3339
3700
|
styleHandler,
|
|
3340
3701
|
debug,
|
|
3341
3702
|
previousCss
|
|
@@ -3917,6 +4278,16 @@ function resolveSourceRootFromBundleGraph(config, bundle) {
|
|
|
3917
4278
|
}
|
|
3918
4279
|
//#endregion
|
|
3919
4280
|
//#region src/bundlers/vite/generate-bundle.ts
|
|
4281
|
+
function inferPlatformFromViteOutDir$1(outDir) {
|
|
4282
|
+
const segment = outDir ? path.basename(path.normalize(outDir)) : void 0;
|
|
4283
|
+
if (!segment) return;
|
|
4284
|
+
const normalized = segment.trim().toLowerCase();
|
|
4285
|
+
if (normalized === "h5" || normalized === "web" || normalized === "app" || normalized === "app-plus" || normalized.startsWith("app-") || normalized.startsWith("mp-") || normalized.startsWith("quickapp-webview")) return normalized;
|
|
4286
|
+
}
|
|
4287
|
+
function isUniAppViteWebviewOutDir$1(outDir) {
|
|
4288
|
+
const normalized = outDir ? path.basename(path.normalize(outDir)).trim().toLowerCase() : void 0;
|
|
4289
|
+
return normalized === "app" || normalized === "app-plus";
|
|
4290
|
+
}
|
|
3920
4291
|
function createGenerateBundleHook(context) {
|
|
3921
4292
|
const state = createBundleBuildState();
|
|
3922
4293
|
const lastCssResultByFile = /* @__PURE__ */ new Map();
|
|
@@ -3946,23 +4317,32 @@ function createGenerateBundleHook(context) {
|
|
|
3946
4317
|
const { cache, onEnd, onStart, onUpdate, styleHandler, templateHandler, jsHandler, uniAppX } = opts;
|
|
3947
4318
|
const resolvedConfig = getResolvedConfig();
|
|
3948
4319
|
const uniUtsPlatform = resolveUniUtsPlatform();
|
|
3949
|
-
const
|
|
4320
|
+
const generatorPlatform = opts.cssOptions?.platform ?? opts.platform ?? inferPlatformFromViteOutDir$1(resolvedConfig?.build?.outDir);
|
|
4321
|
+
const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(opts.generator, {
|
|
3950
4322
|
appType: opts.appType,
|
|
3951
|
-
platform:
|
|
4323
|
+
platform: generatorPlatform,
|
|
3952
4324
|
tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
3953
4325
|
uniAppX,
|
|
3954
4326
|
uniUtsPlatform
|
|
3955
|
-
})
|
|
4327
|
+
});
|
|
4328
|
+
const generatorBranch = resolveGeneratorRuntimeBranch(generatorOptions, {
|
|
3956
4329
|
appType: opts.appType,
|
|
3957
|
-
platform:
|
|
4330
|
+
platform: generatorPlatform,
|
|
3958
4331
|
tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
3959
4332
|
uniAppX,
|
|
3960
4333
|
uniUtsPlatform
|
|
3961
4334
|
});
|
|
3962
4335
|
const isWebGeneratorTarget = generatorBranch.isWeb;
|
|
3963
|
-
const
|
|
3964
|
-
const
|
|
3965
|
-
const
|
|
4336
|
+
const shouldApplyWebviewSafeSelectors = opts.appType === "uni-app-vite" && isUniAppViteWebviewOutDir$1(resolvedConfig?.build?.outDir);
|
|
4337
|
+
const shouldApplyWebviewCssCompat = isWebGeneratorTarget || shouldApplyWebviewSafeSelectors;
|
|
4338
|
+
const transformWebTargetCss = (css) => {
|
|
4339
|
+
const compatCss = isWebGeneratorTarget ? transformWebCssCompat(css, generatorOptions.webCompat) : shouldApplyWebviewCssCompat ? transformWebCssCompat(css, generatorOptions.webCompat ?? true) : css;
|
|
4340
|
+
return withUniAppXWebPreflightReset(shouldApplyWebviewSafeSelectors ? transformWebCssSafeSelectors(compatCss, { escapeMap: opts.escapeMap }) : compatCss, opts.appType === "uni-app-x" && isWebGeneratorTarget);
|
|
4341
|
+
};
|
|
4342
|
+
const isUniAppXStyleTarget = opts.appType === "uni-app-x";
|
|
4343
|
+
const isNativeAppStyleTarget = isUniAppXStyleTarget && uniUtsPlatform.isApp;
|
|
4344
|
+
const canInferHarmonyAppStyleTarget = isUniAppXStyleTarget && (!uniUtsPlatform.normalized || uniUtsPlatform.isApp);
|
|
4345
|
+
const isHarmonyAppStyleTarget = isUniAppXStyleTarget && (uniUtsPlatform.isAppHarmony || canInferHarmonyAppStyleTarget && (isUniAppXHarmonyBundle(bundle) || isUniAppXHarmonyOutDir(resolvedConfig?.build?.outDir)));
|
|
3966
4346
|
const shouldPreserveAppCssExtension = isNativeAppStyleTarget || isHarmonyAppStyleTarget;
|
|
3967
4347
|
const shouldGenerateWebCssByGenerator = isWebGeneratorTarget;
|
|
3968
4348
|
const { getCssHandlerOptions, getCssUserHandlerOptions } = cssHandlerOptions;
|
|
@@ -3984,6 +4364,7 @@ function createGenerateBundleHook(context) {
|
|
|
3984
4364
|
recordViteProcessedCssAssetResult,
|
|
3985
4365
|
resolveViteProcessedCssOutputFile: (file) => resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension, sourceRoot, defaultStyleOutputExtension, Object.keys(bundle)),
|
|
3986
4366
|
subpackageRoots: currentSubpackageRoots,
|
|
4367
|
+
transformCss: transformWebTargetCss,
|
|
3987
4368
|
debug
|
|
3988
4369
|
});
|
|
3989
4370
|
const hmrTimingStartedAt = performance.now();
|
|
@@ -4027,7 +4408,47 @@ function createGenerateBundleHook(context) {
|
|
|
4027
4408
|
const snapshotStart = performance.now();
|
|
4028
4409
|
const snapshot = buildBundleSnapshot(bundle, opts, outDir, state, envFlags.disableDirtyOptimization || !useIncrementalMode, { hasOmittedKnownFiles });
|
|
4029
4410
|
const configuredTailwindV4CssSourceEntriesForScope = getConfiguredTailwindV4CssSourceEntries();
|
|
4030
|
-
const
|
|
4411
|
+
const normalizeSystemAliasPathKey = (file) => file.startsWith("/private/var/") ? file.slice(8) : file;
|
|
4412
|
+
const normalizeConfiguredTailwindV4CssEntryFileKey = (file) => {
|
|
4413
|
+
const cleanFile = file.replace(/[?#].*$/, "");
|
|
4414
|
+
return normalizeSystemAliasPathKey(normalizeOutputPathKey(path.isAbsolute(cleanFile) ? path.resolve(cleanFile) : path.resolve(opts.tailwindcssBasedir ?? rootDir, cleanFile)));
|
|
4415
|
+
};
|
|
4416
|
+
const runtimeTailwindcssOptions = resolveTailwindcssOptions(opts.tailwindcssRuntimeOptions);
|
|
4417
|
+
const tailwindRuntimeOptions = resolveTailwindcssOptions(runtimeState.tailwindRuntime.options);
|
|
4418
|
+
const configuredTailwindV4CssSourceFileKeysForScope = new Set(configuredTailwindV4CssSourceEntriesForScope.map((entry) => normalizeConfiguredTailwindV4CssEntryFileKey(entry.file)));
|
|
4419
|
+
const configuredTailwindV4ExplicitCssEntryFileKeysForScope = new Set([
|
|
4420
|
+
...Array.isArray(opts.cssEntries) ? opts.cssEntries : [],
|
|
4421
|
+
...Array.isArray(opts.tailwindcss?.v4?.cssEntries) ? opts.tailwindcss.v4.cssEntries : [],
|
|
4422
|
+
...Array.isArray(runtimeTailwindcssOptions?.v4?.cssEntries) ? runtimeTailwindcssOptions.v4.cssEntries : [],
|
|
4423
|
+
...Array.isArray(tailwindRuntimeOptions?.v4?.cssEntries) ? tailwindRuntimeOptions.v4.cssEntries : []
|
|
4424
|
+
].filter((file) => typeof file === "string" && file.length > 0).map(normalizeConfiguredTailwindV4CssEntryFileKey));
|
|
4425
|
+
const resolveUniAppViteWebviewRootCssInjectionTarget = (sourceFile, outputFile) => {
|
|
4426
|
+
if (opts.appType !== "uni-app-vite" || !outputFile.replace(/[?#].*$/, "").endsWith(".css") || typeof sourceFile !== "string" || !configuredTailwindV4ExplicitCssEntryFileKeysForScope.has(normalizeConfiguredTailwindV4CssEntryFileKey(sourceFile))) return;
|
|
4427
|
+
const rootCssFiles = bundleFiles.filter((file) => {
|
|
4428
|
+
const normalized = normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
4429
|
+
return opts.cssMatcher(file) && normalized.endsWith(".css") && !normalized.includes("/");
|
|
4430
|
+
});
|
|
4431
|
+
const matchedRootCssFiles = rootCssFiles.filter((file) => getCssHandlerOptions(file).isMainChunk);
|
|
4432
|
+
if (matchedRootCssFiles.length === 1) return matchedRootCssFiles[0];
|
|
4433
|
+
if (matchedRootCssFiles.length > 1) return;
|
|
4434
|
+
return rootCssFiles.length === 1 ? rootCssFiles[0] : void 0;
|
|
4435
|
+
};
|
|
4436
|
+
const resolveConfiguredTailwindV4CssEntryOutputFile = (sourceFile) => resolveViteCssPipelineOutputFile(sourceFile, opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension, sourceRoot, defaultStyleOutputExtension, bundleFiles);
|
|
4437
|
+
const selectUniAppViteWebviewRootCssSourceEntry = (outputFile, entries) => {
|
|
4438
|
+
if (opts.appType !== "uni-app-vite" || !isWebGeneratorTarget || !opts.cssMatcher(outputFile) || normalizeOutputPathKey(outputFile.replace(/[?#].*$/, "")).includes("/")) return;
|
|
4439
|
+
const generationEntries = entries.filter((entry) => hasTailwindGenerationSource(entry.source));
|
|
4440
|
+
if (generationEntries.length <= 1) return generationEntries[0];
|
|
4441
|
+
const rootOutputEntries = generationEntries.filter((entry) => {
|
|
4442
|
+
return !normalizeOutputPathKey(resolveConfiguredTailwindV4CssEntryOutputFile(entry.file).replace(/[?#].*$/, "")).includes("/");
|
|
4443
|
+
});
|
|
4444
|
+
if (rootOutputEntries.length === 1) return rootOutputEntries[0];
|
|
4445
|
+
if (currentSubpackageRoots) {
|
|
4446
|
+
const mainPackageEntries = generationEntries.filter((entry) => {
|
|
4447
|
+
return !isSubpackageOutputFile(resolveConfiguredTailwindV4CssEntryOutputFile(entry.file), currentSubpackageRoots);
|
|
4448
|
+
});
|
|
4449
|
+
if (mainPackageEntries.length === 1) return mainPackageEntries[0];
|
|
4450
|
+
}
|
|
4451
|
+
};
|
|
4031
4452
|
const { createScopedSourceCandidateGetter, createScopedSourceCandidateSourceGetter, shouldExcludeSubpackageSourceCandidates, shouldInjectCssIntoMainFromOutput } = createSubpackageSourceCandidateScope({
|
|
4032
4453
|
cssSourceFiles: configuredTailwindV4CssSourceEntriesForScope.map((entry) => entry.file),
|
|
4033
4454
|
getSourceCandidateSourcesForEntries,
|
|
@@ -4183,10 +4604,14 @@ function createGenerateBundleHook(context) {
|
|
|
4183
4604
|
onUpdate,
|
|
4184
4605
|
debug
|
|
4185
4606
|
});
|
|
4186
|
-
const
|
|
4607
|
+
const createBaseHandlerOptions = createJsHandlerOptionsFactory({
|
|
4187
4608
|
getMajorVersion: () => runtimeState.tailwindRuntime.majorVersion,
|
|
4188
4609
|
moduleGraph: moduleGraphOptions
|
|
4189
4610
|
});
|
|
4611
|
+
const createHandlerOptions = (absoluteFilename, extra) => createBaseHandlerOptions(absoluteFilename, shouldApplyWebviewSafeSelectors ? {
|
|
4612
|
+
needEscaped: true,
|
|
4613
|
+
...extra
|
|
4614
|
+
} : extra);
|
|
4190
4615
|
const linkedByEntry = useIncrementalMode ? /* @__PURE__ */ new Map() : void 0;
|
|
4191
4616
|
const sharedCssResultCache = /* @__PURE__ */ new Map();
|
|
4192
4617
|
const activeProcessCacheKeys = /* @__PURE__ */ new Set();
|
|
@@ -4301,7 +4726,7 @@ function createGenerateBundleHook(context) {
|
|
|
4301
4726
|
return await refreshRememberedCssSource?.(remembered) ?? remembered;
|
|
4302
4727
|
}));
|
|
4303
4728
|
rememberedCssSources = rememberedCssSources.filter((remembered) => {
|
|
4304
|
-
if (!configuredTailwindV4CssSourceFileKeysForScope.has(
|
|
4729
|
+
if (!configuredTailwindV4CssSourceFileKeysForScope.has(normalizeConfiguredTailwindV4CssEntryFileKey(remembered.sourceFile))) return true;
|
|
4305
4730
|
const matchedOutputFile = resolveMatchedOutputFileForCurrentAsset(remembered.sourceFile);
|
|
4306
4731
|
return !matchedOutputFile || normalizeOutputPathKey(matchedOutputFile) === normalizeOutputPathKey(outputFile);
|
|
4307
4732
|
});
|
|
@@ -4312,7 +4737,7 @@ function createGenerateBundleHook(context) {
|
|
|
4312
4737
|
const rememberedSourcesBelongToInferredSfc = rememberedCssSources.length > 0 && rememberedCssSources.every((remembered) => normalizeSfcSourceFileForCompare(remembered.sourceFile) === inferredSourceFile);
|
|
4313
4738
|
if (!hasUsableRememberedTailwindSource || rememberedSourcesBelongToInferredSfc) rememberedCssSources = [inferredSfcStyleSource];
|
|
4314
4739
|
}
|
|
4315
|
-
if (isTemporaryCssAssetFile(outputFile) && rememberedCssSources.some((remembered) => configuredTailwindV4CssSourceFileKeysForScope.has(
|
|
4740
|
+
if (isTemporaryCssAssetFile(outputFile) && rememberedCssSources.some((remembered) => configuredTailwindV4CssSourceFileKeysForScope.has(normalizeConfiguredTailwindV4CssEntryFileKey(remembered.sourceFile)))) {
|
|
4316
4741
|
rememberedCssSources = [];
|
|
4317
4742
|
hasUsableRememberedTailwindSource = false;
|
|
4318
4743
|
}
|
|
@@ -4340,7 +4765,14 @@ function createGenerateBundleHook(context) {
|
|
|
4340
4765
|
}
|
|
4341
4766
|
if (!hasUsableRememberedTailwindSource) {
|
|
4342
4767
|
const configuredTailwindV4CssSourceEntries = getConfiguredTailwindV4CssSourceEntries();
|
|
4343
|
-
const
|
|
4768
|
+
const inferredSourceStyle = resolveSourceStyleSourceFromOutputFile(outputFile, snapshot, outDir, sourceRoot, getCssSource, getSourceCandidateSources, configuredTailwindV4CssSourceEntries.map((entry) => [entry.file, entry.source]), debug);
|
|
4769
|
+
const inferredWebviewRootSourceEntry = inferredSourceStyle ? void 0 : selectUniAppViteWebviewRootCssSourceEntry(outputFile, configuredTailwindV4CssSourceEntries);
|
|
4770
|
+
const inferredWebviewRootSourceStyle = inferredWebviewRootSourceEntry ? {
|
|
4771
|
+
outputFile,
|
|
4772
|
+
rawSource: inferredWebviewRootSourceEntry.source,
|
|
4773
|
+
sourceFile: inferredWebviewRootSourceEntry.file
|
|
4774
|
+
} : void 0;
|
|
4775
|
+
const inferredOriginalSourceStyle = inferredSourceStyle ?? (outputFile === file ? void 0 : resolveSourceStyleSourceFromOutputFile(file, snapshot, outDir, sourceRoot, getCssSource, getSourceCandidateSources, configuredTailwindV4CssSourceEntries.map((entry) => [entry.file, entry.source]), debug)) ?? inferredWebviewRootSourceStyle;
|
|
4344
4776
|
if (inferredOriginalSourceStyle) {
|
|
4345
4777
|
outputFile = resolveMatchedOutputFileForCurrentAsset(inferredOriginalSourceStyle.sourceFile) ?? outputFile;
|
|
4346
4778
|
activeViteCssCacheFiles.add(normalizeViteCssCacheKey(outputFile));
|
|
@@ -4390,7 +4822,7 @@ function createGenerateBundleHook(context) {
|
|
|
4390
4822
|
}
|
|
4391
4823
|
}
|
|
4392
4824
|
let rememberedCssSource = mergeRememberedCssSources(rememberedCssSources, outputFile);
|
|
4393
|
-
if (rememberedCssSource && viteProcessedCssAsset && outputCssHandlerOptions.isMainChunk !== true && configuredTailwindV4CssSourceFileKeysForScope.has(
|
|
4825
|
+
if (rememberedCssSource && viteProcessedCssAsset && outputCssHandlerOptions.isMainChunk !== true && configuredTailwindV4CssSourceFileKeysForScope.has(normalizeConfiguredTailwindV4CssEntryFileKey(rememberedCssSource.sourceFile))) {
|
|
4394
4826
|
const matchedOutputFile = resolveMatchedOutputFileForCurrentAsset(rememberedCssSource.sourceFile);
|
|
4395
4827
|
if (matchedOutputFile && normalizeOutputPathKey(matchedOutputFile) !== normalizeOutputPathKey(outputFile)) {
|
|
4396
4828
|
outputFile = matchedOutputFile;
|
|
@@ -4419,11 +4851,12 @@ function createGenerateBundleHook(context) {
|
|
|
4419
4851
|
}
|
|
4420
4852
|
const hasRememberedApplyDirective = rememberedCssSource != null && hasTailwindApplyDirective(rememberedCssSource.rawSource);
|
|
4421
4853
|
const hasRememberedTailwindGenerationSource = rememberedCssSource != null && hasTailwindGenerationSource(rememberedCssSource.rawSource);
|
|
4422
|
-
const usesConfiguredTailwindV4FallbackSource = rememberedCssSource != null && normalizeOutputPathKey(rememberedCssSource.outputFile) === normalizeOutputPathKey(outputFile) && normalizeOutputPathKey(rememberedCssSource.sourceFile.replace(/[?#].*$/, "")) !== normalizeOutputPathKey(file);
|
|
4423
4854
|
const hasSameOutputRememberedTailwindGenerationSource = hasRememberedTailwindGenerationSource && rememberedCssSource != null && normalizeOutputPathKey(rememberedCssSource.outputFile) === normalizeOutputPathKey(outputFile);
|
|
4424
4855
|
const hasStaleViteProcessedCssSource = vitePipelineCssAsset && hasDifferentRememberedCssSource && (hasCurrentTailwindGenerationDirective || hasRememberedApplyDirective || hasRememberedTailwindGenerationSource);
|
|
4425
4856
|
const generatorSourceFile = vitePipelineCssAsset ? rememberedCssSource?.sourceFile ?? assetSourceFile : assetSourceFile;
|
|
4426
|
-
|
|
4857
|
+
const webviewRootCssInjectionTarget = vitePipelineCssAsset ? resolveUniAppViteWebviewRootCssInjectionTarget(generatorSourceFile, outputFile) : void 0;
|
|
4858
|
+
const usesConfiguredTailwindV4FallbackSource = rememberedCssSource != null && normalizeOutputPathKey(rememberedCssSource.outputFile) === normalizeOutputPathKey(outputFile) && normalizeOutputPathKey(rememberedCssSource.sourceFile.replace(/[?#].*$/, "")) !== normalizeOutputPathKey(file);
|
|
4859
|
+
if (vitePipelineCssAsset && outputCssHandlerOptions.isMainChunk !== true && configuredTailwindV4CssSourceFileKeysForScope.has(normalizeConfiguredTailwindV4CssEntryFileKey(generatorSourceFile))) {
|
|
4427
4860
|
usedConfiguredTailwindV4CssSourceFiles.add(normalizeOutputPathKey(generatorSourceFile));
|
|
4428
4861
|
temporaryCssAssetSourceResolver.markUsed(generatorSourceFile);
|
|
4429
4862
|
}
|
|
@@ -4431,7 +4864,7 @@ function createGenerateBundleHook(context) {
|
|
|
4431
4864
|
...getCssHandlerOptions(generatorSourceFile),
|
|
4432
4865
|
isMainChunk: resolvedFromTemporaryCssAsset ? false : outputCssHandlerOptions.isMainChunk
|
|
4433
4866
|
} : getCssHandlerOptions(file);
|
|
4434
|
-
const generatorCssEntries =
|
|
4867
|
+
const generatorCssEntries = configuredTailwindV4ExplicitCssEntryFileKeysForScope.has(normalizeConfiguredTailwindV4CssEntryFileKey(generatorSourceFile)) ? [generatorSourceFile] : opts.cssEntries;
|
|
4435
4868
|
const generatorCssHandlerOptions = {
|
|
4436
4869
|
...cssHandlerOptions,
|
|
4437
4870
|
sourceOptions: {
|
|
@@ -4449,6 +4882,10 @@ function createGenerateBundleHook(context) {
|
|
|
4449
4882
|
opts,
|
|
4450
4883
|
tokenSources: sourceTraceTokenSources
|
|
4451
4884
|
});
|
|
4885
|
+
const removeRootCoveredCssFromScopedAsset = (css) => {
|
|
4886
|
+
const normalizedOutputFile = normalizeOutputPathKey(outputFile.replace(/[?#].*$/, ""));
|
|
4887
|
+
return !normalizedOutputFile.includes("/") || currentSubpackageRoots != null && isSubpackageOutputFile(normalizedOutputFile, currentSubpackageRoots) ? css : removeCssCoveredByRootStyleBundleSources(bundle, outputFile, css);
|
|
4888
|
+
};
|
|
4452
4889
|
const shouldRegenerateMainPackageCssWithScopedCandidates = vitePipelineCssAsset && shouldExcludeSubpackageSourceCandidates(outputFile, generatorCssHandlerOptions);
|
|
4453
4890
|
const generatorCssUserHandlerOptions = getCssUserHandlerOptions(generatorSourceFile);
|
|
4454
4891
|
const cssRuntimeAffectingSignature = vitePipelineCssAsset ? createRuntimeAffectingSourceSignature(generatorRawSource, "css") : snapshot.runtimeAffectingSignatureByFile.get(file) ?? createRuntimeAffectingSourceSignature(generatorRawSource, "css");
|
|
@@ -4456,19 +4893,30 @@ function createGenerateBundleHook(context) {
|
|
|
4456
4893
|
const cssShareScope = createCssTransformShareScopeKey(opts, outputFile, generatorRawSource);
|
|
4457
4894
|
const shouldRegenerateCollectedViteCss = viteProcessedCssAsset && useIncrementalMode && state.generatorCandidateSignature !== void 0 && generatorCandidatesChanged && (hasTailwindGenerationSource(generatorRawSource) || hasBundlerGeneratedCssMarker(rawSource) || rememberedCssSource != null && hasTailwindGenerationSource(rememberedCssSource.rawSource));
|
|
4458
4895
|
const shouldRefreshViteProcessedCssByCandidates = viteProcessedCssAsset && useIncrementalMode && state.generatorCandidateSignature !== void 0 && generatorCandidatesChanged;
|
|
4459
|
-
const
|
|
4896
|
+
const vitePipelineCssInjectionOutputFile = webviewRootCssInjectionTarget ?? outputFile;
|
|
4897
|
+
const shouldRecordVitePipelineCssByOutput = normalizeOutputPathKey(vitePipelineCssInjectionOutputFile) === normalizeOutputPathKey(outputFile);
|
|
4898
|
+
const shouldInjectVitePipelineCssIntoMain = vitePipelineCssAsset && outputCssHandlerOptions.isMainChunk !== true && (webviewRootCssInjectionTarget != null || shouldInjectCssIntoMainFromOutput(outputFile, generatorSourceFile, outputCssHandlerOptions));
|
|
4460
4899
|
const shouldTrackGeneratorRuntime = hasStaleViteProcessedCssSource || shouldRegenerateMainPackageCssWithScopedCandidates || hasCurrentTailwindGenerationDirective || hasSameOutputRememberedTailwindGenerationSource || shouldProcessTailwindGeneration && (!useIncrementalMode || cssHandlerOptions.isMainChunk || processFiles.css.has(file) || runtimeLinkedCssFiles.has(file) || runtimeLinkedCssFiles.has(outputFile) || shouldRegenerateCollectedViteCss || hasRuntimeAffectingChanges && (alreadyProcessedCssAsset || vitePipelineCssAsset));
|
|
4461
4900
|
const shouldPreserveCollectedViteCssAsset = !shouldRegenerateCollectedViteCss && (state.generatorCandidateSignature === void 0 || !generatorCandidatesChanged) && (collectedBundlerGeneratedCssFiles.has(file) || hasBundlerGeneratedCssMarker(rawSource));
|
|
4462
4901
|
const strippedViteProcessedCss = stripBundlerGeneratedCssMarkers(rawSource);
|
|
4463
4902
|
const shouldPreserveStaleGeneratedCssAsset = hasStaleViteProcessedCssSource && shouldPreserveCollectedViteCssAsset && strippedViteProcessedCss.trim().length > 0 && !strippedViteProcessedCss.includes("weapp-tailwindcss generator-placeholder") && !strippedViteProcessedCss.includes("vite-placeholder") && !hasTailwindGenerationSource(strippedViteProcessedCss) && !hasTailwindApplyDirective(strippedViteProcessedCss);
|
|
4464
4903
|
if (alreadyProcessedCssAsset && !shouldRefreshViteProcessedCssByCandidates && (!hasStaleViteProcessedCssSource || shouldPreserveStaleGeneratedCssAsset) && !hasRememberedApplySource && !shouldRegenerateMainPackageCssWithScopedCandidates && (!shouldTrackGeneratorRuntime || shouldPreserveCollectedViteCssAsset)) {
|
|
4465
|
-
const nextCss = strippedViteProcessedCss;
|
|
4904
|
+
const nextCss = removeRootCoveredCssFromScopedAsset(strippedViteProcessedCss);
|
|
4466
4905
|
applyCssResult(nextCss);
|
|
4467
4906
|
markCssAssetProcessed?.(originalSource, outputFile);
|
|
4468
4907
|
recordCssAssetResult?.(outputFile, nextCss);
|
|
4469
|
-
|
|
4908
|
+
if (vitePipelineCssAsset && rememberedCssSource) rememberCssSource?.({
|
|
4909
|
+
outputFile: vitePipelineCssInjectionOutputFile,
|
|
4910
|
+
rawSource: generatorRawSource,
|
|
4911
|
+
sourceFile: generatorSourceFile
|
|
4912
|
+
});
|
|
4913
|
+
if (shouldRecordVitePipelineCssByOutput) recordViteProcessedCssAssetResult?.(vitePipelineCssInjectionOutputFile, nextCss, {
|
|
4470
4914
|
injectIntoMain: outputCssHandlerOptions.isMainChunk ? false : shouldInjectVitePipelineCssIntoMain,
|
|
4471
|
-
outputFile
|
|
4915
|
+
outputFile: vitePipelineCssInjectionOutputFile
|
|
4916
|
+
});
|
|
4917
|
+
if (vitePipelineCssAsset && shouldInjectVitePipelineCssIntoMain) recordViteProcessedCssAssetResult?.(file, nextCss, {
|
|
4918
|
+
injectIntoMain: shouldInjectVitePipelineCssIntoMain,
|
|
4919
|
+
outputFile: vitePipelineCssInjectionOutputFile
|
|
4472
4920
|
});
|
|
4473
4921
|
onUpdate(outputFile, rawSource, nextCss);
|
|
4474
4922
|
debug("css skip vite-processed asset: %s", outputFile);
|
|
@@ -4506,7 +4954,7 @@ function createGenerateBundleHook(context) {
|
|
|
4506
4954
|
rememberLastCssResult(lastCssResultByFile, lastCssSourceHashByFile, outputFile, source, cssRuntimeAffectingHash);
|
|
4507
4955
|
markCssAssetProcessed?.(originalSource, outputFile);
|
|
4508
4956
|
if (rememberedCssSources.length <= 1) rememberCssSource?.({
|
|
4509
|
-
outputFile,
|
|
4957
|
+
outputFile: vitePipelineCssInjectionOutputFile,
|
|
4510
4958
|
rawSource: generatorRawSource,
|
|
4511
4959
|
sourceFile: generatorSourceFile
|
|
4512
4960
|
}, rememberedCssRuntimeSignature);
|
|
@@ -4541,6 +4989,7 @@ function createGenerateBundleHook(context) {
|
|
|
4541
4989
|
cssUserHandlerOptions: generatorCssUserHandlerOptions,
|
|
4542
4990
|
getSourceCandidatesForEntries: scopedSourceCandidateGetter,
|
|
4543
4991
|
sourceCandidates: scopedGeneratorRuntime,
|
|
4992
|
+
generatorPlatform,
|
|
4544
4993
|
styleHandler,
|
|
4545
4994
|
debug,
|
|
4546
4995
|
previousCss,
|
|
@@ -4548,19 +4997,19 @@ function createGenerateBundleHook(context) {
|
|
|
4548
4997
|
...usesConfiguredTailwindV4FallbackSource ? { restoreLocalCssImports: false } : {}
|
|
4549
4998
|
}) : void 0;
|
|
4550
4999
|
if (generated) {
|
|
4551
|
-
const tracedCss = annotateCss(generated.css);
|
|
5000
|
+
const tracedCss = removeRootCoveredCssFromScopedAsset(annotateCss(transformWebTargetCss(generated.css)));
|
|
4552
5001
|
registerGeneratorDependencies$1({ addWatchFile }, generated.dependencies);
|
|
4553
5002
|
if (envFlags.debugCssDiff) debug("css diff %s: %s", generatorSourceFile, summarizeStringDiff(generatorRawSource, tracedCss));
|
|
4554
5003
|
debug("css generated result: %s bytes=%d", file, tracedCss.length);
|
|
4555
5004
|
for (const candidate of generated.classSet ?? []) transformRuntime.add(candidate);
|
|
4556
5005
|
recordCssAssetResult?.(outputFile, tracedCss);
|
|
4557
|
-
recordViteProcessedCssAssetResult?.(
|
|
5006
|
+
if (shouldRecordVitePipelineCssByOutput) recordViteProcessedCssAssetResult?.(vitePipelineCssInjectionOutputFile, tracedCss, {
|
|
4558
5007
|
injectIntoMain: outputCssHandlerOptions.isMainChunk ? false : shouldInjectVitePipelineCssIntoMain,
|
|
4559
|
-
outputFile
|
|
5008
|
+
outputFile: vitePipelineCssInjectionOutputFile
|
|
4560
5009
|
});
|
|
4561
5010
|
if (vitePipelineCssAsset && shouldInjectVitePipelineCssIntoMain) recordViteProcessedCssAssetResult?.(file, tracedCss, {
|
|
4562
5011
|
injectIntoMain: shouldInjectVitePipelineCssIntoMain,
|
|
4563
|
-
outputFile
|
|
5012
|
+
outputFile: vitePipelineCssInjectionOutputFile
|
|
4564
5013
|
});
|
|
4565
5014
|
metrics.css.elapsed += measureElapsed(start);
|
|
4566
5015
|
metrics.css.transformed++;
|
|
@@ -4568,10 +5017,11 @@ function createGenerateBundleHook(context) {
|
|
|
4568
5017
|
return tracedCss;
|
|
4569
5018
|
}
|
|
4570
5019
|
if (isWebGeneratorTarget) {
|
|
5020
|
+
const outputCss = transformWebTargetCss(rawSource);
|
|
4571
5021
|
metrics.css.elapsed += measureElapsed(start);
|
|
4572
5022
|
metrics.css.transformed++;
|
|
4573
5023
|
debug("css preserve web target: %s", outputFile);
|
|
4574
|
-
return annotateCss(
|
|
5024
|
+
return annotateCss(outputCss);
|
|
4575
5025
|
}
|
|
4576
5026
|
const { css } = await styleHandler(generatorRawSource, cssHandlerOptions);
|
|
4577
5027
|
const tracedCss = annotateCss(css);
|
|
@@ -4591,7 +5041,7 @@ function createGenerateBundleHook(context) {
|
|
|
4591
5041
|
continue;
|
|
4592
5042
|
}
|
|
4593
5043
|
if (type !== "js") continue;
|
|
4594
|
-
if (isWebGeneratorTarget) {
|
|
5044
|
+
if (isWebGeneratorTarget && !shouldApplyWebviewSafeSelectors) {
|
|
4595
5045
|
debug("js skip web target: %s", file);
|
|
4596
5046
|
continue;
|
|
4597
5047
|
}
|
|
@@ -4637,6 +5087,7 @@ function createGenerateBundleHook(context) {
|
|
|
4637
5087
|
debug,
|
|
4638
5088
|
defaultStyleOutputExtension,
|
|
4639
5089
|
emitOrReplayCssAsset,
|
|
5090
|
+
generatorPlatform,
|
|
4640
5091
|
generatorRuntime,
|
|
4641
5092
|
getCssHandlerOptions,
|
|
4642
5093
|
getCssUserHandlerOptions,
|
|
@@ -4716,12 +5167,19 @@ function createGenerateBundleHook(context) {
|
|
|
4716
5167
|
tasks,
|
|
4717
5168
|
timingDetails,
|
|
4718
5169
|
transformRuntime,
|
|
5170
|
+
transformWebTargetCss,
|
|
4719
5171
|
useIncrementalMode
|
|
4720
5172
|
});
|
|
4721
5173
|
};
|
|
4722
5174
|
}
|
|
4723
5175
|
//#endregion
|
|
4724
5176
|
//#region src/bundlers/vite/css-finalizer.ts
|
|
5177
|
+
function inferPlatformFromViteOutDir(outDir) {
|
|
5178
|
+
const segment = outDir ? path.basename(path.normalize(outDir)) : void 0;
|
|
5179
|
+
if (!segment) return;
|
|
5180
|
+
const normalized = segment.trim().toLowerCase();
|
|
5181
|
+
if (normalized === "h5" || normalized === "web" || normalized === "app" || normalized === "app-plus" || normalized.startsWith("app-") || normalized.startsWith("mp-") || normalized.startsWith("quickapp-webview")) return normalized;
|
|
5182
|
+
}
|
|
4725
5183
|
function isAddWatchFileInvalidRollupPhaseError(error) {
|
|
4726
5184
|
const candidate = error;
|
|
4727
5185
|
return candidate?.code === "INVALID_ROLLUP_PHASE" || candidate?.pluginCode === "INVALID_ROLLUP_PHASE" || candidate?.message?.includes("Cannot call \"addWatchFile\" after the build has finished.") === true;
|
|
@@ -4765,8 +5223,13 @@ function shouldFinalizeProcessedCssAsset(opts, file) {
|
|
|
4765
5223
|
function collectViteProcessedCssSources(getViteProcessedCssAssetResults) {
|
|
4766
5224
|
return [...getViteProcessedCssAssetResults?.() ?? []].map(([, record]) => typeof record === "string" ? record : record.css);
|
|
4767
5225
|
}
|
|
4768
|
-
function
|
|
4769
|
-
|
|
5226
|
+
function isUniAppViteWebviewOutDir(outDir) {
|
|
5227
|
+
const normalized = outDir ? path.basename(path.normalize(outDir)).trim().toLowerCase() : void 0;
|
|
5228
|
+
return normalized === "app" || normalized === "app-plus";
|
|
5229
|
+
}
|
|
5230
|
+
function finalizeWebCss(css, enabled, webCompat, options = {}) {
|
|
5231
|
+
const compatCss = enabled ? transformWebCssCompat(css, webCompat) : css;
|
|
5232
|
+
return withUniAppXWebPreflightReset(options.safeSelectors ? transformWebCssSafeSelectors(compatCss, { escapeMap: options.escapeMap }) : compatCss, options.uniAppXWebPreflightReset === true);
|
|
4770
5233
|
}
|
|
4771
5234
|
function createViteCssFinalizerOutputPlugin(context) {
|
|
4772
5235
|
return {
|
|
@@ -4778,24 +5241,27 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
4778
5241
|
const { opts, runtimeState, ensureRuntimeClassSet, isCssAssetProcessed, markCssAssetProcessed, debug, getResolvedConfig, recordCssAssetResult, recordViteProcessedCssAssetResult, getViteProcessedCssAssetResults, getRecordedGeneratorCandidates, getSourceCandidates, getSourceCandidatesForEntries, getSourceCandidateSourcesForEntries, waitForSourceCandidateSyncs, rememberMainCssSource, getRememberedMainCssSource, isViteProcessedCssAsset } = context;
|
|
4779
5242
|
const resolvedConfig = getResolvedConfig();
|
|
4780
5243
|
const uniUtsPlatform = resolveUniUtsPlatform();
|
|
5244
|
+
const generatorPlatform = opts.cssOptions?.platform ?? opts.platform ?? inferPlatformFromViteOutDir(resolvedConfig?.build?.outDir);
|
|
4781
5245
|
const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(opts.generator, {
|
|
4782
5246
|
appType: opts.appType,
|
|
4783
|
-
platform:
|
|
5247
|
+
platform: generatorPlatform,
|
|
4784
5248
|
tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
4785
5249
|
uniAppX: opts.uniAppX,
|
|
4786
5250
|
uniUtsPlatform
|
|
4787
5251
|
});
|
|
4788
5252
|
const generatorBranch = resolveGeneratorRuntimeBranch(generatorOptions, {
|
|
4789
5253
|
appType: opts.appType,
|
|
4790
|
-
platform:
|
|
5254
|
+
platform: generatorPlatform,
|
|
4791
5255
|
tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
4792
5256
|
uniAppX: opts.uniAppX,
|
|
4793
5257
|
uniUtsPlatform
|
|
4794
5258
|
});
|
|
4795
5259
|
const isWebGeneratorTarget = generatorBranch.isWeb;
|
|
4796
|
-
const
|
|
4797
|
-
const
|
|
4798
|
-
const
|
|
5260
|
+
const shouldApplyWebviewSafeSelectors = opts.appType === "uni-app-vite" && isUniAppViteWebviewOutDir(resolvedConfig?.build?.outDir);
|
|
5261
|
+
const isUniAppXStyleTarget = opts.appType === "uni-app-x";
|
|
5262
|
+
const canInferHarmonyAppStyleTarget = isUniAppXStyleTarget && (!uniUtsPlatform.normalized || uniUtsPlatform.isApp);
|
|
5263
|
+
const isHarmonyAppStyleTarget = isUniAppXStyleTarget && (uniUtsPlatform.isAppHarmony || canInferHarmonyAppStyleTarget && (isUniAppXHarmonyBundle(bundle) || isUniAppXHarmonyOutDir(resolvedConfig?.build?.outDir)));
|
|
5264
|
+
const isNativeAppStyleTarget = isUniAppXStyleTarget && (uniUtsPlatform.isApp || isHarmonyAppStyleTarget);
|
|
4799
5265
|
if (resolvedConfig?.command !== "build" && !isNativeAppStyleTarget) return;
|
|
4800
5266
|
const rootDir = resolvedConfig?.root ? path.resolve(resolvedConfig.root) : process$1.cwd();
|
|
4801
5267
|
const sourceRoot = resolveWeappViteSourceRoot(resolvedConfig, opts.appType) ?? resolveSourceRootFromBundleGraph(resolvedConfig, bundle);
|
|
@@ -4812,7 +5278,11 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
4812
5278
|
recordCssAssetResult,
|
|
4813
5279
|
recordViteProcessedCssAssetResult,
|
|
4814
5280
|
resolveViteProcessedCssOutputFile: (file) => resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget, isNativeAppStyleTarget, sourceRoot, resolveMiniProgramStyleOutputExtension({ files: Object.keys(bundle) }), Object.keys(bundle)),
|
|
4815
|
-
transformCss: (css) => finalizeWebCss(css, generatorBranch.isWeb, generatorOptions.webCompat
|
|
5281
|
+
transformCss: (css) => finalizeWebCss(css, generatorBranch.isWeb, generatorOptions.webCompat, {
|
|
5282
|
+
escapeMap: opts.escapeMap,
|
|
5283
|
+
safeSelectors: shouldApplyWebviewSafeSelectors,
|
|
5284
|
+
uniAppXWebPreflightReset: opts.appType === "uni-app-x" && generatorBranch.isWeb
|
|
5285
|
+
}),
|
|
4816
5286
|
debug
|
|
4817
5287
|
});
|
|
4818
5288
|
};
|
|
@@ -4822,6 +5292,11 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
4822
5292
|
getViteProcessedCssAssetResults,
|
|
4823
5293
|
markCssAssetProcessed,
|
|
4824
5294
|
recordCssAssetResult,
|
|
5295
|
+
transformCss: (css) => finalizeWebCss(css, generatorBranch.isWeb, generatorOptions.webCompat, {
|
|
5296
|
+
escapeMap: opts.escapeMap,
|
|
5297
|
+
safeSelectors: shouldApplyWebviewSafeSelectors,
|
|
5298
|
+
uniAppXWebPreflightReset: opts.appType === "uni-app-x" && generatorBranch.isWeb
|
|
5299
|
+
}),
|
|
4825
5300
|
debug,
|
|
4826
5301
|
onUpdate: opts.onUpdate
|
|
4827
5302
|
});
|
|
@@ -4847,6 +5322,7 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
4847
5322
|
isMainChunk: false
|
|
4848
5323
|
},
|
|
4849
5324
|
getSourceCandidatesForEntries,
|
|
5325
|
+
generatorPlatform,
|
|
4850
5326
|
styleHandler: opts.styleHandler,
|
|
4851
5327
|
debug
|
|
4852
5328
|
});
|
|
@@ -4885,7 +5361,11 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
4885
5361
|
const file = output.fileName || bundleFile;
|
|
4886
5362
|
const rawSource = output.source.toString();
|
|
4887
5363
|
if (isViteProcessedCssAsset?.(output, file)) {
|
|
4888
|
-
const nextCss = annotateCss(finalizeWebCss(stripBundlerGeneratedCssMarkers(rawSource), generatorBranch.isWeb, generatorOptions.webCompat
|
|
5364
|
+
const nextCss = annotateCss(finalizeWebCss(stripBundlerGeneratedCssMarkers(rawSource), generatorBranch.isWeb, generatorOptions.webCompat, {
|
|
5365
|
+
escapeMap: opts.escapeMap,
|
|
5366
|
+
safeSelectors: shouldApplyWebviewSafeSelectors,
|
|
5367
|
+
uniAppXWebPreflightReset: opts.appType === "uni-app-x" && generatorBranch.isWeb
|
|
5368
|
+
}));
|
|
4889
5369
|
output.source = nextCss;
|
|
4890
5370
|
markCssAssetProcessed(output, file);
|
|
4891
5371
|
recordCssAssetResult?.(file, nextCss);
|
|
@@ -4916,10 +5396,15 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
4916
5396
|
cssHandlerOptions: generatorCssHandlerOptions,
|
|
4917
5397
|
cssUserHandlerOptions: generatorCssUserHandlerOptions,
|
|
4918
5398
|
getSourceCandidatesForEntries,
|
|
5399
|
+
generatorPlatform,
|
|
4919
5400
|
styleHandler: opts.styleHandler,
|
|
4920
5401
|
debug
|
|
4921
5402
|
}) : void 0;
|
|
4922
|
-
const nextCss = annotateCss(generated?.css ?? (generatorBranch.isWeb ? finalizeWebCss(rawSource, true, generatorOptions.webCompat
|
|
5403
|
+
const nextCss = annotateCss(generated?.css ?? (generatorBranch.isWeb ? finalizeWebCss(rawSource, true, generatorOptions.webCompat, {
|
|
5404
|
+
escapeMap: opts.escapeMap,
|
|
5405
|
+
safeSelectors: shouldApplyWebviewSafeSelectors,
|
|
5406
|
+
uniAppXWebPreflightReset: opts.appType === "uni-app-x" && generatorBranch.isWeb
|
|
5407
|
+
}) : (await opts.styleHandler(rawSource, cssHandlerOptions)).css));
|
|
4923
5408
|
if (generated) {
|
|
4924
5409
|
registerGeneratorDependencies(this, generated.dependencies);
|
|
4925
5410
|
debug("css finalizer generated result: %s bytes=%d", file, nextCss.length);
|
|
@@ -5068,6 +5553,7 @@ function createViteCssMemory(options) {
|
|
|
5068
5553
|
for (const [rememberedKey, remembered] of relatedRememberedEntries) {
|
|
5069
5554
|
touchMapEntry(rememberedCssSources, rememberedKey, {
|
|
5070
5555
|
...remembered,
|
|
5556
|
+
outputFile: entry.outputFile,
|
|
5071
5557
|
rawSource: entry.rawSource,
|
|
5072
5558
|
sourceFile: entry.sourceFile
|
|
5073
5559
|
});
|
|
@@ -5617,6 +6103,12 @@ function isViteServeCssRootRequest(id, command) {
|
|
|
5617
6103
|
function isViteCssHmrModule(code, id, command) {
|
|
5618
6104
|
return isViteServeStyleRequest(id, command) && VITE_CSS_HMR_MODULE_RE.test(code) && /[?&](?:direct|vue)(?:&|$)/.test(id);
|
|
5619
6105
|
}
|
|
6106
|
+
function hasViteServeCssGenerationDirective(code) {
|
|
6107
|
+
return hasTailwindRootDirectives(code) || hasTailwindSourceDirectives(code, { importFallback: true }) || hasTailwindApplyDirective(code);
|
|
6108
|
+
}
|
|
6109
|
+
function hasViteServeCssRootDirective(code) {
|
|
6110
|
+
return hasTailwindRootDirectives(code);
|
|
6111
|
+
}
|
|
5620
6112
|
function createViteServeCssGenerationPlugins(options) {
|
|
5621
6113
|
return [{
|
|
5622
6114
|
name: `${vitePluginName}:generate:serve`,
|
|
@@ -5641,7 +6133,8 @@ function createViteServeCssGenerationPlugins(options) {
|
|
|
5641
6133
|
if (!options.shouldGenerate() || !isViteCssHmrModule(code, id, options.getCommand())) return;
|
|
5642
6134
|
const extracted = extractViteCssHmrModuleCss(code);
|
|
5643
6135
|
if (!extracted) return;
|
|
5644
|
-
|
|
6136
|
+
if (!hasViteServeCssGenerationDirective(extracted.css)) return;
|
|
6137
|
+
if (hasViteServeCssRootDirective(extracted.css)) await options.onTailwindRootCss?.(id, extracted.css);
|
|
5645
6138
|
const generatedCss = await options.generateCss(id, extracted.css, this);
|
|
5646
6139
|
if (generatedCss === void 0 || generatedCss === extracted.css) return;
|
|
5647
6140
|
const nextCode = replaceViteCssHmrModuleCss(code, generatedCss);
|
|
@@ -5718,6 +6211,15 @@ function sameStringList(first, second) {
|
|
|
5718
6211
|
if (!first || !second || first.length !== second.length) return false;
|
|
5719
6212
|
return first.every((item, index) => item === second[index]);
|
|
5720
6213
|
}
|
|
6214
|
+
function collectConfiguredCssEntries(options) {
|
|
6215
|
+
const runtimeCssEntries = options.tailwindcssRuntimeOptions?.tailwindcss?.v4?.cssEntries;
|
|
6216
|
+
const entries = [
|
|
6217
|
+
...Array.isArray(options.cssEntries) ? options.cssEntries : [],
|
|
6218
|
+
...Array.isArray(options.tailwindcss?.v4?.cssEntries) ? options.tailwindcss.v4.cssEntries : [],
|
|
6219
|
+
...Array.isArray(runtimeCssEntries) ? runtimeCssEntries : []
|
|
6220
|
+
].filter((item) => typeof item === "string" && item.length > 0);
|
|
6221
|
+
return entries.length > 0 ? [...new Set(entries)] : void 0;
|
|
6222
|
+
}
|
|
5721
6223
|
function normalizeViteStylePlatform(value, appType) {
|
|
5722
6224
|
return normalizeFrameworkStylePlatform(value, appType);
|
|
5723
6225
|
}
|
|
@@ -5730,6 +6232,13 @@ function inferPlatformFromOutDir(outDir) {
|
|
|
5730
6232
|
function isWebOrNativeAppPlatform(platform) {
|
|
5731
6233
|
return platform === "h5" || platform === "web" || platform?.startsWith("web-") === true || platform === "app" || platform === "app-plus" || platform?.startsWith("app-") === true;
|
|
5732
6234
|
}
|
|
6235
|
+
function isUniAppViteWebviewStylePlatform(platform) {
|
|
6236
|
+
return platform === "app" || platform === "app-plus";
|
|
6237
|
+
}
|
|
6238
|
+
function applyUniAppViteWebviewCssCompat(css, options) {
|
|
6239
|
+
const compatCss = transformWebCssCompat(css, options.compat);
|
|
6240
|
+
return options.safeSelectors ? transformWebCssSafeSelectors(compatCss, { escapeMap: options.escapeMap }) : compatCss;
|
|
6241
|
+
}
|
|
5733
6242
|
/**
|
|
5734
6243
|
* @name WeappTailwindcss
|
|
5735
6244
|
* @description uni-app vite / uni-app-x 版本插件
|
|
@@ -5738,7 +6247,7 @@ function isWebOrNativeAppPlatform(platform) {
|
|
|
5738
6247
|
function WeappTailwindcss(options = {}) {
|
|
5739
6248
|
const hasExplicitAppType = typeof options.appType === "string" && options.appType.trim().length > 0;
|
|
5740
6249
|
const hasExplicitTailwindcssBasedir = typeof options.tailwindcssBasedir === "string" && options.tailwindcssBasedir.trim().length > 0;
|
|
5741
|
-
const rawCssEntries =
|
|
6250
|
+
const rawCssEntries = collectConfiguredCssEntries(options);
|
|
5742
6251
|
const opts = getCompilerContext({
|
|
5743
6252
|
...options,
|
|
5744
6253
|
__internalDeferMissingCssEntriesWarning: true
|
|
@@ -5761,23 +6270,13 @@ function WeappTailwindcss(options = {}) {
|
|
|
5761
6270
|
const initialTailwindRuntime = tailwindRuntime;
|
|
5762
6271
|
const refreshTailwindRuntime = refreshTailwindcssRuntime;
|
|
5763
6272
|
const uniAppXEnabled = isUniAppXEnabled(uniAppX);
|
|
6273
|
+
const shouldEnableUniAppXPlugins = opts.appType === "uni-app-x" || uniAppXEnabled;
|
|
5764
6274
|
const disabledOptions = resolvePluginDisabledState(disabled);
|
|
5765
6275
|
const tailwindcssMajorVersion = initialTailwindRuntime.majorVersion ?? 0;
|
|
5766
6276
|
if (!disabledOptions.plugin && tailwindcssMajorVersion !== 4) throw new Error("weapp-tailwindcss/vite 新生成管线仅支持 Tailwind CSS v4,请升级 tailwindcss 或停留在旧版 weapp-tailwindcss。");
|
|
5767
6277
|
const shouldOwnTailwindGeneration = !disabledOptions.plugin;
|
|
5768
6278
|
const shouldRewriteCssImports = opts.rewriteCssImports === true;
|
|
5769
|
-
|
|
5770
|
-
appType: opts.appType,
|
|
5771
|
-
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
5772
|
-
tailwindcssMajorVersion,
|
|
5773
|
-
uniAppX
|
|
5774
|
-
});
|
|
5775
|
-
const generatorBranch = resolveGeneratorRuntimeBranch(generatorOptions, {
|
|
5776
|
-
appType: opts.appType,
|
|
5777
|
-
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
5778
|
-
tailwindcssMajorVersion,
|
|
5779
|
-
uniAppX
|
|
5780
|
-
});
|
|
6279
|
+
let resolvedConfig;
|
|
5781
6280
|
const resolveViteStylePlatform = () => {
|
|
5782
6281
|
const explicit = normalizeViteStylePlatform(opts.cssOptions?.platform ?? opts.platform, opts.appType);
|
|
5783
6282
|
if (explicit) return explicit;
|
|
@@ -5787,9 +6286,23 @@ function WeappTailwindcss(options = {}) {
|
|
|
5787
6286
|
}
|
|
5788
6287
|
return inferPlatformFromOutDir(resolvedConfig?.build?.outDir);
|
|
5789
6288
|
};
|
|
6289
|
+
const resolveGeneratorPlatform = () => opts.cssOptions?.platform ?? opts.platform ?? resolveViteStylePlatform();
|
|
6290
|
+
const resolveCurrentGeneratorOptions = () => normalizeWeappTailwindcssGeneratorOptions(opts.generator, {
|
|
6291
|
+
appType: opts.appType,
|
|
6292
|
+
platform: resolveGeneratorPlatform(),
|
|
6293
|
+
tailwindcssMajorVersion,
|
|
6294
|
+
uniAppX
|
|
6295
|
+
});
|
|
6296
|
+
const resolveCurrentGeneratorBranch = () => resolveGeneratorRuntimeBranch(resolveCurrentGeneratorOptions(), {
|
|
6297
|
+
appType: opts.appType,
|
|
6298
|
+
platform: resolveGeneratorPlatform(),
|
|
6299
|
+
tailwindcssMajorVersion,
|
|
6300
|
+
uniAppX
|
|
6301
|
+
});
|
|
6302
|
+
const initialGeneratorBranch = resolveCurrentGeneratorBranch();
|
|
5790
6303
|
const transformEarlyMiniProgramCss = (code) => {
|
|
5791
6304
|
const platform = resolveViteStylePlatform();
|
|
5792
|
-
if (!shouldOwnTailwindGeneration || (platform ? isWebOrNativeAppPlatform(platform) :
|
|
6305
|
+
if (!shouldOwnTailwindGeneration || (platform ? isWebOrNativeAppPlatform(platform) : resolveCurrentGeneratorBranch().isWeb)) return code;
|
|
5793
6306
|
let transformedCode = code;
|
|
5794
6307
|
if (transformedCode.includes("#if")) transformedCode = compileCssMacroConditionalComments(transformedCode, { platform: resolveViteStylePlatform() });
|
|
5795
6308
|
if (transformedCode.includes("@layer")) transformedCode = unwrapUnsupportedCascadeLayers(transformedCode);
|
|
@@ -5797,10 +6310,10 @@ function WeappTailwindcss(options = {}) {
|
|
|
5797
6310
|
};
|
|
5798
6311
|
const finalizeViteMiniProgramCss = (css) => {
|
|
5799
6312
|
const platform = resolveViteStylePlatform();
|
|
5800
|
-
if (!shouldOwnTailwindGeneration || (platform ? isWebOrNativeAppPlatform(platform) :
|
|
6313
|
+
if (!shouldOwnTailwindGeneration || (platform ? isWebOrNativeAppPlatform(platform) : resolveCurrentGeneratorBranch().isWeb)) return css;
|
|
5801
6314
|
return unwrapUnsupportedCascadeLayers(css);
|
|
5802
6315
|
};
|
|
5803
|
-
const shouldInferAppType = !hasExplicitAppType && !
|
|
6316
|
+
const shouldInferAppType = !hasExplicitAppType && !initialGeneratorBranch.isWeb;
|
|
5804
6317
|
const hasInitialTailwindCssRoots = hasConfiguredTailwindV4CssRoots({
|
|
5805
6318
|
...options,
|
|
5806
6319
|
cssEntries: opts.cssEntries ?? options.cssEntries
|
|
@@ -5880,7 +6393,6 @@ function WeappTailwindcss(options = {}) {
|
|
|
5880
6393
|
await refreshRuntimeStateForAutoCssSources?.(true);
|
|
5881
6394
|
};
|
|
5882
6395
|
const customAttributesEntities = toCustomAttributesEntities(customAttributes);
|
|
5883
|
-
let resolvedConfig;
|
|
5884
6396
|
let recordedGeneratorCandidates;
|
|
5885
6397
|
const sourceCandidateCollector = createSourceCandidateCollector({ bareArbitraryValues: opts.arbitraryValues?.bareArbitraryValues });
|
|
5886
6398
|
const sourceCandidateScanCache = new LRUCache({ max: SOURCE_CANDIDATE_SCAN_CACHE_MAX });
|
|
@@ -5938,7 +6450,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
5938
6450
|
const isWatchLikeBuild = () => isWatchBuild() || resolvedConfig?.command === "serve" || process$1.env["WEAPP_TW_WATCH_REGRESSION"] === "1" || process$1.env["WEAPP_TW_HMR_TIMING"] === "1";
|
|
5939
6451
|
const isCurrentWebLikeStylePlatform = () => {
|
|
5940
6452
|
const platform = resolveViteStylePlatform();
|
|
5941
|
-
return platform ? isWebOrNativeAppPlatform(platform) :
|
|
6453
|
+
return platform ? isWebOrNativeAppPlatform(platform) : resolveCurrentGeneratorBranch().isWeb;
|
|
5942
6454
|
};
|
|
5943
6455
|
const isNuxtPageMacroHotModule = (id) => {
|
|
5944
6456
|
if (typeof id !== "string" || !/[?&]macro=true(?:&|$)/.test(id)) return false;
|
|
@@ -6158,48 +6670,58 @@ function WeappTailwindcss(options = {}) {
|
|
|
6158
6670
|
const file = cleanUrl(id);
|
|
6159
6671
|
const requestFile = isCSSRequest(id) ? id : file;
|
|
6160
6672
|
if (!isCSSRequest(requestFile) || opts.htmlMatcher(file) || isHTMLRequest(file)) return;
|
|
6673
|
+
const generatorCode = normalizeEmptyTailwindCustomVariants(code);
|
|
6161
6674
|
const rootDir = resolvedConfig?.root ? path.resolve(resolvedConfig.root) : process$1.cwd();
|
|
6162
6675
|
const isHarmonyAppStyleTarget = isHarmonyAppBuildTarget();
|
|
6163
|
-
const isNativeAppStyleTarget = resolveUniUtsPlatform().isApp || isHarmonyAppStyleTarget;
|
|
6676
|
+
const isNativeAppStyleTarget = opts.appType === "uni-app-x" && (resolveUniUtsPlatform().isApp || isHarmonyAppStyleTarget);
|
|
6164
6677
|
const sourceRoot = resolveWeappViteSourceRoot(resolvedConfig, opts.appType);
|
|
6165
|
-
const
|
|
6678
|
+
const currentGeneratorOptions = resolveCurrentGeneratorOptions();
|
|
6679
|
+
const currentGeneratorBranch = resolveCurrentGeneratorBranch();
|
|
6680
|
+
const outputFile = resolveViteCssPipelineOutputFile(requestFile, opts, rootDir, currentGeneratorBranch.isWeb, isNativeAppStyleTarget, sourceRoot);
|
|
6166
6681
|
const runtime = getRecordedGeneratorCandidates() ?? getSourceCandidates() ?? await ensureRuntimeClassSet();
|
|
6167
6682
|
const outputCssHandlerOptions = transformCssHandlerOptions.getCssHandlerOptions(outputFile);
|
|
6168
6683
|
const cssHandlerOptions = {
|
|
6169
6684
|
...transformCssHandlerOptions.getCssHandlerOptions(file),
|
|
6170
6685
|
isMainChunk: outputCssHandlerOptions.isMainChunk
|
|
6171
6686
|
};
|
|
6172
|
-
const transientCssSource = transientAutoCssSources.get(file) ?? (hasTailwindRootDirectives(
|
|
6687
|
+
const transientCssSource = transientAutoCssSources.get(file) ?? (hasTailwindRootDirectives(generatorCode, { importFallback: currentGeneratorOptions.importFallback }) || hasTailwindSourceDirectives(generatorCode, { importFallback: currentGeneratorOptions.importFallback }) || hasTailwindApplyDirective(generatorCode) ? {
|
|
6173
6688
|
base: path.dirname(path.resolve(file)),
|
|
6174
|
-
css:
|
|
6689
|
+
css: generatorCode,
|
|
6175
6690
|
file: path.resolve(file)
|
|
6176
6691
|
} : void 0);
|
|
6177
|
-
const shouldDeferEmptyScopedCssSource = transientCssSource == null && !(opts.appType === "uni-app-x" && !cssHandlerOptions.isMainChunk && hasTailwindApplyDirective(
|
|
6692
|
+
const shouldDeferEmptyScopedCssSource = transientCssSource == null && !(opts.appType === "uni-app-x" && !cssHandlerOptions.isMainChunk && hasTailwindApplyDirective(generatorCode));
|
|
6178
6693
|
const generated = await generateTailwindV4Css({
|
|
6179
6694
|
opts,
|
|
6180
6695
|
runtimeState,
|
|
6181
6696
|
runtime,
|
|
6182
|
-
rawSource:
|
|
6697
|
+
rawSource: generatorCode,
|
|
6183
6698
|
file,
|
|
6184
6699
|
outputFile,
|
|
6185
6700
|
cssHandlerOptions,
|
|
6186
6701
|
cssUserHandlerOptions: transformCssHandlerOptions.getCssUserHandlerOptions(file),
|
|
6187
6702
|
cssSources: transientCssSource ? [transientCssSource] : void 0,
|
|
6188
6703
|
getSourceCandidatesForEntries,
|
|
6704
|
+
generatorPlatform: resolveGeneratorPlatform(),
|
|
6189
6705
|
styleHandler,
|
|
6190
6706
|
debug,
|
|
6191
6707
|
previousCss: viteGeneratedCssByFile.get(file),
|
|
6192
6708
|
deferEmptyScopedCssSource: shouldDeferEmptyScopedCssSource,
|
|
6193
|
-
restoreLocalCssImports: !
|
|
6709
|
+
restoreLocalCssImports: !currentGeneratorBranch.isWeb
|
|
6194
6710
|
});
|
|
6195
6711
|
if (!generated) return;
|
|
6196
|
-
const
|
|
6712
|
+
const finalizedCss = finalizeViteMiniProgramCss(generated.css);
|
|
6713
|
+
const isUniAppViteWebviewPlatform = opts.appType === "uni-app-vite" && isUniAppViteWebviewStylePlatform(resolveViteStylePlatform());
|
|
6714
|
+
const tracedCss = annotateCssSourceTrace(withUniAppXWebPreflightReset(removeScopedTailwindPreflightCss(currentGeneratorBranch.isWeb || isUniAppViteWebviewPlatform ? applyUniAppViteWebviewCssCompat(finalizedCss, {
|
|
6715
|
+
compat: currentGeneratorOptions.webCompat ?? true,
|
|
6716
|
+
escapeMap: opts.escapeMap,
|
|
6717
|
+
safeSelectors: isUniAppViteWebviewPlatform
|
|
6718
|
+
}) : finalizedCss), opts.appType === "uni-app-x" && currentGeneratorBranch.isWeb), {
|
|
6197
6719
|
opts,
|
|
6198
6720
|
tokenSources: createCssTokenSourceMap(getSourceCandidateSourcesForEntries(void 0), opts)
|
|
6199
6721
|
});
|
|
6200
6722
|
for (const dependency of generated.dependencies) hookContext?.addWatchFile?.(dependency);
|
|
6201
6723
|
viteGeneratedCssByFile.set(file, tracedCss);
|
|
6202
|
-
const shouldInjectGeneratedCssIntoMain = mainCssChunkMatcher(outputFile, opts.appType) || hasTailwindRootDirectives(
|
|
6724
|
+
const shouldInjectGeneratedCssIntoMain = mainCssChunkMatcher(outputFile, opts.appType) || hasTailwindRootDirectives(generatorCode, { importFallback: currentGeneratorOptions.importFallback }) && !normalizeOutputPathKey(outputFile).includes("/");
|
|
6203
6725
|
recordViteProcessedCssAssetResult(file, tracedCss, {
|
|
6204
6726
|
injectIntoMain: shouldInjectGeneratedCssIntoMain,
|
|
6205
6727
|
outputFile
|
|
@@ -6231,7 +6753,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
6231
6753
|
onTailwindRootCss: (id, code) => registerAutoCssSource(id, code),
|
|
6232
6754
|
onCssSourceTransform: (id, code) => cssMemory.refreshRememberedCssSourceBySourceFile(id, code),
|
|
6233
6755
|
shouldGenerateCss: (_id, code) => hasVitePipelineTailwindGenerationDirective(code),
|
|
6234
|
-
shouldDeferGeneration: (_id, code) => !shouldRewriteCssImports && hasTailwindRootDirectives(code, { importFallback:
|
|
6756
|
+
shouldDeferGeneration: (_id, code) => !shouldRewriteCssImports && hasTailwindRootDirectives(code, { importFallback: resolveCurrentGeneratorOptions().importFallback }),
|
|
6235
6757
|
shouldOwnTailwindGeneration,
|
|
6236
6758
|
shouldRewrite: shouldRewriteCssImports,
|
|
6237
6759
|
weappTailwindcssDirPosix
|
|
@@ -6298,7 +6820,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
6298
6820
|
if (shouldDiscoverAutoCssSources()) await discoverAndRegisterAutoCssSources();
|
|
6299
6821
|
await syncSourceCandidateScan();
|
|
6300
6822
|
};
|
|
6301
|
-
const uniAppXPlugins =
|
|
6823
|
+
const uniAppXPlugins = shouldEnableUniAppXPlugins ? createUniAppXPlugins({
|
|
6302
6824
|
appType: opts.appType ?? "uni-app-x",
|
|
6303
6825
|
customAttributesEntities,
|
|
6304
6826
|
disabledDefaultTemplateHandler,
|
|
@@ -6330,7 +6852,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
6330
6852
|
order: "pre",
|
|
6331
6853
|
async handler(code, id) {
|
|
6332
6854
|
let transformedCode = code;
|
|
6333
|
-
if (shouldOwnTailwindGeneration && !
|
|
6855
|
+
if (shouldOwnTailwindGeneration && !resolveCurrentGeneratorBranch().isWeb && isCSSRequest(id)) transformedCode = transformEarlyMiniProgramCss(code);
|
|
6334
6856
|
const shouldReturnTransformedCode = transformedCode !== code;
|
|
6335
6857
|
if (shouldOwnTailwindGeneration) cssMemory.rememberKnownSfcSource(id, transformedCode);
|
|
6336
6858
|
if (!shouldOwnTailwindGeneration || !isSourceCandidateRequest(id) || !shouldCollectTransformedSourceCandidates(id)) {
|
|
@@ -6410,10 +6932,10 @@ function WeappTailwindcss(options = {}) {
|
|
|
6410
6932
|
shouldGenerate: () => shouldOwnTailwindGeneration
|
|
6411
6933
|
}),
|
|
6412
6934
|
createViteServeJsTransformPlugin({
|
|
6413
|
-
createHandlerOptions: serveJsHandlerOptions,
|
|
6935
|
+
createHandlerOptions: (file) => serveJsHandlerOptions(file, opts.appType === "uni-app-vite" && isUniAppViteWebviewStylePlatform(resolveViteStylePlatform()) ? { needEscaped: true } : void 0),
|
|
6414
6936
|
getCommand: () => resolvedConfig?.command,
|
|
6415
6937
|
jsHandler,
|
|
6416
|
-
shouldTransform: () => shouldOwnTailwindGeneration && !
|
|
6938
|
+
shouldTransform: () => shouldOwnTailwindGeneration && (!resolveCurrentGeneratorBranch().isWeb || opts.appType === "uni-app-vite" && isUniAppViteWebviewStylePlatform(resolveViteStylePlatform())),
|
|
6417
6939
|
transformRuntime: ensureRuntimeClassSet
|
|
6418
6940
|
}),
|
|
6419
6941
|
{
|