weapp-tailwindcss 5.1.8 → 5.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundlers/shared/generator-css/generation-helpers.d.ts +1 -0
- package/dist/bundlers/shared/generator-css/output-import-shell.d.ts +4 -0
- package/dist/bundlers/shared/generator-css/source-resolver/metadata.d.ts +1 -0
- package/dist/bundlers/shared/generator-css/types.d.ts +2 -0
- package/dist/bundlers/vite/generate-bundle/css-assets.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/remembered-css-replay.d.ts +2 -0
- package/dist/bundlers/vite/generate-bundle/scoped-generator.d.ts +1 -0
- package/dist/bundlers/vite/hot-css-modules.d.ts +1 -1
- package/dist/bundlers/vite/source-candidates.d.ts +7 -2
- package/dist/bundlers/vite/web-css-compat.d.ts +3 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/css-source-resolvers.d.ts +9 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers.d.ts +3 -0
- package/dist/cli.js +3 -2
- package/dist/cli.mjs +2 -1
- package/dist/{context-CfXr3hWz.mjs → context-DzkSFEVL.mjs} +4 -4
- package/dist/{context-CRhUs_5e.js → context-y2BGCok4.js} +10 -10
- package/dist/core.js +1 -1
- package/dist/core.mjs +1 -1
- package/dist/generator/options.d.ts +8 -1
- package/dist/{v4-engine-BZP2462H.js → generator-Bz94KTkH.js} +229 -17
- package/dist/{v4-engine-CjjWONB0.mjs → generator-ROzBodj6.mjs} +185 -9
- package/dist/generator.js +7 -8
- package/dist/generator.mjs +1 -2
- package/dist/{gulp-CRjkPsbX.mjs → gulp-BKqMb_Ds.mjs} +4 -4
- package/dist/{gulp-JUfnhOOo.js → gulp-DfOLvYLs.js} +10 -10
- package/dist/gulp.js +1 -1
- package/dist/gulp.mjs +1 -1
- package/dist/{hmr-timing-DcIEXnf8.js → hmr-timing-DOTdH18A.js} +556 -170
- package/dist/{hmr-timing-BecOXMd8.mjs → hmr-timing-DwtYJdwb.mjs} +430 -56
- package/dist/index.js +4 -4
- package/dist/index.mjs +4 -4
- package/dist/postcss.js +2 -3
- package/dist/postcss.mjs +1 -2
- package/dist/presets.js +7 -6
- package/dist/presets.mjs +5 -4
- package/dist/rspack.js +1 -1
- package/dist/rspack.mjs +1 -1
- package/dist/{source-candidate-scan-signature-10tvdJVC.js → source-candidate-scan-signature-BrWuBTjY.js} +34 -6
- package/dist/{source-candidate-scan-signature-DAg8QSgh.mjs → source-candidate-scan-signature-CQ04hiox.mjs} +29 -7
- package/dist/{tailwindcss-BZjZZi60.js → tailwindcss-Dn5DVlkI.js} +55 -47
- package/dist/{tailwindcss-PA2jHHpx.mjs → tailwindcss-hzy_WaC9.mjs} +14 -6
- package/dist/{transform-wNEbcZeQ.mjs → transform-BgnNYkIG.mjs} +1 -1
- package/dist/{transform-B0BxX3XB.js → transform-DZQETx51.js} +1 -1
- package/dist/{vite-vf2-cDdk.mjs → vite-BimHmlSp.mjs} +892 -233
- package/dist/{vite-GdzlG_lx.js → vite-bztpcI8_.js} +936 -277
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/weapp-tw-css-import-rewrite-loader.js +613 -63
- package/dist/{webpack-2s-TFhgm.mjs → webpack-CCapGlNg.mjs} +235 -38
- package/dist/{webpack-BhM4Hqla.js → webpack-XxBCIrBp.js} +276 -79
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +6 -6
- package/dist/generator-DaaFxR5V.js +0 -174
- package/dist/generator-DugIHBgl.mjs +0 -127
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import { resolveImplicitAppTypeFromViteRoot } from "./framework.mjs";
|
|
2
|
-
import { $ as
|
|
3
|
-
import { a as resolveGeneratorRuntimeBranch, c as shouldUseNativeAppCssBranch, i as normalizeWeappTailwindcssGeneratorOptions, s as shouldUseMiniProgramCssBranch } from "./generator-DugIHBgl.mjs";
|
|
2
|
+
import { $ as normalizeTailwindSourceForGenerator, A as hasUserCssLayerBlocks, G as stripMiniProgramCssSpecificityPlaceholders, H as hasMiniProgramCssSpecificityPlaceholders, J as hasTailwindNonRootGenerationDirectives, K as hasLocalCssImport, M as normalizeEmptyTailwindCustomVariants, Nt as filterUnsupportedMiniProgramTailwindV4Candidates, Pt as omitUndefined, T as resolveTailwindcssOptions, X as hasTailwindSourceDirectives, Y as hasTailwindRootDirectives, Z as normalizeTailwindConfigDirectives, _t as getTailwindV4IncrementalGenerateCacheStats, a as resolveGeneratorRuntimeBranch, b as findNearestPackageRoot, c as shouldUseNativeAppCssBranch, dt as stripGeneratorPlaceholderMarkers, et as parseImportRequest, h as upsertTailwindV4CssSource, i as normalizeWeappTailwindcssGeneratorOptions, kt as resolveTailwindV4CssSourceBase, m as hasConfiguredTailwindV4CssRoots, p as filterTailwindV4CssSourceRoots, q as hasTailwindApplyDirective, s as shouldUseMiniProgramCssBranch, st as hasTailwindGeneratedCssMarkers, tt as removeTailwindSourceDirectives, v as isTailwindV4CssEntry, y as normalizeCssEntries } from "./generator-ROzBodj6.mjs";
|
|
4
3
|
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 { E as
|
|
8
|
-
import { A as
|
|
4
|
+
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-DzkSFEVL.mjs";
|
|
5
|
+
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-hzy_WaC9.mjs";
|
|
6
|
+
import { A as processCachedTask, D as createCssSourceTraceCacheSignature, E as annotateCssSourceTrace, O as createCssTokenSourceMap, S as scoreTailwindV4CssSourceFileMatch, _ as normalizeMiniProgramGeneratorCssSource, a as isSourceCandidateRequest, d as validateCandidatesByGenerator, g as mergeMarkedUserLayerComponentsCss, h as extractMarkedUserLayerComponentsCss, m as runWithConcurrency, r as createSourceCandidateCollector, s as createBundleRuntimeClassSetManager, t as createHmrTimingRecorder, v as normalizeMiniProgramImportShell, y as isPureLocalCssImportWrapper } from "./hmr-timing-DwtYJdwb.mjs";
|
|
7
|
+
import { A as createBundlerGeneratedCssMarker, B as resolveViteFrameworkProfile, C as createBundleModuleGraphOptions, D as normalizeOutputPathKey, E as stripRequestQuery, F as resolvePluginDisabledState, I as createBuiltinViteStyleInjectorPlugins, M as parseBundlerGeneratedCssMarkerBlocks, N as stripBundlerGeneratedCssMarkers, P as resolvePackageDir, R as viteStyleInjectorDelegates, S as applyLinkedResults, T as isSourceStyleRequest, _ as isCSSRequest, a as createCandidateSignature, b as slash, c as getSnapshotHash, d as buildBundleSnapshot, g as formatPostcssSourceMap, h as cleanUrl, i as createScopedGeneratorSourceTraceMap, j as hasBundlerGeneratedCssMarker, k as toAbsoluteOutputPath, l as hasRuntimeAffectingSourceChanges, m as updateBundleBuildState, n as createScopedGeneratorCandidateSignature, o as createJsHashSalt, p as createBundleBuildState, r as createScopedGeneratorRuntime, s as createLinkedImpactSignature, t as createSourceCandidateScanSignature, u as summarizeStringDiff, v as isHTMLRequest, w as generateTailwindV4Css, x as createRuntimeAffectingSourceSignature, y as normalizePath } from "./source-candidate-scan-signature-CQ04hiox.mjs";
|
|
9
8
|
import { t as logger$1 } from "./logger-BNzxZbZj.mjs";
|
|
10
9
|
import fs, { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
11
10
|
import path from "node:path";
|
|
12
11
|
import process$1 from "node:process";
|
|
13
12
|
import { splitCandidateTokens } from "@tailwindcss-mangle/engine";
|
|
14
|
-
import { compileCssMacroConditionalComments, containsCssAfterMinify, filterExistingCssRules, mergeCoveredCssRuleDeclarations, mergeMiniProgramPreflightRuleDeclarations, mergeMiniProgramThemeScopeRuleDeclarations, postcss, removeTailwindPostcssPlugins, resolveFilteredPostcssConfig, transformWebCssCompat, transformWebCssSafeSelectors, unwrapUnsupportedCascadeLayers } from "@weapp-tailwindcss/postcss";
|
|
13
|
+
import { collectCssImportRequestsRoot, compileCssMacroConditionalComments, containsCssAfterMinify, filterExistingCssRules, isMiniProgramLocalCssImportRequest, mergeCoveredCssRuleDeclarations, mergeMiniProgramPreflightRuleDeclarations, mergeMiniProgramThemeScopeRuleDeclarations, parseTailwindCssDirectiveRequest, postcss, removeTailwindPostcssPlugins, removeTailwindSourceDirectivesRoot, removeUnsupportedMiniProgramCssImportsRoot, resolveFilteredPostcssConfig, transformWebCssCompat, transformWebCssSafeSelectors, unwrapUnsupportedCascadeLayers } from "@weapp-tailwindcss/postcss";
|
|
15
14
|
import { LRUCache } from "lru-cache";
|
|
16
15
|
import { readFile } from "node:fs/promises";
|
|
17
16
|
import micromatch from "micromatch";
|
|
@@ -541,8 +540,13 @@ function registerGeneratorDependencies$1(ctx, dependencies) {
|
|
|
541
540
|
}
|
|
542
541
|
//#endregion
|
|
543
542
|
//#region src/bundlers/vite/generate-bundle/css-assets.ts
|
|
544
|
-
function createCssAssetEmitter(context) {
|
|
543
|
+
function createCssAssetEmitter(context, bundle) {
|
|
545
544
|
return (fileName, source) => {
|
|
545
|
+
const existing = bundle?.[fileName];
|
|
546
|
+
if (existing && typeof existing === "object" && "type" in existing && existing.type === "asset") {
|
|
547
|
+
existing.source = source;
|
|
548
|
+
return existing;
|
|
549
|
+
}
|
|
546
550
|
if (context.emitFile) {
|
|
547
551
|
context.emitFile({
|
|
548
552
|
type: "asset",
|
|
@@ -652,9 +656,9 @@ function resolveReplayCssOutputFileFromSourceRoot(rootDir, file, sourceRoot) {
|
|
|
652
656
|
return outputFile;
|
|
653
657
|
}
|
|
654
658
|
function resolveViteCssOutputFile(file, opts, isWebGeneratorTarget, preserveCssExtension = false, styleOutputExtension, styleOutputFiles) {
|
|
655
|
-
if (isWebGeneratorTarget || preserveCssExtension || opts.cssMatcher(file) || !
|
|
656
|
-
const stem = file.replace(/[?#].*$/, "").replace(
|
|
657
|
-
return file.replace(
|
|
659
|
+
if (isWebGeneratorTarget || preserveCssExtension || opts.cssMatcher(file) || !CSS_SOURCE_OUTPUT_EXT_RE.test(file) || !isCSSRequest(file)) return file;
|
|
660
|
+
const stem = file.replace(/[?#].*$/, "").replace(CSS_SOURCE_OUTPUT_EXT_RE, "");
|
|
661
|
+
return file.replace(CSS_SOURCE_OUTPUT_EXT_RE, resolveMiniProgramStyleOutputExtension({
|
|
658
662
|
cssMatcher: opts.cssMatcher,
|
|
659
663
|
fallback: styleOutputExtension,
|
|
660
664
|
files: styleOutputFiles,
|
|
@@ -1651,6 +1655,10 @@ function resolveSourceStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot
|
|
|
1651
1655
|
debug("source style sibling chunk skipped: no source style modules for %s -> %s", outputFile, siblingJsFile);
|
|
1652
1656
|
return;
|
|
1653
1657
|
}
|
|
1658
|
+
if (sourceFiles.length === 1) {
|
|
1659
|
+
debug("source style sibling chunk inferred from single css module: %s -> %s", outputFile, sourceFiles[0]);
|
|
1660
|
+
return sourceFiles[0];
|
|
1661
|
+
}
|
|
1654
1662
|
const scoredSources = sourceFiles.map((sourceFile) => ({
|
|
1655
1663
|
sourceFile,
|
|
1656
1664
|
score: scoreMatchingStyleFileBase(outputFile, sourceFile, outputRoot, sourceRoot)
|
|
@@ -1669,11 +1677,23 @@ function resolveSourceStyleSourceFromOutputFile(outputFile, snapshot, outputRoot
|
|
|
1669
1677
|
let sourceFile = resolveSourceStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot, sourceRoot, debug);
|
|
1670
1678
|
let rawSource = sourceFile ? getSourceStyleSource?.(sourceFile) : void 0;
|
|
1671
1679
|
if (!sourceFile || !rawSource || !hasTailwindGenerationSourceForFile(sourceFile, rawSource)) {
|
|
1672
|
-
const
|
|
1680
|
+
const cachedSources = [...getSourceStyleSources?.() ?? []].filter(([file, source]) => CSS_SOURCE_OUTPUT_EXT_RE.test(file) && hasTailwindGenerationSourceForFile(file, source)).map(([file, source]) => ({
|
|
1673
1681
|
file,
|
|
1674
1682
|
source,
|
|
1675
|
-
score:
|
|
1676
|
-
|
|
1683
|
+
score: scoreTailwindV4CssSourceFileMatch(outputFile, file, {
|
|
1684
|
+
outputRoot,
|
|
1685
|
+
projectRoot: sourceRoot
|
|
1686
|
+
})
|
|
1687
|
+
}));
|
|
1688
|
+
const configuredSources = [...configuredSourceEntries ?? []].filter(([file, source]) => CSS_SOURCE_OUTPUT_EXT_RE.test(file) && hasTailwindGenerationSourceForFile(file, source)).map(([file, source]) => ({
|
|
1689
|
+
file,
|
|
1690
|
+
source,
|
|
1691
|
+
score: scoreTailwindV4CssSourceFileMatch(outputFile, file, {
|
|
1692
|
+
outputRoot,
|
|
1693
|
+
projectRoot: sourceRoot
|
|
1694
|
+
})
|
|
1695
|
+
}));
|
|
1696
|
+
const scoredSources = [...cachedSources, ...configuredSources].filter((item) => item.score > 0).sort((a, b) => b.score - a.score);
|
|
1677
1697
|
const bestScore = scoredSources[0]?.score;
|
|
1678
1698
|
const bestSources = bestScore ? scoredSources.filter((item) => item.score === bestScore) : [];
|
|
1679
1699
|
if (bestSources.length === 1) {
|
|
@@ -1810,30 +1830,65 @@ function dedupeViteCssResults(records) {
|
|
|
1810
1830
|
return true;
|
|
1811
1831
|
});
|
|
1812
1832
|
}
|
|
1813
|
-
function
|
|
1814
|
-
|
|
1833
|
+
function removeTailwindSourceMediaWrappersRoot(root) {
|
|
1834
|
+
let changed = false;
|
|
1835
|
+
root.walkAtRules("media", (atRule) => {
|
|
1836
|
+
if (!atRule.params.startsWith("source(")) return;
|
|
1837
|
+
if (atRule.nodes && atRule.nodes.length > 0) atRule.replaceWith(...atRule.nodes);
|
|
1838
|
+
else atRule.remove();
|
|
1839
|
+
changed = true;
|
|
1840
|
+
});
|
|
1841
|
+
if (changed) root.walkAtRules((atRule) => {
|
|
1842
|
+
if (atRule.nodes && atRule.nodes.length === 0) atRule.remove();
|
|
1843
|
+
});
|
|
1844
|
+
return changed;
|
|
1845
|
+
}
|
|
1846
|
+
function removeTailwindSourceMediaWrappersFallback(css) {
|
|
1847
|
+
return css.replace(/@media\s+source\([^)]*\)\s*\{\s*\/\*!\s*weapp-tailwindcss generator-placeholder\s*\*\/?\s*\}/gi, "").replace(/@media\s+source\([^)]*\)\s*\{\s*\}/gi, "");
|
|
1848
|
+
}
|
|
1849
|
+
function removeTailwindEntryDirectivesFromCss(css) {
|
|
1815
1850
|
try {
|
|
1816
|
-
const
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
else atRule.remove();
|
|
1822
|
-
changed = true;
|
|
1823
|
-
});
|
|
1824
|
-
root.walkAtRules((atRule) => {
|
|
1825
|
-
if (atRule.nodes && atRule.nodes.length === 0) {
|
|
1826
|
-
atRule.remove();
|
|
1827
|
-
changed = true;
|
|
1828
|
-
}
|
|
1829
|
-
});
|
|
1830
|
-
return changed ? root.toString() : css;
|
|
1851
|
+
const source = stripGeneratorPlaceholderMarkers(css);
|
|
1852
|
+
const root = postcss.parse(source);
|
|
1853
|
+
const removedMediaWrappers = removeTailwindSourceMediaWrappersRoot(root);
|
|
1854
|
+
const removedTailwindDirectives = removeTailwindSourceDirectivesRoot(root);
|
|
1855
|
+
return removedMediaWrappers || removedTailwindDirectives ? root.toString() : source;
|
|
1831
1856
|
} catch {
|
|
1832
|
-
return
|
|
1857
|
+
return removeTailwindSourceDirectives(removeTailwindSourceMediaWrappersFallback(css));
|
|
1833
1858
|
}
|
|
1834
1859
|
}
|
|
1835
|
-
function
|
|
1836
|
-
|
|
1860
|
+
function removeUnsupportedMiniProgramCssImportsFallback(css, file) {
|
|
1861
|
+
if (!isMiniProgramStyleOutputFile(file) || !css.includes("@import")) return css;
|
|
1862
|
+
return css.split(/\r?\n/).filter((line) => {
|
|
1863
|
+
const trimmed = line.trim();
|
|
1864
|
+
if (!trimmed.startsWith("@import")) return true;
|
|
1865
|
+
const request = parseTailwindCssDirectiveRequest(trimmed.slice(7).trim().replace(/;$/, "").trim());
|
|
1866
|
+
return request === void 0 || isMiniProgramLocalCssImportRequest(request);
|
|
1867
|
+
}).join("\n");
|
|
1868
|
+
}
|
|
1869
|
+
function normalizeInjectableCssForTarget(css, file) {
|
|
1870
|
+
return normalizeInjectableCssForTargetWithImports(css, file).css;
|
|
1871
|
+
}
|
|
1872
|
+
function normalizeInjectableCssForTargetWithImports(css, file) {
|
|
1873
|
+
if (!css.includes("@import")) return {
|
|
1874
|
+
css,
|
|
1875
|
+
importedStyleFiles: /* @__PURE__ */ new Set()
|
|
1876
|
+
};
|
|
1877
|
+
try {
|
|
1878
|
+
const root = postcss.parse(css);
|
|
1879
|
+
const changed = isMiniProgramStyleOutputFile(file) ? removeUnsupportedMiniProgramCssImportsRoot(root) : false;
|
|
1880
|
+
const importedStyleFiles = collectImportedStyleFilesRoot(root, file);
|
|
1881
|
+
return {
|
|
1882
|
+
css: changed ? root.toString() : css,
|
|
1883
|
+
importedStyleFiles: importedStyleFiles.size > 0 ? importedStyleFiles : collectImportedStyleFilesFallback(css, file)
|
|
1884
|
+
};
|
|
1885
|
+
} catch {
|
|
1886
|
+
const fallbackCss = removeUnsupportedMiniProgramCssImportsFallback(css, file);
|
|
1887
|
+
return {
|
|
1888
|
+
css: fallbackCss,
|
|
1889
|
+
importedStyleFiles: collectImportedStyleFiles(fallbackCss, file)
|
|
1890
|
+
};
|
|
1891
|
+
}
|
|
1837
1892
|
}
|
|
1838
1893
|
function stripStyleExtension(file) {
|
|
1839
1894
|
return file.replace(/[?#].*$/, "").replace(/\.(?:css|wxss|acss|ttss|qss|jxss|tyss|scss|sass|less|styl|stylus|pcss|postcss)$/i, "");
|
|
@@ -1848,15 +1903,27 @@ function resolveImportedStyleFile(targetFile, request) {
|
|
|
1848
1903
|
const targetDir = posix.posix.dirname(normalizeOutputPathKey(targetFile));
|
|
1849
1904
|
return normalizeOutputPathKey(posix.posix.join(targetDir === "." ? "" : targetDir, cleanRequest));
|
|
1850
1905
|
}
|
|
1851
|
-
function
|
|
1906
|
+
function collectImportedStyleFilesFromRequests(requests, targetFile) {
|
|
1852
1907
|
const imports = /* @__PURE__ */ new Set();
|
|
1908
|
+
for (const request of requests) {
|
|
1909
|
+
const importedFile = resolveImportedStyleFile(targetFile, request);
|
|
1910
|
+
if (importedFile) imports.add(importedFile);
|
|
1911
|
+
}
|
|
1912
|
+
return imports;
|
|
1913
|
+
}
|
|
1914
|
+
function collectImportedStyleFilesRoot(root, targetFile) {
|
|
1915
|
+
return collectImportedStyleFilesFromRequests(collectCssImportRequestsRoot(root), targetFile);
|
|
1916
|
+
}
|
|
1917
|
+
function collectImportedStyleFilesFallback(css, targetFile) {
|
|
1918
|
+
return collectImportedStyleFilesFromRequests([...css.matchAll(/@import\s+(?:url\(\s*)?(?:"([^"]+)"|'([^']+)'|([^\s;)]+))/g)].map((match) => match[1] ?? match[2] ?? match[3]).filter((request) => typeof request === "string" && request.length > 0), targetFile);
|
|
1919
|
+
}
|
|
1920
|
+
function collectImportedStyleFiles(css, targetFile) {
|
|
1921
|
+
if (!css.includes("@import")) return /* @__PURE__ */ new Set();
|
|
1853
1922
|
try {
|
|
1854
|
-
postcss.parse(css)
|
|
1855
|
-
|
|
1856
|
-
if (importedFile) imports.add(importedFile);
|
|
1857
|
-
});
|
|
1923
|
+
const imports = collectImportedStyleFilesRoot(postcss.parse(css), targetFile);
|
|
1924
|
+
return imports.size > 0 ? imports : collectImportedStyleFilesFallback(css, targetFile);
|
|
1858
1925
|
} catch {}
|
|
1859
|
-
return
|
|
1926
|
+
return collectImportedStyleFilesFallback(css, targetFile);
|
|
1860
1927
|
}
|
|
1861
1928
|
function normalizeMarkerOutputFile(markerFile, resolveViteProcessedCssOutputFile) {
|
|
1862
1929
|
return resolveViteProcessedCssOutputFile?.(markerFile) ?? markerFile;
|
|
@@ -2013,9 +2080,21 @@ function isUnscopedMiniProgramTailwindPreflightRule(rule) {
|
|
|
2013
2080
|
const declarations = rule.nodes?.filter((node) => node.type === "decl") ?? [];
|
|
2014
2081
|
return declarations.length > 0 && declarations.every(isMiniProgramTailwindPreflightDeclaration);
|
|
2015
2082
|
}
|
|
2083
|
+
function isScopedMiniProgramTailwindContentInitRule(rule) {
|
|
2084
|
+
const selectors = rule.selectors ?? [rule.selector];
|
|
2085
|
+
if (selectors.length === 0 || !selectors.every((selector) => {
|
|
2086
|
+
const normalized = normalizeCssSignatureValue(selector);
|
|
2087
|
+
return hasVueScopedAttr(selector) && MINI_PROGRAM_PREFLIGHT_SELECTORS.has(normalized);
|
|
2088
|
+
})) return false;
|
|
2089
|
+
const declarations = rule.nodes?.filter((node) => node.type === "decl") ?? [];
|
|
2090
|
+
return declarations.length > 0 && declarations.every((decl) => decl.prop === "--tw-content");
|
|
2091
|
+
}
|
|
2016
2092
|
function hasUnscopedMiniProgramTailwindPreflightRule(css) {
|
|
2017
2093
|
return /(?:^|[{}])\s*view\s*,\s*text\s*,\s*::after\s*,\s*::before\s*\{/.test(css);
|
|
2018
2094
|
}
|
|
2095
|
+
function hasScopedMiniProgramTailwindContentInitRule(css) {
|
|
2096
|
+
return /(?:^|[{}])[^{}]*\.data-v-[\w-][^{}]*\{\s*--tw-content\s*:/.test(css);
|
|
2097
|
+
}
|
|
2019
2098
|
function collectRootScopedComparableCssCoverage(cssSources) {
|
|
2020
2099
|
const rules = /* @__PURE__ */ new Set();
|
|
2021
2100
|
const atRules = /* @__PURE__ */ new Set();
|
|
@@ -2052,14 +2131,15 @@ function isRuleCoveredByRootCss(rule, coverage) {
|
|
|
2052
2131
|
return declarationKeys.length > 0 && selectors.every((selector) => {
|
|
2053
2132
|
const rootDeclarations = coverage.declarationsBySelector.get(normalizeCssSignatureValue(selector));
|
|
2054
2133
|
return rootDeclarations != null && declarationKeys.every((declaration) => rootDeclarations.has(declaration));
|
|
2055
|
-
})
|
|
2134
|
+
});
|
|
2056
2135
|
}
|
|
2057
2136
|
function removeScopedCssCoveredByRootStyleSources(css, rootSources) {
|
|
2058
2137
|
if (!hasVueScopedAttr(css)) return css;
|
|
2059
2138
|
const hasScopedTailwindGeneratedCss = /tailwindcss v\d/i.test(css);
|
|
2060
2139
|
const hasUnscopedMiniProgramPreflight = hasUnscopedMiniProgramTailwindPreflightRule(css);
|
|
2140
|
+
const hasScopedMiniProgramContentInit = hasScopedMiniProgramTailwindContentInitRule(css);
|
|
2061
2141
|
const coverage = collectRootScopedComparableCssCoverage(rootSources);
|
|
2062
|
-
if (coverage.rules.size === 0 && coverage.atRules.size === 0 && !hasScopedTailwindGeneratedCss && !hasUnscopedMiniProgramPreflight) return css;
|
|
2142
|
+
if (coverage.rules.size === 0 && coverage.atRules.size === 0 && !hasScopedTailwindGeneratedCss && !hasUnscopedMiniProgramPreflight && !hasScopedMiniProgramContentInit) return css;
|
|
2063
2143
|
try {
|
|
2064
2144
|
const root = postcss.parse(css);
|
|
2065
2145
|
let changed = false;
|
|
@@ -2070,7 +2150,7 @@ function removeScopedCssCoveredByRootStyleSources(css, rootSources) {
|
|
|
2070
2150
|
}
|
|
2071
2151
|
});
|
|
2072
2152
|
root.walkRules((rule) => {
|
|
2073
|
-
if (isRuleCoveredByRootCss(rule, coverage) || hasScopedTailwindGeneratedCss && isLikelyTailwindGlobalRule(rule) || isUnscopedMiniProgramTailwindPreflightRule(rule)) {
|
|
2153
|
+
if (isRuleCoveredByRootCss(rule, coverage) || hasScopedTailwindGeneratedCss && isLikelyTailwindGlobalRule(rule) || isUnscopedMiniProgramTailwindPreflightRule(rule) || isScopedMiniProgramTailwindContentInitRule(rule)) {
|
|
2074
2154
|
rule.remove();
|
|
2075
2155
|
changed = true;
|
|
2076
2156
|
}
|
|
@@ -2204,6 +2284,7 @@ function shouldUseCssAssetAsMainInjectionTarget(opts, file, records, options, bu
|
|
|
2204
2284
|
}) === true && !isMiniProgramStyleOutputFile(file) && matchedRootWebOutputTargets.length > 0) return matchedRootWebOutputTargets.includes(fileKey);
|
|
2205
2285
|
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));
|
|
2206
2286
|
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));
|
|
2287
|
+
const explicitStyleOutputTargets = records.filter((record) => record.injectIntoMain === true).map((record) => typeof record.outputFile === "string" ? normalizeOutputPathKey(record.outputFile) : void 0).filter((outputFile) => typeof outputFile === "string" && isRootStyleOutputFile(outputFile));
|
|
2207
2288
|
if (context !== void 0 && options.cssPipelineStrategy?.shouldPreferExplicitWebCssTargets?.({
|
|
2208
2289
|
...context,
|
|
2209
2290
|
explicitRootTargets,
|
|
@@ -2213,12 +2294,25 @@ function shouldUseCssAssetAsMainInjectionTarget(opts, file, records, options, bu
|
|
|
2213
2294
|
if (explicitRootTargets.length > 0) return explicitRootTargets.includes(fileKey);
|
|
2214
2295
|
if (records.some((record) => {
|
|
2215
2296
|
if (record.injectIntoMain !== true) return false;
|
|
2297
|
+
if (explicitStyleOutputTargets.length > 0) return explicitStyleOutputTargets.includes(fileKey) || isRootStyleOutputFile(file) && isViteProcessedRootStyleImportingTargets(bundle, file, explicitStyleOutputTargets) || isRootStyleOutputFile(file) && opts.mainCssChunkMatcher(file, opts.appType) && explicitStyleOutputTargets.some((outputFile) => opts.mainCssChunkMatcher(outputFile, opts.appType));
|
|
2216
2298
|
return isRootStyleOutputFile(file) || typeof record.outputFile === "string" && normalizeOutputPathKey(record.outputFile) === fileKey;
|
|
2217
2299
|
})) return true;
|
|
2218
|
-
if (records.some((record) => record.injectIntoMain === true))
|
|
2300
|
+
if (records.some((record) => record.injectIntoMain === true)) {
|
|
2301
|
+
const matchedExplicitMiniProgramTargets = explicitStyleOutputTargets.filter((outputFile) => isMiniProgramStyleOutputFile(outputFile) && opts.mainCssChunkMatcher(outputFile, opts.appType));
|
|
2302
|
+
if (matchedExplicitMiniProgramTargets.length > 0) return matchedExplicitMiniProgramTargets.includes(fileKey);
|
|
2303
|
+
return isRootStyleOutputFile(file) && isMiniProgramStyleOutputFile(file);
|
|
2304
|
+
}
|
|
2219
2305
|
if (opts.mainCssChunkMatcher(file, opts.appType)) return true;
|
|
2220
2306
|
return isRootStyleOutputFile(file) && records.some((record) => record.injectIntoMain === true);
|
|
2221
2307
|
}
|
|
2308
|
+
function isViteProcessedRootStyleImportingTargets(bundle, file, targetFiles) {
|
|
2309
|
+
const targetFileSet = new Set(targetFiles.map(normalizeOutputPathKey));
|
|
2310
|
+
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2311
|
+
if (output.type !== "asset" || normalizeOutputPathKey(getAssetFile$1(bundleFile, output)) !== normalizeOutputPathKey(file)) continue;
|
|
2312
|
+
return [...collectImportedStyleFiles(readAssetSource$2(output), file)].some((importedFile) => targetFileSet.has(normalizeOutputPathKey(importedFile)));
|
|
2313
|
+
}
|
|
2314
|
+
return false;
|
|
2315
|
+
}
|
|
2222
2316
|
function isViteProcessedCssResultImported(record, importedStyleFiles) {
|
|
2223
2317
|
return importedStyleFiles.has(normalizeOutputPathKey(record.file)) || typeof record.outputFile === "string" && importedStyleFiles.has(normalizeOutputPathKey(record.outputFile));
|
|
2224
2318
|
}
|
|
@@ -2262,7 +2356,84 @@ function removeCssCoveredByImportedViteResults(css, importedCssSources) {
|
|
|
2262
2356
|
if (importedCssSources.length === 0) return css;
|
|
2263
2357
|
const importedCss = importedCssSources.map((source) => stripBundlerGeneratedCssMarkers(source).trim()).filter(Boolean).join("\n");
|
|
2264
2358
|
if (importedCss.length === 0) return css;
|
|
2265
|
-
return
|
|
2359
|
+
return restoreCssImportAtRules(css, removeCssRulesCoveredBySources(css, [importedCss], { exactOnly: true }));
|
|
2360
|
+
}
|
|
2361
|
+
function removeCssRulesCoveredBySources(css, sources, options = {}) {
|
|
2362
|
+
if (sources.length === 0 || css.trim().length === 0) return css;
|
|
2363
|
+
const coverage = collectRootScopedComparableCssCoverage(sources);
|
|
2364
|
+
const coveredRuleCss = collectNormalizedRuleCss(sources);
|
|
2365
|
+
if (coverage.rules.size === 0 && coverage.declarationsBySelector.size === 0 && coveredRuleCss.size === 0) return css;
|
|
2366
|
+
try {
|
|
2367
|
+
const root = postcss.parse(css);
|
|
2368
|
+
let changed = false;
|
|
2369
|
+
root.walkRules((rule) => {
|
|
2370
|
+
if (!coveredRuleCss.has(normalizeCssSignatureValue(rule.toString())) && (options.exactOnly === true || !isRuleCoveredByRootCss(rule, coverage))) return;
|
|
2371
|
+
rule.remove();
|
|
2372
|
+
changed = true;
|
|
2373
|
+
});
|
|
2374
|
+
return changed ? root.toString() : css;
|
|
2375
|
+
} catch {
|
|
2376
|
+
return css;
|
|
2377
|
+
}
|
|
2378
|
+
}
|
|
2379
|
+
function collectNormalizedRuleCss(sources) {
|
|
2380
|
+
const rules = /* @__PURE__ */ new Set();
|
|
2381
|
+
for (const source of sources) try {
|
|
2382
|
+
postcss.parse(source).walkRules((rule) => {
|
|
2383
|
+
rules.add(normalizeCssSignatureValue(rule.toString()));
|
|
2384
|
+
});
|
|
2385
|
+
} catch {}
|
|
2386
|
+
return rules;
|
|
2387
|
+
}
|
|
2388
|
+
function collectCssImportAtRuleCss(css) {
|
|
2389
|
+
if (!css.includes("@import")) return [];
|
|
2390
|
+
const fallbackImports = [...css.matchAll(/@import\s[^;]+;?/g)].map((match) => match[0]);
|
|
2391
|
+
if (fallbackImports.length > 0) return fallbackImports;
|
|
2392
|
+
try {
|
|
2393
|
+
const root = postcss.parse(css);
|
|
2394
|
+
const imports = [];
|
|
2395
|
+
root.each((node) => {
|
|
2396
|
+
if (node.type === "atrule" && node.name === "import") imports.push(node.toString());
|
|
2397
|
+
});
|
|
2398
|
+
return imports;
|
|
2399
|
+
} catch {
|
|
2400
|
+
return [];
|
|
2401
|
+
}
|
|
2402
|
+
}
|
|
2403
|
+
function parseCssImportRequest(importCss) {
|
|
2404
|
+
const trimmed = importCss.trim();
|
|
2405
|
+
if (!trimmed.startsWith("@import")) return;
|
|
2406
|
+
return parseTailwindCssDirectiveRequest(trimmed.slice(7).trim().replace(/;$/, "").trim());
|
|
2407
|
+
}
|
|
2408
|
+
function shouldRestoreCssImportAtRule(importCss, file) {
|
|
2409
|
+
if (file === void 0 || !isMiniProgramStyleOutputFile(file)) return true;
|
|
2410
|
+
const request = parseCssImportRequest(importCss);
|
|
2411
|
+
if (request === void 0) return false;
|
|
2412
|
+
if (isMiniProgramLocalCssImportRequest(request)) return true;
|
|
2413
|
+
return isStyleImportRequest(request) && !request.includes("/");
|
|
2414
|
+
}
|
|
2415
|
+
function restoreCssImportAtRules(source, filtered, file) {
|
|
2416
|
+
const imports = collectCssImportAtRuleCss(source).filter((importCss) => shouldRestoreCssImportAtRule(importCss, file));
|
|
2417
|
+
if (imports.length === 0) return filtered;
|
|
2418
|
+
const missingImports = imports.filter((importCss) => !filtered.includes(importCss));
|
|
2419
|
+
if (missingImports.length === 0) return filtered;
|
|
2420
|
+
return appendCss$1(missingImports.join("\n"), filtered);
|
|
2421
|
+
}
|
|
2422
|
+
function removeCommentOnlyAtRules(css) {
|
|
2423
|
+
if (!css.includes("@")) return css;
|
|
2424
|
+
try {
|
|
2425
|
+
const root = postcss.parse(css);
|
|
2426
|
+
let changed = false;
|
|
2427
|
+
root.walkAtRules((atRule) => {
|
|
2428
|
+
if (!atRule.nodes || atRule.nodes.length === 0) return;
|
|
2429
|
+
if (atRule.nodes.some((node) => node.type !== "comment")) return;
|
|
2430
|
+
atRule.remove();
|
|
2431
|
+
changed = true;
|
|
2432
|
+
});
|
|
2433
|
+
return changed ? root.toString() : css;
|
|
2434
|
+
} catch {
|
|
2435
|
+
return css;
|
|
2436
|
+
}
|
|
2266
2437
|
}
|
|
2267
2438
|
function collectImportedBundleCssSources(bundle, importedStyleFiles) {
|
|
2268
2439
|
if (importedStyleFiles.size === 0) return [];
|
|
@@ -2477,8 +2648,9 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
2477
2648
|
}
|
|
2478
2649
|
const fileKey = normalizeOutputPathKey(file);
|
|
2479
2650
|
const mainFileKey = normalizeOutputPathKey(file);
|
|
2480
|
-
|
|
2481
|
-
|
|
2651
|
+
const normalizedOriginalCss = normalizeInjectableCssForTargetWithImports(transformCss(removeTailwindEntryDirectivesFromCss(originalSource), file), file);
|
|
2652
|
+
let nextCss = normalizedOriginalCss.css;
|
|
2653
|
+
const importedStyleFiles = normalizedOriginalCss.importedStyleFiles;
|
|
2482
2654
|
const importedBundleCssSources = collectImportedBundleCssSources(bundle, importedStyleFiles);
|
|
2483
2655
|
nextCss = removeCssCoveredByImportedViteResults(nextCss, importedBundleCssSources);
|
|
2484
2656
|
const importedViteCssResults = viteCssResults.filter((record) => isViteProcessedCssResultImported(record, importedStyleFiles));
|
|
@@ -2494,7 +2666,7 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
2494
2666
|
if (!shouldInjectViteProcessedCssResult(options.opts, mainFileKey, record.file, record)) continue;
|
|
2495
2667
|
if (isViteProcessedCssResultImported(record, importedStyleFiles)) continue;
|
|
2496
2668
|
targetViteCssResults.push(record);
|
|
2497
|
-
let css = stripBundlerGeneratedCssMarkers(record.css).trim();
|
|
2669
|
+
let css = normalizeInjectableCssForTarget(stripBundlerGeneratedCssMarkers(record.css).trim(), file).trim();
|
|
2498
2670
|
css = removeCssCoveredByImportedViteResults(css, importedCssSources).trim();
|
|
2499
2671
|
if (css.length === 0) continue;
|
|
2500
2672
|
const mergedLayerCss = mergeMarkedUserLayerComponentsCss(nextCss, css);
|
|
@@ -2527,7 +2699,9 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
2527
2699
|
if (missingCss.length === 0 || !hasNonCommentCss(missingCss) || containsCssAfterMinify(nextCss, missingCss)) continue;
|
|
2528
2700
|
nextCss = appendCss$1(nextCss, missingCss);
|
|
2529
2701
|
}
|
|
2530
|
-
|
|
2702
|
+
const finalImportedCssSources = collectImportedBundleCssSources(bundle, collectImportedStyleFiles(originalSource, file));
|
|
2703
|
+
nextCss = transformCss(removeCommentOnlyAtRules(restoreCssImportAtRules(originalSource, removeCssRulesCoveredBySources(nextCss, finalImportedCssSources, { exactOnly: true }).trim(), file)), file);
|
|
2704
|
+
if (nextCss.trim() === originalSource.trim()) nextCss = originalSource;
|
|
2531
2705
|
if (nextCss !== originalSource) {
|
|
2532
2706
|
output.source = nextCss;
|
|
2533
2707
|
options.markCssAssetProcessed?.(output, file);
|
|
@@ -2812,14 +2986,15 @@ function getAssetFile(bundleFile, asset) {
|
|
|
2812
2986
|
return asset.fileName || bundleFile;
|
|
2813
2987
|
}
|
|
2814
2988
|
function finalizeWebviewCssCompat(bundle, options) {
|
|
2815
|
-
|
|
2989
|
+
const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(options.opts.generator);
|
|
2990
|
+
if (generatorOptions.webCompat === false) return 0;
|
|
2816
2991
|
let transformed = 0;
|
|
2817
2992
|
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2818
2993
|
if (output.type !== "asset") continue;
|
|
2819
2994
|
const file = getAssetFile(bundleFile, output);
|
|
2820
2995
|
if (!options.opts.cssMatcher(file) || !/\.css(?:$|[?#])/i.test(file)) continue;
|
|
2821
2996
|
const rawSource = readAssetSource(output);
|
|
2822
|
-
const nextCss = transformWebCssSafeSelectors(transformWebCssCompat(rawSource,
|
|
2997
|
+
const nextCss = transformWebCssSafeSelectors(transformWebCssCompat(rawSource, generatorOptions.webCompat ?? true), { escapeMap: options.opts.escapeMap });
|
|
2823
2998
|
if (nextCss === rawSource) continue;
|
|
2824
2999
|
output.source = nextCss;
|
|
2825
3000
|
options.recordCssAssetResult?.(file, nextCss);
|
|
@@ -3279,7 +3454,7 @@ function resolveUniAppXStyleIsolationEnabled(root) {
|
|
|
3279
3454
|
//#region src/uni-app-x/vite.ts
|
|
3280
3455
|
let transformUVuePromise;
|
|
3281
3456
|
function loadTransformUVue() {
|
|
3282
|
-
transformUVuePromise ?? (transformUVuePromise = import("./transform-
|
|
3457
|
+
transformUVuePromise ?? (transformUVuePromise = import("./transform-BgnNYkIG.mjs").then((mod) => mod.transformUVue));
|
|
3283
3458
|
return transformUVuePromise;
|
|
3284
3459
|
}
|
|
3285
3460
|
const preprocessorLangs = /* @__PURE__ */ new Set([
|
|
@@ -3737,7 +3912,7 @@ function collectRememberedCssReplayGroups(sources, opts, rootDir, isWebGenerator
|
|
|
3737
3912
|
//#endregion
|
|
3738
3913
|
//#region src/bundlers/vite/generate-bundle/remembered-css-replay.ts
|
|
3739
3914
|
async function processRememberedCssReplay(options) {
|
|
3740
|
-
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;
|
|
3915
|
+
const { addWatchFile, activeViteCssCacheFiles, bundleFiles, cache, changedCssFiles = /* @__PURE__ */ new Set(), createScopedGeneratorRuntime, createScopedSourceCandidateGetter, createScopedSourceCandidateSourceGetter, cssTaskFactories, debug, defaultStyleOutputExtension, emitOrReplayCssAsset, generatorRuntime, generatorPlatform, getCssHandlerOptions, getCssUserHandlerOptions, getRememberedCssSignature, getRememberedCssSources, isNativeAppStyleTarget, isWebGeneratorTarget, lastCssRawSourceHashByFile = /* @__PURE__ */ new Map(), lastCssResultByFile, lastCssSourceHashByFile, markCssAssetProcessed, metrics, normalizeViteCssCacheKey, onUpdate, opts, recordCssAssetResult, recordViteProcessedCssAssetResult, refreshRememberedCssSource, rootDir, runtimeState, setRememberedCssSignature, shouldInjectCssIntoMainFromOutput, shouldPreserveAppCssExtension, sourceRoot, styleHandler, timeTask, useIncrementalMode } = options;
|
|
3741
3916
|
const rememberedReplayGroups = collectRememberedCssReplayGroups(getRememberedCssSources?.(), opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension, sourceRoot, defaultStyleOutputExtension, bundleFiles);
|
|
3742
3917
|
for (const [outputFile, rememberedGroup] of rememberedReplayGroups) {
|
|
3743
3918
|
if (isHTMLRequest(outputFile) || options.opts.htmlMatcher(outputFile)) continue;
|
|
@@ -3749,6 +3924,7 @@ async function processRememberedCssReplay(options) {
|
|
|
3749
3924
|
const rememberedCssSource = mergeRememberedCssSources(refreshedRememberedGroup.map((item) => item.remembered), outputFile);
|
|
3750
3925
|
if (!rememberedCssSource) continue;
|
|
3751
3926
|
const { rawSource, sourceFile } = rememberedCssSource;
|
|
3927
|
+
const generatorRawSource = isWebGeneratorTarget ? rawSource : normalizeMiniProgramGeneratorCssSource(rawSource, outputFile);
|
|
3752
3928
|
activeViteCssCacheFiles.add(normalizeViteCssCacheKey(outputFile));
|
|
3753
3929
|
activeViteCssCacheFiles.add(normalizeViteCssCacheKey(sourceFile));
|
|
3754
3930
|
const outputCssHandlerOptions = getCssHandlerOptions(outputFile);
|
|
@@ -3758,17 +3934,21 @@ async function processRememberedCssReplay(options) {
|
|
|
3758
3934
|
};
|
|
3759
3935
|
const scopedSourceCandidateGetter = createScopedSourceCandidateGetter(outputFile, cssHandlerOptions);
|
|
3760
3936
|
const scopedSourceCandidateSourceGetter = createScopedSourceCandidateSourceGetter(outputFile, cssHandlerOptions);
|
|
3761
|
-
const scopedGeneratorRuntime = await createScopedGeneratorRuntime(outputFile, cssHandlerOptions, generatorRuntime,
|
|
3762
|
-
const cssRuntimeSignature = createCssRuntimeSignature(createCandidateSignature(scopedGeneratorRuntime), await createScopedGeneratorCandidateSignature(
|
|
3937
|
+
const scopedGeneratorRuntime = await createScopedGeneratorRuntime(outputFile, cssHandlerOptions, generatorRuntime, generatorRawSource, sourceFile);
|
|
3938
|
+
const cssRuntimeSignature = createCssRuntimeSignature(createCandidateSignature(scopedGeneratorRuntime), await createScopedGeneratorCandidateSignature(generatorRawSource, sourceFile, createCandidateSignature(scopedGeneratorRuntime), scopedSourceCandidateGetter, {
|
|
3763
3939
|
includeFallbackSignature: cssHandlerOptions.isMainChunk,
|
|
3764
3940
|
majorVersion: runtimeState.tailwindRuntime.majorVersion
|
|
3765
3941
|
}));
|
|
3766
3942
|
const cssRuntimeAffectingHash = cache.computeHash(createRuntimeAffectingSourceSignature(rawSource, "css"));
|
|
3767
3943
|
const rememberedCssRuntimeSignature = createRememberedCssRuntimeSignature(cssRuntimeSignature, cssRuntimeAffectingHash);
|
|
3768
|
-
const
|
|
3944
|
+
const rawSourceHash = cache.computeHash(rawSource);
|
|
3945
|
+
const previousRawSourceHash = lastCssRawSourceHashByFile.get(outputFile);
|
|
3946
|
+
const cssSourceChanged = changedCssFiles.has(outputFile) || changedCssFiles.has(sourceFile) || previousRawSourceHash != null && previousRawSourceHash !== rawSourceHash;
|
|
3947
|
+
const previousCss = useIncrementalMode && !cssSourceChanged && getLastCssSourceHash(lastCssSourceHashByFile, outputFile) === cssRuntimeAffectingHash ? getLastCssResult(lastCssResultByFile, outputFile) : void 0;
|
|
3769
3948
|
const allRememberedSignaturesFresh = rememberedKeys.length > 0 && rememberedKeys.every((key) => getRememberedCssSignature?.(key) === rememberedCssRuntimeSignature);
|
|
3770
3949
|
if (bundleFiles.includes(outputFile) || bundleFiles.includes(sourceFile) || allRememberedSignaturesFresh) continue;
|
|
3771
|
-
const
|
|
3950
|
+
const sourceTraceSources = scopedSourceCandidateSourceGetter ? await createScopedGeneratorSourceTraceMap(generatorRawSource, sourceFile, scopedSourceCandidateSourceGetter) : void 0;
|
|
3951
|
+
const sourceTraceTokenSources = sourceTraceSources ? createCssTokenSourceMap(sourceTraceSources, opts) : void 0;
|
|
3772
3952
|
const annotateCss = (css) => annotateCssSourceTrace(css, {
|
|
3773
3953
|
opts,
|
|
3774
3954
|
tokenSources: sourceTraceTokenSources
|
|
@@ -3776,13 +3956,32 @@ async function processRememberedCssReplay(options) {
|
|
|
3776
3956
|
const shouldRecordRememberedReplayCss = useIncrementalMode || isNativeAppStyleTarget;
|
|
3777
3957
|
const shouldEmitRememberedReplayCssAsset = shouldRecordRememberedReplayCss;
|
|
3778
3958
|
if (!shouldRecordRememberedReplayCss) continue;
|
|
3959
|
+
if (!isWebGeneratorTarget && isPureLocalCssImportWrapper(rawSource)) {
|
|
3960
|
+
cssTaskFactories.push(() => timeTask("css.replay", async () => {
|
|
3961
|
+
const start = performance.now();
|
|
3962
|
+
const css = annotateCss(normalizeMiniProgramImportShell(rawSource));
|
|
3963
|
+
lastCssRawSourceHashByFile.set(outputFile, rawSourceHash);
|
|
3964
|
+
rememberLastCssResult(lastCssResultByFile, lastCssSourceHashByFile, outputFile, css, cssRuntimeAffectingHash);
|
|
3965
|
+
for (const key of rememberedKeys) setRememberedCssSignature?.(key, rememberedCssRuntimeSignature);
|
|
3966
|
+
recordCssAssetResult?.(outputFile, css);
|
|
3967
|
+
if (shouldEmitRememberedReplayCssAsset) {
|
|
3968
|
+
const replayAsset = emitOrReplayCssAsset(outputFile, css);
|
|
3969
|
+
if (replayAsset) markCssAssetProcessed?.(replayAsset, outputFile);
|
|
3970
|
+
}
|
|
3971
|
+
metrics.css.elapsed += measureElapsed(start);
|
|
3972
|
+
metrics.css.transformed++;
|
|
3973
|
+
onUpdate(outputFile, rawSource, css);
|
|
3974
|
+
debug("css replay preserve local import shell: %s", outputFile);
|
|
3975
|
+
}));
|
|
3976
|
+
continue;
|
|
3977
|
+
}
|
|
3779
3978
|
cssTaskFactories.push(() => timeTask("css.replay", async () => {
|
|
3780
3979
|
const start = performance.now();
|
|
3781
3980
|
const generated = await generateTailwindV4Css({
|
|
3782
3981
|
opts,
|
|
3783
3982
|
runtimeState,
|
|
3784
3983
|
runtime: scopedGeneratorRuntime,
|
|
3785
|
-
rawSource,
|
|
3984
|
+
rawSource: generatorRawSource,
|
|
3786
3985
|
file: sourceFile,
|
|
3787
3986
|
outputFile,
|
|
3788
3987
|
cssHandlerOptions,
|
|
@@ -3793,7 +3992,8 @@ async function processRememberedCssReplay(options) {
|
|
|
3793
3992
|
debug,
|
|
3794
3993
|
previousCss
|
|
3795
3994
|
});
|
|
3796
|
-
const css = annotateCss(generated?.css ?? (await styleHandler(
|
|
3995
|
+
const css = annotateCss(generated?.css ?? (await styleHandler(generatorRawSource, cssHandlerOptions)).css);
|
|
3996
|
+
lastCssRawSourceHashByFile.set(outputFile, rawSourceHash);
|
|
3797
3997
|
rememberLastCssResult(lastCssResultByFile, lastCssSourceHashByFile, outputFile, css, cssRuntimeAffectingHash);
|
|
3798
3998
|
for (const key of rememberedKeys) setRememberedCssSignature?.(key, rememberedCssRuntimeSignature);
|
|
3799
3999
|
if (generated) {
|
|
@@ -3804,6 +4004,10 @@ async function processRememberedCssReplay(options) {
|
|
|
3804
4004
|
injectIntoMain: outputCssHandlerOptions.isMainChunk ? false : shouldInjectReplayCssIntoMain,
|
|
3805
4005
|
outputFile
|
|
3806
4006
|
});
|
|
4007
|
+
if (outputFile !== sourceFile) recordViteProcessedCssAssetResult?.(outputFile, css, {
|
|
4008
|
+
injectIntoMain: outputCssHandlerOptions.isMainChunk ? false : shouldInjectReplayCssIntoMain,
|
|
4009
|
+
outputFile
|
|
4010
|
+
});
|
|
3807
4011
|
debug("css replay generated result: %s bytes=%d", outputFile, css.length);
|
|
3808
4012
|
}
|
|
3809
4013
|
if (shouldEmitRememberedReplayCssAsset) {
|
|
@@ -4062,37 +4266,119 @@ function createStableTextSignature(input) {
|
|
|
4062
4266
|
}
|
|
4063
4267
|
return (hash >>> 0).toString(36);
|
|
4064
4268
|
}
|
|
4269
|
+
function parseQuotedRequest(params) {
|
|
4270
|
+
const input = params.trim();
|
|
4271
|
+
const quote = input[0];
|
|
4272
|
+
if (quote !== "\"" && quote !== "'") return;
|
|
4273
|
+
let escaped = false;
|
|
4274
|
+
for (let index = 1; index < input.length; index++) {
|
|
4275
|
+
const char = input[index];
|
|
4276
|
+
if (escaped) {
|
|
4277
|
+
escaped = false;
|
|
4278
|
+
continue;
|
|
4279
|
+
}
|
|
4280
|
+
if (char === "\\") {
|
|
4281
|
+
escaped = true;
|
|
4282
|
+
continue;
|
|
4283
|
+
}
|
|
4284
|
+
if (char === quote) return input.slice(1, index);
|
|
4285
|
+
}
|
|
4286
|
+
}
|
|
4287
|
+
function parseSourceParams(params) {
|
|
4288
|
+
let input = params.trim();
|
|
4289
|
+
let negated = false;
|
|
4290
|
+
if (input.startsWith("not ")) {
|
|
4291
|
+
negated = true;
|
|
4292
|
+
input = input.slice(4).trim();
|
|
4293
|
+
}
|
|
4294
|
+
if (input.startsWith("inline(") && input.endsWith(")")) return {
|
|
4295
|
+
prefix: negated ? "source:inline:not" : "source:inline",
|
|
4296
|
+
value: input.slice(7, -1).trim()
|
|
4297
|
+
};
|
|
4298
|
+
const request = parseQuotedRequest(input);
|
|
4299
|
+
if (!request) return;
|
|
4300
|
+
return {
|
|
4301
|
+
prefix: negated ? "source:not" : "source",
|
|
4302
|
+
value: request
|
|
4303
|
+
};
|
|
4304
|
+
}
|
|
4305
|
+
function parseTailwindImportSource(params) {
|
|
4306
|
+
if (parseQuotedRequest(params) !== "tailwindcss") return;
|
|
4307
|
+
return /\bsource\(([^)]*)\)/.exec(params)?.[1]?.trim();
|
|
4308
|
+
}
|
|
4309
|
+
function hasExplicitTailwindV4Directive(source) {
|
|
4310
|
+
try {
|
|
4311
|
+
let found = false;
|
|
4312
|
+
postcss.parse(source).walkAtRules((rule) => {
|
|
4313
|
+
if (rule.name === "config" || rule.name === "source" || rule.name === "plugin" || rule.name === "custom-variant" || rule.name === "theme" || rule.name === "utility" || rule.name === "variant" || rule.name === "apply") {
|
|
4314
|
+
found = true;
|
|
4315
|
+
return false;
|
|
4316
|
+
}
|
|
4317
|
+
});
|
|
4318
|
+
return found;
|
|
4319
|
+
} catch {
|
|
4320
|
+
return false;
|
|
4321
|
+
}
|
|
4322
|
+
}
|
|
4065
4323
|
function collectTailwindV4SourceFingerprint(source) {
|
|
4066
4324
|
const tokens = /* @__PURE__ */ new Set();
|
|
4067
4325
|
const add = (prefix, value) => {
|
|
4068
4326
|
tokens.add(`${prefix}:${value.trim()}`);
|
|
4069
4327
|
};
|
|
4070
|
-
for (const match of source.matchAll(/@config\s+(["'])(.+?)\1\s*;?/g)) {
|
|
4071
|
-
const configRequest = match[2];
|
|
4072
|
-
add("config", path.basename(configRequest));
|
|
4073
|
-
add("config-request", configRequest.replace(/\\/g, "/"));
|
|
4074
|
-
}
|
|
4075
|
-
for (const match of source.matchAll(/@source\s+(not\s+)?(["'])(.+?)\2\s*;?/g)) add(match[1] ? "source:not" : "source", match[3]);
|
|
4076
|
-
for (const match of source.matchAll(/@plugin\s+(["'])(.+?)\1\s*(?:\{([\s\S]*?)\}|;)/g)) {
|
|
4077
|
-
const request = match[2];
|
|
4078
|
-
const optionBlock = match[3];
|
|
4079
|
-
add("plugin", request);
|
|
4080
|
-
add("plugin-request", request.replace(/\\/g, "/"));
|
|
4081
|
-
if (optionBlock !== void 0) add("plugin-options", `${request}:${createStableTextSignature(optionBlock)}`);
|
|
4082
|
-
}
|
|
4083
4328
|
try {
|
|
4084
|
-
postcss.parse(source)
|
|
4085
|
-
|
|
4086
|
-
if (
|
|
4087
|
-
|
|
4088
|
-
add("
|
|
4089
|
-
|
|
4329
|
+
const root = postcss.parse(source);
|
|
4330
|
+
root.walkAtRules((rule) => {
|
|
4331
|
+
if (rule.name === "import") {
|
|
4332
|
+
const sourceMode = parseTailwindImportSource(rule.params);
|
|
4333
|
+
if (sourceMode) add("import-source", sourceMode);
|
|
4334
|
+
return;
|
|
4335
|
+
}
|
|
4336
|
+
if (rule.name === "config") {
|
|
4337
|
+
const configRequest = parseQuotedRequest(rule.params);
|
|
4338
|
+
if (configRequest) {
|
|
4339
|
+
add("config", path.basename(configRequest));
|
|
4340
|
+
add("config-request", configRequest.replace(/\\/g, "/"));
|
|
4341
|
+
}
|
|
4342
|
+
return;
|
|
4343
|
+
}
|
|
4344
|
+
if (rule.name === "source") {
|
|
4345
|
+
const parsed = parseSourceParams(rule.params);
|
|
4346
|
+
if (parsed) add(parsed.prefix, parsed.value);
|
|
4347
|
+
return;
|
|
4348
|
+
}
|
|
4349
|
+
if (rule.name === "plugin") {
|
|
4350
|
+
const request = parseQuotedRequest(rule.params);
|
|
4351
|
+
if (!request) return;
|
|
4352
|
+
add("plugin", request);
|
|
4353
|
+
add("plugin-request", request.replace(/\\/g, "/"));
|
|
4354
|
+
if (rule.nodes?.length) {
|
|
4355
|
+
add("plugin-options", `${request}:${createStableTextSignature(rule.toString())}`);
|
|
4356
|
+
rule.walkDecls((decl) => {
|
|
4357
|
+
add("plugin-option", `${request}:${decl.prop}:${decl.value}`);
|
|
4358
|
+
});
|
|
4359
|
+
}
|
|
4360
|
+
return;
|
|
4361
|
+
}
|
|
4362
|
+
if (rule.name === "custom-variant") {
|
|
4363
|
+
const [name] = rule.params.trim().split(/\s+/, 1);
|
|
4364
|
+
if (name) add("custom-variant", name);
|
|
4365
|
+
return;
|
|
4366
|
+
}
|
|
4367
|
+
if (rule.name === "theme" || rule.name === "utility" || rule.name === "variant" || rule.name === "layer") {
|
|
4368
|
+
const [name] = rule.params.trim().split(/\s+/, 1);
|
|
4369
|
+
if (name) add("directive", name);
|
|
4370
|
+
}
|
|
4371
|
+
});
|
|
4372
|
+
root.walkDecls((decl) => {
|
|
4373
|
+
if (decl.prop.startsWith("--")) add("theme-token", decl.prop);
|
|
4374
|
+
});
|
|
4375
|
+
root.walkRules((rule) => {
|
|
4376
|
+
for (const selector of rule.selectors ?? []) {
|
|
4377
|
+
const match = /\.([_a-z][\w-]*)/i.exec(selector);
|
|
4378
|
+
if (match?.[1]) add("selector", match[1]);
|
|
4379
|
+
}
|
|
4090
4380
|
});
|
|
4091
4381
|
} catch {}
|
|
4092
|
-
for (const match of source.matchAll(/@custom-variant\s+([^{\s]+)/g)) add("custom-variant", match[1]);
|
|
4093
|
-
for (const match of source.matchAll(/@(?:theme|utility|variant|layer)\s+([^{;\s]+)/g)) add("directive", match[1]);
|
|
4094
|
-
for (const match of source.matchAll(/--[\w-]+(?=\s*:)/g)) add("theme-token", match[0]);
|
|
4095
|
-
for (const match of source.matchAll(/\.([_a-z][\w-]*)\s*[{,]/gi)) add("selector", match[1]);
|
|
4096
4382
|
return tokens;
|
|
4097
4383
|
}
|
|
4098
4384
|
function scoreConfiguredTailwindV4SourceForRawSource(rawSource, entrySource) {
|
|
@@ -4108,7 +4394,7 @@ function selectTailwindV4GenerationCssSourceForOutput(outputFile, entries, rawSo
|
|
|
4108
4394
|
const generationSources = entries.filter((entry) => hasTailwindGenerationSource(entry.source));
|
|
4109
4395
|
if (generationSources.length <= 1) return generationSources[0];
|
|
4110
4396
|
const canMatchByOutputPath = Boolean(options.cwd || options.outputRoot || options.projectRoot);
|
|
4111
|
-
const selectByOutputPath = (candidates) => {
|
|
4397
|
+
const selectByOutputPath = (candidates, shouldUseScore = (score) => score > 0) => {
|
|
4112
4398
|
if (!canMatchByOutputPath) return;
|
|
4113
4399
|
const scoredSources = candidates.map((entry) => ({
|
|
4114
4400
|
entry,
|
|
@@ -4117,7 +4403,7 @@ function selectTailwindV4GenerationCssSourceForOutput(outputFile, entries, rawSo
|
|
|
4117
4403
|
outputRoot: options.outputRoot,
|
|
4118
4404
|
projectRoot: options.projectRoot
|
|
4119
4405
|
})
|
|
4120
|
-
})).filter((item) => item.score
|
|
4406
|
+
})).filter((item) => shouldUseScore(item.score)).sort((a, b) => b.score - a.score);
|
|
4121
4407
|
const bestScore = scoredSources[0]?.score;
|
|
4122
4408
|
const bestSources = bestScore ? scoredSources.filter((item) => item.score === bestScore) : [];
|
|
4123
4409
|
return bestSources.length === 1 ? bestSources[0]?.entry : void 0;
|
|
@@ -4131,10 +4417,12 @@ function selectTailwindV4GenerationCssSourceForOutput(outputFile, entries, rawSo
|
|
|
4131
4417
|
const bestSources = bestScore ? scoredSources.filter((item) => item.score === bestScore) : [];
|
|
4132
4418
|
return bestSources.length === 1 ? bestSources[0]?.entry : void 0;
|
|
4133
4419
|
};
|
|
4420
|
+
const explicitSources = generationSources.filter((entry) => hasExplicitTailwindV4Directive(entry.source));
|
|
4421
|
+
const candidates = explicitSources.length === 1 ? explicitSources : generationSources;
|
|
4422
|
+
const directoryIndexOutputPathMatched = selectByOutputPath(candidates, (score) => score >= 25e3 && score < 5e4);
|
|
4423
|
+
if (directoryIndexOutputPathMatched) return directoryIndexOutputPathMatched;
|
|
4134
4424
|
const rawSourceMatched = selectByRawSourceFingerprint(generationSources);
|
|
4135
4425
|
if (rawSourceMatched) return rawSourceMatched;
|
|
4136
|
-
const explicitSources = generationSources.filter((entry) => /@(?:config|source|plugin|custom-variant|theme|utility|variant|apply)\b/.test(entry.source));
|
|
4137
|
-
const candidates = explicitSources.length === 1 ? explicitSources : generationSources;
|
|
4138
4426
|
const outputPathMatched = selectByOutputPath(candidates);
|
|
4139
4427
|
if (outputPathMatched) return outputPathMatched;
|
|
4140
4428
|
if (candidates.length === 1) return candidates[0];
|
|
@@ -4153,8 +4441,7 @@ function createTemporaryCssAssetSourceResolver(entries) {
|
|
|
4153
4441
|
const seenEntryFiles = /* @__PURE__ */ new Set();
|
|
4154
4442
|
const queuedEntries = entries.filter((entry) => {
|
|
4155
4443
|
const entryFile = normalizeCssSourceKey(entry.file);
|
|
4156
|
-
|
|
4157
|
-
if (outputFile === entryFile || !outputFile.includes("/") || seenEntryFiles.has(entryFile)) return false;
|
|
4444
|
+
if (normalizeCssSourceKey(entry.outputFile) === entryFile || seenEntryFiles.has(entryFile)) return false;
|
|
4158
4445
|
seenEntryFiles.add(entryFile);
|
|
4159
4446
|
return true;
|
|
4160
4447
|
});
|
|
@@ -4167,14 +4454,18 @@ function createTemporaryCssAssetSourceResolver(entries) {
|
|
|
4167
4454
|
},
|
|
4168
4455
|
resolve(outputFile, rawSource) {
|
|
4169
4456
|
if (!isTemporaryCssAssetFile(outputFile)) return;
|
|
4170
|
-
const
|
|
4457
|
+
const outputFileKey = normalizeCssSourceKey(outputFile);
|
|
4458
|
+
const unusedEntries = queuedEntries.filter((item) => !usedEntryFiles.has(normalizeCssSourceKey(item.file)));
|
|
4459
|
+
const matchedOutputEntries = unusedEntries.filter((item) => normalizeCssSourceKey(item.outputFile) === outputFileKey);
|
|
4460
|
+
const usesMatchedOutputEntries = matchedOutputEntries.length > 0;
|
|
4461
|
+
const availableEntries = matchedOutputEntries.length > 0 ? matchedOutputEntries : unusedEntries.filter((item) => normalizeCssSourceKey(item.outputFile).includes("/"));
|
|
4171
4462
|
const scoredEntries = rawSource ? availableEntries.map((entry) => ({
|
|
4172
4463
|
entry,
|
|
4173
4464
|
score: scoreConfiguredTailwindV4SourceForRawSource(rawSource, entry.source)
|
|
4174
4465
|
})).filter((item) => item.score > 0).sort((a, b) => b.score - a.score) : [];
|
|
4175
4466
|
const bestScore = scoredEntries[0]?.score;
|
|
4176
4467
|
const bestEntries = bestScore ? scoredEntries.filter((item) => item.score === bestScore) : [];
|
|
4177
|
-
const entry = bestEntries.length === 1 ? bestEntries[0]?.entry : availableEntries.find((item) => hasTailwindGenerationSource(item.source));
|
|
4468
|
+
const entry = bestEntries.length === 1 ? bestEntries[0]?.entry : usesMatchedOutputEntries || rawSource == null ? availableEntries.find((item) => hasTailwindGenerationSource(item.source)) : void 0;
|
|
4178
4469
|
if (!entry) return;
|
|
4179
4470
|
usedEntryFiles.add(normalizeCssSourceKey(entry.file));
|
|
4180
4471
|
return {
|
|
@@ -4348,6 +4639,19 @@ function resolveSourceRootFromBundleGraph(config, bundle) {
|
|
|
4348
4639
|
return sourceRoots.size === 1 ? [...sourceRoots][0] : void 0;
|
|
4349
4640
|
}
|
|
4350
4641
|
//#endregion
|
|
4642
|
+
//#region src/bundlers/vite/web-css-compat.ts
|
|
4643
|
+
/**
|
|
4644
|
+
* Web target 的 Tailwind 兼容转换由 generator-css 负责;Vite 外层只处理非 Web 生成目标
|
|
4645
|
+
* 落到 WebView 产物时的最终兼容需求,避免同一份 CSS 在 dev/build 中被重复解析转换。
|
|
4646
|
+
*/
|
|
4647
|
+
function shouldApplyViteWebCssCompat(context, strategy) {
|
|
4648
|
+
if (strategy?.shouldApplyWebCssCompat?.(context) !== true) return false;
|
|
4649
|
+
return !context.currentGeneratorBranch.isWeb || context.currentGeneratorOptions.webCompat !== void 0;
|
|
4650
|
+
}
|
|
4651
|
+
function resolveViteWebCssCompatOptions(context) {
|
|
4652
|
+
return context.currentGeneratorBranch.isWeb ? context.currentGeneratorOptions.webCompat : context.currentGeneratorOptions.webCompat ?? true;
|
|
4653
|
+
}
|
|
4654
|
+
//#endregion
|
|
4351
4655
|
//#region src/bundlers/vite/generate-bundle.ts
|
|
4352
4656
|
function inferPlatformFromViteOutDir$1(outDir) {
|
|
4353
4657
|
const segment = outDir ? path.basename(path.normalize(outDir)) : void 0;
|
|
@@ -4359,6 +4663,7 @@ function createGenerateBundleHook(context) {
|
|
|
4359
4663
|
const state = createBundleBuildState();
|
|
4360
4664
|
const lastCssResultByFile = /* @__PURE__ */ new Map();
|
|
4361
4665
|
const lastCssSourceHashByFile = /* @__PURE__ */ new Map();
|
|
4666
|
+
const lastCssRawSourceHashByFile = /* @__PURE__ */ new Map();
|
|
4362
4667
|
let currentOutDir;
|
|
4363
4668
|
let currentSubpackageRoots;
|
|
4364
4669
|
const createInitialCssPipelineContext = (file) => {
|
|
@@ -4431,14 +4736,14 @@ function createGenerateBundleHook(context) {
|
|
|
4431
4736
|
resolveStylePlatform: () => generatorPlatform
|
|
4432
4737
|
};
|
|
4433
4738
|
const isWebGeneratorTarget = generatorBranch.isWeb;
|
|
4434
|
-
const shouldApplyWebCssCompat = context.cssPipelineStrategy
|
|
4739
|
+
const shouldApplyWebCssCompat = shouldApplyViteWebCssCompat(cssPipelineContext, context.cssPipelineStrategy);
|
|
4435
4740
|
const transformWebTargetCss = (css) => {
|
|
4436
4741
|
return context.cssPipelineStrategy?.transformGeneratedCss?.(css, {
|
|
4437
4742
|
...cssPipelineContext,
|
|
4438
|
-
defaultWebCssCompat: (value) => transformWebCssCompat(value,
|
|
4743
|
+
defaultWebCssCompat: (value) => transformWebCssCompat(value, resolveViteWebCssCompatOptions(cssPipelineContext)),
|
|
4439
4744
|
removeScopedPreflight: (value) => value,
|
|
4440
4745
|
shouldApplyWebCssCompat
|
|
4441
|
-
}) ?? (shouldApplyWebCssCompat ? transformWebCssCompat(css,
|
|
4746
|
+
}) ?? (shouldApplyWebCssCompat ? transformWebCssCompat(css, resolveViteWebCssCompatOptions(cssPipelineContext)) : css);
|
|
4442
4747
|
};
|
|
4443
4748
|
const isNativeAppStyleTarget = context.cssPipelineStrategy?.isNativeAppStyleTarget?.(cssPipelineContext) === true;
|
|
4444
4749
|
const isHarmonyAppStyleTarget = context.cssPipelineStrategy?.isHarmonyAppStyleTarget?.(cssPipelineContext) === true;
|
|
@@ -4449,6 +4754,9 @@ function createGenerateBundleHook(context) {
|
|
|
4449
4754
|
const sourceRoot = resolveWeappViteSourceRoot(resolvedConfig, opts.appType) ?? resolveSourceRootFromBundleGraph(resolvedConfig, bundle);
|
|
4450
4755
|
const outDir = resolvedConfig?.build?.outDir ? path.resolve(rootDir, resolvedConfig.build.outDir) : rootDir;
|
|
4451
4756
|
const defaultStyleOutputExtension = resolveMiniProgramStyleOutputExtension({ files: Object.keys(bundle) });
|
|
4757
|
+
const normalizeMiniProgramGeneratorRawSource = (source, outputFile) => {
|
|
4758
|
+
return isWebGeneratorTarget ? source : normalizeMiniProgramGeneratorCssSource(source, outputFile);
|
|
4759
|
+
};
|
|
4452
4760
|
await runtimeState.readyPromise;
|
|
4453
4761
|
debug("start");
|
|
4454
4762
|
onStart();
|
|
@@ -4474,7 +4782,7 @@ function createGenerateBundleHook(context) {
|
|
|
4474
4782
|
timingDetails[name] = (timingDetails[name] ?? 0) + Math.max(0, performance.now() - startedAt);
|
|
4475
4783
|
};
|
|
4476
4784
|
const timeTask = createBundleTaskTimer(recordTimingDetail);
|
|
4477
|
-
const emitOrReplayCssAsset = createCssAssetEmitter(this);
|
|
4785
|
+
const emitOrReplayCssAsset = createCssAssetEmitter(this, bundle);
|
|
4478
4786
|
const metrics = createEmptyMetrics();
|
|
4479
4787
|
const envFlags = resolveGenerateBundleEnvFlags();
|
|
4480
4788
|
const bundleFiles = Object.keys(bundle);
|
|
@@ -4541,15 +4849,20 @@ function createGenerateBundleHook(context) {
|
|
|
4541
4849
|
});
|
|
4542
4850
|
};
|
|
4543
4851
|
const resolveConfiguredTailwindV4CssEntryOutputFile = (sourceFile) => resolveViteCssPipelineOutputFile(sourceFile, opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension, sourceRoot, defaultStyleOutputExtension, bundleFiles);
|
|
4544
|
-
const
|
|
4545
|
-
|
|
4546
|
-
|
|
4547
|
-
if (!(context.cssPipelineStrategy?.shouldSelectConfiguredCssEntryRootSource?.({
|
|
4852
|
+
const shouldSelectConfiguredRootCssOutput = (outputFile) => {
|
|
4853
|
+
if (!opts.cssMatcher(outputFile) || !isRootStyleOutputFile(outputFile)) return false;
|
|
4854
|
+
return context.cssPipelineStrategy?.shouldSelectConfiguredCssEntryRootSource?.({
|
|
4548
4855
|
...cssPipelineContext,
|
|
4549
4856
|
isRootStyleOutputFile,
|
|
4550
4857
|
outputFile
|
|
4551
|
-
}) === true || cssPipelineContext.currentGeneratorBranch.isWeb
|
|
4552
|
-
|
|
4858
|
+
}) === true || cssPipelineContext.currentGeneratorBranch.isWeb;
|
|
4859
|
+
};
|
|
4860
|
+
const selectConfiguredRootCssSourceEntry = (outputFile, entries, originalFileNames) => {
|
|
4861
|
+
const matchedOriginalEntry = entries.find((entry) => originalFileNames?.some((originalFile) => normalizeConfiguredTailwindV4CssEntryFileKey(originalFile) === normalizeConfiguredTailwindV4CssEntryFileKey(entry.file)) === true);
|
|
4862
|
+
if (matchedOriginalEntry && outputFile.replace(/[?#].*$/, "").endsWith(".css")) return matchedOriginalEntry;
|
|
4863
|
+
if (!shouldSelectConfiguredRootCssOutput(outputFile)) return;
|
|
4864
|
+
const shouldRequireExplicitConfiguredEntry = !cssPipelineContext.currentGeneratorBranch.isWeb && opts.cssMatcher(outputFile) && isRootStyleOutputFile(outputFile);
|
|
4865
|
+
const generationEntries = entries.filter((entry) => hasTailwindGenerationSource(entry.source) && (!shouldRequireExplicitConfiguredEntry || configuredTailwindV4ExplicitCssEntryFileKeysForScope.has(normalizeConfiguredTailwindV4CssEntryFileKey(entry.file))));
|
|
4553
4866
|
if (generationEntries.length <= 1) return generationEntries[0];
|
|
4554
4867
|
const rootOutputEntries = generationEntries.filter((entry) => {
|
|
4555
4868
|
return !normalizeOutputPathKey(resolveConfiguredTailwindV4CssEntryOutputFile(entry.file).replace(/[?#].*$/, "")).includes("/");
|
|
@@ -4562,6 +4875,35 @@ function createGenerateBundleHook(context) {
|
|
|
4562
4875
|
if (mainPackageEntries.length === 1) return mainPackageEntries[0];
|
|
4563
4876
|
}
|
|
4564
4877
|
};
|
|
4878
|
+
const resolveConfiguredRootCssSourceStyle = (outputFile, entries, originalFileNames) => {
|
|
4879
|
+
const entry = selectConfiguredRootCssSourceEntry(outputFile, entries, originalFileNames);
|
|
4880
|
+
return entry ? {
|
|
4881
|
+
outputFile,
|
|
4882
|
+
rawSource: entry.source,
|
|
4883
|
+
sourceFile: entry.file
|
|
4884
|
+
} : void 0;
|
|
4885
|
+
};
|
|
4886
|
+
const shouldKeepCurrentRootMiniProgramStyleOutputAsImportShell = (outputFile, css) => {
|
|
4887
|
+
const normalizedOutputFile = normalizeOutputPathKey(outputFile.replace(/[?#].*$/, ""));
|
|
4888
|
+
return opts.cssMatcher(outputFile) && isMiniProgramStyleOutputFile(outputFile) && !normalizedOutputFile.includes("/") && shouldKeepRootMiniProgramStyleAsImportShell(context.cssPipelineStrategy?.shouldKeepRootMiniProgramStyleAsImportShell?.({
|
|
4889
|
+
...cssPipelineContext,
|
|
4890
|
+
css,
|
|
4891
|
+
file: outputFile
|
|
4892
|
+
}));
|
|
4893
|
+
};
|
|
4894
|
+
const shouldKeepCurrentRootCssOutputForConfiguredSource = (sourceFile, outputFile) => {
|
|
4895
|
+
const normalizedOutputFile = normalizeOutputPathKey(outputFile.replace(/[?#].*$/, ""));
|
|
4896
|
+
const isRootConfiguredStyleOutput = normalizedOutputFile.endsWith(".css") ? isRootStyleOutputFile(outputFile) : isMiniProgramStyleOutputFile(outputFile) && !normalizedOutputFile.includes("/");
|
|
4897
|
+
return typeof sourceFile === "string" && opts.cssMatcher(outputFile) && isRootConfiguredStyleOutput && !shouldKeepCurrentRootMiniProgramStyleOutputAsImportShell(outputFile) && configuredTailwindV4ExplicitCssEntryFileKeysForScope.has(normalizeConfiguredTailwindV4CssEntryFileKey(sourceFile));
|
|
4898
|
+
};
|
|
4899
|
+
const hasExplicitConfiguredRootCssEntryForOutput = (outputFile) => {
|
|
4900
|
+
if (cssPipelineContext.currentGeneratorBranch.isWeb || !opts.cssMatcher(outputFile) || !isRootStyleOutputFile(outputFile) || !shouldSelectConfiguredRootCssOutput(outputFile)) return false;
|
|
4901
|
+
return configuredTailwindV4CssSourceEntriesForScope.some((entry) => {
|
|
4902
|
+
if (!configuredTailwindV4ExplicitCssEntryFileKeysForScope.has(normalizeConfiguredTailwindV4CssEntryFileKey(entry.file))) return false;
|
|
4903
|
+
const entryOutputFile = resolveConfiguredTailwindV4CssEntryOutputFile(entry.file);
|
|
4904
|
+
return !normalizeOutputPathKey(entryOutputFile.replace(/[?#].*$/, "")).includes("/") || currentSubpackageRoots != null && !isSubpackageOutputFile(entryOutputFile, currentSubpackageRoots);
|
|
4905
|
+
});
|
|
4906
|
+
};
|
|
4565
4907
|
const { createScopedSourceCandidateGetter, createScopedSourceCandidateSourceGetter, shouldExcludeSubpackageSourceCandidates, shouldInjectCssIntoMainFromOutput } = createSubpackageSourceCandidateScope({
|
|
4566
4908
|
cssSourceFiles: configuredTailwindV4CssSourceEntriesForScope.map((entry) => entry.file),
|
|
4567
4909
|
getSourceCandidateSourcesForEntries,
|
|
@@ -4624,6 +4966,7 @@ function createGenerateBundleHook(context) {
|
|
|
4624
4966
|
if (mainCssEntry) {
|
|
4625
4967
|
const mainCssRawSource = typeof mainCssEntry.output.source === "string" ? mainCssEntry.output.source : Buffer.from(mainCssEntry.output.source).toString();
|
|
4626
4968
|
if (!hasTailwindApplyDirective(mainCssRawSource)) {
|
|
4969
|
+
const validationRawSource = normalizeMiniProgramGeneratorRawSource(mainCssRawSource, mainCssEntry.file);
|
|
4627
4970
|
const generatedCssSources = /* @__PURE__ */ new Set();
|
|
4628
4971
|
for (const [, record] of getViteProcessedCssAssetResults?.() ?? []) if (typeof record === "string") generatedCssSources.add(record);
|
|
4629
4972
|
else if (typeof record?.css === "string") generatedCssSources.add(record.css);
|
|
@@ -4631,7 +4974,7 @@ function createGenerateBundleHook(context) {
|
|
|
4631
4974
|
opts,
|
|
4632
4975
|
runtimeState,
|
|
4633
4976
|
candidates: filteredSourceCandidates,
|
|
4634
|
-
rawSource:
|
|
4977
|
+
rawSource: validationRawSource,
|
|
4635
4978
|
generatedCssSources,
|
|
4636
4979
|
file: mainCssEntry.file,
|
|
4637
4980
|
cssHandlerOptions: getCssHandlerOptions(mainCssEntry.file),
|
|
@@ -4649,6 +4992,9 @@ function createGenerateBundleHook(context) {
|
|
|
4649
4992
|
const cssExtensionByStem = collectCssExtensionByStem(bundleFiles, opts.cssMatcher);
|
|
4650
4993
|
const jsImportedCssFiles = collectJsImportedCssFiles(snapshot);
|
|
4651
4994
|
const runtimeLinkedCssFiles = /* @__PURE__ */ new Set([...collectRuntimeLinkedCssFiles(snapshot, cssExtensionByStem, defaultStyleOutputExtension), ...jsImportedCssFiles]);
|
|
4995
|
+
const shouldQueueTemporaryCssSourceEntry = (sourceFile, outputFile) => {
|
|
4996
|
+
return normalizeOutputPathKey(outputFile).includes("/") || typeof sourceFile === "string" && shouldSelectConfiguredRootCssOutput(outputFile) && configuredTailwindV4ExplicitCssEntryFileKeysForScope.has(normalizeConfiguredTailwindV4CssEntryFileKey(sourceFile));
|
|
4997
|
+
};
|
|
4652
4998
|
rememberRuntimeLinkedCssSources({
|
|
4653
4999
|
bundleFiles,
|
|
4654
5000
|
debug,
|
|
@@ -4671,7 +5017,7 @@ function createGenerateBundleHook(context) {
|
|
|
4671
5017
|
...[...runtimeLinkedCssFiles].filter((file) => !snapshot.sourceHashByFile.has(file)).map((file) => {
|
|
4672
5018
|
const outputFile = resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension, sourceRoot, defaultStyleOutputExtension, bundleFiles);
|
|
4673
5019
|
const inferredSourceStyle = resolveSourceStyleSourceFromOutputFile(outputFile, snapshot, outDir, sourceRoot, getCssSource, jsImportedCssFiles.has(file) ? getSourceCandidateSources : void 0, getConfiguredTailwindV4CssSourceEntries().map((entry) => [entry.file, entry.source]), debug);
|
|
4674
|
-
return inferredSourceStyle && currentSubpackageRoots ? {
|
|
5020
|
+
return inferredSourceStyle && currentSubpackageRoots && shouldQueueTemporaryCssSourceEntry(inferredSourceStyle.sourceFile, outputFile) ? {
|
|
4675
5021
|
file: inferredSourceStyle.sourceFile,
|
|
4676
5022
|
outputFile,
|
|
4677
5023
|
source: inferredSourceStyle.rawSource
|
|
@@ -4681,10 +5027,11 @@ function createGenerateBundleHook(context) {
|
|
|
4681
5027
|
file: remembered.sourceFile,
|
|
4682
5028
|
outputFile: remembered.outputFile,
|
|
4683
5029
|
source: remembered.rawSource
|
|
4684
|
-
})),
|
|
5030
|
+
})).filter((entry) => shouldQueueTemporaryCssSourceEntry(entry.file, entry.outputFile)),
|
|
4685
5031
|
...getConfiguredTailwindV4CssSourceEntries().map((entry) => {
|
|
4686
5032
|
const outputFile = resolveMatchedCssSourceOutputFile(entry.file);
|
|
4687
|
-
|
|
5033
|
+
const isExplicitConfiguredEntry = configuredTailwindV4ExplicitCssEntryFileKeysForScope.has(normalizeConfiguredTailwindV4CssEntryFileKey(entry.file));
|
|
5034
|
+
return outputFile && (normalizeOutputPathKey(outputFile).includes("/") || isExplicitConfiguredEntry && shouldSelectConfiguredRootCssOutput(outputFile)) ? {
|
|
4688
5035
|
file: entry.file,
|
|
4689
5036
|
outputFile,
|
|
4690
5037
|
source: entry.source
|
|
@@ -4861,6 +5208,7 @@ function createGenerateBundleHook(context) {
|
|
|
4861
5208
|
return await refreshRememberedCssSource?.(remembered) ?? remembered;
|
|
4862
5209
|
}));
|
|
4863
5210
|
rememberedCssSources = rememberedCssSources.filter((remembered) => {
|
|
5211
|
+
if (hasExplicitConfiguredRootCssEntryForOutput(outputFile) && !configuredTailwindV4ExplicitCssEntryFileKeysForScope.has(normalizeConfiguredTailwindV4CssEntryFileKey(remembered.sourceFile))) return false;
|
|
4864
5212
|
if (!configuredTailwindV4CssSourceFileKeysForScope.has(normalizeConfiguredTailwindV4CssEntryFileKey(remembered.sourceFile))) return true;
|
|
4865
5213
|
const matchedOutputFile = resolveMatchedOutputFileForCurrentAsset(remembered.sourceFile);
|
|
4866
5214
|
return !matchedOutputFile || normalizeOutputPathKey(matchedOutputFile) === normalizeOutputPathKey(outputFile);
|
|
@@ -4877,10 +5225,17 @@ function createGenerateBundleHook(context) {
|
|
|
4877
5225
|
hasUsableRememberedTailwindSource = false;
|
|
4878
5226
|
}
|
|
4879
5227
|
let outputCssHandlerOptions = getCssHandlerOptions(outputFile);
|
|
4880
|
-
|
|
5228
|
+
const configuredRootSourceStyle = resolveConfiguredRootCssSourceStyle(outputFile, getConfiguredTailwindV4CssSourceEntries(), originalSource.originalFileNames);
|
|
5229
|
+
const hasExplicitRememberedRootSource = rememberedCssSources.some((remembered) => configuredTailwindV4ExplicitCssEntryFileKeysForScope.has(normalizeConfiguredTailwindV4CssEntryFileKey(remembered.sourceFile)));
|
|
5230
|
+
if (configuredRootSourceStyle && (!hasUsableRememberedTailwindSource || !hasExplicitRememberedRootSource)) {
|
|
5231
|
+
rememberedCssSources = [configuredRootSourceStyle];
|
|
5232
|
+
hasUsableRememberedTailwindSource = true;
|
|
5233
|
+
debug("source style source inferred from configured root tailwind v4 css source: %s -> %s", outputFile, configuredRootSourceStyle.sourceFile);
|
|
5234
|
+
}
|
|
5235
|
+
if (!hasUsableRememberedTailwindSource && isTemporaryCssAssetFile(outputFile) && hasTailwindGenerationSource(rawSource)) {
|
|
4881
5236
|
const resolvedTemporarySource = temporaryCssAssetSourceResolver.resolve(outputFile, rawSource);
|
|
4882
5237
|
if (resolvedTemporarySource) {
|
|
4883
|
-
outputFile = resolveMatchedOutputFileForCurrentAsset(resolvedTemporarySource.sourceFile) ?? resolvedTemporarySource.outputFile;
|
|
5238
|
+
outputFile = shouldKeepCurrentRootCssOutputForConfiguredSource(resolvedTemporarySource.sourceFile, outputFile) ? outputFile : resolveMatchedOutputFileForCurrentAsset(resolvedTemporarySource.sourceFile) ?? resolvedTemporarySource.outputFile;
|
|
4884
5239
|
activeViteCssCacheFiles.add(normalizeViteCssCacheKey(outputFile));
|
|
4885
5240
|
outputCssHandlerOptions = getCssHandlerOptions(outputFile);
|
|
4886
5241
|
outputCssHandlerOptions = {
|
|
@@ -4900,50 +5255,19 @@ function createGenerateBundleHook(context) {
|
|
|
4900
5255
|
}
|
|
4901
5256
|
if (!hasUsableRememberedTailwindSource) {
|
|
4902
5257
|
const configuredTailwindV4CssSourceEntries = getConfiguredTailwindV4CssSourceEntries();
|
|
4903
|
-
const
|
|
4904
|
-
|
|
4905
|
-
|
|
4906
|
-
outputFile,
|
|
4907
|
-
rawSource: inferredWebviewRootSourceEntry.source,
|
|
4908
|
-
sourceFile: inferredWebviewRootSourceEntry.file
|
|
4909
|
-
} : void 0;
|
|
4910
|
-
const inferredOriginalSourceStyle = inferredSourceStyle ?? (outputFile === file ? void 0 : resolveSourceStyleSourceFromOutputFile(file, snapshot, outDir, sourceRoot, getCssSource, getSourceCandidateSources, configuredTailwindV4CssSourceEntries.map((entry) => [entry.file, entry.source]), debug)) ?? inferredWebviewRootSourceStyle;
|
|
4911
|
-
if (inferredOriginalSourceStyle) {
|
|
4912
|
-
outputFile = resolveMatchedOutputFileForCurrentAsset(inferredOriginalSourceStyle.sourceFile) ?? outputFile;
|
|
4913
|
-
activeViteCssCacheFiles.add(normalizeViteCssCacheKey(outputFile));
|
|
4914
|
-
outputCssHandlerOptions = getCssHandlerOptions(outputFile);
|
|
4915
|
-
rememberedCssSources = [{
|
|
4916
|
-
...inferredOriginalSourceStyle,
|
|
4917
|
-
outputFile
|
|
4918
|
-
}];
|
|
4919
|
-
} else if (isTemporaryCssAssetFile(outputFile) && configuredTailwindV4CssSourceEntries.length > 1) {
|
|
4920
|
-
const resolvedTemporarySource = temporaryCssAssetSourceResolver.resolve(outputFile, rawSource);
|
|
4921
|
-
if (resolvedTemporarySource) {
|
|
4922
|
-
outputFile = resolveMatchedOutputFileForCurrentAsset(resolvedTemporarySource.sourceFile) ?? resolvedTemporarySource.outputFile;
|
|
4923
|
-
activeViteCssCacheFiles.add(normalizeViteCssCacheKey(outputFile));
|
|
4924
|
-
outputCssHandlerOptions = getCssHandlerOptions(outputFile);
|
|
4925
|
-
outputCssHandlerOptions = {
|
|
4926
|
-
...outputCssHandlerOptions,
|
|
4927
|
-
isMainChunk: false
|
|
4928
|
-
};
|
|
4929
|
-
resolvedFromTemporaryCssAsset = true;
|
|
4930
|
-
usedConfiguredTailwindV4CssSourceFiles.add(normalizeOutputPathKey(resolvedTemporarySource.sourceFile));
|
|
4931
|
-
rememberedCssSources = [{
|
|
4932
|
-
outputFile,
|
|
4933
|
-
rawSource: resolvedTemporarySource.rawSource,
|
|
4934
|
-
sourceFile: resolvedTemporarySource.sourceFile
|
|
4935
|
-
}];
|
|
4936
|
-
debug("source style source inferred from temporary configured tailwind v4 css source: %s -> %s", outputFile, resolvedTemporarySource.sourceFile);
|
|
4937
|
-
}
|
|
4938
|
-
} else if (hasTailwindGenerationSource(rawSource) && (originalSource.originalFileNames?.length ?? 0) === 0) {
|
|
4939
|
-
const availableConfiguredTailwindV4CssSourceEntries = configuredTailwindV4CssSourceEntries.filter((entry) => !usedConfiguredTailwindV4CssSourceFiles.has(normalizeOutputPathKey(entry.file)));
|
|
4940
|
-
const configuredGenerationSource = selectTailwindV4GenerationCssSourceForOutput(outputFile, availableConfiguredTailwindV4CssSourceEntries, rawSource, {
|
|
5258
|
+
const isCurrentRootMiniProgramStyleOutput = opts.cssMatcher(outputFile) && isMiniProgramStyleOutputFile(outputFile) && !normalizeOutputPathKey(outputFile.replace(/[?#].*$/, "")).includes("/");
|
|
5259
|
+
if (isCurrentRootMiniProgramStyleOutput && hasTailwindGenerationSource(rawSource)) {
|
|
5260
|
+
const configuredGenerationSource = selectTailwindV4GenerationCssSourceForOutput(outputFile, configuredTailwindV4CssSourceEntries, rawSource, {
|
|
4941
5261
|
cwd: opts.tailwindcssBasedir,
|
|
4942
5262
|
outputRoot: outDir,
|
|
4943
5263
|
projectRoot: sourceRoot ?? rootDir
|
|
4944
5264
|
});
|
|
4945
|
-
|
|
4946
|
-
|
|
5265
|
+
const configuredGenerationOutputFile = configuredGenerationSource ? shouldKeepCurrentRootMiniProgramStyleOutputAsImportShell(outputFile, rawSource) ? resolveMatchedOutputFileForCurrentAsset(configuredGenerationSource.file) ?? outputFile : outputFile : void 0;
|
|
5266
|
+
const hasConfiguredGenerationSourceAlreadyUsed = configuredGenerationSource ? usedConfiguredTailwindV4CssSourceFiles.has(normalizeOutputPathKey(configuredGenerationSource.file)) : false;
|
|
5267
|
+
const hasConfiguredGenerationSourceAlreadyProcessed = configuredGenerationSource ? hasViteProcessedCssResultForSource(configuredGenerationSource.file, getViteProcessedCssAssetResults) : false;
|
|
5268
|
+
const shouldUseConfiguredGenerationSource = configuredGenerationSource && (!hasConfiguredGenerationSourceAlreadyUsed && !hasConfiguredGenerationSourceAlreadyProcessed || normalizeOutputPathKey(configuredGenerationOutputFile ?? outputFile) === normalizeOutputPathKey(outputFile));
|
|
5269
|
+
if (configuredGenerationSource && shouldUseConfiguredGenerationSource) {
|
|
5270
|
+
outputFile = configuredGenerationOutputFile ?? outputFile;
|
|
4947
5271
|
activeViteCssCacheFiles.add(normalizeViteCssCacheKey(outputFile));
|
|
4948
5272
|
outputCssHandlerOptions = getCssHandlerOptions(outputFile);
|
|
4949
5273
|
usedConfiguredTailwindV4CssSourceFiles.add(normalizeOutputPathKey(configuredGenerationSource.file));
|
|
@@ -4952,9 +5276,70 @@ function createGenerateBundleHook(context) {
|
|
|
4952
5276
|
rawSource: configuredGenerationSource.source,
|
|
4953
5277
|
sourceFile: configuredGenerationSource.file
|
|
4954
5278
|
}];
|
|
5279
|
+
hasUsableRememberedTailwindSource = true;
|
|
4955
5280
|
debug("source style source inferred from scoped configured tailwind v4 css source: %s -> %s", outputFile, configuredGenerationSource.file);
|
|
4956
5281
|
}
|
|
4957
5282
|
}
|
|
5283
|
+
if (!hasUsableRememberedTailwindSource) {
|
|
5284
|
+
const inferredSourceStyle = resolveSourceStyleSourceFromOutputFile(outputFile, snapshot, outDir, sourceRoot, getCssSource, getSourceCandidateSources, configuredTailwindV4CssSourceEntries.map((entry) => [entry.file, entry.source]), debug);
|
|
5285
|
+
const inferredWebviewRootSourceEntry = inferredSourceStyle ? void 0 : selectConfiguredRootCssSourceEntry(outputFile, configuredTailwindV4CssSourceEntries, originalSource.originalFileNames);
|
|
5286
|
+
const inferredWebviewRootSourceStyle = inferredWebviewRootSourceEntry ? {
|
|
5287
|
+
outputFile,
|
|
5288
|
+
rawSource: inferredWebviewRootSourceEntry.source,
|
|
5289
|
+
sourceFile: inferredWebviewRootSourceEntry.file
|
|
5290
|
+
} : void 0;
|
|
5291
|
+
const inferredOriginalSourceStyle = inferredSourceStyle ?? (outputFile === file ? void 0 : resolveSourceStyleSourceFromOutputFile(file, snapshot, outDir, sourceRoot, getCssSource, getSourceCandidateSources, configuredTailwindV4CssSourceEntries.map((entry) => [entry.file, entry.source]), debug)) ?? inferredWebviewRootSourceStyle;
|
|
5292
|
+
if (inferredOriginalSourceStyle) {
|
|
5293
|
+
const matchedOutputFile = normalizeOutputPathKey(inferredOriginalSourceStyle.outputFile) === normalizeOutputPathKey(outputFile) ? outputFile : resolveMatchedOutputFileForCurrentAsset(inferredOriginalSourceStyle.sourceFile) ?? outputFile;
|
|
5294
|
+
debug("source style output resolved: %s -> %s from %s", outputFile, matchedOutputFile, inferredOriginalSourceStyle.sourceFile);
|
|
5295
|
+
outputFile = matchedOutputFile;
|
|
5296
|
+
activeViteCssCacheFiles.add(normalizeViteCssCacheKey(outputFile));
|
|
5297
|
+
outputCssHandlerOptions = getCssHandlerOptions(outputFile);
|
|
5298
|
+
rememberedCssSources = [{
|
|
5299
|
+
...inferredOriginalSourceStyle,
|
|
5300
|
+
outputFile
|
|
5301
|
+
}];
|
|
5302
|
+
} else if (isTemporaryCssAssetFile(outputFile) && configuredTailwindV4CssSourceEntries.length > 1) {
|
|
5303
|
+
const resolvedTemporarySource = temporaryCssAssetSourceResolver.resolve(outputFile, rawSource);
|
|
5304
|
+
if (resolvedTemporarySource) {
|
|
5305
|
+
outputFile = shouldKeepCurrentRootCssOutputForConfiguredSource(resolvedTemporarySource.sourceFile, outputFile) ? outputFile : resolveMatchedOutputFileForCurrentAsset(resolvedTemporarySource.sourceFile) ?? resolvedTemporarySource.outputFile;
|
|
5306
|
+
activeViteCssCacheFiles.add(normalizeViteCssCacheKey(outputFile));
|
|
5307
|
+
outputCssHandlerOptions = getCssHandlerOptions(outputFile);
|
|
5308
|
+
outputCssHandlerOptions = {
|
|
5309
|
+
...outputCssHandlerOptions,
|
|
5310
|
+
isMainChunk: false
|
|
5311
|
+
};
|
|
5312
|
+
resolvedFromTemporaryCssAsset = true;
|
|
5313
|
+
usedConfiguredTailwindV4CssSourceFiles.add(normalizeOutputPathKey(resolvedTemporarySource.sourceFile));
|
|
5314
|
+
rememberedCssSources = [{
|
|
5315
|
+
outputFile,
|
|
5316
|
+
rawSource: resolvedTemporarySource.rawSource,
|
|
5317
|
+
sourceFile: resolvedTemporarySource.sourceFile
|
|
5318
|
+
}];
|
|
5319
|
+
debug("source style source inferred from temporary configured tailwind v4 css source: %s -> %s", outputFile, resolvedTemporarySource.sourceFile);
|
|
5320
|
+
}
|
|
5321
|
+
} else if (!isCurrentRootMiniProgramStyleOutput && hasTailwindGenerationSource(rawSource) && (originalSource.originalFileNames?.length ?? 0) === 0) {
|
|
5322
|
+
const availableConfiguredTailwindV4CssSourceEntries = configuredTailwindV4CssSourceEntries.filter((entry) => !usedConfiguredTailwindV4CssSourceFiles.has(normalizeOutputPathKey(entry.file)));
|
|
5323
|
+
const configuredGenerationSource = selectTailwindV4GenerationCssSourceForOutput(outputFile, availableConfiguredTailwindV4CssSourceEntries, rawSource, {
|
|
5324
|
+
cwd: opts.tailwindcssBasedir,
|
|
5325
|
+
outputRoot: outDir,
|
|
5326
|
+
projectRoot: sourceRoot ?? rootDir
|
|
5327
|
+
});
|
|
5328
|
+
if (configuredGenerationSource && !hasViteProcessedCssResultForSource(configuredGenerationSource.file, getViteProcessedCssAssetResults)) {
|
|
5329
|
+
outputFile = resolveMatchedOutputFileForCurrentAsset(configuredGenerationSource.file) ?? outputFile;
|
|
5330
|
+
activeViteCssCacheFiles.add(normalizeViteCssCacheKey(outputFile));
|
|
5331
|
+
outputCssHandlerOptions = getCssHandlerOptions(outputFile);
|
|
5332
|
+
usedConfiguredTailwindV4CssSourceFiles.add(normalizeOutputPathKey(configuredGenerationSource.file));
|
|
5333
|
+
rememberedCssSources = [{
|
|
5334
|
+
outputFile,
|
|
5335
|
+
rawSource: configuredGenerationSource.source,
|
|
5336
|
+
sourceFile: configuredGenerationSource.file
|
|
5337
|
+
}];
|
|
5338
|
+
hasUsableRememberedTailwindSource = true;
|
|
5339
|
+
debug("source style source inferred from scoped configured tailwind v4 css source: %s -> %s", outputFile, configuredGenerationSource.file);
|
|
5340
|
+
}
|
|
5341
|
+
}
|
|
5342
|
+
}
|
|
4958
5343
|
}
|
|
4959
5344
|
let rememberedCssSource = mergeRememberedCssSources(rememberedCssSources, outputFile);
|
|
4960
5345
|
if (rememberedCssSource && viteProcessedCssAsset && outputCssHandlerOptions.isMainChunk !== true && configuredTailwindV4CssSourceFileKeysForScope.has(normalizeConfiguredTailwindV4CssEntryFileKey(rememberedCssSource.sourceFile))) {
|
|
@@ -4972,7 +5357,7 @@ function createGenerateBundleHook(context) {
|
|
|
4972
5357
|
const shouldKeepImportedCssShell = isCssImportOnlyBundleAsset(bundle, file, rawSource);
|
|
4973
5358
|
const useRememberedCssSource = !shouldKeepImportedCssShell && rememberedCssSource != null && (normalizeOutputPathKey(rememberedCssSource.sourceFile) !== normalizeOutputPathKey(file) || !hasTailwindGenerationSource(rawSource) && hasTailwindGenerationSource(rememberedCssSource.rawSource));
|
|
4974
5359
|
const vitePipelineCssAsset = viteProcessedCssAsset || useRememberedCssSource;
|
|
4975
|
-
const generatorRawSource = vitePipelineCssAsset ? rememberedCssSource?.rawSource ?? rawSource : rawSource;
|
|
5360
|
+
const generatorRawSource = normalizeMiniProgramGeneratorRawSource(vitePipelineCssAsset ? rememberedCssSource?.rawSource ?? rawSource : rawSource, outputFile);
|
|
4976
5361
|
const hasRememberedApplySource = vitePipelineCssAsset && rememberedCssSource != null && hasTailwindApplyDirective(generatorRawSource);
|
|
4977
5362
|
const hasDifferentRememberedCssSource = rememberedCssSource != null && normalizeCssSourceForCompare(rememberedCssSource.rawSource) !== normalizeCssSourceForCompare(rawSource);
|
|
4978
5363
|
const hasCurrentTailwindGenerationDirective = hasTailwindSourceDirectives(rawSource, { importFallback: true }) || hasTailwindRootDirectives(rawSource, { importFallback: true }) || hasTailwindApplyDirective(rawSource);
|
|
@@ -4999,7 +5384,10 @@ function createGenerateBundleHook(context) {
|
|
|
4999
5384
|
...getCssHandlerOptions(generatorSourceFile),
|
|
5000
5385
|
isMainChunk: resolvedFromTemporaryCssAsset ? false : outputCssHandlerOptions.isMainChunk
|
|
5001
5386
|
} : getCssHandlerOptions(file);
|
|
5002
|
-
const
|
|
5387
|
+
const generatorSourceFileKey = normalizeConfiguredTailwindV4CssEntryFileKey(generatorSourceFile);
|
|
5388
|
+
const isExplicitGeneratorCssEntry = configuredTailwindV4ExplicitCssEntryFileKeysForScope.has(generatorSourceFileKey);
|
|
5389
|
+
const shouldUsePipelineSourceAsCssEntry = !isExplicitGeneratorCssEntry && vitePipelineCssAsset && opts.cssMatcher(generatorSourceFile) && hasTailwindGenerationSource(generatorRawSource);
|
|
5390
|
+
const generatorCssEntries = isExplicitGeneratorCssEntry || shouldUsePipelineSourceAsCssEntry ? [generatorSourceFile] : opts.cssEntries;
|
|
5003
5391
|
const generatorCssHandlerOptions = {
|
|
5004
5392
|
...cssHandlerOptions,
|
|
5005
5393
|
sourceOptions: {
|
|
@@ -5010,7 +5398,8 @@ function createGenerateBundleHook(context) {
|
|
|
5010
5398
|
};
|
|
5011
5399
|
const scopedSourceCandidateGetter = createScopedSourceCandidateGetter(outputFile, generatorCssHandlerOptions);
|
|
5012
5400
|
const scopedSourceCandidateSourceGetter = createScopedSourceCandidateSourceGetter(outputFile, generatorCssHandlerOptions);
|
|
5013
|
-
const
|
|
5401
|
+
const sourceTraceSources = scopedSourceCandidateSourceGetter ? await createScopedGeneratorSourceTraceMap(generatorRawSource, generatorSourceFile, scopedSourceCandidateSourceGetter) : void 0;
|
|
5402
|
+
const sourceTraceTokenSources = sourceTraceSources ? createCssTokenSourceMap(sourceTraceSources, opts) : void 0;
|
|
5014
5403
|
const sourceTraceSignature = createCssSourceTraceCacheSignature(sourceTraceTokenSources, opts);
|
|
5015
5404
|
const scopedGeneratorRuntime = await createScopedGeneratorRuntime$1(outputFile, generatorCssHandlerOptions, generatorRuntime, generatorRawSource, generatorSourceFile);
|
|
5016
5405
|
const annotateCss = (css) => annotateCssSourceTrace(css, {
|
|
@@ -5113,11 +5502,13 @@ function createGenerateBundleHook(context) {
|
|
|
5113
5502
|
const start = performance.now();
|
|
5114
5503
|
await runtimeState.readyPromise;
|
|
5115
5504
|
const previousCss = !vitePipelineCssAsset && useIncrementalMode && !hasRuntimeAffectingChanges && !snapshot.changedByType.css.has(file) ? getLastCssResult(lastCssResultByFile, outputFile, file) : void 0;
|
|
5116
|
-
const
|
|
5505
|
+
const generatorTransformRawSource = generatorRawSource;
|
|
5506
|
+
const previousGeneratorCss = previousCss && !isWebGeneratorTarget ? normalizeMiniProgramGeneratorRawSource(previousCss, outputFile) : previousCss;
|
|
5507
|
+
const generated = hasTailwindGenerationSource(generatorTransformRawSource) || hasBundlerGeneratedCssMarker(rawSource) ? await generateTailwindV4Css({
|
|
5117
5508
|
opts,
|
|
5118
5509
|
runtimeState,
|
|
5119
5510
|
runtime: scopedGeneratorRuntime,
|
|
5120
|
-
rawSource:
|
|
5511
|
+
rawSource: generatorTransformRawSource,
|
|
5121
5512
|
file: generatorSourceFile,
|
|
5122
5513
|
outputFile,
|
|
5123
5514
|
cssHandlerOptions: generatorCssHandlerOptions,
|
|
@@ -5127,8 +5518,8 @@ function createGenerateBundleHook(context) {
|
|
|
5127
5518
|
generatorPlatform,
|
|
5128
5519
|
styleHandler,
|
|
5129
5520
|
debug,
|
|
5130
|
-
previousCss,
|
|
5131
|
-
...vitePipelineCssAsset && !hasBundlerGeneratedCssMarker(rawSource) && normalizeCssSourceForCompare(rawSource) !== normalizeCssSourceForCompare(generatorRawSource) ? { userRawSource: normalizeGeneratorUserRawSource(rawSource, generatorSourceFile, assetSourceFile) } : {},
|
|
5521
|
+
previousCss: previousGeneratorCss,
|
|
5522
|
+
...vitePipelineCssAsset && !hasBundlerGeneratedCssMarker(rawSource) && normalizeCssSourceForCompare(rawSource) !== normalizeCssSourceForCompare(generatorRawSource) ? { userRawSource: normalizeMiniProgramGeneratorRawSource(normalizeGeneratorUserRawSource(rawSource, generatorSourceFile, assetSourceFile), outputFile) } : {},
|
|
5132
5523
|
...usesConfiguredTailwindV4FallbackSource ? { restoreLocalCssImports: false } : {}
|
|
5133
5524
|
}) : void 0;
|
|
5134
5525
|
if (generated) {
|
|
@@ -5158,9 +5549,17 @@ function createGenerateBundleHook(context) {
|
|
|
5158
5549
|
debug("css preserve web target: %s", outputFile);
|
|
5159
5550
|
return annotateCss(outputCss);
|
|
5160
5551
|
}
|
|
5161
|
-
|
|
5552
|
+
if (isPureLocalCssImportWrapper(generatorTransformRawSource)) {
|
|
5553
|
+
const tracedCss = annotateCss(generatorTransformRawSource);
|
|
5554
|
+
recordCssAssetResult?.(outputFile, tracedCss);
|
|
5555
|
+
metrics.css.elapsed += measureElapsed(start);
|
|
5556
|
+
metrics.css.transformed++;
|
|
5557
|
+
debug("css preserve mini-program import shell: %s", outputFile);
|
|
5558
|
+
return tracedCss;
|
|
5559
|
+
}
|
|
5560
|
+
const { css } = await styleHandler(generatorTransformRawSource, cssHandlerOptions);
|
|
5162
5561
|
const tracedCss = annotateCss(css);
|
|
5163
|
-
if (envFlags.debugCssDiff) debug("css diff %s: %s", generatorSourceFile, summarizeStringDiff(
|
|
5562
|
+
if (envFlags.debugCssDiff) debug("css diff %s: %s", generatorSourceFile, summarizeStringDiff(generatorTransformRawSource, tracedCss));
|
|
5164
5563
|
metrics.css.elapsed += measureElapsed(start);
|
|
5165
5564
|
metrics.css.transformed++;
|
|
5166
5565
|
return tracedCss;
|
|
@@ -5215,6 +5614,7 @@ function createGenerateBundleHook(context) {
|
|
|
5215
5614
|
bundle,
|
|
5216
5615
|
bundleFiles,
|
|
5217
5616
|
cache,
|
|
5617
|
+
changedCssFiles: snapshot.changedByType.css,
|
|
5218
5618
|
cssTaskFactories,
|
|
5219
5619
|
createScopedGeneratorRuntime: createScopedGeneratorRuntime$1,
|
|
5220
5620
|
createScopedSourceCandidateGetter,
|
|
@@ -5230,6 +5630,7 @@ function createGenerateBundleHook(context) {
|
|
|
5230
5630
|
getRememberedCssSources,
|
|
5231
5631
|
isNativeAppStyleTarget,
|
|
5232
5632
|
isWebGeneratorTarget,
|
|
5633
|
+
lastCssRawSourceHashByFile,
|
|
5233
5634
|
lastCssResultByFile,
|
|
5234
5635
|
lastCssSourceHashByFile,
|
|
5235
5636
|
markCssAssetProcessed,
|
|
@@ -5333,12 +5734,13 @@ function registerGeneratorDependencies(ctx, dependencies) {
|
|
|
5333
5734
|
throw error;
|
|
5334
5735
|
}
|
|
5335
5736
|
}
|
|
5336
|
-
function createCssHandlerOptions(opts, majorVersion, file, extraOptions = {}) {
|
|
5737
|
+
function createCssHandlerOptions(opts, majorVersion, file, outputRoot, extraOptions = {}) {
|
|
5738
|
+
const from = path.isAbsolute(file) ? file : outputRoot ? path.resolve(outputRoot, file) : file;
|
|
5337
5739
|
return {
|
|
5338
5740
|
...extraOptions,
|
|
5339
5741
|
cssPreflight: opts.cssPreflight,
|
|
5340
5742
|
isMainChunk: opts.mainCssChunkMatcher(file, opts.appType),
|
|
5341
|
-
postcssOptions: { options: { from
|
|
5743
|
+
postcssOptions: { options: { from } },
|
|
5342
5744
|
...normalizeStyleHandlerMajorVersion(majorVersion) === void 0 ? {} : { majorVersion: 4 }
|
|
5343
5745
|
};
|
|
5344
5746
|
}
|
|
@@ -5349,6 +5751,7 @@ function shouldGenerateCssByGenerator(opts, majorVersion, file, rawSource, proce
|
|
|
5349
5751
|
tailwindcssMajorVersion: majorVersion,
|
|
5350
5752
|
uniAppX: opts.uniAppX
|
|
5351
5753
|
});
|
|
5754
|
+
if (!generatorOptions.enabled) return false;
|
|
5352
5755
|
if (hasLocalCssImport(rawSource)) return false;
|
|
5353
5756
|
if (hasTailwindGeneratedCssMarkers(rawSource)) return true;
|
|
5354
5757
|
if (hasTailwindRootDirectives(rawSource, { importFallback: generatorOptions.importFallback })) return true;
|
|
@@ -5361,8 +5764,8 @@ function collectViteProcessedCssSources(getViteProcessedCssAssetResults) {
|
|
|
5361
5764
|
return [...getViteProcessedCssAssetResults?.() ?? []].map(([, record]) => typeof record === "string" ? record : record.css);
|
|
5362
5765
|
}
|
|
5363
5766
|
function finalizeWebCss(css, context, cssPipelineStrategy) {
|
|
5364
|
-
const shouldApplyWebCssCompat =
|
|
5365
|
-
const defaultWebCssCompat = (value) => transformWebCssCompat(value, context
|
|
5767
|
+
const shouldApplyWebCssCompat = shouldApplyViteWebCssCompat(context, cssPipelineStrategy);
|
|
5768
|
+
const defaultWebCssCompat = (value) => transformWebCssCompat(value, resolveViteWebCssCompatOptions(context));
|
|
5366
5769
|
return cssPipelineStrategy?.transformGeneratedCss?.(css, {
|
|
5367
5770
|
...context,
|
|
5368
5771
|
defaultWebCssCompat,
|
|
@@ -5408,6 +5811,7 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
5408
5811
|
const isNativeAppStyleTarget = cssPipelineStrategy?.isNativeAppStyleTarget?.(createCssPipelineContext("")) === true;
|
|
5409
5812
|
if (resolvedConfig?.command !== "build" && !isNativeAppStyleTarget) return;
|
|
5410
5813
|
const rootDir = resolvedConfig?.root ? path.resolve(resolvedConfig.root) : process$1.cwd();
|
|
5814
|
+
const outDir = resolvedConfig?.build?.outDir ? path.resolve(rootDir, resolvedConfig.build.outDir) : rootDir;
|
|
5411
5815
|
const sourceRoot = resolveWeappViteSourceRoot(resolvedConfig, opts.appType) ?? resolveSourceRootFromBundleGraph(resolvedConfig, bundle);
|
|
5412
5816
|
const sourceTraceTokenSources = getSourceCandidateSourcesForEntries ? createCssTokenSourceMap(getSourceCandidateSourcesForEntries(void 0), opts) : void 0;
|
|
5413
5817
|
const annotateCss = (css) => annotateCssSourceTrace(css, {
|
|
@@ -5454,7 +5858,7 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
5454
5858
|
const applyStyleSources = collectUniAppXHarmonyApplyStyleSources(bundle);
|
|
5455
5859
|
if (applyUtilities.size === 0 || applyStyleSources.length === 0) return cssSources;
|
|
5456
5860
|
const harmonyRuntime = /* @__PURE__ */ new Set([...runtime, ...applyUtilities]);
|
|
5457
|
-
const harmonyCssHandlerOptions = createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, "uni-app-x-harmony-apply.css", cssPipelineStrategy?.getCssHandlerExtraOptions?.({
|
|
5861
|
+
const harmonyCssHandlerOptions = createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, "uni-app-x-harmony-apply.css", outDir, cssPipelineStrategy?.getCssHandlerExtraOptions?.({
|
|
5458
5862
|
...createCssPipelineContext("uni-app-x-harmony-apply.css"),
|
|
5459
5863
|
file: "uni-app-x-harmony-apply.css"
|
|
5460
5864
|
}) ?? {});
|
|
@@ -5520,7 +5924,7 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
5520
5924
|
debug("css finalizer skip vite-processed css: %s", file);
|
|
5521
5925
|
return;
|
|
5522
5926
|
}
|
|
5523
|
-
const cssHandlerOptions = createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, file, cssPipelineStrategy?.getCssHandlerExtraOptions?.({
|
|
5927
|
+
const cssHandlerOptions = createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, file, outDir, cssPipelineStrategy?.getCssHandlerExtraOptions?.({
|
|
5524
5928
|
...createCssPipelineContext(file),
|
|
5525
5929
|
file
|
|
5526
5930
|
}) ?? {});
|
|
@@ -5528,11 +5932,21 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
5528
5932
|
...cssHandlerOptions,
|
|
5529
5933
|
isMainChunk: false
|
|
5530
5934
|
};
|
|
5935
|
+
const cleanRawSource = stripBundlerGeneratedCssMarkers(rawSource);
|
|
5936
|
+
if (cleanRawSource !== rawSource && cleanRawSource.trim().length === 0) {
|
|
5937
|
+
output.source = cleanRawSource;
|
|
5938
|
+
markCssAssetProcessed(output, file);
|
|
5939
|
+
recordCssAssetResult?.(file, cleanRawSource);
|
|
5940
|
+
opts.onUpdate(file, rawSource, cleanRawSource);
|
|
5941
|
+
debug("css finalizer strip empty marker asset: %s", file);
|
|
5942
|
+
return;
|
|
5943
|
+
}
|
|
5531
5944
|
const processed = isCssAssetProcessed(output, file);
|
|
5532
5945
|
const rememberedMainCssSource = processed && cssHandlerOptions.isMainChunk ? getRememberedMainCssSource?.(file) : void 0;
|
|
5533
|
-
const
|
|
5946
|
+
const resolvedGeneratorRawSource = rememberedMainCssSource?.rawSource ?? cleanRawSource;
|
|
5947
|
+
const generatorRawSource = generatorBranch.isWeb ? resolvedGeneratorRawSource : normalizeMiniProgramGeneratorCssSource(resolvedGeneratorRawSource, file);
|
|
5534
5948
|
const generatorSourceFile = rememberedMainCssSource?.sourceFile ?? file;
|
|
5535
|
-
const generatorCssHandlerOptions = rememberedMainCssSource ? createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, generatorSourceFile, cssPipelineStrategy?.getCssHandlerExtraOptions?.({
|
|
5949
|
+
const generatorCssHandlerOptions = rememberedMainCssSource ? createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, generatorSourceFile, outDir, cssPipelineStrategy?.getCssHandlerExtraOptions?.({
|
|
5536
5950
|
...createCssPipelineContext(generatorSourceFile),
|
|
5537
5951
|
file: generatorSourceFile
|
|
5538
5952
|
}) ?? {}) : cssHandlerOptions;
|
|
@@ -5540,11 +5954,12 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
5540
5954
|
...generatorCssHandlerOptions,
|
|
5541
5955
|
isMainChunk: false
|
|
5542
5956
|
} : cssUserHandlerOptions;
|
|
5543
|
-
const
|
|
5957
|
+
const generatorTransformRawSource = generatorRawSource;
|
|
5958
|
+
const generated = shouldGenerateCssByGenerator(opts, runtimeState.tailwindRuntime.majorVersion, file, generatorTransformRawSource, processed) ? await generateTailwindV4Css({
|
|
5544
5959
|
opts,
|
|
5545
5960
|
runtimeState,
|
|
5546
5961
|
runtime: generatorRuntime,
|
|
5547
|
-
rawSource:
|
|
5962
|
+
rawSource: generatorTransformRawSource,
|
|
5548
5963
|
file: generatorSourceFile,
|
|
5549
5964
|
outputFile: file,
|
|
5550
5965
|
cssHandlerOptions: generatorCssHandlerOptions,
|
|
@@ -5554,10 +5969,21 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
5554
5969
|
styleHandler: opts.styleHandler,
|
|
5555
5970
|
debug
|
|
5556
5971
|
}) : void 0;
|
|
5557
|
-
|
|
5972
|
+
if (!generated && !generatorBranch.isWeb && isPureLocalCssImportWrapper(generatorTransformRawSource)) {
|
|
5973
|
+
const nextCss = generatorTransformRawSource;
|
|
5974
|
+
if (nextCss !== rawSource) {
|
|
5975
|
+
output.source = nextCss;
|
|
5976
|
+
opts.onUpdate(file, rawSource, nextCss);
|
|
5977
|
+
}
|
|
5978
|
+
markCssAssetProcessed(output, file);
|
|
5979
|
+
recordCssAssetResult?.(file, nextCss);
|
|
5980
|
+
debug("css finalizer preserve mini-program import shell: %s", file);
|
|
5981
|
+
return;
|
|
5982
|
+
}
|
|
5983
|
+
const nextCss = annotateCss(generated?.css ?? (generatorBranch.isWeb ? finalizeWebCss(cleanRawSource, {
|
|
5558
5984
|
...createCssPipelineContext(file),
|
|
5559
5985
|
file
|
|
5560
|
-
}, cssPipelineStrategy) : (await opts.styleHandler(
|
|
5986
|
+
}, cssPipelineStrategy) : (await opts.styleHandler(generatorTransformRawSource, cssHandlerOptions)).css));
|
|
5561
5987
|
if (generated) {
|
|
5562
5988
|
registerGeneratorDependencies(this, generated.dependencies);
|
|
5563
5989
|
debug("css finalizer generated result: %s bytes=%d", file, nextCss.length);
|
|
@@ -5843,9 +6269,21 @@ function createViteCssMemory(options) {
|
|
|
5843
6269
|
function resolveHotTailwindCssModules(ctx, tailwindRootCssModuleIds) {
|
|
5844
6270
|
const modules = [];
|
|
5845
6271
|
const seenModules = /* @__PURE__ */ new Set();
|
|
6272
|
+
const root = ctx.server.config?.root ?? process$1.cwd();
|
|
6273
|
+
const outDir = ctx.server.config?.build?.outDir ? normalizeAbsoluteFilePath(path.resolve(root, ctx.server.config.build.outDir)) : void 0;
|
|
6274
|
+
const isHotSourceStyleModule = (id) => {
|
|
6275
|
+
if (!isSourceStyleRequest(id)) return false;
|
|
6276
|
+
const file = cleanUrl(id);
|
|
6277
|
+
if (isRootMiniProgramStyleUrl(file) || !isAbsoluteFilePath(file) && !file.startsWith("/")) return false;
|
|
6278
|
+
if (outDir && isAbsoluteFilePath(file)) {
|
|
6279
|
+
const normalizedFile = normalizeAbsoluteFilePath(file);
|
|
6280
|
+
if (normalizedFile === outDir || normalizedFile.startsWith(`${outDir}/`)) return false;
|
|
6281
|
+
}
|
|
6282
|
+
return true;
|
|
6283
|
+
};
|
|
5846
6284
|
const collectModule = (mod) => {
|
|
5847
6285
|
if (mod == null || seenModules.has(mod)) return;
|
|
5848
|
-
if (!
|
|
6286
|
+
if (!isHotSourceStyleModule(mod.id ?? mod.url)) return;
|
|
5849
6287
|
seenModules.add(mod);
|
|
5850
6288
|
ctx.server.moduleGraph.invalidateModule(mod);
|
|
5851
6289
|
modules.push(mod);
|
|
@@ -5881,6 +6319,29 @@ function resolveModuleHotUrl(mod) {
|
|
|
5881
6319
|
if (typeof mod.url === "string" && mod.url.length > 0) return mod.url;
|
|
5882
6320
|
if (typeof mod.id === "string" && mod.id.startsWith("/")) return mod.id;
|
|
5883
6321
|
}
|
|
6322
|
+
function isAbsoluteFilePath(file) {
|
|
6323
|
+
return path.isAbsolute(file) || /^[A-Z]:[\\/]/i.test(file) || file.startsWith("\\\\");
|
|
6324
|
+
}
|
|
6325
|
+
function normalizeAbsoluteFilePath(file) {
|
|
6326
|
+
if (/^[A-Z]:[\\/]/i.test(file) || file.startsWith("\\\\")) return slash(path.win32.resolve(file));
|
|
6327
|
+
return slash(path.resolve(file));
|
|
6328
|
+
}
|
|
6329
|
+
function isRootMiniProgramStyleUrl(file) {
|
|
6330
|
+
return /^\/[^/]+\.(?:wxss|acss|ttss|qss|jxss|tyss)(?:$|[?#])/i.test(file);
|
|
6331
|
+
}
|
|
6332
|
+
function resolveCssHotUrl(id, root) {
|
|
6333
|
+
const suffix = /[?#]/.test(id) ? id.slice(id.search(/[?#]/)) : "";
|
|
6334
|
+
const file = cleanUrl(id);
|
|
6335
|
+
if (/^\/(?![A-Z]:)/i.test(file) && !file.startsWith(slash(root))) {
|
|
6336
|
+
if (isRootMiniProgramStyleUrl(file)) return;
|
|
6337
|
+
return `${file}${suffix}`;
|
|
6338
|
+
}
|
|
6339
|
+
if (!isAbsoluteFilePath(file)) return;
|
|
6340
|
+
const normalizedRoot = normalizeAbsoluteFilePath(root);
|
|
6341
|
+
const normalizedFile = normalizeAbsoluteFilePath(file);
|
|
6342
|
+
if (!normalizedFile.startsWith(`${normalizedRoot}/`)) return;
|
|
6343
|
+
return `/${slash(path.relative(normalizedRoot, normalizedFile))}${suffix}`;
|
|
6344
|
+
}
|
|
5884
6345
|
function includesHotModule(modules, target) {
|
|
5885
6346
|
const targetUrl = resolveModuleHotUrl(target);
|
|
5886
6347
|
const targetId = target.id;
|
|
@@ -5889,24 +6350,46 @@ function includesHotModule(modules, target) {
|
|
|
5889
6350
|
return targetUrl !== void 0 && resolveModuleHotUrl(mod) === targetUrl || typeof targetId === "string" && targetId.length > 0 && mod.id === targetId;
|
|
5890
6351
|
});
|
|
5891
6352
|
}
|
|
6353
|
+
function createSupplementalHotUpdate(hotUrl, timestamp) {
|
|
6354
|
+
if (/[?&](?:direct|vue)(?:&|$)/.test(hotUrl)) return {
|
|
6355
|
+
type: "js-update",
|
|
6356
|
+
timestamp,
|
|
6357
|
+
path: hotUrl,
|
|
6358
|
+
acceptedPath: hotUrl,
|
|
6359
|
+
explicitImportRequired: false,
|
|
6360
|
+
isWithinCircularImport: false
|
|
6361
|
+
};
|
|
6362
|
+
return {
|
|
6363
|
+
type: "css-update",
|
|
6364
|
+
timestamp,
|
|
6365
|
+
path: hotUrl,
|
|
6366
|
+
acceptedPath: hotUrl
|
|
6367
|
+
};
|
|
6368
|
+
}
|
|
5892
6369
|
function hasSelfAcceptingNonStyleHotModule(modules) {
|
|
5893
6370
|
return modules.some((mod) => {
|
|
5894
6371
|
return !isSourceStyleRequest(mod.id ?? mod.url) && mod.isSelfAccepting === true;
|
|
5895
6372
|
});
|
|
5896
6373
|
}
|
|
5897
|
-
function sendSupplementalCssHotUpdates(ctx, cssModules) {
|
|
5898
|
-
const
|
|
5899
|
-
|
|
5900
|
-
|
|
5901
|
-
|
|
5902
|
-
|
|
5903
|
-
|
|
5904
|
-
|
|
5905
|
-
|
|
5906
|
-
|
|
5907
|
-
|
|
5908
|
-
|
|
5909
|
-
|
|
6374
|
+
function sendSupplementalCssHotUpdates(ctx, cssModules, fallbackCssIds = []) {
|
|
6375
|
+
const seenUrls = /* @__PURE__ */ new Set();
|
|
6376
|
+
const root = ctx.server.config?.root ?? process$1.cwd();
|
|
6377
|
+
const updates = [];
|
|
6378
|
+
for (const id of fallbackCssIds) {
|
|
6379
|
+
if (!isSourceStyleRequest(id)) continue;
|
|
6380
|
+
const hotUrl = resolveCssHotUrl(id, root);
|
|
6381
|
+
if (!hotUrl || seenUrls.has(hotUrl)) continue;
|
|
6382
|
+
seenUrls.add(hotUrl);
|
|
6383
|
+
updates.push(createSupplementalHotUpdate(hotUrl, ctx.timestamp));
|
|
6384
|
+
}
|
|
6385
|
+
for (const mod of cssModules) {
|
|
6386
|
+
if (includesHotModule(ctx.modules, mod)) continue;
|
|
6387
|
+
const moduleHotUrl = resolveModuleHotUrl(mod);
|
|
6388
|
+
const hotUrl = moduleHotUrl ? resolveCssHotUrl(moduleHotUrl, root) : void 0;
|
|
6389
|
+
if (!hotUrl || seenUrls.has(hotUrl)) continue;
|
|
6390
|
+
seenUrls.add(hotUrl);
|
|
6391
|
+
updates.push(createSupplementalHotUpdate(hotUrl, ctx.timestamp));
|
|
6392
|
+
}
|
|
5910
6393
|
if (updates.length === 0) return;
|
|
5911
6394
|
queueMicrotask(() => {
|
|
5912
6395
|
ctx.server.ws?.send?.({
|
|
@@ -6059,7 +6542,7 @@ function createRewriteCssImportsPlugins(options) {
|
|
|
6059
6542
|
const file = cleanUrl(id);
|
|
6060
6543
|
const normalizedCode = hasTailwindRootDirectives(code) || code.includes("@config") ? normalizeTailwindConfigDirectives(code, path.dirname(file)) : code;
|
|
6061
6544
|
await options.onCssSourceTransform?.(id, normalizedCode);
|
|
6062
|
-
const hasTailwindRoot = hasTailwindRootDirectives(normalizedCode);
|
|
6545
|
+
const hasTailwindRoot = hasTailwindRootDirectives(normalizedCode, { importFallback: true });
|
|
6063
6546
|
if (hasTailwindRoot) await options.onTailwindRootCss?.(id, normalizedCode);
|
|
6064
6547
|
const shouldGenerateInPreTransform = !options.shouldDeferGeneration?.(id, normalizedCode) && (hasTailwindRoot || options.shouldGenerateCss?.(id, normalizedCode));
|
|
6065
6548
|
if (options.shouldOwnTailwindGeneration && shouldGenerateInPreTransform) {
|
|
@@ -6221,6 +6704,7 @@ const SPECIAL_QUERY_RE$1 = /[?&](?:worker|sharedworker|raw|url)\b/;
|
|
|
6221
6704
|
const COMMON_JS_PROXY_RE = /\?commonjs-proxy/;
|
|
6222
6705
|
const VITE_CSS_HMR_MODULE_RE = /\b__vite__updateStyle\s*\(/;
|
|
6223
6706
|
const VITE_CSS_CONST_RE = /\bconst\s+__vite__css\s*=\s*("(?:\\[\s\S]|[^"])*")/;
|
|
6707
|
+
const DEFERRED_CSS_HMR_QUERY_RE = /[?&](?:hmr(?:[=&]|$)|t=\d+)/;
|
|
6224
6708
|
function decodeJsStringLiteral(literal) {
|
|
6225
6709
|
try {
|
|
6226
6710
|
return JSON.parse(literal);
|
|
@@ -6254,7 +6738,7 @@ function isViteServeCssRootRequest(id, command) {
|
|
|
6254
6738
|
return command === "serve" && isSourceStyleRequest(id) && !SPECIAL_QUERY_RE$1.test(id) && !COMMON_JS_PROXY_RE.test(id);
|
|
6255
6739
|
}
|
|
6256
6740
|
function isViteCssHmrModule(code, id, command) {
|
|
6257
|
-
return isViteServeStyleRequest(id, command) && VITE_CSS_HMR_MODULE_RE.test(code) && /[?&](?:direct|vue)(?:&|$)/.test(id);
|
|
6741
|
+
return isViteServeStyleRequest(id, command) && VITE_CSS_HMR_MODULE_RE.test(code) && (/[?&](?:direct|vue)(?:&|$)/.test(id) || DEFERRED_CSS_HMR_QUERY_RE.test(id));
|
|
6258
6742
|
}
|
|
6259
6743
|
function hasViteServeCssGenerationDirective(code) {
|
|
6260
6744
|
return hasTailwindRootDirectives(code) || hasTailwindSourceDirectives(code, { importFallback: true }) || hasTailwindApplyDirective(code);
|
|
@@ -6270,6 +6754,7 @@ function createViteServeCssGenerationPlugins(options) {
|
|
|
6270
6754
|
async transform(code, id) {
|
|
6271
6755
|
if (!options.shouldGenerate() || !isViteServeCssRootRequest(id, options.getCommand())) return;
|
|
6272
6756
|
if (!hasTailwindRootDirectives(code)) return;
|
|
6757
|
+
if (DEFERRED_CSS_HMR_QUERY_RE.test(id)) return;
|
|
6273
6758
|
await options.onTailwindRootCss?.(id, code);
|
|
6274
6759
|
const generatedCss = await options.generateCss(id, code, this);
|
|
6275
6760
|
if (generatedCss === void 0 || generatedCss === code) return;
|
|
@@ -6351,6 +6836,7 @@ const debug = createDebug();
|
|
|
6351
6836
|
const weappTailwindcssPackageDir = resolvePackageDir("weapp-tailwindcss");
|
|
6352
6837
|
const weappTailwindcssDirPosix = slash(weappTailwindcssPackageDir);
|
|
6353
6838
|
const SOURCE_CANDIDATE_SCAN_CACHE_MAX = 8;
|
|
6839
|
+
const WEB_HMR_RUNTIME_AFFECTING_DIRECTIVE_RE = /@(?:theme|source|config|plugin|apply)\b/;
|
|
6354
6840
|
const sourceCandidateScanSnapshotCache = new LRUCache({ max: SOURCE_CANDIDATE_SCAN_CACHE_MAX });
|
|
6355
6841
|
const ENV_PLATFORM_KEYS = [
|
|
6356
6842
|
"UNI_PLATFORM",
|
|
@@ -6385,9 +6871,6 @@ function inferPlatformFromOutDir(outDir) {
|
|
|
6385
6871
|
function isWebOrNativeAppPlatform(platform) {
|
|
6386
6872
|
return platform === "h5" || platform === "web" || platform?.startsWith("web-") === true || platform === "app" || platform === "app-plus" || platform?.startsWith("app-") === true;
|
|
6387
6873
|
}
|
|
6388
|
-
function applyViteWebCssCompat(css, options) {
|
|
6389
|
-
return transformWebCssCompat(css, options.compat);
|
|
6390
|
-
}
|
|
6391
6874
|
function isInternalUserDefinedOptions(options) {
|
|
6392
6875
|
return typeof options.onLoad === "function" && typeof options.mainCssChunkMatcher === "function" && typeof options.tailwindRuntime === "object" && typeof options.refreshTailwindcssRuntime === "function";
|
|
6393
6876
|
}
|
|
@@ -6427,7 +6910,6 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
6427
6910
|
const disabledOptions = resolvePluginDisabledState(disabled);
|
|
6428
6911
|
const tailwindcssMajorVersion = initialTailwindRuntime.majorVersion ?? 0;
|
|
6429
6912
|
if (!disabledOptions.plugin && tailwindcssMajorVersion !== 4) throw new Error("weapp-tailwindcss/vite 新生成管线仅支持 Tailwind CSS v4,请升级 tailwindcss 或停留在旧版 weapp-tailwindcss。");
|
|
6430
|
-
const shouldOwnTailwindGeneration = !disabledOptions.plugin;
|
|
6431
6913
|
const shouldRewriteCssImports = opts.rewriteCssImports === true;
|
|
6432
6914
|
let resolvedConfig;
|
|
6433
6915
|
const resolveViteStylePlatform = () => {
|
|
@@ -6446,6 +6928,7 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
6446
6928
|
tailwindcssMajorVersion,
|
|
6447
6929
|
uniAppX
|
|
6448
6930
|
});
|
|
6931
|
+
const shouldOwnTailwindGeneration = !disabledOptions.plugin && resolveCurrentGeneratorOptions().enabled;
|
|
6449
6932
|
const resolveCurrentGeneratorBranch = () => resolveGeneratorRuntimeBranch(resolveCurrentGeneratorOptions(), {
|
|
6450
6933
|
appType: opts.appType,
|
|
6451
6934
|
platform: resolveGeneratorPlatform(),
|
|
@@ -6566,8 +7049,11 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
6566
7049
|
const pendingSourceCandidateSyncs = /* @__PURE__ */ new Set();
|
|
6567
7050
|
const pendingSourceCandidateSyncByFile = /* @__PURE__ */ new Map();
|
|
6568
7051
|
const processedCssAssets = /* @__PURE__ */ new WeakSet();
|
|
7052
|
+
const processedCssAssetSourceByFile = /* @__PURE__ */ new Map();
|
|
6569
7053
|
const viteProcessedCssSourceFiles = /* @__PURE__ */ new Set();
|
|
6570
|
-
const
|
|
7054
|
+
const cleanGeneratedCssByFile = /* @__PURE__ */ new Map();
|
|
7055
|
+
const tracedGeneratedCssByFile = /* @__PURE__ */ new Map();
|
|
7056
|
+
const generatedClassSetByFile = /* @__PURE__ */ new Map();
|
|
6571
7057
|
const viteProcessedCssAssetResults = /* @__PURE__ */ new Map();
|
|
6572
7058
|
const cssMemory = createViteCssMemory({
|
|
6573
7059
|
debug,
|
|
@@ -6587,15 +7073,21 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
6587
7073
|
refreshRuntimeStateForAutoCssSources = refreshRuntimeState;
|
|
6588
7074
|
onLoad();
|
|
6589
7075
|
const getResolvedConfig = () => resolvedConfig;
|
|
6590
|
-
const
|
|
7076
|
+
const readCssAssetSource = (asset) => {
|
|
7077
|
+
return typeof asset.source === "string" ? asset.source : asset.source instanceof Uint8Array ? Buffer.from(asset.source).toString() : String(asset.source ?? "");
|
|
7078
|
+
};
|
|
7079
|
+
const markCssAssetProcessed = (asset, file) => {
|
|
6591
7080
|
processedCssAssets.add(asset);
|
|
7081
|
+
if (file) processedCssAssetSourceByFile.set(normalizeOutputPathKey(file), readCssAssetSource(asset));
|
|
6592
7082
|
};
|
|
6593
7083
|
const isCssAssetProcessed = (asset, file) => {
|
|
6594
7084
|
if (processedCssAssets.has(asset)) return true;
|
|
6595
7085
|
if (!file) return false;
|
|
7086
|
+
const source = readCssAssetSource(asset);
|
|
7087
|
+
if (processedCssAssetSourceByFile.get(normalizeOutputPathKey(file)) === source) return true;
|
|
6596
7088
|
const record = viteProcessedCssAssetResults.get(normalizeOutputPathKey(file));
|
|
6597
7089
|
if (!record) return false;
|
|
6598
|
-
return
|
|
7090
|
+
return source === record.css;
|
|
6599
7091
|
};
|
|
6600
7092
|
const recordGeneratorCandidates = (candidates) => {
|
|
6601
7093
|
recordedGeneratorCandidates = new Set(candidates);
|
|
@@ -6618,6 +7110,95 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
6618
7110
|
const cleanId = cleanUrl(id);
|
|
6619
7111
|
return cleanId.includes("/pages/") && /\.(?:vue|tsx?|jsx?)$/.test(cleanId);
|
|
6620
7112
|
};
|
|
7113
|
+
const hasWebHmrRuntimeAffectingDirectives = (source) => typeof source === "string" && WEB_HMR_RUNTIME_AFFECTING_DIRECTIVE_RE.test(source);
|
|
7114
|
+
let pendingHmrCandidateChange;
|
|
7115
|
+
let pendingHmrCssTargetFiles;
|
|
7116
|
+
let pendingFullHmrCssRegeneration = false;
|
|
7117
|
+
const normalizeHmrCssTargetFile = (file) => normalizeVitePersistentCacheKey(cleanUrl(file));
|
|
7118
|
+
const collectPendingHmrCssTargetFiles = (cssModules, fallbackCssIds) => {
|
|
7119
|
+
const targets = /* @__PURE__ */ new Set();
|
|
7120
|
+
const addTarget = (file) => {
|
|
7121
|
+
if (typeof file !== "string" || file.length === 0) return;
|
|
7122
|
+
const key = normalizeHmrCssTargetFile(file);
|
|
7123
|
+
if (cleanGeneratedCssByFile.has(key)) targets.add(key);
|
|
7124
|
+
};
|
|
7125
|
+
for (const mod of cssModules) {
|
|
7126
|
+
addTarget(mod.id);
|
|
7127
|
+
addTarget(mod.file);
|
|
7128
|
+
addTarget(mod.url);
|
|
7129
|
+
}
|
|
7130
|
+
for (const id of fallbackCssIds) addTarget(id);
|
|
7131
|
+
return targets.size > 0 ? targets : void 0;
|
|
7132
|
+
};
|
|
7133
|
+
const armPendingHmrCssTargetFiles = (cssModules, fallbackCssIds) => {
|
|
7134
|
+
if (!pendingHmrCandidateChange) {
|
|
7135
|
+
pendingHmrCssTargetFiles = void 0;
|
|
7136
|
+
return;
|
|
7137
|
+
}
|
|
7138
|
+
pendingHmrCssTargetFiles = collectPendingHmrCssTargetFiles(cssModules, fallbackCssIds);
|
|
7139
|
+
};
|
|
7140
|
+
const createViteSourceCandidateChange = (file, change, options = {}) => ({
|
|
7141
|
+
...change,
|
|
7142
|
+
file,
|
|
7143
|
+
runtimeAffecting: options.runtimeAffecting === true || isSourceStyleRequest(file) || hasWebHmrRuntimeAffectingDirectives(sourceCandidateCollector.source(file))
|
|
7144
|
+
});
|
|
7145
|
+
const clearPendingHmrCandidateChange = () => {
|
|
7146
|
+
pendingHmrCandidateChange = void 0;
|
|
7147
|
+
pendingHmrCssTargetFiles = void 0;
|
|
7148
|
+
pendingFullHmrCssRegeneration = false;
|
|
7149
|
+
};
|
|
7150
|
+
const queueHmrCandidateChange = (change) => {
|
|
7151
|
+
pendingFullHmrCssRegeneration = false;
|
|
7152
|
+
if (!pendingHmrCandidateChange) {
|
|
7153
|
+
pendingHmrCandidateChange = {
|
|
7154
|
+
file: change.file,
|
|
7155
|
+
runtimeAffecting: change.runtimeAffecting,
|
|
7156
|
+
addedCandidates: new Set(change.addedCandidates),
|
|
7157
|
+
removedCandidates: new Set(change.removedCandidates)
|
|
7158
|
+
};
|
|
7159
|
+
return;
|
|
7160
|
+
}
|
|
7161
|
+
for (const candidate of change.addedCandidates) {
|
|
7162
|
+
pendingHmrCandidateChange.addedCandidates.add(candidate);
|
|
7163
|
+
pendingHmrCandidateChange.removedCandidates.delete(candidate);
|
|
7164
|
+
}
|
|
7165
|
+
for (const candidate of change.removedCandidates) if (!pendingHmrCandidateChange.addedCandidates.delete(candidate)) pendingHmrCandidateChange.removedCandidates.add(candidate);
|
|
7166
|
+
pendingHmrCandidateChange.runtimeAffecting = pendingHmrCandidateChange.runtimeAffecting || change.runtimeAffecting;
|
|
7167
|
+
pendingHmrCandidateChange.file = change.file;
|
|
7168
|
+
};
|
|
7169
|
+
const queueFullHmrCssRegeneration = () => {
|
|
7170
|
+
pendingHmrCandidateChange = void 0;
|
|
7171
|
+
pendingHmrCssTargetFiles = void 0;
|
|
7172
|
+
pendingFullHmrCssRegeneration = true;
|
|
7173
|
+
};
|
|
7174
|
+
const applySourceCandidateHmrState = (change) => {
|
|
7175
|
+
if (isSourceStyleRequest(change.file)) {
|
|
7176
|
+
clearPendingHmrCandidateChange();
|
|
7177
|
+
return change;
|
|
7178
|
+
}
|
|
7179
|
+
const preserveDeletedCssInHmr = resolveCurrentGeneratorOptions().hmr.preserveDeletedCss;
|
|
7180
|
+
if (preserveDeletedCssInHmr && !change.runtimeAffecting) {
|
|
7181
|
+
if (change.addedCandidates.size > 0) queueHmrCandidateChange(change);
|
|
7182
|
+
else if (!pendingHmrCandidateChange) clearPendingHmrCandidateChange();
|
|
7183
|
+
return change;
|
|
7184
|
+
}
|
|
7185
|
+
clearPendingHmrCandidateChange();
|
|
7186
|
+
if (!preserveDeletedCssInHmr) queueFullHmrCssRegeneration();
|
|
7187
|
+
return change;
|
|
7188
|
+
};
|
|
7189
|
+
const resolvePendingHmrCandidateChange = (generatorCode, file) => {
|
|
7190
|
+
if (resolvedConfig?.command !== "serve" || !pendingHmrCandidateChange || pendingHmrCandidateChange.runtimeAffecting || pendingHmrCandidateChange.addedCandidates.size === 0 || resolveCurrentGeneratorOptions().target === "weapp" && hasUserCssLayerBlocks(generatorCode) || !cleanGeneratedCssByFile.has(file) || !generatedClassSetByFile.has(file) || pendingHmrCssTargetFiles !== void 0 && !pendingHmrCssTargetFiles.has(normalizeHmrCssTargetFile(file))) return;
|
|
7191
|
+
return pendingHmrCandidateChange;
|
|
7192
|
+
};
|
|
7193
|
+
const finishPendingHmrCssTargetFile = (file) => {
|
|
7194
|
+
if (!pendingHmrCandidateChange) return;
|
|
7195
|
+
if (!pendingHmrCssTargetFiles) {
|
|
7196
|
+
clearPendingHmrCandidateChange();
|
|
7197
|
+
return;
|
|
7198
|
+
}
|
|
7199
|
+
pendingHmrCssTargetFiles.delete(normalizeHmrCssTargetFile(file));
|
|
7200
|
+
if (pendingHmrCssTargetFiles.size === 0) clearPendingHmrCandidateChange();
|
|
7201
|
+
};
|
|
6621
7202
|
const hasSourceCandidateScanState = () => sourceCandidateScanSignature !== void 0;
|
|
6622
7203
|
const normalizeSourceScanDependency = (file) => path.normalize(path.resolve(cleanUrl(file)));
|
|
6623
7204
|
const isSourceScanDependency = (file) => sourceScanDependencies.has(normalizeSourceScanDependency(file));
|
|
@@ -6722,34 +7303,41 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
6722
7303
|
const waitForSourceCandidateSyncs = async () => {
|
|
6723
7304
|
while (pendingSourceCandidateSyncs.size > 0) await Promise.all(pendingSourceCandidateSyncs);
|
|
6724
7305
|
};
|
|
6725
|
-
const syncChangedSourceCandidateFile = (id) => {
|
|
6726
|
-
if (!shouldOwnTailwindGeneration || !isSourceCandidateRequest(id)) return Promise.resolve();
|
|
7306
|
+
const syncChangedSourceCandidateFile = (id, sourceOverride) => {
|
|
7307
|
+
if (!shouldOwnTailwindGeneration || !isSourceCandidateRequest(id)) return Promise.resolve(void 0);
|
|
6727
7308
|
const file = cleanUrl(id);
|
|
6728
|
-
|
|
7309
|
+
const runtimeAffectingByDependency = isSourceScanDependency(file);
|
|
7310
|
+
if (runtimeAffectingByDependency) invalidateSourceCandidateScan();
|
|
6729
7311
|
if (sourceScanMatcher && !sourceScanMatcher(file)) {
|
|
6730
|
-
sourceCandidateCollector.remove(file);
|
|
7312
|
+
const change = sourceCandidateCollector.remove(file);
|
|
6731
7313
|
cacheCurrentSourceCandidateScan();
|
|
6732
7314
|
if (isSourceStyleRequest(file)) return readFile(file, "utf8").then((source) => cssMemory.refreshRememberedCssSourceBySourceFile(file, source)).catch((error) => {
|
|
6733
7315
|
if ((typeof error === "object" && error !== null && "code" in error ? error.code : void 0) !== "ENOENT") debug("remembered css source watch refresh failed: %s %O", file, error);
|
|
6734
|
-
}).then(() => cssMemory.refreshRememberedCssSourceByCurrentFile(file)).then(() =>
|
|
6735
|
-
return cssMemory.refreshRememberedCssSourceByCurrentFile(file);
|
|
7316
|
+
}).then(() => cssMemory.refreshRememberedCssSourceByCurrentFile(file)).then(() => applySourceCandidateHmrState(createViteSourceCandidateChange(file, change, { runtimeAffecting: true })));
|
|
7317
|
+
return cssMemory.refreshRememberedCssSourceByCurrentFile(file).then(() => applySourceCandidateHmrState(createViteSourceCandidateChange(file, change, { runtimeAffecting: true })));
|
|
6736
7318
|
}
|
|
6737
|
-
const existingTask = pendingSourceCandidateSyncByFile.get(file);
|
|
6738
|
-
if (existingTask) return existingTask.then(
|
|
6739
|
-
|
|
7319
|
+
const existingTask = sourceOverride === void 0 ? pendingSourceCandidateSyncByFile.get(file) : void 0;
|
|
7320
|
+
if (existingTask) return existingTask.then(async () => {
|
|
7321
|
+
return await syncChangedSourceCandidateFile(id);
|
|
7322
|
+
});
|
|
7323
|
+
const task = (sourceOverride === void 0 ? sourceCandidateCollector.syncCurrentFile(id) : sourceCandidateCollector.syncCurrentSource(id, sourceOverride)).catch((error) => {
|
|
6740
7324
|
debug("source candidate watch sync failed: %s %O", id, error);
|
|
6741
|
-
}).then(() => {
|
|
7325
|
+
}).then((change) => {
|
|
6742
7326
|
cacheCurrentSourceCandidateScan();
|
|
7327
|
+
return change ? applySourceCandidateHmrState(createViteSourceCandidateChange(file, change, { runtimeAffecting: runtimeAffectingByDependency })) : void 0;
|
|
6743
7328
|
}).finally(() => {
|
|
6744
7329
|
pendingSourceCandidateSyncs.delete(task);
|
|
6745
7330
|
pendingSourceCandidateSyncByFile.delete(file);
|
|
6746
7331
|
});
|
|
6747
7332
|
pendingSourceCandidateSyncs.add(task);
|
|
6748
7333
|
pendingSourceCandidateSyncByFile.set(file, task);
|
|
6749
|
-
return task.then(
|
|
7334
|
+
return task.then(async (change) => {
|
|
7335
|
+
await cssMemory.refreshRememberedCssSourceByCurrentFile(file);
|
|
7336
|
+
return change;
|
|
7337
|
+
});
|
|
6750
7338
|
};
|
|
6751
7339
|
const recordCssAssetResult = (file, css) => {
|
|
6752
|
-
touchMapEntry(
|
|
7340
|
+
touchMapEntry(cleanGeneratedCssByFile, normalizeVitePersistentCacheKey(file), css);
|
|
6753
7341
|
};
|
|
6754
7342
|
const recordViteProcessedCssAssetResult = (file, css, options = {}) => {
|
|
6755
7343
|
const key = normalizeVitePersistentCacheKey(file);
|
|
@@ -6763,8 +7351,11 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
6763
7351
|
const getViteProcessedCssAssetResults = () => viteProcessedCssAssetResults.entries();
|
|
6764
7352
|
const getViteProcessedCssAssetResult = (file) => viteProcessedCssAssetResults.get(normalizeVitePersistentCacheKey(file));
|
|
6765
7353
|
const getViteCssCacheStats = () => ({
|
|
6766
|
-
|
|
6767
|
-
|
|
7354
|
+
cleanGeneratedCssByFile: cleanGeneratedCssByFile.size,
|
|
7355
|
+
cleanGeneratedCssByFileRaw: summarizeStringCache(cleanGeneratedCssByFile),
|
|
7356
|
+
tracedGeneratedCssByFile: tracedGeneratedCssByFile.size,
|
|
7357
|
+
tracedGeneratedCssByFileRaw: summarizeStringCache(tracedGeneratedCssByFile),
|
|
7358
|
+
generatedClassSetByFile: generatedClassSetByFile.size,
|
|
6768
7359
|
viteProcessedCssAssetResults: viteProcessedCssAssetResults.size,
|
|
6769
7360
|
viteProcessedCssAssetResultsRaw: summarizeViteProcessedCssResults(viteProcessedCssAssetResults),
|
|
6770
7361
|
...cssMemory.getStats(),
|
|
@@ -6774,7 +7365,9 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
6774
7365
|
});
|
|
6775
7366
|
const pruneViteCssCaches = (options) => {
|
|
6776
7367
|
const activeFiles = new Set([...options.activeFiles].map(normalizeVitePersistentCacheKey));
|
|
6777
|
-
for (const key of
|
|
7368
|
+
for (const key of cleanGeneratedCssByFile.keys()) if (!activeFiles.has(key)) cleanGeneratedCssByFile.delete(key);
|
|
7369
|
+
for (const key of tracedGeneratedCssByFile.keys()) if (!activeFiles.has(key)) tracedGeneratedCssByFile.delete(key);
|
|
7370
|
+
for (const key of generatedClassSetByFile.keys()) if (!activeFiles.has(key)) generatedClassSetByFile.delete(key);
|
|
6778
7371
|
for (const [key, record] of viteProcessedCssAssetResults) {
|
|
6779
7372
|
const outputKey = typeof record.outputFile === "string" ? normalizeVitePersistentCacheKey(record.outputFile) : void 0;
|
|
6780
7373
|
if (!activeFiles.has(key) && (outputKey == null || !activeFiles.has(outputKey))) viteProcessedCssAssetResults.delete(key);
|
|
@@ -6788,7 +7381,12 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
6788
7381
|
const rememberTailwindRootCssModule = (id) => {
|
|
6789
7382
|
if (!shouldOwnTailwindGeneration) return;
|
|
6790
7383
|
tailwindRootCssModuleIds.add(id);
|
|
6791
|
-
|
|
7384
|
+
const cleanId = cleanUrl(id);
|
|
7385
|
+
if (isSourceStyleRequest(cleanId)) tailwindRootCssModuleIds.add(cleanId);
|
|
7386
|
+
};
|
|
7387
|
+
const registerTailwindRootCss = async (id, code) => {
|
|
7388
|
+
rememberTailwindRootCssModule(id);
|
|
7389
|
+
await registerAutoCssSource(id, code);
|
|
6792
7390
|
};
|
|
6793
7391
|
const isUniViteProject = () => {
|
|
6794
7392
|
return resolvedConfig?.plugins?.some((plugin) => plugin.name.includes("uni")) ?? false;
|
|
@@ -6841,28 +7439,41 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
6841
7439
|
const shouldPreserveStyleOutputExtension = frameworkCssPipelineStrategy?.shouldPreserveStyleOutputExtension?.(cssPipelineContext) ?? frameworkCssPipelineStrategy?.isNativeAppStyleTarget?.(cssPipelineContext) === true;
|
|
6842
7440
|
const sourceRoot = resolveWeappViteSourceRoot(resolvedConfig, opts.appType);
|
|
6843
7441
|
const outputFile = resolveViteCssPipelineOutputFile(requestFile, opts, rootDir, currentGeneratorBranch.isWeb, shouldPreserveStyleOutputExtension, sourceRoot);
|
|
6844
|
-
const
|
|
7442
|
+
const generatorTransformCode = currentGeneratorBranch.isWeb ? generatorCode : normalizeMiniProgramGeneratorCssSource(generatorCode, outputFile);
|
|
7443
|
+
const fullRuntime = getSourceCandidates() ?? getRecordedGeneratorCandidates() ?? await ensureRuntimeClassSet();
|
|
7444
|
+
const pendingHmrChange = resolvePendingHmrCandidateChange(generatorCode, file);
|
|
7445
|
+
const forceFullHmrCssRegeneration = pendingFullHmrCssRegeneration || resolvedConfig?.command === "serve" && pendingHmrCandidateChange !== void 0 && pendingHmrChange === void 0;
|
|
7446
|
+
const runtime = pendingHmrChange ? new Set(pendingHmrChange.addedCandidates) : fullRuntime;
|
|
7447
|
+
if (pendingHmrChange && currentGeneratorOptions.target === "weapp" && filterUnsupportedMiniProgramTailwindV4Candidates(pendingHmrChange.addedCandidates).size === 0) {
|
|
7448
|
+
const previousTracedCss = tracedGeneratedCssByFile.get(file);
|
|
7449
|
+
if (previousTracedCss !== void 0) {
|
|
7450
|
+
finishPendingHmrCssTargetFile(file);
|
|
7451
|
+
return `${createBundlerGeneratedCssMarker("vite", normalizeViteProcessedCssFile(file))}\n${previousTracedCss}`;
|
|
7452
|
+
}
|
|
7453
|
+
}
|
|
6845
7454
|
const sourceCssHandlerOptions = transformCssHandlerOptions.getCssHandlerOptions(requestFile);
|
|
6846
7455
|
const outputCssHandlerOptions = transformCssHandlerOptions.getCssHandlerOptions(outputFile);
|
|
6847
7456
|
const cssHandlerOptions = {
|
|
6848
7457
|
...sourceCssHandlerOptions,
|
|
6849
7458
|
isMainChunk: outputCssHandlerOptions.isMainChunk
|
|
6850
7459
|
};
|
|
6851
|
-
const transientCssSource = transientAutoCssSources.get(file) ?? (hasTailwindRootDirectives(
|
|
7460
|
+
const transientCssSource = transientAutoCssSources.get(file) ?? (hasTailwindRootDirectives(generatorTransformCode, { importFallback: currentGeneratorOptions.importFallback }) || hasTailwindSourceDirectives(generatorTransformCode, { importFallback: currentGeneratorOptions.importFallback }) || hasTailwindApplyDirective(generatorTransformCode) ? {
|
|
6852
7461
|
base: path.dirname(path.resolve(file)),
|
|
6853
|
-
css:
|
|
7462
|
+
css: generatorTransformCode,
|
|
6854
7463
|
file: path.resolve(file)
|
|
6855
7464
|
} : void 0);
|
|
6856
7465
|
const shouldDeferEmptyScopedCssSource = transientCssSource == null && (frameworkCssPipelineStrategy?.shouldDeferEmptyScopedCssSource?.({
|
|
6857
7466
|
...cssPipelineContext,
|
|
6858
7467
|
cssHandlerOptions,
|
|
6859
|
-
generatorCode
|
|
7468
|
+
generatorCode: generatorTransformCode
|
|
6860
7469
|
}) ?? true);
|
|
6861
|
-
const
|
|
7470
|
+
const previousCss = pendingHmrChange && !forceFullHmrCssRegeneration ? cleanGeneratedCssByFile.get(file) : void 0;
|
|
7471
|
+
const previousGeneratorCss = previousCss && !currentGeneratorBranch.isWeb ? normalizeMiniProgramGeneratorCssSource(previousCss, outputFile) : previousCss;
|
|
7472
|
+
const generated = await hmrTimingRecorder.measure("generateCss.serve", () => generateTailwindV4Css({
|
|
6862
7473
|
opts,
|
|
6863
7474
|
runtimeState,
|
|
6864
7475
|
runtime,
|
|
6865
|
-
rawSource:
|
|
7476
|
+
rawSource: generatorTransformCode,
|
|
6866
7477
|
file,
|
|
6867
7478
|
outputFile,
|
|
6868
7479
|
cssHandlerOptions,
|
|
@@ -6872,25 +7483,45 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
6872
7483
|
generatorPlatform: resolveGeneratorPlatform(),
|
|
6873
7484
|
styleHandler,
|
|
6874
7485
|
debug,
|
|
6875
|
-
previousCss:
|
|
7486
|
+
previousCss: previousGeneratorCss,
|
|
7487
|
+
previousClassSet: pendingHmrChange && !forceFullHmrCssRegeneration ? generatedClassSetByFile.get(file) : void 0,
|
|
6876
7488
|
deferEmptyScopedCssSource: shouldDeferEmptyScopedCssSource,
|
|
7489
|
+
disableSourceScan: pendingHmrChange !== void 0,
|
|
6877
7490
|
restoreLocalCssImports: !currentGeneratorBranch.isWeb
|
|
7491
|
+
}), {
|
|
7492
|
+
file,
|
|
7493
|
+
memoryDebug: {
|
|
7494
|
+
cleanCacheHit: cleanGeneratedCssByFile.has(file),
|
|
7495
|
+
forceFullHmrCssRegeneration,
|
|
7496
|
+
pendingAddedCandidates: pendingHmrCandidateChange?.addedCandidates.size ?? 0,
|
|
7497
|
+
pendingCssTargets: pendingHmrCssTargetFiles?.size ?? 0,
|
|
7498
|
+
pendingResolved: pendingHmrChange !== void 0,
|
|
7499
|
+
runtimeCandidates: runtime.size,
|
|
7500
|
+
target: currentGeneratorOptions.target
|
|
7501
|
+
}
|
|
6878
7502
|
});
|
|
6879
|
-
if (!generated)
|
|
7503
|
+
if (!generated) {
|
|
7504
|
+
if (pendingHmrChange) finishPendingHmrCssTargetFile(file);
|
|
7505
|
+
else if (!pendingHmrCandidateChange) clearPendingHmrCandidateChange();
|
|
7506
|
+
return;
|
|
7507
|
+
}
|
|
6880
7508
|
const finalizedCss = finalizeViteMiniProgramCss(generated.css);
|
|
6881
|
-
const shouldApplyWebCssCompat =
|
|
6882
|
-
const
|
|
7509
|
+
const shouldApplyWebCssCompat = shouldApplyViteWebCssCompat(cssPipelineContext, frameworkCssPipelineStrategy);
|
|
7510
|
+
const outputCss = frameworkCssPipelineStrategy?.transformGeneratedCss?.(finalizedCss, {
|
|
6883
7511
|
...cssPipelineContext,
|
|
6884
|
-
defaultWebCssCompat: (css) =>
|
|
7512
|
+
defaultWebCssCompat: (css) => transformWebCssCompat(css, resolveViteWebCssCompatOptions(cssPipelineContext)),
|
|
6885
7513
|
removeScopedPreflight: removeScopedTailwindPreflightCss,
|
|
6886
7514
|
shouldApplyWebCssCompat
|
|
6887
|
-
}) ?? removeScopedTailwindPreflightCss(shouldApplyWebCssCompat ?
|
|
7515
|
+
}) ?? removeScopedTailwindPreflightCss(shouldApplyWebCssCompat ? transformWebCssCompat(finalizedCss, resolveViteWebCssCompatOptions(cssPipelineContext)) : finalizedCss);
|
|
7516
|
+
const tracedCss = annotateCssSourceTrace(outputCss, {
|
|
6888
7517
|
opts,
|
|
6889
7518
|
tokenSources: createCssTokenSourceMap(getSourceCandidateSourcesForEntries(void 0), opts)
|
|
6890
7519
|
});
|
|
6891
7520
|
for (const dependency of generated.dependencies) hookContext?.addWatchFile?.(dependency);
|
|
6892
|
-
|
|
6893
|
-
|
|
7521
|
+
cleanGeneratedCssByFile.set(file, outputCss);
|
|
7522
|
+
tracedGeneratedCssByFile.set(file, tracedCss);
|
|
7523
|
+
generatedClassSetByFile.set(file, new Set(generated.classSet));
|
|
7524
|
+
const shouldInjectGeneratedCssIntoMain = mainCssChunkMatcher(outputFile, opts.appType) || hasTailwindRootDirectives(generatorTransformCode, { importFallback: currentGeneratorOptions.importFallback }) && !normalizeOutputPathKey(outputFile).includes("/");
|
|
6894
7525
|
recordViteProcessedCssAssetResult(file, tracedCss, {
|
|
6895
7526
|
injectIntoMain: shouldInjectGeneratedCssIntoMain,
|
|
6896
7527
|
outputFile
|
|
@@ -6906,7 +7537,9 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
6906
7537
|
});
|
|
6907
7538
|
markViteProcessedCssSource(file);
|
|
6908
7539
|
rememberTailwindRootCssModule(id);
|
|
6909
|
-
recordGeneratorCandidates(
|
|
7540
|
+
recordGeneratorCandidates(fullRuntime);
|
|
7541
|
+
if (pendingHmrChange) finishPendingHmrCssTargetFile(file);
|
|
7542
|
+
else if (!pendingHmrCandidateChange) clearPendingHmrCandidateChange();
|
|
6910
7543
|
cssMemory.rememberCssSource({
|
|
6911
7544
|
outputFile,
|
|
6912
7545
|
rawSource: code,
|
|
@@ -6919,7 +7552,7 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
6919
7552
|
getAppType: () => opts.appType,
|
|
6920
7553
|
generateTailwindCss: generateTailwindCssForVitePipeline,
|
|
6921
7554
|
rootImport: shouldOwnTailwindGeneration ? `${weappTailwindcssDirPosix}/generator-placeholder.css` : void 0,
|
|
6922
|
-
onTailwindRootCss:
|
|
7555
|
+
onTailwindRootCss: registerTailwindRootCss,
|
|
6923
7556
|
onCssSourceTransform: (id, code) => cssMemory.refreshRememberedCssSourceBySourceFile(id, code),
|
|
6924
7557
|
shouldGenerateCss: (_id, code) => hasVitePipelineTailwindGenerationDirective(code),
|
|
6925
7558
|
shouldDeferGeneration: (_id, code) => !shouldRewriteCssImports && hasTailwindRootDirectives(code, { importFallback: resolveCurrentGeneratorOptions().importFallback }),
|
|
@@ -7025,7 +7658,10 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7025
7658
|
let transformedCode = code;
|
|
7026
7659
|
if (shouldOwnTailwindGeneration && !resolveCurrentGeneratorBranch().isWeb && isCSSRequest(id)) transformedCode = transformEarlyMiniProgramCss(code);
|
|
7027
7660
|
const shouldReturnTransformedCode = transformedCode !== code;
|
|
7028
|
-
if (shouldOwnTailwindGeneration)
|
|
7661
|
+
if (shouldOwnTailwindGeneration) {
|
|
7662
|
+
cssMemory.rememberKnownSfcSource(id, transformedCode);
|
|
7663
|
+
if (isCSSRequest(id) && hasTailwindRootDirectives(transformedCode, { importFallback: resolveCurrentGeneratorOptions().importFallback })) rememberTailwindRootCssModule(id);
|
|
7664
|
+
}
|
|
7029
7665
|
if (!shouldOwnTailwindGeneration || !isSourceCandidateRequest(id) || !shouldCollectTransformedSourceCandidates(id)) {
|
|
7030
7666
|
if (shouldReturnTransformedCode) return {
|
|
7031
7667
|
code: transformedCode,
|
|
@@ -7055,8 +7691,10 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7055
7691
|
if (shouldOwnTailwindGeneration && isSourceCandidateRequest(id)) invalidateRecordedGeneratorCandidates();
|
|
7056
7692
|
if (isSourceScanDependency(id)) invalidateSourceCandidateScan();
|
|
7057
7693
|
if (change.event === "delete") {
|
|
7058
|
-
|
|
7694
|
+
const file = cleanUrl(id);
|
|
7695
|
+
const sourceCandidateChange = sourceCandidateCollector.remove(file);
|
|
7059
7696
|
cacheCurrentSourceCandidateScan();
|
|
7697
|
+
applySourceCandidateHmrState(createViteSourceCandidateChange(file, sourceCandidateChange, { runtimeAffecting: isSourceScanDependency(file) }));
|
|
7060
7698
|
return;
|
|
7061
7699
|
}
|
|
7062
7700
|
await syncChangedSourceCandidateFile(id);
|
|
@@ -7065,18 +7703,36 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7065
7703
|
async handleHotUpdate(ctx) {
|
|
7066
7704
|
return hmrTimingRecorder.measure("sourceCandidates.handleHotUpdate", async () => {
|
|
7067
7705
|
const isSourceCandidateHotUpdate = shouldOwnTailwindGeneration && isSourceCandidateRequest(ctx.file);
|
|
7068
|
-
|
|
7706
|
+
if (isSourceCandidateHotUpdate && isSourceStyleRequest(ctx.file)) for (const mod of ctx.modules) {
|
|
7707
|
+
if (mod.id) rememberTailwindRootCssModule(mod.id);
|
|
7708
|
+
if (mod.url) rememberTailwindRootCssModule(mod.url);
|
|
7709
|
+
if (mod.file) rememberTailwindRootCssModule(mod.file);
|
|
7710
|
+
}
|
|
7711
|
+
const canReadHotSource = typeof ctx.read === "function";
|
|
7712
|
+
const hotSource = isSourceCandidateHotUpdate && canReadHotSource ? await ctx.read().catch(() => void 0) : void 0;
|
|
7713
|
+
const sourceCandidateChange = await syncChangedSourceCandidateFile(ctx.file, hotSource);
|
|
7069
7714
|
const isWebLikeHotUpdate = isCurrentWebLikeStylePlatform();
|
|
7715
|
+
let canUseHmrCandidateAppend = false;
|
|
7070
7716
|
if (isSourceCandidateHotUpdate) {
|
|
7071
7717
|
invalidateRecordedGeneratorCandidates();
|
|
7072
|
-
|
|
7073
|
-
|
|
7074
|
-
|
|
7718
|
+
const preserveDeletedCssInHmr = resolveCurrentGeneratorOptions().hmr.preserveDeletedCss;
|
|
7719
|
+
canUseHmrCandidateAppend = preserveDeletedCssInHmr && !isSourceStyleRequest(ctx.file) && sourceCandidateChange !== void 0 && !sourceCandidateChange.runtimeAffecting;
|
|
7720
|
+
if (!canUseHmrCandidateAppend) {
|
|
7721
|
+
if (sourceCandidateChange === void 0) {
|
|
7722
|
+
clearPendingHmrCandidateChange();
|
|
7723
|
+
if (!preserveDeletedCssInHmr && !isSourceStyleRequest(ctx.file)) queueFullHmrCssRegeneration();
|
|
7724
|
+
}
|
|
7725
|
+
if (isWebLikeHotUpdate) {
|
|
7726
|
+
await refreshRuntimeStateForAutoCssSources?.(true);
|
|
7727
|
+
await syncSourceCandidateScan({ force: true });
|
|
7728
|
+
}
|
|
7075
7729
|
}
|
|
7076
7730
|
}
|
|
7731
|
+
if (isSourceCandidateHotUpdate) await waitForSourceCandidateSyncs();
|
|
7077
7732
|
const cssModules = resolveHotTailwindCssModules(ctx, tailwindRootCssModuleIds);
|
|
7078
7733
|
const sourceModules = isSourceCandidateHotUpdate && !isSourceStyleRequest(ctx.file) ? resolveHotSourceModules(ctx) : ctx.modules;
|
|
7079
|
-
|
|
7734
|
+
const hasHmrCandidateAppend = pendingHmrCandidateChange !== void 0 && !pendingHmrCandidateChange.runtimeAffecting && pendingHmrCandidateChange.addedCandidates.size > 0 || canUseHmrCandidateAppend && sourceCandidateChange !== void 0 && sourceCandidateChange.addedCandidates.size > 0;
|
|
7735
|
+
if (isSourceCandidateHotUpdate && !isSourceStyleRequest(ctx.file) && !hasHmrCandidateAppend && !isWebLikeHotUpdate && (!hasSelfAcceptingNonStyleHotModule(sourceModules) && cssModules.length === 0 || cssModules.length > 0 && isUniViteProject())) {
|
|
7080
7736
|
sendFullReloadForUnresolvedHotUpdate(ctx);
|
|
7081
7737
|
return [];
|
|
7082
7738
|
}
|
|
@@ -7084,7 +7740,10 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7084
7740
|
sendFullReloadForUnresolvedHotUpdate(ctx);
|
|
7085
7741
|
return [];
|
|
7086
7742
|
}
|
|
7087
|
-
|
|
7743
|
+
const shouldSendSupplementalCssHotUpdates = !(isWebLikeHotUpdate && isSourceCandidateHotUpdate && !isSourceStyleRequest(ctx.file) && resolveCurrentGeneratorOptions().hmr.preserveDeletedCss && sourceCandidateChange !== void 0 && !sourceCandidateChange.runtimeAffecting && sourceCandidateChange.addedCandidates.size === 0 && sourceCandidateChange.removedCandidates.size > 0);
|
|
7744
|
+
const supplementalCssFallbackIds = /* @__PURE__ */ new Set([...tailwindRootCssModuleIds, ...viteProcessedCssSourceFiles]);
|
|
7745
|
+
if (hasHmrCandidateAppend) armPendingHmrCssTargetFiles(cssModules, supplementalCssFallbackIds);
|
|
7746
|
+
if (shouldSendSupplementalCssHotUpdates) sendSupplementalCssHotUpdates(ctx, cssModules, supplementalCssFallbackIds);
|
|
7088
7747
|
if (isWebLikeHotUpdate && isSourceCandidateHotUpdate && !isSourceStyleRequest(ctx.file)) return;
|
|
7089
7748
|
if (isSourceCandidateHotUpdate && !isSourceStyleRequest(ctx.file) && cssModules.length > 0) return [...sourceModules, ...cssModules];
|
|
7090
7749
|
return cssModules.length > 0 ? [...ctx.modules, ...cssModules] : void 0;
|
|
@@ -7099,7 +7758,7 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7099
7758
|
...createViteServeCssGenerationPlugins({
|
|
7100
7759
|
generateCss: generateTailwindCssForVitePipeline,
|
|
7101
7760
|
getCommand: () => resolvedConfig?.command,
|
|
7102
|
-
onTailwindRootCss:
|
|
7761
|
+
onTailwindRootCss: registerTailwindRootCss,
|
|
7103
7762
|
shouldGenerate: () => shouldOwnTailwindGeneration
|
|
7104
7763
|
}),
|
|
7105
7764
|
createViteServeJsTransformPlugin({
|
|
@@ -7284,13 +7943,13 @@ const uniAppCssPipelineStrategy = {
|
|
|
7284
7943
|
return context.isWebGeneratorTarget && isUniAppWebviewAppBundle(context.bundleFiles);
|
|
7285
7944
|
},
|
|
7286
7945
|
shouldSelectConfiguredCssEntryRootSource(context) {
|
|
7287
|
-
return context.
|
|
7946
|
+
return context.opts.cssMatcher(context.outputFile) && context.isRootStyleOutputFile(context.outputFile);
|
|
7288
7947
|
},
|
|
7289
7948
|
shouldTransformServeJs(context) {
|
|
7290
7949
|
return !context.currentGeneratorBranch.isWeb || isUniAppWebviewStylePlatform(context.resolveStylePlatform());
|
|
7291
7950
|
},
|
|
7292
7951
|
transformGeneratedCss(css, context) {
|
|
7293
|
-
const webCss = context.shouldApplyWebCssCompat ?
|
|
7952
|
+
const webCss = context.shouldApplyWebCssCompat ? context.defaultWebCssCompat(css) : css;
|
|
7294
7953
|
const safeCss = isUniAppWebviewStylePlatform(context.resolveStylePlatform()) ? transformWebCssSafeSelectors(webCss, { escapeMap: context.opts.escapeMap }) : webCss;
|
|
7295
7954
|
return context.removeScopedPreflight(safeCss);
|
|
7296
7955
|
}
|