weapp-tailwindcss 5.1.15 → 5.1.16
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/gulp/shared/create-native-framework-plugins/cache-state.d.ts +71 -0
- package/dist/bundlers/gulp/shared/create-native-framework-plugins/file-transforms.d.ts +43 -0
- package/dist/bundlers/gulp/shared/create-native-framework-plugins.d.ts +2 -2
- package/dist/bundlers/shared/framework-postcss.d.ts +14 -0
- package/dist/bundlers/shared/generator-css/generation-helpers/preflight.d.ts +18 -0
- package/dist/bundlers/shared/generator-css/generation-helpers/results.d.ts +25 -0
- package/dist/bundlers/shared/generator-css/generation-helpers/runtime-isolation.d.ts +30 -0
- package/dist/bundlers/shared/generator-css/generation-helpers/source-order.d.ts +2 -0
- package/dist/bundlers/shared/generator-css/generation-helpers.d.ts +4 -72
- package/dist/bundlers/shared/generator-css/legacy-compat.d.ts +3 -1
- package/dist/bundlers/shared/generator-css/pipeline/deferred-output.d.ts +14 -0
- package/dist/bundlers/shared/generator-css/pipeline/execution.d.ts +12 -0
- package/dist/bundlers/shared/generator-css/pipeline/fallback-output.d.ts +12 -0
- package/dist/bundlers/shared/generator-css/pipeline/ordered-output.d.ts +25 -0
- package/dist/bundlers/shared/generator-css/pipeline.d.ts +2 -0
- package/dist/bundlers/shared/generator-css/result-helpers.d.ts +6 -0
- package/dist/bundlers/shared/generator-css/scoped-rules.d.ts +1 -0
- package/dist/bundlers/shared/generator-css/source-resolver/configuration.d.ts +33 -0
- package/dist/bundlers/shared/generator-css/source-resolver/resolve-source.d.ts +4 -0
- package/dist/bundlers/shared/generator-css/source-resolver/resolve-sources.d.ts +4 -0
- package/dist/bundlers/shared/generator-css/source-resolver/single-source.d.ts +16 -0
- package/dist/bundlers/shared/generator-css/source-resolver/source-entries.d.ts +3 -0
- package/dist/bundlers/shared/generator-css/source-resolver/source-matching.d.ts +5 -0
- package/dist/bundlers/shared/generator-css/source-resolver.d.ts +3 -6
- package/dist/bundlers/shared/generator-css/user-css/apply-only.d.ts +9 -0
- package/dist/bundlers/shared/generator-css/user-css/at-rules.d.ts +3 -0
- package/dist/bundlers/shared/generator-css/user-css/generated-cleanup.d.ts +4 -0
- package/dist/bundlers/shared/generator-css/user-css/source-fragments.d.ts +9 -0
- package/dist/bundlers/shared/generator-css/user-css/transform.d.ts +10 -0
- package/dist/bundlers/shared/generator-css/user-css/user-layers.d.ts +15 -0
- package/dist/bundlers/shared/generator-css/user-css.d.ts +5 -33
- package/dist/bundlers/shared/generator-css.d.ts +1 -2
- package/dist/bundlers/shared/v4-generation-core.d.ts +3 -0
- package/dist/bundlers/vite/css-finalizer/options.d.ts +54 -0
- package/dist/bundlers/vite/css-finalizer/plugin.d.ts +3 -0
- package/dist/bundlers/vite/css-finalizer.d.ts +1 -43
- package/dist/bundlers/vite/generate-bundle/finalize/bundle.d.ts +2 -0
- package/dist/bundlers/vite/generate-bundle/finalize/root-import-shell.d.ts +69 -0
- package/dist/bundlers/vite/generate-bundle/finalize.d.ts +2 -70
- package/dist/bundlers/vite/generate-bundle-runtime.d.ts +6 -0
- package/dist/bundlers/vite/generate-bundle.d.ts +1 -1
- package/dist/bundlers/vite/processed-css-assets/cleanup.d.ts +12 -0
- package/dist/bundlers/vite/processed-css-assets/collector.d.ts +4 -0
- package/dist/bundlers/vite/processed-css-assets/coverage.d.ts +34 -0
- package/dist/bundlers/vite/processed-css-assets/injection-plan.d.ts +42 -0
- package/dist/bundlers/vite/processed-css-assets/markers-imports.d.ts +89 -0
- package/dist/bundlers/vite/processed-css-assets/style-files.d.ts +3 -0
- package/dist/bundlers/vite/processed-css-assets.d.ts +4 -71
- package/dist/bundlers/vite/rewrite-css-imports.d.ts +1 -0
- package/dist/bundlers/vite/serve-css-generation.d.ts +1 -0
- package/dist/bundlers/vite/shared/create-framework-plugins-runtime.d.ts +2 -0
- package/dist/bundlers/vite/shared/create-framework-plugins.d.ts +4 -4
- package/dist/bundlers/vite/source-candidates/collector.d.ts +8 -0
- package/dist/bundlers/vite/source-candidates/store.d.ts +2 -0
- package/dist/bundlers/vite/source-candidates/types-and-cache.d.ts +69 -0
- package/dist/bundlers/vite/source-candidates.d.ts +4 -68
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/finalize-assets.d.ts +2 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/generated-css-result.d.ts +3 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/generated-css-task.d.ts +2 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/html-js-tasks.d.ts +5 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/finalize.d.ts +30 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/generated-css.d.ts +8 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/memory-trace.d.ts +78 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/preflight-runtime.d.ts +43 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/resources.d.ts +30 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/runtime-candidates.d.ts +1 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/sources.d.ts +28 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/user-css-markers.d.ts +1 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers/user-css.d.ts +21 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers.d.ts +9 -219
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/processed-css-task.d.ts +4 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +4 -0
- package/dist/bundlers/webpack/loaders/runtime-registry.d.ts +5 -0
- package/dist/bundlers/webpack/shared/create-framework-plugin/plugin.d.ts +20 -0
- package/dist/bundlers/webpack/shared/create-framework-plugin/watch-output.d.ts +13 -0
- package/dist/bundlers/webpack/shared/create-framework-plugin.d.ts +3 -21
- package/dist/cli.js +14 -18
- package/dist/cli.mjs +14 -18
- package/dist/{context-VeFq_8vW.js → context-BtLIID4m.js} +3 -3
- package/dist/{context-BgGWVAmN.mjs → context-JzwzSX36.mjs} +3 -3
- package/dist/core.js +1 -1
- package/dist/core.mjs +1 -1
- package/dist/{generator-CEnUsjed.js → generator-B91GhUJQ.js} +636 -505
- package/dist/{generator-CEo920So.mjs → generator-Bv7myuhY.mjs} +556 -431
- package/dist/generator.js +1 -1
- package/dist/generator.mjs +1 -1
- package/dist/{gulp-DP71z1jG.mjs → gulp-CKSklPlH.mjs} +217 -186
- package/dist/{gulp-3m1dAiig.js → gulp-Q1wITegn.js} +217 -186
- package/dist/gulp.js +1 -1
- package/dist/gulp.mjs +1 -1
- package/dist/{hmr-timing-1aS6--U7.mjs → hmr-timing-BXg7nI8N.mjs} +3411 -3276
- package/dist/{hmr-timing-B8p4f0ca.js → hmr-timing-CMPaWn9P.js} +3425 -3278
- package/dist/index.js +4 -4
- package/dist/index.mjs +4 -4
- package/dist/postcss.js +1 -1
- package/dist/postcss.mjs +1 -1
- package/dist/presets.js +1 -1
- package/dist/presets.mjs +1 -1
- package/dist/rspack.js +1 -1
- package/dist/rspack.mjs +1 -1
- package/dist/shared/mpx-plugin-owner.d.ts +2 -0
- package/dist/{source-candidate-scan-signature-BAahhiwb.js → source-candidate-scan-signature-BKZZk_e6.js} +144 -4
- package/dist/{source-candidate-scan-signature-Cf7259PR.mjs → source-candidate-scan-signature-CtK-mB_C.mjs} +127 -4
- package/dist/tailwindcss/v4-engine/generator/cache-stats.d.ts +26 -0
- package/dist/tailwindcss/v4-engine/generator/engine.d.ts +2 -0
- package/dist/tailwindcss/v4-engine/generator/incremental-cache.d.ts +52 -0
- package/dist/tailwindcss/v4-engine/generator.d.ts +2 -28
- package/dist/{tailwindcss-KBYPJ2DW.js → tailwindcss-B4phC0kB.js} +2 -2
- package/dist/{tailwindcss-xs704TRw.mjs → tailwindcss-BTcXX8Ka.mjs} +2 -2
- package/dist/{vite-nXZEiwG0.mjs → vite-BwQWl9ft.mjs} +806 -692
- package/dist/{vite-DUVjMduj.js → vite-DhVnXvAQ.js} +805 -691
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/weapp-tw-css-generation-loader.js +1 -1
- package/dist/{weapp-tw-css-import-rewrite-loader-DNk0IxAt.js → weapp-tw-css-import-rewrite-loader-B0tVkJLH.js} +2410 -2084
- package/dist/weapp-tw-css-import-rewrite-loader.js +1 -1
- package/dist/weapp-tw-runtime-classset-loader.js +10 -4
- package/dist/{webpack-C_UUFRgj.mjs → webpack-Bo1QrFPf.mjs} +1387 -1114
- package/dist/{webpack-nppysF4B.js → webpack-kh78iMSS.js} +1386 -1113
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +9 -7
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import { resolveImplicitAppTypeFromViteRoot } from "./framework.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { $ as normalizeTailwindConfigDirectives, Ct as isFileMatchedByTailwindSourceEntries, E as resolveTailwindcssOptions, G as hasUserCssLayerBlocks, H as normalizeEmptyTailwindCustomVariants, I as hasMiniProgramCssSpecificityPlaceholders, J as hasLocalCssImport, K as splitUserCssLayerBlocks, Nt as getTailwindV4IncrementalGenerateCacheStats, Ot as resolveTailwindV4CssSourceBase, Pt as filterUnsupportedMiniProgramTailwindV4Candidates, Q as hasTailwindSourceDirectives, X as hasTailwindNonRootGenerationDirectives, Y as hasTailwindApplyDirective, Z as hasTailwindRootDirectives, a as resolveGeneratorRuntimeBranch, b as normalizeCssEntries, c as shouldUseNativeAppCssBranch, g as upsertTailwindV4CssSource, h as hasConfiguredTailwindV4CssRoots, i as normalizeWeappTailwindcssGeneratorOptions, l as resolveUniUtsPlatform, lt as hasTailwindGeneratedCssMarkers, m as filterTailwindV4CssSourceRoots, nt as parseImportRequest, pt as stripGeneratorPlaceholderMarkers, rt as removeTailwindSourceDirectives, s as shouldUseMiniProgramCssBranch, tt as normalizeTailwindSourceForGenerator, x as findNearestPackageRoot, y as isTailwindV4CssEntry, z as stripMiniProgramCssSpecificityPlaceholders } from "./generator-Bv7myuhY.mjs";
|
|
3
3
|
import { t as omitUndefined } from "./object-BJSWl-E5.mjs";
|
|
4
|
-
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-
|
|
4
|
+
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-BTcXX8Ka.mjs";
|
|
5
5
|
import "./utils-MVwpU07P.mjs";
|
|
6
6
|
import { g as replaceWxml, y as createDebug } from "./wxml-DdGdeqaH.mjs";
|
|
7
|
-
import { a as vitePluginName, c as collectRuntimeClassSet, d as refreshTailwindRuntimeState, f as normalizeFrameworkStylePlatform, l as createTailwindRuntimeReadyPromise, n as normalizeStyleHandlerMajorVersion, o as shouldSkipJsTransform, s as toCustomAttributesEntities, t as getCompilerContext } from "./context-
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
7
|
+
import { a as vitePluginName, c as collectRuntimeClassSet, d as refreshTailwindRuntimeState, f as normalizeFrameworkStylePlatform, l as createTailwindRuntimeReadyPromise, n as normalizeStyleHandlerMajorVersion, o as shouldSkipJsTransform, s as toCustomAttributesEntities, t as getCompilerContext } from "./context-JzwzSX36.mjs";
|
|
8
|
+
import { A as processCachedTask, C as hasBundlerGeneratedCssMarker, D as createCssSourceTraceCacheSignature, E as annotateCssSourceTrace, I as createBundleRuntimeClassSetManager, N as isSourceCandidateRequest, O as createCssTokenSourceMap, P as extractCandidatesFromSource, S as createBundlerGeneratedCssMarker, T as stripBundlerGeneratedCssMarkers, a as extractMarkedUserLayerComponentsCss, d as normalizeMiniProgramGeneratorCssSource, f as normalizeMiniProgramImportShell, g as isSourceStyleRequest, j as createSourceCandidateCollector, o as mergeMarkedUserLayerComponentsCss, r as validateCandidatesByGenerator, t as createHmrTimingRecorder, u as runWithConcurrency, v as stripRequestQuery, w as parseBundlerGeneratedCssMarkerBlocks, y as scoreTailwindV4CssSourceFileMatch, z as isPureLocalCssImportWrapper } from "./hmr-timing-BXg7nI8N.mjs";
|
|
9
|
+
import { C as createBundleModuleGraphOptions, D as toAbsoluteOutputPath, F as viteStyleInjectorDelegates, L as resolveViteFrameworkProfile, M as resolvePluginDisabledState, N as createBuiltinViteStyleInjectorPlugins, O as captureFrameworkPostcssOptions, S as applyLinkedResults, T as normalizeOutputPathKey, _ 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 resolvePackageDir, 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-CtK-mB_C.mjs";
|
|
10
10
|
import { t as logger$1 } from "./logger-BNzxZbZj.mjs";
|
|
11
11
|
import fs, { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
12
12
|
import path from "node:path";
|
|
13
13
|
import process$1 from "node:process";
|
|
14
14
|
import { splitCandidateTokens } from "@tailwindcss-mangle/engine";
|
|
15
|
-
import { collectCssImportRequestsRoot, compileCssMacroConditionalComments, containsCssAfterMinify, filterExistingCssRules, isMiniProgramLocalCssImportRequest, mergeCoveredCssRuleDeclarations, mergeMiniProgramPreflightRuleDeclarations, mergeMiniProgramThemeScopeRuleDeclarations, parseTailwindCssDirectiveRequest, postcss, removeTailwindPostcssPlugins, removeTailwindSourceDirectivesRoot, removeUnsupportedMiniProgramCssImportsRoot,
|
|
15
|
+
import { collectCssImportRequestsRoot, compileCssMacroConditionalComments, containsCssAfterMinify, filterExistingCssRules, isMiniProgramLocalCssImportRequest, mergeCoveredCssRuleDeclarations, mergeMiniProgramPreflightRuleDeclarations, mergeMiniProgramThemeScopeRuleDeclarations, parseTailwindCssDirectiveRequest, postcss, removeTailwindPostcssPlugins, removeTailwindSourceDirectivesRoot, removeUnsupportedMiniProgramCssImportsRoot, resolvePostcssConfig, transformWebCssCompat, transformWebCssSafeSelectors, unwrapUnsupportedCascadeLayers } from "@weapp-tailwindcss/postcss";
|
|
16
16
|
import { LRUCache } from "lru-cache";
|
|
17
17
|
import { readFile } from "node:fs/promises";
|
|
18
18
|
import micromatch from "micromatch";
|
|
19
|
-
import { Buffer } from "node:buffer";
|
|
20
19
|
import { logger } from "@weapp-tailwindcss/logger";
|
|
20
|
+
import { Buffer } from "node:buffer";
|
|
21
21
|
import { parse } from "comment-json";
|
|
22
22
|
//#region src/uni-app-x/style-asset/style-value.ts
|
|
23
23
|
const GEN_APP_STYLES_RE = /const\s+GenAppStyles\s*=\s*\[_uM\(\[([\s\S]*?)\]\)\]/;
|
|
@@ -496,6 +496,17 @@ function createUniAppXBundleAssetSourceGetter(bundle) {
|
|
|
496
496
|
};
|
|
497
497
|
}
|
|
498
498
|
//#endregion
|
|
499
|
+
//#region src/bundlers/vite/generate-bundle/bundle-file-names.ts
|
|
500
|
+
function normalizeBundleFileNameKeysForTest(bundle) {
|
|
501
|
+
for (const [file, output] of Object.entries(bundle)) {
|
|
502
|
+
if (!output.fileName || output.fileName === file) continue;
|
|
503
|
+
const existing = bundle[output.fileName];
|
|
504
|
+
if (existing != null && existing !== output) continue;
|
|
505
|
+
bundle[output.fileName] = output;
|
|
506
|
+
delete bundle[file];
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
//#endregion
|
|
499
510
|
//#region src/bundlers/vite/generate-bundle/transform-filter.ts
|
|
500
511
|
function toArray(value) {
|
|
501
512
|
return Array.isArray(value) ? value : value === void 0 ? [] : [value];
|
|
@@ -1699,159 +1710,553 @@ const mix = (del = delimiter) => {
|
|
|
1699
1710
|
const posix = /* @__PURE__ */ mix(":");
|
|
1700
1711
|
const win32 = /* @__PURE__ */ mix(";");
|
|
1701
1712
|
//#endregion
|
|
1702
|
-
//#region src/bundlers/vite/
|
|
1703
|
-
const
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
".nvue",
|
|
1707
|
-
".svelte",
|
|
1708
|
-
".mpx"
|
|
1709
|
-
];
|
|
1710
|
-
const SFC_STYLE_BLOCK_RE$1 = /<style\b([^>]*)>([\s\S]*?)<\/style>/gi;
|
|
1711
|
-
const SFC_SCOPED_STYLE_ATTR_RE = /(?:^|\s)scoped(?:\s|=|$)/i;
|
|
1712
|
-
const SFC_LANG_STYLE_ATTR_RE = /(?:^|\s)lang(?:=(?:"([^"]+)"|'([^']+)'|([^\s"'=<>`]+)))?/i;
|
|
1713
|
-
function isSfcStyleSourceFile(file) {
|
|
1714
|
-
const normalizedFile = file.replace(/[?#].*$/, "");
|
|
1715
|
-
return SFC_STYLE_SOURCE_EXTENSIONS.some((extension) => normalizedFile.endsWith(extension));
|
|
1713
|
+
//#region src/bundlers/vite/processed-css-assets/style-files.ts
|
|
1714
|
+
const CSS_OUTPUT_FILE_RE = /\.(?:css|wxss|acss|ttss|qss|jxss|tyss)(?:$|[?#])/i;
|
|
1715
|
+
function isCssOutputFile(file) {
|
|
1716
|
+
return CSS_OUTPUT_FILE_RE.test(file);
|
|
1716
1717
|
}
|
|
1717
|
-
function
|
|
1718
|
-
const
|
|
1719
|
-
|
|
1720
|
-
let index = 0;
|
|
1721
|
-
let match = SFC_STYLE_BLOCK_RE$1.exec(source);
|
|
1722
|
-
while (match !== null) {
|
|
1723
|
-
const attrs = match[1] ?? "";
|
|
1724
|
-
styleSources.push({
|
|
1725
|
-
attrs,
|
|
1726
|
-
index,
|
|
1727
|
-
scoped: SFC_SCOPED_STYLE_ATTR_RE.test(attrs),
|
|
1728
|
-
source: match[2] ?? ""
|
|
1729
|
-
});
|
|
1730
|
-
index += 1;
|
|
1731
|
-
match = SFC_STYLE_BLOCK_RE$1.exec(source);
|
|
1732
|
-
}
|
|
1733
|
-
return styleSources;
|
|
1718
|
+
function isRootStyleOutputFile(file) {
|
|
1719
|
+
const normalized = normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
1720
|
+
return isCssOutputFile(normalized) && !normalized.includes("/");
|
|
1734
1721
|
}
|
|
1735
|
-
function
|
|
1736
|
-
return
|
|
1722
|
+
function isMiniProgramStyleOutputFile(file) {
|
|
1723
|
+
return /\.(?:wxss|acss|ttss|qss|jxss|tyss)(?:$|[?#])/i.test(file);
|
|
1737
1724
|
}
|
|
1738
|
-
|
|
1739
|
-
|
|
1725
|
+
//#endregion
|
|
1726
|
+
//#region src/bundlers/vite/processed-css-assets/markers-imports.ts
|
|
1727
|
+
function createCssAssetPipelineContext(options, file, bundle) {
|
|
1728
|
+
const context = options.createCssPipelineContext?.(file);
|
|
1729
|
+
return context ? {
|
|
1730
|
+
...context,
|
|
1731
|
+
bundle
|
|
1732
|
+
} : void 0;
|
|
1740
1733
|
}
|
|
1741
|
-
function
|
|
1742
|
-
|
|
1743
|
-
return scopedStyleBlock ? `${sourceFile}?vue&type=style&index=${scopedStyleBlock.index}&scoped=true` : sourceFile;
|
|
1734
|
+
function getAssetFile$1(bundleFile, asset) {
|
|
1735
|
+
return asset.fileName || bundleFile;
|
|
1744
1736
|
}
|
|
1745
|
-
function
|
|
1746
|
-
return source
|
|
1737
|
+
function readAssetSource$2(asset) {
|
|
1738
|
+
return typeof asset.source === "string" ? asset.source : asset.source.toString();
|
|
1747
1739
|
}
|
|
1748
|
-
function
|
|
1749
|
-
|
|
1750
|
-
return match?.[1] ?? match?.[2] ?? match?.[3];
|
|
1740
|
+
function clearAssetSource(asset) {
|
|
1741
|
+
asset.source = "";
|
|
1751
1742
|
}
|
|
1752
|
-
function
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
params.set("index", String(styleBlock.index));
|
|
1757
|
-
if (styleBlock.scoped) params.set("scoped", "true");
|
|
1758
|
-
const lang = resolveSfcStyleBlockLang(styleBlock.attrs);
|
|
1759
|
-
if (lang) params.set("lang", lang);
|
|
1760
|
-
return `${sourceFile}?${params.toString()}`;
|
|
1743
|
+
function appendCss$1(baseCss, css) {
|
|
1744
|
+
if (baseCss.length === 0) return css;
|
|
1745
|
+
if (css.length === 0) return baseCss;
|
|
1746
|
+
return `${baseCss}\n${css}`;
|
|
1761
1747
|
}
|
|
1762
|
-
function
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1748
|
+
function normalizeCssRecordIdentity(css) {
|
|
1749
|
+
return css.trim();
|
|
1750
|
+
}
|
|
1751
|
+
function hasNonCommentCss(css) {
|
|
1752
|
+
return css.replace(/\/\*[\s\S]*?\*\//g, "").trim().length > 0;
|
|
1753
|
+
}
|
|
1754
|
+
function dedupeViteCssResults(records) {
|
|
1755
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1756
|
+
return records.filter((record) => {
|
|
1757
|
+
const key = `${normalizeOutputPathKey(record.outputFile ?? "")}\0${normalizeCssRecordIdentity(record.css)}`;
|
|
1758
|
+
if (seen.has(key)) return false;
|
|
1759
|
+
seen.add(key);
|
|
1760
|
+
return true;
|
|
1770
1761
|
});
|
|
1771
|
-
const requestIndex = currentRequest ? Number.parseInt(new URLSearchParams(currentRequest.split("?", 2)[1] ?? "").get("index") ?? "", 10) : NaN;
|
|
1772
|
-
const styleBlock = (Number.isInteger(requestIndex) ? styleBlocks.find((styleBlock) => styleBlock.index === requestIndex) : void 0) ?? (matchedBlocks.length === 1 ? matchedBlocks[0] : styleBlocks.length === 1 ? styleBlocks[0] : void 0);
|
|
1773
|
-
return styleBlock ? createSfcStyleRequest(sourceFile, styleBlock) : sourceFile;
|
|
1774
1762
|
}
|
|
1775
|
-
function
|
|
1776
|
-
|
|
1777
|
-
|
|
1763
|
+
function removeTailwindSourceMediaWrappersRoot(root) {
|
|
1764
|
+
let changed = false;
|
|
1765
|
+
root.walkAtRules("media", (atRule) => {
|
|
1766
|
+
if (!atRule.params.startsWith("source(")) return;
|
|
1767
|
+
if (atRule.nodes && atRule.nodes.length > 0) atRule.replaceWith(...atRule.nodes);
|
|
1768
|
+
else atRule.remove();
|
|
1769
|
+
changed = true;
|
|
1770
|
+
});
|
|
1771
|
+
if (changed) root.walkAtRules((atRule) => {
|
|
1772
|
+
if (atRule.nodes && atRule.nodes.length === 0) atRule.remove();
|
|
1773
|
+
});
|
|
1774
|
+
return changed;
|
|
1778
1775
|
}
|
|
1779
|
-
function
|
|
1780
|
-
|
|
1781
|
-
return hasTailwindGenerationSource(source, { allowRootDirectives: false });
|
|
1776
|
+
function removeTailwindSourceMediaWrappersFallback(css) {
|
|
1777
|
+
return css.replace(/@media\s+source\([^)]*\)\s*\{\s*\/\*!\s*weapp-tailwindcss generator-placeholder\s*\*\/?\s*\}/gi, "").replace(/@media\s+source\([^)]*\)\s*\{\s*\}/gi, "");
|
|
1782
1778
|
}
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
return;
|
|
1793
|
-
}
|
|
1794
|
-
const styleBlocks = extractSfcStyleBlocks(source);
|
|
1795
|
-
const rawSource = styleBlocks.map((style) => style.source).join("\n");
|
|
1796
|
-
if (!rawSource || !hasTailwindGenerationSourceForFile(sourceFile, rawSource)) {
|
|
1797
|
-
debug("sfc style source infer skipped: no tailwind generation source for %s -> %s", outputFile, sourceFile);
|
|
1798
|
-
return;
|
|
1779
|
+
function removeTailwindEntryDirectivesFromCss(css) {
|
|
1780
|
+
try {
|
|
1781
|
+
const source = stripGeneratorPlaceholderMarkers(css);
|
|
1782
|
+
const root = postcss.parse(source);
|
|
1783
|
+
const removedMediaWrappers = removeTailwindSourceMediaWrappersRoot(root);
|
|
1784
|
+
const removedTailwindDirectives = removeTailwindSourceDirectivesRoot(root);
|
|
1785
|
+
return removedMediaWrappers || removedTailwindDirectives ? root.toString() : source;
|
|
1786
|
+
} catch {
|
|
1787
|
+
return removeTailwindSourceDirectives(removeTailwindSourceMediaWrappersFallback(css));
|
|
1799
1788
|
}
|
|
1800
|
-
|
|
1801
|
-
|
|
1802
|
-
|
|
1803
|
-
|
|
1804
|
-
|
|
1789
|
+
}
|
|
1790
|
+
function removeUnsupportedMiniProgramCssImportsFallback(css, file) {
|
|
1791
|
+
if (!isMiniProgramStyleOutputFile(file) || !css.includes("@import")) return css;
|
|
1792
|
+
return css.split(/\r?\n/).filter((line) => {
|
|
1793
|
+
const trimmed = line.trim();
|
|
1794
|
+
if (!trimmed.startsWith("@import")) return true;
|
|
1795
|
+
const request = parseTailwindCssDirectiveRequest(trimmed.slice(7).trim().replace(/;$/, "").trim());
|
|
1796
|
+
return request === void 0 || isMiniProgramLocalCssImportRequest(request);
|
|
1797
|
+
}).join("\n");
|
|
1798
|
+
}
|
|
1799
|
+
function normalizeInjectableCssForTarget(css, file) {
|
|
1800
|
+
return normalizeInjectableCssForTargetWithImports(css, file).css;
|
|
1801
|
+
}
|
|
1802
|
+
function normalizeInjectableCssForTargetWithImports(css, file) {
|
|
1803
|
+
if (!css.includes("@import")) return {
|
|
1804
|
+
css,
|
|
1805
|
+
importedStyleFiles: /* @__PURE__ */ new Set()
|
|
1805
1806
|
};
|
|
1807
|
+
try {
|
|
1808
|
+
const root = postcss.parse(css);
|
|
1809
|
+
const changed = isMiniProgramStyleOutputFile(file) ? removeUnsupportedMiniProgramCssImportsRoot(root) : false;
|
|
1810
|
+
const importedStyleFiles = collectImportedStyleFilesRoot(root, file);
|
|
1811
|
+
return {
|
|
1812
|
+
css: changed ? root.toString() : css,
|
|
1813
|
+
importedStyleFiles: importedStyleFiles.size > 0 ? importedStyleFiles : collectImportedStyleFilesFallback(css, file)
|
|
1814
|
+
};
|
|
1815
|
+
} catch {
|
|
1816
|
+
const fallbackCss = removeUnsupportedMiniProgramCssImportsFallback(css, file);
|
|
1817
|
+
return {
|
|
1818
|
+
css: fallbackCss,
|
|
1819
|
+
importedStyleFiles: collectImportedStyleFiles(fallbackCss, file)
|
|
1820
|
+
};
|
|
1821
|
+
}
|
|
1806
1822
|
}
|
|
1807
|
-
function
|
|
1808
|
-
return
|
|
1823
|
+
function stripStyleExtension(file) {
|
|
1824
|
+
return file.replace(/[?#].*$/, "").replace(/\.(?:css|wxss|acss|ttss|qss|jxss|tyss|scss|sass|less|styl|stylus|pcss|postcss)$/i, "");
|
|
1809
1825
|
}
|
|
1810
|
-
function
|
|
1811
|
-
|
|
1812
|
-
return [
|
|
1813
|
-
output.facadeModuleId,
|
|
1814
|
-
...moduleIds,
|
|
1815
|
-
...Object.keys(output.modules ?? {})
|
|
1816
|
-
].filter((id, index, ids) => typeof id === "string" && id.length > 0 && ids.indexOf(id) === index);
|
|
1826
|
+
function isStyleImportRequest(request) {
|
|
1827
|
+
return typeof request === "string" && request.length > 0 && !/^(?:https?:)?\/\//i.test(request) && /\.(?:css|wxss|acss|ttss|qss|jxss|tyss)(?:$|[?#])/i.test(request);
|
|
1817
1828
|
}
|
|
1818
|
-
function
|
|
1819
|
-
|
|
1820
|
-
|
|
1821
|
-
if (
|
|
1822
|
-
|
|
1829
|
+
function resolveImportedStyleFile(targetFile, request) {
|
|
1830
|
+
if (!isStyleImportRequest(request)) return;
|
|
1831
|
+
const cleanRequest = request.replace(/[?#].*$/, "");
|
|
1832
|
+
if (cleanRequest.startsWith("/")) return normalizeOutputPathKey(cleanRequest.slice(1));
|
|
1833
|
+
const targetDir = posix.posix.dirname(normalizeOutputPathKey(targetFile));
|
|
1834
|
+
return normalizeOutputPathKey(posix.posix.join(targetDir === "." ? "" : targetDir, cleanRequest));
|
|
1823
1835
|
}
|
|
1824
|
-
function
|
|
1825
|
-
const
|
|
1826
|
-
|
|
1827
|
-
const
|
|
1828
|
-
|
|
1836
|
+
function collectImportedStyleFilesFromRequests(requests, targetFile) {
|
|
1837
|
+
const imports = /* @__PURE__ */ new Set();
|
|
1838
|
+
for (const request of requests) {
|
|
1839
|
+
const importedFile = resolveImportedStyleFile(targetFile, request);
|
|
1840
|
+
if (importedFile) imports.add(importedFile);
|
|
1829
1841
|
}
|
|
1830
|
-
|
|
1842
|
+
return imports;
|
|
1831
1843
|
}
|
|
1832
|
-
function
|
|
1833
|
-
|
|
1834
|
-
if (!isSfcStyleSourceFile(file)) return;
|
|
1835
|
-
if (!path.isAbsolute(file)) return;
|
|
1836
|
-
return path.resolve(file);
|
|
1844
|
+
function collectImportedStyleFilesRoot(root, targetFile) {
|
|
1845
|
+
return collectImportedStyleFilesFromRequests(collectCssImportRequestsRoot(root), targetFile);
|
|
1837
1846
|
}
|
|
1838
|
-
function
|
|
1839
|
-
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1848
|
-
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1847
|
+
function collectImportedStyleFilesFallback(css, targetFile) {
|
|
1848
|
+
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);
|
|
1849
|
+
}
|
|
1850
|
+
function collectImportedStyleFiles(css, targetFile) {
|
|
1851
|
+
if (!css.includes("@import")) return /* @__PURE__ */ new Set();
|
|
1852
|
+
try {
|
|
1853
|
+
const imports = collectImportedStyleFilesRoot(postcss.parse(css), targetFile);
|
|
1854
|
+
return imports.size > 0 ? imports : collectImportedStyleFilesFallback(css, targetFile);
|
|
1855
|
+
} catch {}
|
|
1856
|
+
return collectImportedStyleFilesFallback(css, targetFile);
|
|
1857
|
+
}
|
|
1858
|
+
function normalizeMarkerOutputFile(markerFile, resolveViteProcessedCssOutputFile) {
|
|
1859
|
+
return resolveViteProcessedCssOutputFile?.(markerFile) ?? markerFile;
|
|
1860
|
+
}
|
|
1861
|
+
function isMatchingGeneratedCssMarkerFile(targetFile, markerFile, resolveViteProcessedCssOutputFile) {
|
|
1862
|
+
if (!markerFile) return false;
|
|
1863
|
+
return normalizeOutputPathKey(stripStyleExtension(targetFile)) === normalizeOutputPathKey(stripStyleExtension(normalizeMarkerOutputFile(markerFile, resolveViteProcessedCssOutputFile)));
|
|
1864
|
+
}
|
|
1865
|
+
function resolveViteProcessedCssAssetSource(file, rawSource, resolveViteProcessedCssOutputFile) {
|
|
1866
|
+
const blocks = parseBundlerGeneratedCssMarkerBlocks(rawSource).filter((block) => block.bundler === "vite");
|
|
1867
|
+
if (blocks.length <= 1) return stripBundlerGeneratedCssMarkers(rawSource);
|
|
1868
|
+
const matchedCss = blocks.filter((block) => isMatchingGeneratedCssMarkerFile(file, block.file, resolveViteProcessedCssOutputFile)).map((block) => block.css);
|
|
1869
|
+
return matchedCss.length > 0 ? matchedCss.join("\n") : stripBundlerGeneratedCssMarkers(rawSource);
|
|
1870
|
+
}
|
|
1871
|
+
function collectMatchingGeneratedCssMarkerFiles(file, rawSource, resolveViteProcessedCssOutputFile) {
|
|
1872
|
+
return parseBundlerGeneratedCssMarkerBlocks(rawSource).filter((block) => block.bundler === "vite").filter((block) => isMatchingGeneratedCssMarkerFile(file, block.file, resolveViteProcessedCssOutputFile)).map((block) => block.file).filter((markerFile) => typeof markerFile === "string" && markerFile.length > 0);
|
|
1873
|
+
}
|
|
1874
|
+
function collectRootStyleBundleCssSources(bundle, excludedFile) {
|
|
1875
|
+
const sources = [];
|
|
1876
|
+
const excludedFileKey = normalizeOutputPathKey(excludedFile);
|
|
1877
|
+
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
1878
|
+
if (output.type !== "asset") continue;
|
|
1879
|
+
const file = normalizeOutputPathKey(getAssetFile$1(bundleFile, output));
|
|
1880
|
+
if (file === excludedFileKey || !isRootStyleOutputFile(file)) continue;
|
|
1881
|
+
const source = stripBundlerGeneratedCssMarkers(readAssetSource$2(output)).trim();
|
|
1882
|
+
if (source.length > 0) sources.push(source);
|
|
1883
|
+
}
|
|
1884
|
+
return sources;
|
|
1885
|
+
}
|
|
1886
|
+
function isHtmlOutputFile(file) {
|
|
1887
|
+
return /\.html(?:$|[?#])/i.test(file);
|
|
1888
|
+
}
|
|
1889
|
+
function stripQueryAndHash(file) {
|
|
1890
|
+
return file.replace(/[?#].*$/, "");
|
|
1891
|
+
}
|
|
1892
|
+
function resolveHtmlLinkedStyleFile(htmlFile, request) {
|
|
1893
|
+
if (!isStyleImportRequest(request)) return;
|
|
1894
|
+
const cleanRequest = stripQueryAndHash(request);
|
|
1895
|
+
if (cleanRequest.startsWith("/")) return normalizeOutputPathKey(cleanRequest.slice(1));
|
|
1896
|
+
const htmlDir = posix.posix.dirname(normalizeOutputPathKey(stripQueryAndHash(htmlFile)));
|
|
1897
|
+
return normalizeOutputPathKey(posix.posix.join(htmlDir === "." ? "" : htmlDir, cleanRequest));
|
|
1898
|
+
}
|
|
1899
|
+
function collectHtmlLinkedStyleFiles(bundle) {
|
|
1900
|
+
const linkedFiles = /* @__PURE__ */ new Set();
|
|
1901
|
+
const linkedBasenames = /* @__PURE__ */ new Set();
|
|
1902
|
+
const linkHrefRE = /<link\s[^>]*href\s*=\s*(["'])([^"']+)\1[^>]*>/gi;
|
|
1903
|
+
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
1904
|
+
if (output.type !== "asset") continue;
|
|
1905
|
+
const htmlFile = getAssetFile$1(bundleFile, output);
|
|
1906
|
+
if (!isHtmlOutputFile(htmlFile)) continue;
|
|
1907
|
+
const html = readAssetSource$2(output);
|
|
1908
|
+
for (const match of html.matchAll(linkHrefRE)) {
|
|
1909
|
+
const href = match[2];
|
|
1910
|
+
if (!href) continue;
|
|
1911
|
+
const linkedFile = resolveHtmlLinkedStyleFile(htmlFile, href);
|
|
1912
|
+
if (!linkedFile || !isRootStyleOutputFile(linkedFile)) continue;
|
|
1913
|
+
linkedFiles.add(linkedFile);
|
|
1914
|
+
linkedBasenames.add(posix.posix.basename(linkedFile));
|
|
1915
|
+
}
|
|
1916
|
+
}
|
|
1917
|
+
return {
|
|
1918
|
+
linkedBasenames,
|
|
1919
|
+
linkedFiles
|
|
1920
|
+
};
|
|
1921
|
+
}
|
|
1922
|
+
function isLinkedStyleFile(file, linked) {
|
|
1923
|
+
const fileKey = normalizeOutputPathKey(stripQueryAndHash(file));
|
|
1924
|
+
return linked.linkedFiles.has(fileKey) || isRootStyleOutputFile(fileKey) && linked.linkedBasenames.has(posix.posix.basename(fileKey));
|
|
1925
|
+
}
|
|
1926
|
+
function removeDuplicateUnlinkedRootCssAssetsReferencedByHtml(bundle, options = {}) {
|
|
1927
|
+
const linked = collectHtmlLinkedStyleFiles(bundle);
|
|
1928
|
+
if (linked.linkedFiles.size === 0 && linked.linkedBasenames.size === 0) return 0;
|
|
1929
|
+
const linkedSources = /* @__PURE__ */ new Set();
|
|
1930
|
+
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
1931
|
+
if (output.type !== "asset") continue;
|
|
1932
|
+
const file = getAssetFile$1(bundleFile, output);
|
|
1933
|
+
if (!isCssOutputFile(file) || isMiniProgramStyleOutputFile(file) || !isLinkedStyleFile(file, linked)) continue;
|
|
1934
|
+
const source = stripBundlerGeneratedCssMarkers(readAssetSource$2(output)).trim();
|
|
1935
|
+
if (source.length > 0) linkedSources.add(source);
|
|
1936
|
+
}
|
|
1937
|
+
if (linkedSources.size === 0) return 0;
|
|
1938
|
+
let removed = 0;
|
|
1939
|
+
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
1940
|
+
if (output.type !== "asset") continue;
|
|
1941
|
+
const file = getAssetFile$1(bundleFile, output);
|
|
1942
|
+
if (!isRootStyleOutputFile(file) || isMiniProgramStyleOutputFile(file) || isLinkedStyleFile(file, linked)) continue;
|
|
1943
|
+
const source = stripBundlerGeneratedCssMarkers(readAssetSource$2(output)).trim();
|
|
1944
|
+
if (!linkedSources.has(source)) continue;
|
|
1945
|
+
delete bundle[bundleFile];
|
|
1946
|
+
options.debug?.("remove duplicate unlinked root css asset referenced by html: %s", file);
|
|
1947
|
+
removed++;
|
|
1948
|
+
}
|
|
1949
|
+
return removed;
|
|
1950
|
+
}
|
|
1951
|
+
//#endregion
|
|
1952
|
+
//#region src/bundlers/vite/processed-css-assets/cleanup.ts
|
|
1953
|
+
function collectCssImportAtRuleCss(css) {
|
|
1954
|
+
if (!css.includes("@import")) return [];
|
|
1955
|
+
const fallbackImports = [...css.matchAll(/@import\s[^;]+;?/g)].map((match) => match[0]);
|
|
1956
|
+
if (fallbackImports.length > 0) return fallbackImports;
|
|
1957
|
+
try {
|
|
1958
|
+
const root = postcss.parse(css);
|
|
1959
|
+
const imports = [];
|
|
1960
|
+
root.each((node) => {
|
|
1961
|
+
if (node.type === "atrule" && node.name === "import") imports.push(node.toString());
|
|
1962
|
+
});
|
|
1963
|
+
return imports;
|
|
1964
|
+
} catch {
|
|
1965
|
+
return [];
|
|
1966
|
+
}
|
|
1967
|
+
}
|
|
1968
|
+
function parseCssImportRequest(importCss) {
|
|
1969
|
+
const trimmed = importCss.trim();
|
|
1970
|
+
if (!trimmed.startsWith("@import")) return;
|
|
1971
|
+
return parseTailwindCssDirectiveRequest(trimmed.slice(7).trim().replace(/;$/, "").trim());
|
|
1972
|
+
}
|
|
1973
|
+
function shouldRestoreCssImportAtRule(importCss, file) {
|
|
1974
|
+
if (file === void 0 || !isMiniProgramStyleOutputFile(file)) return true;
|
|
1975
|
+
const request = parseCssImportRequest(importCss);
|
|
1976
|
+
if (request === void 0) return false;
|
|
1977
|
+
if (isMiniProgramLocalCssImportRequest(request)) return true;
|
|
1978
|
+
return isStyleImportRequest(request) && !request.includes("/");
|
|
1979
|
+
}
|
|
1980
|
+
function restoreCssImportAtRules(source, filtered, file) {
|
|
1981
|
+
const imports = collectCssImportAtRuleCss(source).filter((importCss) => shouldRestoreCssImportAtRule(importCss, file));
|
|
1982
|
+
if (imports.length === 0) return filtered;
|
|
1983
|
+
const missingImports = imports.filter((importCss) => !filtered.includes(importCss));
|
|
1984
|
+
if (missingImports.length === 0) return filtered;
|
|
1985
|
+
return appendCss$1(missingImports.join("\n"), filtered);
|
|
1986
|
+
}
|
|
1987
|
+
function removeCommentOnlyAtRules(css) {
|
|
1988
|
+
if (!css.includes("@")) return css;
|
|
1989
|
+
try {
|
|
1990
|
+
const root = postcss.parse(css);
|
|
1991
|
+
let changed = false;
|
|
1992
|
+
root.walkAtRules((atRule) => {
|
|
1993
|
+
if (!atRule.nodes || atRule.nodes.length === 0) return;
|
|
1994
|
+
if (atRule.nodes.some((node) => node.type !== "comment")) return;
|
|
1995
|
+
atRule.remove();
|
|
1996
|
+
changed = true;
|
|
1997
|
+
});
|
|
1998
|
+
return changed ? root.toString() : css;
|
|
1999
|
+
} catch {
|
|
2000
|
+
return css;
|
|
2001
|
+
}
|
|
2002
|
+
}
|
|
2003
|
+
function collectImportedBundleCssSources(bundle, importedStyleFiles) {
|
|
2004
|
+
if (importedStyleFiles.size === 0) return [];
|
|
2005
|
+
const importedFileNames = new Set([...importedStyleFiles].map((file) => posix.posix.basename(file)));
|
|
2006
|
+
const importedSources = [];
|
|
2007
|
+
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2008
|
+
if (output.type !== "asset") continue;
|
|
2009
|
+
const file = normalizeOutputPathKey(getAssetFile$1(bundleFile, output));
|
|
2010
|
+
if (!(importedStyleFiles.has(file) || !file.includes("/") && importedFileNames.has(posix.posix.basename(file)))) continue;
|
|
2011
|
+
importedSources.push(readAssetSource$2(output));
|
|
2012
|
+
}
|
|
2013
|
+
return importedSources;
|
|
2014
|
+
}
|
|
2015
|
+
function collectBundleAssetFiles(bundle) {
|
|
2016
|
+
const files = /* @__PURE__ */ new Set();
|
|
2017
|
+
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2018
|
+
if (output.type !== "asset") continue;
|
|
2019
|
+
files.add(normalizeOutputPathKey(getAssetFile$1(bundleFile, output)));
|
|
2020
|
+
}
|
|
2021
|
+
return files;
|
|
2022
|
+
}
|
|
2023
|
+
function normalizeComparableStyleFile(file) {
|
|
2024
|
+
return normalizeOutputPathKey(posix.normalize(file.replace(/[?#].*$/, "")));
|
|
2025
|
+
}
|
|
2026
|
+
function collectConfiguredTailwindV4CssEntryFiles(opts) {
|
|
2027
|
+
const runtimeCssEntries = opts.tailwindRuntime?.options?.tailwindcss?.v4?.cssEntries;
|
|
2028
|
+
return [
|
|
2029
|
+
...Array.isArray(opts.cssEntries) ? opts.cssEntries : [],
|
|
2030
|
+
...Array.isArray(opts.tailwindcss?.v4?.cssEntries) ? opts.tailwindcss.v4.cssEntries : [],
|
|
2031
|
+
...Array.isArray(opts.tailwindcssRuntimeOptions?.tailwindcss?.v4?.cssEntries) ? opts.tailwindcssRuntimeOptions.tailwindcss.v4.cssEntries : [],
|
|
2032
|
+
...Array.isArray(runtimeCssEntries) ? runtimeCssEntries : []
|
|
2033
|
+
].filter((file) => typeof file === "string" && file.length > 0);
|
|
2034
|
+
}
|
|
2035
|
+
function isConfiguredTailwindV4CssEntryFile(opts, file) {
|
|
2036
|
+
if (typeof file !== "string" || file.length === 0) return false;
|
|
2037
|
+
const fileKey = normalizeComparableStyleFile(file);
|
|
2038
|
+
return collectConfiguredTailwindV4CssEntryFiles(opts).some((entry) => normalizeComparableStyleFile(entry) === fileKey);
|
|
2039
|
+
}
|
|
2040
|
+
function resolveConfiguredCssEntryRootInjectionTarget(bundle, options, sourceFile, outputFile) {
|
|
2041
|
+
const opts = options.opts;
|
|
2042
|
+
if (opts === void 0 || isMiniProgramStyleOutputFile(outputFile) || !isConfiguredTailwindV4CssEntryFile(opts, sourceFile)) return;
|
|
2043
|
+
const context = createCssAssetPipelineContext(options, outputFile, bundle);
|
|
2044
|
+
if (context === void 0) return;
|
|
2045
|
+
const resolvedByStrategy = options.cssPipelineStrategy?.resolveConfiguredCssEntryRootInjectionTarget?.({
|
|
2046
|
+
...context,
|
|
2047
|
+
bundle,
|
|
2048
|
+
isConfiguredCssEntryFile: (file) => isConfiguredTailwindV4CssEntryFile(opts, file),
|
|
2049
|
+
isMiniProgramStyleOutputFile,
|
|
2050
|
+
isRootStyleOutputFile,
|
|
2051
|
+
outputFile,
|
|
2052
|
+
sourceFile
|
|
2053
|
+
});
|
|
2054
|
+
if (resolvedByStrategy !== void 0) return resolvedByStrategy;
|
|
2055
|
+
if (options.cssPipelineStrategy?.resolveConfiguredCssEntryRootInjectionTarget == null) return;
|
|
2056
|
+
const rootCssFiles = [];
|
|
2057
|
+
const matchedRootCssFiles = [];
|
|
2058
|
+
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2059
|
+
if (output.type !== "asset") continue;
|
|
2060
|
+
const file = getAssetFile$1(bundleFile, output);
|
|
2061
|
+
if (!opts.cssMatcher(file) || !isRootStyleOutputFile(file) || isMiniProgramStyleOutputFile(file)) continue;
|
|
2062
|
+
rootCssFiles.push(file);
|
|
2063
|
+
if (opts.mainCssChunkMatcher(file, opts.appType)) matchedRootCssFiles.push(file);
|
|
2064
|
+
}
|
|
2065
|
+
if (matchedRootCssFiles.length === 1) return matchedRootCssFiles[0];
|
|
2066
|
+
if (matchedRootCssFiles.length > 1) return;
|
|
2067
|
+
return rootCssFiles.length === 1 ? rootCssFiles[0] : void 0;
|
|
2068
|
+
}
|
|
2069
|
+
function findBundleAssetByOutputFile(bundle, file) {
|
|
2070
|
+
const fileKey = normalizeOutputPathKey(file);
|
|
2071
|
+
return Object.entries(bundle).find(([bundleFile, output]) => {
|
|
2072
|
+
return output.type === "asset" && normalizeOutputPathKey(getAssetFile$1(bundleFile, output)) === fileKey;
|
|
2073
|
+
})?.[1];
|
|
2074
|
+
}
|
|
2075
|
+
function isCssImportOnlyBundleAsset(bundle, file, css) {
|
|
2076
|
+
const importedStyleFiles = collectImportedStyleFiles(css, file);
|
|
2077
|
+
if (importedStyleFiles.size === 0) return false;
|
|
2078
|
+
let hasNonImportNode = false;
|
|
2079
|
+
try {
|
|
2080
|
+
postcss.parse(css).each((node) => {
|
|
2081
|
+
if (node.type === "comment") return;
|
|
2082
|
+
if (node.type !== "atrule" || node.name !== "import") hasNonImportNode = true;
|
|
2083
|
+
});
|
|
2084
|
+
} catch {
|
|
2085
|
+
return false;
|
|
2086
|
+
}
|
|
2087
|
+
if (hasNonImportNode) return false;
|
|
2088
|
+
return collectImportedBundleCssSources(bundle, importedStyleFiles).length > 0;
|
|
2089
|
+
}
|
|
2090
|
+
function isCoveredViteGeneratedSourceAsset(file, existingAssetFiles, resolveViteProcessedCssOutputFile) {
|
|
2091
|
+
const resolvedOutputFile = normalizeOutputPathKey(resolveViteProcessedCssOutputFile?.(file) ?? file);
|
|
2092
|
+
return resolvedOutputFile !== normalizeOutputPathKey(file) && existingAssetFiles.has(resolvedOutputFile);
|
|
2093
|
+
}
|
|
2094
|
+
function resolveViteGeneratedCssMarkerOutputFile(file, markerFile, existingAssetFiles, resolveViteProcessedCssOutputFile) {
|
|
2095
|
+
const resolvedFromFile = normalizeOutputPathKey(resolveViteProcessedCssOutputFile?.(file) ?? file);
|
|
2096
|
+
if (!markerFile) return resolvedFromFile;
|
|
2097
|
+
const resolvedFromMarker = normalizeOutputPathKey(resolveViteProcessedCssOutputFile?.(markerFile) ?? markerFile);
|
|
2098
|
+
if (resolvedFromMarker !== resolvedFromFile && existingAssetFiles.has(resolvedFromMarker)) return resolvedFromMarker;
|
|
2099
|
+
return resolvedFromFile;
|
|
2100
|
+
}
|
|
2101
|
+
function isSourceRootPrefixedOutputFile(file, outputFile) {
|
|
2102
|
+
const fileKey = normalizeOutputPathKey(file);
|
|
2103
|
+
const outputFileKey = normalizeOutputPathKey(outputFile);
|
|
2104
|
+
return fileKey !== outputFileKey && fileKey.endsWith(`/${outputFileKey}`);
|
|
2105
|
+
}
|
|
2106
|
+
//#endregion
|
|
2107
|
+
//#region src/bundlers/vite/generate-bundle/sfc-style-source.ts
|
|
2108
|
+
const SFC_STYLE_SOURCE_EXTENSIONS = [
|
|
2109
|
+
".vue",
|
|
2110
|
+
".uvue",
|
|
2111
|
+
".nvue",
|
|
2112
|
+
".svelte",
|
|
2113
|
+
".mpx"
|
|
2114
|
+
];
|
|
2115
|
+
const SFC_STYLE_BLOCK_RE$1 = /<style\b([^>]*)>([\s\S]*?)<\/style>/gi;
|
|
2116
|
+
const SFC_SCOPED_STYLE_ATTR_RE = /(?:^|\s)scoped(?:\s|=|$)/i;
|
|
2117
|
+
const SFC_LANG_STYLE_ATTR_RE = /(?:^|\s)lang(?:=(?:"([^"]+)"|'([^']+)'|([^\s"'=<>`]+)))?/i;
|
|
2118
|
+
function isSfcStyleSourceFile(file) {
|
|
2119
|
+
const normalizedFile = file.replace(/[?#].*$/, "");
|
|
2120
|
+
return SFC_STYLE_SOURCE_EXTENSIONS.some((extension) => normalizedFile.endsWith(extension));
|
|
2121
|
+
}
|
|
2122
|
+
function extractSfcStyleBlocks(source) {
|
|
2123
|
+
const styleSources = [];
|
|
2124
|
+
SFC_STYLE_BLOCK_RE$1.lastIndex = 0;
|
|
2125
|
+
let index = 0;
|
|
2126
|
+
let match = SFC_STYLE_BLOCK_RE$1.exec(source);
|
|
2127
|
+
while (match !== null) {
|
|
2128
|
+
const attrs = match[1] ?? "";
|
|
2129
|
+
styleSources.push({
|
|
2130
|
+
attrs,
|
|
2131
|
+
index,
|
|
2132
|
+
scoped: SFC_SCOPED_STYLE_ATTR_RE.test(attrs),
|
|
2133
|
+
source: match[2] ?? ""
|
|
2134
|
+
});
|
|
2135
|
+
index += 1;
|
|
2136
|
+
match = SFC_STYLE_BLOCK_RE$1.exec(source);
|
|
2137
|
+
}
|
|
2138
|
+
return styleSources;
|
|
2139
|
+
}
|
|
2140
|
+
function extractSfcStyleSources(source) {
|
|
2141
|
+
return extractSfcStyleBlocks(source).map((style) => style.source);
|
|
2142
|
+
}
|
|
2143
|
+
function hasSfcStyleSources(source) {
|
|
2144
|
+
return extractSfcStyleSources(source).length > 0;
|
|
2145
|
+
}
|
|
2146
|
+
function resolveSfcStyleHandlerSourceFile(sourceFile, styleBlocks) {
|
|
2147
|
+
const scopedStyleBlock = styleBlocks.find((style) => style.scoped);
|
|
2148
|
+
return scopedStyleBlock ? `${sourceFile}?vue&type=style&index=${scopedStyleBlock.index}&scoped=true` : sourceFile;
|
|
2149
|
+
}
|
|
2150
|
+
function normalizeSfcStyleSourceForCompare(source) {
|
|
2151
|
+
return source.replace(/\r\n?/g, "\n").trim();
|
|
2152
|
+
}
|
|
2153
|
+
function resolveSfcStyleBlockLang(attrs) {
|
|
2154
|
+
const match = SFC_LANG_STYLE_ATTR_RE.exec(attrs);
|
|
2155
|
+
return match?.[1] ?? match?.[2] ?? match?.[3];
|
|
2156
|
+
}
|
|
2157
|
+
function createSfcStyleRequest(sourceFile, styleBlock) {
|
|
2158
|
+
const params = new URLSearchParams();
|
|
2159
|
+
params.set("vue", "");
|
|
2160
|
+
params.set("type", "style");
|
|
2161
|
+
params.set("index", String(styleBlock.index));
|
|
2162
|
+
if (styleBlock.scoped) params.set("scoped", "true");
|
|
2163
|
+
const lang = resolveSfcStyleBlockLang(styleBlock.attrs);
|
|
2164
|
+
if (lang) params.set("lang", lang);
|
|
2165
|
+
return `${sourceFile}?${params.toString()}`;
|
|
2166
|
+
}
|
|
2167
|
+
function resolveSfcStyleRequestFromKnownSource(sourceFile, sfcSource, styleSource, currentRequest) {
|
|
2168
|
+
if (!sfcSource) return sourceFile;
|
|
2169
|
+
const styleBlocks = extractSfcStyleBlocks(sfcSource);
|
|
2170
|
+
if (styleBlocks.length === 0) return sourceFile;
|
|
2171
|
+
const normalizedStyleSource = normalizeSfcStyleSourceForCompare(styleSource);
|
|
2172
|
+
const matchedBlocks = styleBlocks.filter((styleBlock) => {
|
|
2173
|
+
const normalizedBlockSource = normalizeSfcStyleSourceForCompare(styleBlock.source);
|
|
2174
|
+
return normalizedBlockSource === normalizedStyleSource || normalizedBlockSource.includes(normalizedStyleSource) || normalizedStyleSource.includes(normalizedBlockSource);
|
|
2175
|
+
});
|
|
2176
|
+
const requestIndex = currentRequest ? Number.parseInt(new URLSearchParams(currentRequest.split("?", 2)[1] ?? "").get("index") ?? "", 10) : NaN;
|
|
2177
|
+
const styleBlock = (Number.isInteger(requestIndex) ? styleBlocks.find((styleBlock) => styleBlock.index === requestIndex) : void 0) ?? (matchedBlocks.length === 1 ? matchedBlocks[0] : styleBlocks.length === 1 ? styleBlocks[0] : void 0);
|
|
2178
|
+
return styleBlock ? createSfcStyleRequest(sourceFile, styleBlock) : sourceFile;
|
|
2179
|
+
}
|
|
2180
|
+
function hasTailwindGenerationSource(source, options = {}) {
|
|
2181
|
+
const allowRootDirectives = options.allowRootDirectives !== false;
|
|
2182
|
+
return hasTailwindNonRootGenerationDirectives(source, { importFallback: true }) || allowRootDirectives && hasTailwindSourceDirectives(source, { importFallback: true }) || allowRootDirectives && hasTailwindRootDirectives(source, { importFallback: true }) || hasTailwindApplyDirective(source);
|
|
2183
|
+
}
|
|
2184
|
+
function hasTailwindGenerationSourceForFile(file, source) {
|
|
2185
|
+
if (isTailwindV4CssEntry(file)) return hasTailwindGenerationSource(source);
|
|
2186
|
+
return hasTailwindGenerationSource(source, { allowRootDirectives: false });
|
|
2187
|
+
}
|
|
2188
|
+
async function resolveSfcStyleSourceFromOutputFile(outputFile, snapshot, outputRoot, sourceRoot, cssMatcher, getSfcSource, debug) {
|
|
2189
|
+
const sourceFile = resolveSfcStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot, sourceRoot, cssMatcher, debug);
|
|
2190
|
+
if (!sourceFile) {
|
|
2191
|
+
debug("sfc style source infer skipped: no source file for %s", outputFile);
|
|
2192
|
+
return;
|
|
2193
|
+
}
|
|
2194
|
+
const source = getSfcSource?.(sourceFile);
|
|
2195
|
+
if (source == null) {
|
|
2196
|
+
debug("sfc style source infer skipped: missing known source for %s -> %s", outputFile, sourceFile);
|
|
2197
|
+
return;
|
|
2198
|
+
}
|
|
2199
|
+
const styleBlocks = extractSfcStyleBlocks(source);
|
|
2200
|
+
const rawSource = styleBlocks.map((style) => style.source).join("\n");
|
|
2201
|
+
if (!rawSource || !hasTailwindGenerationSourceForFile(sourceFile, rawSource)) {
|
|
2202
|
+
debug("sfc style source infer skipped: no tailwind generation source for %s -> %s", outputFile, sourceFile);
|
|
2203
|
+
return;
|
|
2204
|
+
}
|
|
2205
|
+
debug("sfc style source inferred: %s -> %s", outputFile, sourceFile);
|
|
2206
|
+
return {
|
|
2207
|
+
outputFile,
|
|
2208
|
+
rawSource,
|
|
2209
|
+
sourceFile: resolveSfcStyleHandlerSourceFile(sourceFile, styleBlocks)
|
|
2210
|
+
};
|
|
2211
|
+
}
|
|
2212
|
+
function normalizeSfcSourceFileForCompare(file) {
|
|
2213
|
+
return normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
2214
|
+
}
|
|
2215
|
+
function collectChunkModuleIds$1(output) {
|
|
2216
|
+
const moduleIds = Array.isArray(output.moduleIds) ? output.moduleIds : [];
|
|
2217
|
+
return [
|
|
2218
|
+
output.facadeModuleId,
|
|
2219
|
+
...moduleIds,
|
|
2220
|
+
...Object.keys(output.modules ?? {})
|
|
2221
|
+
].filter((id, index, ids) => typeof id === "string" && id.length > 0 && ids.indexOf(id) === index);
|
|
2222
|
+
}
|
|
2223
|
+
function normalizeSourceStyleModuleId(id) {
|
|
2224
|
+
const file = id.replace(/[?#].*$/, "");
|
|
2225
|
+
if (!CSS_SOURCE_OUTPUT_EXT_RE.test(file)) return;
|
|
2226
|
+
if (!path.isAbsolute(file)) return;
|
|
2227
|
+
return path.resolve(file);
|
|
2228
|
+
}
|
|
2229
|
+
function resolveSiblingJsChunkFile(outputFile, cssMatcher) {
|
|
2230
|
+
const normalizedOutputFile = outputFile.replace(/[?#].*$/, "");
|
|
2231
|
+
if (cssMatcher?.(normalizedOutputFile)) {
|
|
2232
|
+
const extension = path.extname(normalizedOutputFile);
|
|
2233
|
+
return extension ? `${normalizedOutputFile.slice(0, -extension.length)}.js` : void 0;
|
|
2234
|
+
}
|
|
2235
|
+
if (CSS_SOURCE_OUTPUT_EXT_RE.test(normalizedOutputFile)) return normalizedOutputFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, ".js");
|
|
2236
|
+
}
|
|
2237
|
+
function normalizeSfcModuleId(id) {
|
|
2238
|
+
const file = id.replace(/[?#].*$/, "");
|
|
2239
|
+
if (!isSfcStyleSourceFile(file)) return;
|
|
2240
|
+
if (!path.isAbsolute(file)) return;
|
|
2241
|
+
return path.resolve(file);
|
|
2242
|
+
}
|
|
2243
|
+
function resolveSfcStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot, sourceRoot, cssMatcher, debug) {
|
|
2244
|
+
const siblingJsFile = resolveSiblingJsChunkFile(outputFile, cssMatcher);
|
|
2245
|
+
if (!siblingJsFile) {
|
|
2246
|
+
debug("sfc style sibling chunk skipped: no sibling js for %s", outputFile);
|
|
2247
|
+
return;
|
|
2248
|
+
}
|
|
2249
|
+
const normalizedSiblingJsFile = normalizeOutputPathKey(siblingJsFile);
|
|
2250
|
+
const siblingChunk = snapshot.entries.find((entry) => entry.type === "js" && entry.output.type === "chunk" && normalizeOutputPathKey(entry.file) === normalizedSiblingJsFile);
|
|
2251
|
+
if (!siblingChunk || siblingChunk.output.type !== "chunk") {
|
|
2252
|
+
debug("sfc style sibling chunk skipped: missing chunk for %s -> %s", outputFile, siblingJsFile);
|
|
2253
|
+
return;
|
|
2254
|
+
}
|
|
2255
|
+
const sourceFiles = collectChunkModuleIds$1(siblingChunk.output).map(normalizeSfcModuleId).filter((file, index, files) => Boolean(file) && files.indexOf(file) === index);
|
|
2256
|
+
if (sourceFiles.length === 0) {
|
|
2257
|
+
debug("sfc style sibling chunk skipped: no sfc modules for %s -> %s", outputFile, siblingJsFile);
|
|
2258
|
+
return;
|
|
2259
|
+
}
|
|
1855
2260
|
const scoredSources = sourceFiles.map((sourceFile) => ({
|
|
1856
2261
|
sourceFile,
|
|
1857
2262
|
score: scoreMatchingStyleFileBase(outputFile, sourceFile, outputRoot, sourceRoot)
|
|
@@ -1998,254 +2403,26 @@ function collectMiniProgramSubpackageSourceEntries(snapshot, subpackageRoots, so
|
|
|
1998
2403
|
const matchedSubpackageRoot = [...subpackageRoots].find((root) => isSubpackageOutputFile(entry.file, /* @__PURE__ */ new Set([root])));
|
|
1999
2404
|
if (!matchedSubpackageRoot) continue;
|
|
2000
2405
|
for (const moduleId of collectChunkModuleIds$1(entry.output)) {
|
|
2001
|
-
if (!path.isAbsolute(moduleId.replace(/[?#].*$/, ""))) continue;
|
|
2002
|
-
const sourceRoot = resolveSubpackageSourceRootFromModuleId(moduleId, matchedSubpackageRoot);
|
|
2003
|
-
if (sourceRoot) sourceRoots.add(sourceRoot);
|
|
2004
|
-
}
|
|
2005
|
-
}
|
|
2006
|
-
sourceEntries.push(...[...sourceRoots].map((sourceRoot) => ({
|
|
2007
|
-
base: sourceRoot,
|
|
2008
|
-
negated: false,
|
|
2009
|
-
pattern: "**/*"
|
|
2010
|
-
})));
|
|
2011
|
-
const resolvedBaseRoots = sourceBaseRoots.filter((baseRoot) => typeof baseRoot === "string" && baseRoot.length > 0).map((baseRoot) => path.resolve(baseRoot)).filter((baseRoot, index, roots) => roots.indexOf(baseRoot) === index);
|
|
2012
|
-
for (const baseRoot of resolvedBaseRoots) for (const subpackageRoot of subpackageRoots) sourceEntries.push({
|
|
2013
|
-
base: baseRoot,
|
|
2014
|
-
negated: false,
|
|
2015
|
-
pattern: `**/${normalizePackageRoot(subpackageRoot)}/**`
|
|
2016
|
-
});
|
|
2017
|
-
return sourceEntries;
|
|
2018
|
-
}
|
|
2019
|
-
//#endregion
|
|
2020
|
-
//#region src/bundlers/vite/processed-css-assets.ts
|
|
2021
|
-
const CSS_OUTPUT_FILE_RE = /\.(?:css|wxss|acss|ttss|qss|jxss|tyss)(?:$|[?#])/i;
|
|
2022
|
-
function createCssAssetPipelineContext(options, file, bundle) {
|
|
2023
|
-
const context = options.createCssPipelineContext?.(file);
|
|
2024
|
-
return context ? {
|
|
2025
|
-
...context,
|
|
2026
|
-
bundle
|
|
2027
|
-
} : void 0;
|
|
2028
|
-
}
|
|
2029
|
-
function isCssOutputFile(file) {
|
|
2030
|
-
return CSS_OUTPUT_FILE_RE.test(file);
|
|
2031
|
-
}
|
|
2032
|
-
function getAssetFile$1(bundleFile, asset) {
|
|
2033
|
-
return asset.fileName || bundleFile;
|
|
2034
|
-
}
|
|
2035
|
-
function readAssetSource$2(asset) {
|
|
2036
|
-
return typeof asset.source === "string" ? asset.source : asset.source.toString();
|
|
2037
|
-
}
|
|
2038
|
-
function clearAssetSource(asset) {
|
|
2039
|
-
asset.source = "";
|
|
2040
|
-
}
|
|
2041
|
-
function appendCss$1(baseCss, css) {
|
|
2042
|
-
if (baseCss.length === 0) return css;
|
|
2043
|
-
if (css.length === 0) return baseCss;
|
|
2044
|
-
return `${baseCss}\n${css}`;
|
|
2045
|
-
}
|
|
2046
|
-
function normalizeCssRecordIdentity(css) {
|
|
2047
|
-
return css.trim();
|
|
2048
|
-
}
|
|
2049
|
-
function hasNonCommentCss(css) {
|
|
2050
|
-
return css.replace(/\/\*[\s\S]*?\*\//g, "").trim().length > 0;
|
|
2051
|
-
}
|
|
2052
|
-
function dedupeViteCssResults(records) {
|
|
2053
|
-
const seen = /* @__PURE__ */ new Set();
|
|
2054
|
-
return records.filter((record) => {
|
|
2055
|
-
const key = `${normalizeOutputPathKey(record.outputFile ?? "")}\0${normalizeCssRecordIdentity(record.css)}`;
|
|
2056
|
-
if (seen.has(key)) return false;
|
|
2057
|
-
seen.add(key);
|
|
2058
|
-
return true;
|
|
2059
|
-
});
|
|
2060
|
-
}
|
|
2061
|
-
function removeTailwindSourceMediaWrappersRoot(root) {
|
|
2062
|
-
let changed = false;
|
|
2063
|
-
root.walkAtRules("media", (atRule) => {
|
|
2064
|
-
if (!atRule.params.startsWith("source(")) return;
|
|
2065
|
-
if (atRule.nodes && atRule.nodes.length > 0) atRule.replaceWith(...atRule.nodes);
|
|
2066
|
-
else atRule.remove();
|
|
2067
|
-
changed = true;
|
|
2068
|
-
});
|
|
2069
|
-
if (changed) root.walkAtRules((atRule) => {
|
|
2070
|
-
if (atRule.nodes && atRule.nodes.length === 0) atRule.remove();
|
|
2071
|
-
});
|
|
2072
|
-
return changed;
|
|
2073
|
-
}
|
|
2074
|
-
function removeTailwindSourceMediaWrappersFallback(css) {
|
|
2075
|
-
return css.replace(/@media\s+source\([^)]*\)\s*\{\s*\/\*!\s*weapp-tailwindcss generator-placeholder\s*\*\/?\s*\}/gi, "").replace(/@media\s+source\([^)]*\)\s*\{\s*\}/gi, "");
|
|
2076
|
-
}
|
|
2077
|
-
function removeTailwindEntryDirectivesFromCss(css) {
|
|
2078
|
-
try {
|
|
2079
|
-
const source = stripGeneratorPlaceholderMarkers(css);
|
|
2080
|
-
const root = postcss.parse(source);
|
|
2081
|
-
const removedMediaWrappers = removeTailwindSourceMediaWrappersRoot(root);
|
|
2082
|
-
const removedTailwindDirectives = removeTailwindSourceDirectivesRoot(root);
|
|
2083
|
-
return removedMediaWrappers || removedTailwindDirectives ? root.toString() : source;
|
|
2084
|
-
} catch {
|
|
2085
|
-
return removeTailwindSourceDirectives(removeTailwindSourceMediaWrappersFallback(css));
|
|
2086
|
-
}
|
|
2087
|
-
}
|
|
2088
|
-
function removeUnsupportedMiniProgramCssImportsFallback(css, file) {
|
|
2089
|
-
if (!isMiniProgramStyleOutputFile(file) || !css.includes("@import")) return css;
|
|
2090
|
-
return css.split(/\r?\n/).filter((line) => {
|
|
2091
|
-
const trimmed = line.trim();
|
|
2092
|
-
if (!trimmed.startsWith("@import")) return true;
|
|
2093
|
-
const request = parseTailwindCssDirectiveRequest(trimmed.slice(7).trim().replace(/;$/, "").trim());
|
|
2094
|
-
return request === void 0 || isMiniProgramLocalCssImportRequest(request);
|
|
2095
|
-
}).join("\n");
|
|
2096
|
-
}
|
|
2097
|
-
function normalizeInjectableCssForTarget(css, file) {
|
|
2098
|
-
return normalizeInjectableCssForTargetWithImports(css, file).css;
|
|
2099
|
-
}
|
|
2100
|
-
function normalizeInjectableCssForTargetWithImports(css, file) {
|
|
2101
|
-
if (!css.includes("@import")) return {
|
|
2102
|
-
css,
|
|
2103
|
-
importedStyleFiles: /* @__PURE__ */ new Set()
|
|
2104
|
-
};
|
|
2105
|
-
try {
|
|
2106
|
-
const root = postcss.parse(css);
|
|
2107
|
-
const changed = isMiniProgramStyleOutputFile(file) ? removeUnsupportedMiniProgramCssImportsRoot(root) : false;
|
|
2108
|
-
const importedStyleFiles = collectImportedStyleFilesRoot(root, file);
|
|
2109
|
-
return {
|
|
2110
|
-
css: changed ? root.toString() : css,
|
|
2111
|
-
importedStyleFiles: importedStyleFiles.size > 0 ? importedStyleFiles : collectImportedStyleFilesFallback(css, file)
|
|
2112
|
-
};
|
|
2113
|
-
} catch {
|
|
2114
|
-
const fallbackCss = removeUnsupportedMiniProgramCssImportsFallback(css, file);
|
|
2115
|
-
return {
|
|
2116
|
-
css: fallbackCss,
|
|
2117
|
-
importedStyleFiles: collectImportedStyleFiles(fallbackCss, file)
|
|
2118
|
-
};
|
|
2119
|
-
}
|
|
2120
|
-
}
|
|
2121
|
-
function stripStyleExtension(file) {
|
|
2122
|
-
return file.replace(/[?#].*$/, "").replace(/\.(?:css|wxss|acss|ttss|qss|jxss|tyss|scss|sass|less|styl|stylus|pcss|postcss)$/i, "");
|
|
2123
|
-
}
|
|
2124
|
-
function isStyleImportRequest(request) {
|
|
2125
|
-
return typeof request === "string" && request.length > 0 && !/^(?:https?:)?\/\//i.test(request) && /\.(?:css|wxss|acss|ttss|qss|jxss|tyss)(?:$|[?#])/i.test(request);
|
|
2126
|
-
}
|
|
2127
|
-
function resolveImportedStyleFile(targetFile, request) {
|
|
2128
|
-
if (!isStyleImportRequest(request)) return;
|
|
2129
|
-
const cleanRequest = request.replace(/[?#].*$/, "");
|
|
2130
|
-
if (cleanRequest.startsWith("/")) return normalizeOutputPathKey(cleanRequest.slice(1));
|
|
2131
|
-
const targetDir = posix.posix.dirname(normalizeOutputPathKey(targetFile));
|
|
2132
|
-
return normalizeOutputPathKey(posix.posix.join(targetDir === "." ? "" : targetDir, cleanRequest));
|
|
2133
|
-
}
|
|
2134
|
-
function collectImportedStyleFilesFromRequests(requests, targetFile) {
|
|
2135
|
-
const imports = /* @__PURE__ */ new Set();
|
|
2136
|
-
for (const request of requests) {
|
|
2137
|
-
const importedFile = resolveImportedStyleFile(targetFile, request);
|
|
2138
|
-
if (importedFile) imports.add(importedFile);
|
|
2139
|
-
}
|
|
2140
|
-
return imports;
|
|
2141
|
-
}
|
|
2142
|
-
function collectImportedStyleFilesRoot(root, targetFile) {
|
|
2143
|
-
return collectImportedStyleFilesFromRequests(collectCssImportRequestsRoot(root), targetFile);
|
|
2144
|
-
}
|
|
2145
|
-
function collectImportedStyleFilesFallback(css, targetFile) {
|
|
2146
|
-
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);
|
|
2147
|
-
}
|
|
2148
|
-
function collectImportedStyleFiles(css, targetFile) {
|
|
2149
|
-
if (!css.includes("@import")) return /* @__PURE__ */ new Set();
|
|
2150
|
-
try {
|
|
2151
|
-
const imports = collectImportedStyleFilesRoot(postcss.parse(css), targetFile);
|
|
2152
|
-
return imports.size > 0 ? imports : collectImportedStyleFilesFallback(css, targetFile);
|
|
2153
|
-
} catch {}
|
|
2154
|
-
return collectImportedStyleFilesFallback(css, targetFile);
|
|
2155
|
-
}
|
|
2156
|
-
function normalizeMarkerOutputFile(markerFile, resolveViteProcessedCssOutputFile) {
|
|
2157
|
-
return resolveViteProcessedCssOutputFile?.(markerFile) ?? markerFile;
|
|
2158
|
-
}
|
|
2159
|
-
function isMatchingGeneratedCssMarkerFile(targetFile, markerFile, resolveViteProcessedCssOutputFile) {
|
|
2160
|
-
if (!markerFile) return false;
|
|
2161
|
-
return normalizeOutputPathKey(stripStyleExtension(targetFile)) === normalizeOutputPathKey(stripStyleExtension(normalizeMarkerOutputFile(markerFile, resolveViteProcessedCssOutputFile)));
|
|
2162
|
-
}
|
|
2163
|
-
function resolveViteProcessedCssAssetSource(file, rawSource, resolveViteProcessedCssOutputFile) {
|
|
2164
|
-
const blocks = parseBundlerGeneratedCssMarkerBlocks(rawSource).filter((block) => block.bundler === "vite");
|
|
2165
|
-
if (blocks.length <= 1) return stripBundlerGeneratedCssMarkers(rawSource);
|
|
2166
|
-
const matchedCss = blocks.filter((block) => isMatchingGeneratedCssMarkerFile(file, block.file, resolveViteProcessedCssOutputFile)).map((block) => block.css);
|
|
2167
|
-
return matchedCss.length > 0 ? matchedCss.join("\n") : stripBundlerGeneratedCssMarkers(rawSource);
|
|
2168
|
-
}
|
|
2169
|
-
function collectMatchingGeneratedCssMarkerFiles(file, rawSource, resolveViteProcessedCssOutputFile) {
|
|
2170
|
-
return parseBundlerGeneratedCssMarkerBlocks(rawSource).filter((block) => block.bundler === "vite").filter((block) => isMatchingGeneratedCssMarkerFile(file, block.file, resolveViteProcessedCssOutputFile)).map((block) => block.file).filter((markerFile) => typeof markerFile === "string" && markerFile.length > 0);
|
|
2171
|
-
}
|
|
2172
|
-
function collectRootStyleBundleCssSources(bundle, excludedFile) {
|
|
2173
|
-
const sources = [];
|
|
2174
|
-
const excludedFileKey = normalizeOutputPathKey(excludedFile);
|
|
2175
|
-
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2176
|
-
if (output.type !== "asset") continue;
|
|
2177
|
-
const file = normalizeOutputPathKey(getAssetFile$1(bundleFile, output));
|
|
2178
|
-
if (file === excludedFileKey || !isRootStyleOutputFile(file)) continue;
|
|
2179
|
-
const source = stripBundlerGeneratedCssMarkers(readAssetSource$2(output)).trim();
|
|
2180
|
-
if (source.length > 0) sources.push(source);
|
|
2181
|
-
}
|
|
2182
|
-
return sources;
|
|
2183
|
-
}
|
|
2184
|
-
function isHtmlOutputFile(file) {
|
|
2185
|
-
return /\.html(?:$|[?#])/i.test(file);
|
|
2186
|
-
}
|
|
2187
|
-
function stripQueryAndHash(file) {
|
|
2188
|
-
return file.replace(/[?#].*$/, "");
|
|
2189
|
-
}
|
|
2190
|
-
function resolveHtmlLinkedStyleFile(htmlFile, request) {
|
|
2191
|
-
if (!isStyleImportRequest(request)) return;
|
|
2192
|
-
const cleanRequest = stripQueryAndHash(request);
|
|
2193
|
-
if (cleanRequest.startsWith("/")) return normalizeOutputPathKey(cleanRequest.slice(1));
|
|
2194
|
-
const htmlDir = posix.posix.dirname(normalizeOutputPathKey(stripQueryAndHash(htmlFile)));
|
|
2195
|
-
return normalizeOutputPathKey(posix.posix.join(htmlDir === "." ? "" : htmlDir, cleanRequest));
|
|
2196
|
-
}
|
|
2197
|
-
function collectHtmlLinkedStyleFiles(bundle) {
|
|
2198
|
-
const linkedFiles = /* @__PURE__ */ new Set();
|
|
2199
|
-
const linkedBasenames = /* @__PURE__ */ new Set();
|
|
2200
|
-
const linkHrefRE = /<link\s[^>]*href\s*=\s*(["'])([^"']+)\1[^>]*>/gi;
|
|
2201
|
-
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2202
|
-
if (output.type !== "asset") continue;
|
|
2203
|
-
const htmlFile = getAssetFile$1(bundleFile, output);
|
|
2204
|
-
if (!isHtmlOutputFile(htmlFile)) continue;
|
|
2205
|
-
const html = readAssetSource$2(output);
|
|
2206
|
-
for (const match of html.matchAll(linkHrefRE)) {
|
|
2207
|
-
const href = match[2];
|
|
2208
|
-
if (!href) continue;
|
|
2209
|
-
const linkedFile = resolveHtmlLinkedStyleFile(htmlFile, href);
|
|
2210
|
-
if (!linkedFile || !isRootStyleOutputFile(linkedFile)) continue;
|
|
2211
|
-
linkedFiles.add(linkedFile);
|
|
2212
|
-
linkedBasenames.add(posix.posix.basename(linkedFile));
|
|
2213
|
-
}
|
|
2214
|
-
}
|
|
2215
|
-
return {
|
|
2216
|
-
linkedBasenames,
|
|
2217
|
-
linkedFiles
|
|
2218
|
-
};
|
|
2219
|
-
}
|
|
2220
|
-
function isLinkedStyleFile(file, linked) {
|
|
2221
|
-
const fileKey = normalizeOutputPathKey(stripQueryAndHash(file));
|
|
2222
|
-
return linked.linkedFiles.has(fileKey) || isRootStyleOutputFile(fileKey) && linked.linkedBasenames.has(posix.posix.basename(fileKey));
|
|
2223
|
-
}
|
|
2224
|
-
function removeDuplicateUnlinkedRootCssAssetsReferencedByHtml(bundle, options = {}) {
|
|
2225
|
-
const linked = collectHtmlLinkedStyleFiles(bundle);
|
|
2226
|
-
if (linked.linkedFiles.size === 0 && linked.linkedBasenames.size === 0) return 0;
|
|
2227
|
-
const linkedSources = /* @__PURE__ */ new Set();
|
|
2228
|
-
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2229
|
-
if (output.type !== "asset") continue;
|
|
2230
|
-
const file = getAssetFile$1(bundleFile, output);
|
|
2231
|
-
if (!isCssOutputFile(file) || isMiniProgramStyleOutputFile(file) || !isLinkedStyleFile(file, linked)) continue;
|
|
2232
|
-
const source = stripBundlerGeneratedCssMarkers(readAssetSource$2(output)).trim();
|
|
2233
|
-
if (source.length > 0) linkedSources.add(source);
|
|
2234
|
-
}
|
|
2235
|
-
if (linkedSources.size === 0) return 0;
|
|
2236
|
-
let removed = 0;
|
|
2237
|
-
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2238
|
-
if (output.type !== "asset") continue;
|
|
2239
|
-
const file = getAssetFile$1(bundleFile, output);
|
|
2240
|
-
if (!isRootStyleOutputFile(file) || isMiniProgramStyleOutputFile(file) || isLinkedStyleFile(file, linked)) continue;
|
|
2241
|
-
const source = stripBundlerGeneratedCssMarkers(readAssetSource$2(output)).trim();
|
|
2242
|
-
if (!linkedSources.has(source)) continue;
|
|
2243
|
-
delete bundle[bundleFile];
|
|
2244
|
-
options.debug?.("remove duplicate unlinked root css asset referenced by html: %s", file);
|
|
2245
|
-
removed++;
|
|
2406
|
+
if (!path.isAbsolute(moduleId.replace(/[?#].*$/, ""))) continue;
|
|
2407
|
+
const sourceRoot = resolveSubpackageSourceRootFromModuleId(moduleId, matchedSubpackageRoot);
|
|
2408
|
+
if (sourceRoot) sourceRoots.add(sourceRoot);
|
|
2409
|
+
}
|
|
2246
2410
|
}
|
|
2247
|
-
|
|
2411
|
+
sourceEntries.push(...[...sourceRoots].map((sourceRoot) => ({
|
|
2412
|
+
base: sourceRoot,
|
|
2413
|
+
negated: false,
|
|
2414
|
+
pattern: "**/*"
|
|
2415
|
+
})));
|
|
2416
|
+
const resolvedBaseRoots = sourceBaseRoots.filter((baseRoot) => typeof baseRoot === "string" && baseRoot.length > 0).map((baseRoot) => path.resolve(baseRoot)).filter((baseRoot, index, roots) => roots.indexOf(baseRoot) === index);
|
|
2417
|
+
for (const baseRoot of resolvedBaseRoots) for (const subpackageRoot of subpackageRoots) sourceEntries.push({
|
|
2418
|
+
base: baseRoot,
|
|
2419
|
+
negated: false,
|
|
2420
|
+
pattern: `**/${normalizePackageRoot(subpackageRoot)}/**`
|
|
2421
|
+
});
|
|
2422
|
+
return sourceEntries;
|
|
2248
2423
|
}
|
|
2424
|
+
//#endregion
|
|
2425
|
+
//#region src/bundlers/vite/processed-css-assets/coverage.ts
|
|
2249
2426
|
const VUE_SCOPED_ATTR_RE = /\[data-v-[^\]]+\]/gi;
|
|
2250
2427
|
const VUE_SCOPED_CLASS_RE = /\.data-v-[\w-]+/gi;
|
|
2251
2428
|
function hasVueScopedAttr(value) {
|
|
@@ -2327,9 +2504,11 @@ function collectRootScopedComparableCssCoverage(cssSources) {
|
|
|
2327
2504
|
const rules = /* @__PURE__ */ new Set();
|
|
2328
2505
|
const atRules = /* @__PURE__ */ new Set();
|
|
2329
2506
|
const declarationsBySelector = /* @__PURE__ */ new Map();
|
|
2507
|
+
const normalizedRuleCss = /* @__PURE__ */ new Set();
|
|
2330
2508
|
for (const source of cssSources) try {
|
|
2331
2509
|
const root = postcss.parse(source);
|
|
2332
2510
|
root.walkRules((rule) => {
|
|
2511
|
+
normalizedRuleCss.add(normalizeCssSignatureValue(rule.toString()));
|
|
2333
2512
|
const declarations = createDeclarationSignature(rule);
|
|
2334
2513
|
if (declarations.length === 0) return;
|
|
2335
2514
|
for (const selector of rule.selectors ?? [rule.selector]) {
|
|
@@ -2347,7 +2526,16 @@ function collectRootScopedComparableCssCoverage(cssSources) {
|
|
|
2347
2526
|
return {
|
|
2348
2527
|
rules,
|
|
2349
2528
|
atRules,
|
|
2350
|
-
declarationsBySelector
|
|
2529
|
+
declarationsBySelector,
|
|
2530
|
+
normalizedRuleCss
|
|
2531
|
+
};
|
|
2532
|
+
}
|
|
2533
|
+
function prepareImportedCssCoverage(importedCssSources) {
|
|
2534
|
+
const sources = importedCssSources.map((source) => stripBundlerGeneratedCssMarkers(source).trim()).filter(Boolean);
|
|
2535
|
+
if (sources.length === 0) return;
|
|
2536
|
+
return {
|
|
2537
|
+
coverage: collectRootScopedComparableCssCoverage(sources),
|
|
2538
|
+
sources
|
|
2351
2539
|
};
|
|
2352
2540
|
}
|
|
2353
2541
|
function isRuleCoveredByRootCss(rule, coverage) {
|
|
@@ -2415,7 +2603,48 @@ function shouldFilterRootGeneratedCssMarkerForScopedAsset(targetFile, markerFile
|
|
|
2415
2603
|
}
|
|
2416
2604
|
function removeCssCoveredByRootStyleBundleSources(bundle, file, css) {
|
|
2417
2605
|
const rootSources = collectRootStyleBundleCssSources(bundle, file);
|
|
2418
|
-
|
|
2606
|
+
if (css.trim().length === 0) return css;
|
|
2607
|
+
const hasScopedCss = hasVueScopedAttr(css);
|
|
2608
|
+
const hasScopedTailwindGeneratedCss = hasScopedCss && /tailwindcss v\d/i.test(css);
|
|
2609
|
+
const hasUnscopedMiniProgramPreflight = hasScopedCss && hasUnscopedMiniProgramTailwindPreflightRule(css);
|
|
2610
|
+
const hasScopedMiniProgramContentInit = hasScopedCss && hasScopedMiniProgramTailwindContentInitRule(css);
|
|
2611
|
+
if (rootSources.length === 0 && !hasScopedTailwindGeneratedCss && !hasUnscopedMiniProgramPreflight && !hasScopedMiniProgramContentInit) return css;
|
|
2612
|
+
const coverage = collectRootScopedComparableCssCoverage(rootSources);
|
|
2613
|
+
let nextCss = css;
|
|
2614
|
+
try {
|
|
2615
|
+
const root = postcss.parse(css);
|
|
2616
|
+
let changed = false;
|
|
2617
|
+
root.walkRules((rule) => {
|
|
2618
|
+
if (coverage.normalizedRuleCss.has(normalizeCssSignatureValue(rule.toString())) || hasScopedCss && (isRuleCoveredByRootCss(rule, coverage) || hasScopedTailwindGeneratedCss && isLikelyTailwindGlobalRule(rule) || isUnscopedMiniProgramTailwindPreflightRule(rule) || isScopedMiniProgramTailwindContentInitRule(rule))) {
|
|
2619
|
+
rule.remove();
|
|
2620
|
+
changed = true;
|
|
2621
|
+
}
|
|
2622
|
+
});
|
|
2623
|
+
if (hasScopedCss) root.walkAtRules((atRule) => {
|
|
2624
|
+
if (coverage.atRules.has(createAtRuleCoverageKey(atRule)) || hasScopedTailwindGeneratedCss && isLikelyTailwindPropertyAtRule(atRule)) {
|
|
2625
|
+
atRule.remove();
|
|
2626
|
+
changed = true;
|
|
2627
|
+
return;
|
|
2628
|
+
}
|
|
2629
|
+
if (atRule.nodes !== void 0 && atRule.nodes.length === 0) {
|
|
2630
|
+
atRule.remove();
|
|
2631
|
+
changed = true;
|
|
2632
|
+
}
|
|
2633
|
+
});
|
|
2634
|
+
root.walkComments((comment) => {
|
|
2635
|
+
if (hasScopedCss && /tailwindcss v\d/i.test(comment.text)) {
|
|
2636
|
+
comment.remove();
|
|
2637
|
+
changed = true;
|
|
2638
|
+
return;
|
|
2639
|
+
}
|
|
2640
|
+
if (!comment.text.trim().startsWith("tokens:")) return;
|
|
2641
|
+
const next = comment.next();
|
|
2642
|
+
if (next?.type === "rule" || next?.type === "atrule") return;
|
|
2643
|
+
comment.remove();
|
|
2644
|
+
changed = true;
|
|
2645
|
+
});
|
|
2646
|
+
if (changed) nextCss = root.toString().trim();
|
|
2647
|
+
} catch {}
|
|
2419
2648
|
return hasNonCommentCss(nextCss) ? nextCss : "";
|
|
2420
2649
|
}
|
|
2421
2650
|
function removeDanglingCssSourceTraceComments(css) {
|
|
@@ -2455,6 +2684,8 @@ function removeCssCoveredByRootStyleAssets(bundle, options) {
|
|
|
2455
2684
|
}
|
|
2456
2685
|
return updated;
|
|
2457
2686
|
}
|
|
2687
|
+
//#endregion
|
|
2688
|
+
//#region src/bundlers/vite/processed-css-assets/injection-plan.ts
|
|
2458
2689
|
function shouldInjectViteProcessedCssResult(opts, targetFile, sourceFile, options) {
|
|
2459
2690
|
if (options.injectIntoMain === true) return isRootStyleOutputFile(targetFile) || typeof options.outputFile === "string" && normalizeOutputPathKey(options.outputFile) === normalizeOutputPathKey(targetFile);
|
|
2460
2691
|
if (options.injectIntoMain === false) return false;
|
|
@@ -2470,13 +2701,6 @@ function shouldReplayViteProcessedCssIntoMainCss(opts, file, sourceFile, outputF
|
|
|
2470
2701
|
}
|
|
2471
2702
|
return isRootStyleOutputFile(file) && opts.mainCssChunkMatcher(file, opts.appType) || isSourceRootPrefixedOutputFile(file, outputFile) && isRootStyleOutputFile(outputFile) && opts.mainCssChunkMatcher(outputFile, opts.appType);
|
|
2472
2703
|
}
|
|
2473
|
-
function isRootStyleOutputFile(file) {
|
|
2474
|
-
const normalized = normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
2475
|
-
return isCssOutputFile(normalized) && !normalized.includes("/");
|
|
2476
|
-
}
|
|
2477
|
-
function isMiniProgramStyleOutputFile(file) {
|
|
2478
|
-
return /\.(?:wxss|acss|ttss|qss|jxss|tyss)(?:$|[?#])/i.test(file);
|
|
2479
|
-
}
|
|
2480
2704
|
function shouldPreserveMiniProgramImportShell(options, bundle, file, css) {
|
|
2481
2705
|
const context = createCssAssetPipelineContext(options, file, bundle);
|
|
2482
2706
|
return context !== void 0 && shouldPreserveFrameworkRootMiniProgramImportShell({
|
|
@@ -2560,48 +2784,41 @@ function isViteProcessedCssResultCoveredByImportedBundleAsset(record, importedSt
|
|
|
2560
2784
|
return false;
|
|
2561
2785
|
}
|
|
2562
2786
|
function removeCoveredInjectedSourceAssets(bundle, targetFile, targetCss, records, options) {
|
|
2563
|
-
let removed = 0;
|
|
2564
2787
|
const targetFileKey = normalizeOutputPathKey(targetFile);
|
|
2565
2788
|
const targetIsRootWebStyle = isRootStyleOutputFile(targetFileKey) && !isMiniProgramStyleOutputFile(targetFileKey);
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
options.debug?.("remove injected vite-processed source css asset: %s -> %s", candidateKey, targetFile);
|
|
2584
|
-
removed++;
|
|
2585
|
-
}
|
|
2789
|
+
const removableRecords = records.filter((record) => options.shouldRemoveInjectedSourceAsset?.(targetFile, record) === true);
|
|
2790
|
+
if (removableRecords.length === 0) return 0;
|
|
2791
|
+
const recordFileKeys = new Set(removableRecords.map((record) => normalizeOutputPathKey(record.file)));
|
|
2792
|
+
const recordCss = new Set(removableRecords.map((record) => record.css.trim()));
|
|
2793
|
+
let removed = 0;
|
|
2794
|
+
for (const [candidateFile, candidateOutput] of Object.entries(bundle)) {
|
|
2795
|
+
if (candidateOutput.type !== "asset") continue;
|
|
2796
|
+
const candidateKey = normalizeOutputPathKey(getAssetFile$1(candidateFile, candidateOutput));
|
|
2797
|
+
if (candidateKey === targetFileKey || !isCssOutputFile(candidateKey)) continue;
|
|
2798
|
+
const candidateIsRootWebStyle = isRootStyleOutputFile(candidateKey) && !isMiniProgramStyleOutputFile(candidateKey);
|
|
2799
|
+
if (candidateIsRootWebStyle && !targetIsRootWebStyle) continue;
|
|
2800
|
+
const candidateSource = readAssetSource$2(candidateOutput).trim();
|
|
2801
|
+
if (!(recordFileKeys.has(candidateKey) || candidateSource.length > 0 && (recordCss.has(candidateSource) || containsCssAfterMinify(targetCss, candidateSource) || targetIsRootWebStyle && candidateIsRootWebStyle && !hasNonCommentCss(filterExistingCssRules(targetCss, candidateSource).trim())))) continue;
|
|
2802
|
+
if (candidateIsRootWebStyle) delete bundle[candidateFile];
|
|
2803
|
+
else clearAssetSource(candidateOutput);
|
|
2804
|
+
options.debug?.("remove injected vite-processed source css asset: %s -> %s", candidateKey, targetFile);
|
|
2805
|
+
removed++;
|
|
2586
2806
|
}
|
|
2587
2807
|
return removed;
|
|
2588
2808
|
}
|
|
2589
|
-
function removeCssCoveredByImportedViteResults(css, importedCssSources) {
|
|
2590
|
-
if (
|
|
2591
|
-
|
|
2592
|
-
if (importedCss.length === 0) return css;
|
|
2593
|
-
return restoreCssImportAtRules(css, removeCssRulesCoveredBySources(css, [importedCss], { exactOnly: true }));
|
|
2809
|
+
function removeCssCoveredByImportedViteResults(css, importedCssSources, prepared = prepareImportedCssCoverage(importedCssSources)) {
|
|
2810
|
+
if (!prepared) return css;
|
|
2811
|
+
return restoreCssImportAtRules(css, removeCssRulesCoveredBySources(css, prepared.sources, { exactOnly: true }, prepared.coverage));
|
|
2594
2812
|
}
|
|
2595
|
-
function removeCssRulesCoveredBySources(css, sources, options = {}) {
|
|
2813
|
+
function removeCssRulesCoveredBySources(css, sources, options = {}, preparedCoverage) {
|
|
2596
2814
|
if (sources.length === 0 || css.trim().length === 0) return css;
|
|
2597
|
-
const coverage = collectRootScopedComparableCssCoverage(sources);
|
|
2598
|
-
|
|
2599
|
-
if (coverage.rules.size === 0 && coverage.declarationsBySelector.size === 0 && coveredRuleCss.size === 0) return css;
|
|
2815
|
+
const coverage = preparedCoverage ?? collectRootScopedComparableCssCoverage(sources);
|
|
2816
|
+
if (coverage.rules.size === 0 && coverage.declarationsBySelector.size === 0 && coverage.normalizedRuleCss.size === 0) return css;
|
|
2600
2817
|
try {
|
|
2601
2818
|
const root = postcss.parse(css);
|
|
2602
2819
|
let changed = false;
|
|
2603
2820
|
root.walkRules((rule) => {
|
|
2604
|
-
if (!
|
|
2821
|
+
if (!coverage.normalizedRuleCss.has(normalizeCssSignatureValue(rule.toString())) && (options.exactOnly === true || !isRuleCoveredByRootCss(rule, coverage))) return;
|
|
2605
2822
|
rule.remove();
|
|
2606
2823
|
changed = true;
|
|
2607
2824
|
});
|
|
@@ -2610,168 +2827,8 @@ function removeCssRulesCoveredBySources(css, sources, options = {}) {
|
|
|
2610
2827
|
return css;
|
|
2611
2828
|
}
|
|
2612
2829
|
}
|
|
2613
|
-
|
|
2614
|
-
|
|
2615
|
-
for (const source of sources) try {
|
|
2616
|
-
postcss.parse(source).walkRules((rule) => {
|
|
2617
|
-
rules.add(normalizeCssSignatureValue(rule.toString()));
|
|
2618
|
-
});
|
|
2619
|
-
} catch {}
|
|
2620
|
-
return rules;
|
|
2621
|
-
}
|
|
2622
|
-
function collectCssImportAtRuleCss(css) {
|
|
2623
|
-
if (!css.includes("@import")) return [];
|
|
2624
|
-
const fallbackImports = [...css.matchAll(/@import\s[^;]+;?/g)].map((match) => match[0]);
|
|
2625
|
-
if (fallbackImports.length > 0) return fallbackImports;
|
|
2626
|
-
try {
|
|
2627
|
-
const root = postcss.parse(css);
|
|
2628
|
-
const imports = [];
|
|
2629
|
-
root.each((node) => {
|
|
2630
|
-
if (node.type === "atrule" && node.name === "import") imports.push(node.toString());
|
|
2631
|
-
});
|
|
2632
|
-
return imports;
|
|
2633
|
-
} catch {
|
|
2634
|
-
return [];
|
|
2635
|
-
}
|
|
2636
|
-
}
|
|
2637
|
-
function parseCssImportRequest(importCss) {
|
|
2638
|
-
const trimmed = importCss.trim();
|
|
2639
|
-
if (!trimmed.startsWith("@import")) return;
|
|
2640
|
-
return parseTailwindCssDirectiveRequest(trimmed.slice(7).trim().replace(/;$/, "").trim());
|
|
2641
|
-
}
|
|
2642
|
-
function shouldRestoreCssImportAtRule(importCss, file) {
|
|
2643
|
-
if (file === void 0 || !isMiniProgramStyleOutputFile(file)) return true;
|
|
2644
|
-
const request = parseCssImportRequest(importCss);
|
|
2645
|
-
if (request === void 0) return false;
|
|
2646
|
-
if (isMiniProgramLocalCssImportRequest(request)) return true;
|
|
2647
|
-
return isStyleImportRequest(request) && !request.includes("/");
|
|
2648
|
-
}
|
|
2649
|
-
function restoreCssImportAtRules(source, filtered, file) {
|
|
2650
|
-
const imports = collectCssImportAtRuleCss(source).filter((importCss) => shouldRestoreCssImportAtRule(importCss, file));
|
|
2651
|
-
if (imports.length === 0) return filtered;
|
|
2652
|
-
const missingImports = imports.filter((importCss) => !filtered.includes(importCss));
|
|
2653
|
-
if (missingImports.length === 0) return filtered;
|
|
2654
|
-
return appendCss$1(missingImports.join("\n"), filtered);
|
|
2655
|
-
}
|
|
2656
|
-
function removeCommentOnlyAtRules(css) {
|
|
2657
|
-
if (!css.includes("@")) return css;
|
|
2658
|
-
try {
|
|
2659
|
-
const root = postcss.parse(css);
|
|
2660
|
-
let changed = false;
|
|
2661
|
-
root.walkAtRules((atRule) => {
|
|
2662
|
-
if (!atRule.nodes || atRule.nodes.length === 0) return;
|
|
2663
|
-
if (atRule.nodes.some((node) => node.type !== "comment")) return;
|
|
2664
|
-
atRule.remove();
|
|
2665
|
-
changed = true;
|
|
2666
|
-
});
|
|
2667
|
-
return changed ? root.toString() : css;
|
|
2668
|
-
} catch {
|
|
2669
|
-
return css;
|
|
2670
|
-
}
|
|
2671
|
-
}
|
|
2672
|
-
function collectImportedBundleCssSources(bundle, importedStyleFiles) {
|
|
2673
|
-
if (importedStyleFiles.size === 0) return [];
|
|
2674
|
-
const importedFileNames = new Set([...importedStyleFiles].map((file) => posix.posix.basename(file)));
|
|
2675
|
-
const importedSources = [];
|
|
2676
|
-
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2677
|
-
if (output.type !== "asset") continue;
|
|
2678
|
-
const file = normalizeOutputPathKey(getAssetFile$1(bundleFile, output));
|
|
2679
|
-
if (!(importedStyleFiles.has(file) || !file.includes("/") && importedFileNames.has(posix.posix.basename(file)))) continue;
|
|
2680
|
-
importedSources.push(readAssetSource$2(output));
|
|
2681
|
-
}
|
|
2682
|
-
return importedSources;
|
|
2683
|
-
}
|
|
2684
|
-
function collectBundleAssetFiles(bundle) {
|
|
2685
|
-
const files = /* @__PURE__ */ new Set();
|
|
2686
|
-
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2687
|
-
if (output.type !== "asset") continue;
|
|
2688
|
-
files.add(normalizeOutputPathKey(getAssetFile$1(bundleFile, output)));
|
|
2689
|
-
}
|
|
2690
|
-
return files;
|
|
2691
|
-
}
|
|
2692
|
-
function normalizeComparableStyleFile(file) {
|
|
2693
|
-
return normalizeOutputPathKey(posix.normalize(file.replace(/[?#].*$/, "")));
|
|
2694
|
-
}
|
|
2695
|
-
function collectConfiguredTailwindV4CssEntryFiles(opts) {
|
|
2696
|
-
const runtimeCssEntries = opts.tailwindRuntime?.options?.tailwindcss?.v4?.cssEntries;
|
|
2697
|
-
return [
|
|
2698
|
-
...Array.isArray(opts.cssEntries) ? opts.cssEntries : [],
|
|
2699
|
-
...Array.isArray(opts.tailwindcss?.v4?.cssEntries) ? opts.tailwindcss.v4.cssEntries : [],
|
|
2700
|
-
...Array.isArray(opts.tailwindcssRuntimeOptions?.tailwindcss?.v4?.cssEntries) ? opts.tailwindcssRuntimeOptions.tailwindcss.v4.cssEntries : [],
|
|
2701
|
-
...Array.isArray(runtimeCssEntries) ? runtimeCssEntries : []
|
|
2702
|
-
].filter((file) => typeof file === "string" && file.length > 0);
|
|
2703
|
-
}
|
|
2704
|
-
function isConfiguredTailwindV4CssEntryFile(opts, file) {
|
|
2705
|
-
if (typeof file !== "string" || file.length === 0) return false;
|
|
2706
|
-
const fileKey = normalizeComparableStyleFile(file);
|
|
2707
|
-
return collectConfiguredTailwindV4CssEntryFiles(opts).some((entry) => normalizeComparableStyleFile(entry) === fileKey);
|
|
2708
|
-
}
|
|
2709
|
-
function resolveConfiguredCssEntryRootInjectionTarget(bundle, options, sourceFile, outputFile) {
|
|
2710
|
-
const opts = options.opts;
|
|
2711
|
-
if (opts === void 0 || isMiniProgramStyleOutputFile(outputFile) || !isConfiguredTailwindV4CssEntryFile(opts, sourceFile)) return;
|
|
2712
|
-
const context = createCssAssetPipelineContext(options, outputFile, bundle);
|
|
2713
|
-
if (context === void 0) return;
|
|
2714
|
-
const resolvedByStrategy = options.cssPipelineStrategy?.resolveConfiguredCssEntryRootInjectionTarget?.({
|
|
2715
|
-
...context,
|
|
2716
|
-
bundle,
|
|
2717
|
-
isConfiguredCssEntryFile: (file) => isConfiguredTailwindV4CssEntryFile(opts, file),
|
|
2718
|
-
isMiniProgramStyleOutputFile,
|
|
2719
|
-
isRootStyleOutputFile,
|
|
2720
|
-
outputFile,
|
|
2721
|
-
sourceFile
|
|
2722
|
-
});
|
|
2723
|
-
if (resolvedByStrategy !== void 0) return resolvedByStrategy;
|
|
2724
|
-
if (options.cssPipelineStrategy?.resolveConfiguredCssEntryRootInjectionTarget == null) return;
|
|
2725
|
-
const rootCssFiles = [];
|
|
2726
|
-
const matchedRootCssFiles = [];
|
|
2727
|
-
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2728
|
-
if (output.type !== "asset") continue;
|
|
2729
|
-
const file = getAssetFile$1(bundleFile, output);
|
|
2730
|
-
if (!opts.cssMatcher(file) || !isRootStyleOutputFile(file) || isMiniProgramStyleOutputFile(file)) continue;
|
|
2731
|
-
rootCssFiles.push(file);
|
|
2732
|
-
if (opts.mainCssChunkMatcher(file, opts.appType)) matchedRootCssFiles.push(file);
|
|
2733
|
-
}
|
|
2734
|
-
if (matchedRootCssFiles.length === 1) return matchedRootCssFiles[0];
|
|
2735
|
-
if (matchedRootCssFiles.length > 1) return;
|
|
2736
|
-
return rootCssFiles.length === 1 ? rootCssFiles[0] : void 0;
|
|
2737
|
-
}
|
|
2738
|
-
function findBundleAssetByOutputFile(bundle, file) {
|
|
2739
|
-
const fileKey = normalizeOutputPathKey(file);
|
|
2740
|
-
return Object.entries(bundle).find(([bundleFile, output]) => {
|
|
2741
|
-
return output.type === "asset" && normalizeOutputPathKey(getAssetFile$1(bundleFile, output)) === fileKey;
|
|
2742
|
-
})?.[1];
|
|
2743
|
-
}
|
|
2744
|
-
function isCssImportOnlyBundleAsset(bundle, file, css) {
|
|
2745
|
-
const importedStyleFiles = collectImportedStyleFiles(css, file);
|
|
2746
|
-
if (importedStyleFiles.size === 0) return false;
|
|
2747
|
-
let hasNonImportNode = false;
|
|
2748
|
-
try {
|
|
2749
|
-
postcss.parse(css).each((node) => {
|
|
2750
|
-
if (node.type === "comment") return;
|
|
2751
|
-
if (node.type !== "atrule" || node.name !== "import") hasNonImportNode = true;
|
|
2752
|
-
});
|
|
2753
|
-
} catch {
|
|
2754
|
-
return false;
|
|
2755
|
-
}
|
|
2756
|
-
if (hasNonImportNode) return false;
|
|
2757
|
-
return collectImportedBundleCssSources(bundle, importedStyleFiles).length > 0;
|
|
2758
|
-
}
|
|
2759
|
-
function isCoveredViteGeneratedSourceAsset(file, existingAssetFiles, resolveViteProcessedCssOutputFile) {
|
|
2760
|
-
const resolvedOutputFile = normalizeOutputPathKey(resolveViteProcessedCssOutputFile?.(file) ?? file);
|
|
2761
|
-
return resolvedOutputFile !== normalizeOutputPathKey(file) && existingAssetFiles.has(resolvedOutputFile);
|
|
2762
|
-
}
|
|
2763
|
-
function resolveViteGeneratedCssMarkerOutputFile(file, markerFile, existingAssetFiles, resolveViteProcessedCssOutputFile) {
|
|
2764
|
-
const resolvedFromFile = normalizeOutputPathKey(resolveViteProcessedCssOutputFile?.(file) ?? file);
|
|
2765
|
-
if (!markerFile) return resolvedFromFile;
|
|
2766
|
-
const resolvedFromMarker = normalizeOutputPathKey(resolveViteProcessedCssOutputFile?.(markerFile) ?? markerFile);
|
|
2767
|
-
if (resolvedFromMarker !== resolvedFromFile && existingAssetFiles.has(resolvedFromMarker)) return resolvedFromMarker;
|
|
2768
|
-
return resolvedFromFile;
|
|
2769
|
-
}
|
|
2770
|
-
function isSourceRootPrefixedOutputFile(file, outputFile) {
|
|
2771
|
-
const fileKey = normalizeOutputPathKey(file);
|
|
2772
|
-
const outputFileKey = normalizeOutputPathKey(outputFile);
|
|
2773
|
-
return fileKey !== outputFileKey && fileKey.endsWith(`/${outputFileKey}`);
|
|
2774
|
-
}
|
|
2830
|
+
//#endregion
|
|
2831
|
+
//#region src/bundlers/vite/processed-css-assets/collector.ts
|
|
2775
2832
|
function collectViteProcessedCssAssetResults(bundle, options) {
|
|
2776
2833
|
let collected = 0;
|
|
2777
2834
|
const existingAssetFiles = collectBundleAssetFiles(bundle);
|
|
@@ -2841,8 +2898,14 @@ function collectViteProcessedCssAssetResults(bundle, options) {
|
|
|
2841
2898
|
return collected;
|
|
2842
2899
|
}
|
|
2843
2900
|
function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
2901
|
+
const measure = (name, task) => {
|
|
2902
|
+
const startedAt = performance.now();
|
|
2903
|
+
const result = task();
|
|
2904
|
+
options.recordTimingDetail?.(`finalize.processedCss.inject.${name}`, startedAt);
|
|
2905
|
+
return result;
|
|
2906
|
+
};
|
|
2844
2907
|
const transformCss = (css, file) => options.transformCss?.(css, file) ?? css;
|
|
2845
|
-
const viteCssResults = dedupeViteCssResults([...options.getViteProcessedCssAssetResults?.() ?? []].map(([file, record]) => {
|
|
2908
|
+
const viteCssResults = measure("prepareResults", () => dedupeViteCssResults([...options.getViteProcessedCssAssetResults?.() ?? []].map(([file, record]) => {
|
|
2846
2909
|
return typeof record === "string" ? {
|
|
2847
2910
|
file,
|
|
2848
2911
|
css: record,
|
|
@@ -2856,7 +2919,7 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
2856
2919
|
})).map((record) => ({
|
|
2857
2920
|
...record,
|
|
2858
2921
|
css: transformCss(record.css, record.outputFile ?? record.file)
|
|
2859
|
-
})).filter((record) => record.css.length > 0);
|
|
2922
|
+
})).filter((record) => record.css.length > 0));
|
|
2860
2923
|
let injected = 0;
|
|
2861
2924
|
for (const [bundleFile, bundleOutput] of Object.entries(bundle)) {
|
|
2862
2925
|
let output = bundleOutput;
|
|
@@ -2882,16 +2945,19 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
2882
2945
|
}
|
|
2883
2946
|
const fileKey = normalizeOutputPathKey(file);
|
|
2884
2947
|
const mainFileKey = normalizeOutputPathKey(file);
|
|
2885
|
-
const normalizedOriginalCss = normalizeInjectableCssForTargetWithImports(transformCss(removeTailwindEntryDirectivesFromCss(originalSource), file), file);
|
|
2948
|
+
const normalizedOriginalCss = measure("normalizeTarget", () => normalizeInjectableCssForTargetWithImports(transformCss(removeTailwindEntryDirectivesFromCss(originalSource), file), file));
|
|
2886
2949
|
let nextCss = normalizedOriginalCss.css;
|
|
2887
2950
|
const importedStyleFiles = normalizedOriginalCss.importedStyleFiles;
|
|
2888
2951
|
const importedBundleCssSources = collectImportedBundleCssSources(bundle, importedStyleFiles);
|
|
2889
|
-
|
|
2952
|
+
const importedBundleCssCoverage = prepareImportedCssCoverage(importedBundleCssSources);
|
|
2953
|
+
nextCss = removeCssCoveredByImportedViteResults(nextCss, importedBundleCssSources, importedBundleCssCoverage);
|
|
2890
2954
|
const importedViteCssResults = viteCssResults.filter((record) => isViteProcessedCssResultImported(record, importedStyleFiles));
|
|
2891
2955
|
const bundleAssetFiles = collectBundleAssetFiles(bundle);
|
|
2892
2956
|
const uncoveredImportedViteCssResults = importedViteCssResults.filter((record) => !isViteProcessedCssResultCoveredByImportedBundleAsset(record, importedStyleFiles, bundleAssetFiles));
|
|
2893
2957
|
const importedCssSources = [...importedBundleCssSources, ...uncoveredImportedViteCssResults.map((record) => record.css)];
|
|
2894
|
-
|
|
2958
|
+
const uncoveredImportedCssSources = uncoveredImportedViteCssResults.map((record) => record.css);
|
|
2959
|
+
nextCss = removeCssCoveredByImportedViteResults(nextCss, uncoveredImportedCssSources, prepareImportedCssCoverage(uncoveredImportedCssSources));
|
|
2960
|
+
const importedCssCoverage = prepareImportedCssCoverage(importedCssSources);
|
|
2895
2961
|
const targetViteCssResults = [];
|
|
2896
2962
|
for (const record of viteCssResults) {
|
|
2897
2963
|
if (!isRootStyleOutputFile(file)) {
|
|
@@ -2900,41 +2966,40 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
2900
2966
|
if (!shouldInjectViteProcessedCssResult(options.opts, mainFileKey, record.file, record)) continue;
|
|
2901
2967
|
if (isViteProcessedCssResultImported(record, importedStyleFiles)) continue;
|
|
2902
2968
|
targetViteCssResults.push(record);
|
|
2903
|
-
let css = normalizeInjectableCssForTarget(stripBundlerGeneratedCssMarkers(record.css).trim(), file).trim();
|
|
2904
|
-
css = removeCssCoveredByImportedViteResults(css, importedCssSources).trim();
|
|
2969
|
+
let css = measure("normalizeRecord", () => normalizeInjectableCssForTarget(stripBundlerGeneratedCssMarkers(record.css).trim(), file).trim());
|
|
2970
|
+
css = measure("importCoverage", () => removeCssCoveredByImportedViteResults(css, importedCssSources, importedCssCoverage).trim());
|
|
2905
2971
|
if (css.length === 0) continue;
|
|
2906
|
-
const mergedLayerCss = mergeMarkedUserLayerComponentsCss(nextCss, css);
|
|
2972
|
+
const mergedLayerCss = measure("mergeLayers", () => mergeMarkedUserLayerComponentsCss(nextCss, css));
|
|
2907
2973
|
if (mergedLayerCss.merged) {
|
|
2908
2974
|
nextCss = mergedLayerCss.css;
|
|
2909
2975
|
css = extractMarkedUserLayerComponentsCss(css).rest.trim();
|
|
2910
2976
|
if (css.length === 0) continue;
|
|
2911
2977
|
}
|
|
2912
|
-
|
|
2913
|
-
if (containsCssAfterMinify(nextCss, css)) continue;
|
|
2914
|
-
const mergedPreflightDeclarations = mergeMiniProgramPreflightRuleDeclarations(nextCss, css);
|
|
2978
|
+
const mergedPreflightDeclarations = measure("mergePreflight", () => mergeMiniProgramPreflightRuleDeclarations(nextCss, css));
|
|
2915
2979
|
if (mergedPreflightDeclarations.changed) {
|
|
2916
2980
|
nextCss = mergedPreflightDeclarations.baseCss;
|
|
2917
2981
|
css = mergedPreflightDeclarations.css.trim();
|
|
2918
2982
|
if (css.length === 0) continue;
|
|
2919
2983
|
}
|
|
2920
|
-
const mergedThemeScopeDeclarations = mergeMiniProgramThemeScopeRuleDeclarations(nextCss, css);
|
|
2984
|
+
const mergedThemeScopeDeclarations = measure("mergeTheme", () => mergeMiniProgramThemeScopeRuleDeclarations(nextCss, css));
|
|
2921
2985
|
if (mergedThemeScopeDeclarations.changed) {
|
|
2922
2986
|
nextCss = mergedThemeScopeDeclarations.baseCss;
|
|
2923
2987
|
css = mergedThemeScopeDeclarations.css.trim();
|
|
2924
2988
|
if (css.length === 0) continue;
|
|
2925
2989
|
}
|
|
2926
|
-
const mergedRuleDeclarations = mergeCoveredCssRuleDeclarations(nextCss, css);
|
|
2990
|
+
const mergedRuleDeclarations = measure("mergeDeclarations", () => mergeCoveredCssRuleDeclarations(nextCss, css));
|
|
2927
2991
|
if (mergedRuleDeclarations.changed) {
|
|
2928
2992
|
nextCss = mergedRuleDeclarations.baseCss;
|
|
2929
2993
|
css = mergedRuleDeclarations.css.trim();
|
|
2930
2994
|
if (css.length === 0) continue;
|
|
2931
2995
|
}
|
|
2932
|
-
const missingCss = filterExistingCssRules(nextCss, css);
|
|
2933
|
-
if (missingCss.length === 0 || !hasNonCommentCss(missingCss) || containsCssAfterMinify(nextCss, missingCss)) continue;
|
|
2996
|
+
const missingCss = measure("filterRules", () => filterExistingCssRules(nextCss, css));
|
|
2997
|
+
if (missingCss.length === 0 || !hasNonCommentCss(missingCss) || measure("containsMissing", () => containsCssAfterMinify(nextCss, missingCss))) continue;
|
|
2934
2998
|
nextCss = appendCss$1(nextCss, missingCss);
|
|
2935
2999
|
}
|
|
2936
3000
|
const finalImportedCssSources = collectImportedBundleCssSources(bundle, collectImportedStyleFiles(originalSource, file));
|
|
2937
|
-
|
|
3001
|
+
const finalImportedCssCoverage = prepareImportedCssCoverage(finalImportedCssSources);
|
|
3002
|
+
nextCss = measure("finalizeTarget", () => transformCss(removeCommentOnlyAtRules(restoreCssImportAtRules(originalSource, removeCssRulesCoveredBySources(nextCss, finalImportedCssSources, { exactOnly: true }, finalImportedCssCoverage?.coverage).trim(), file)), file));
|
|
2938
3003
|
if (nextCss.trim() === originalSource.trim()) nextCss = originalSource;
|
|
2939
3004
|
if (nextCss !== originalSource) {
|
|
2940
3005
|
output.source = nextCss;
|
|
@@ -2943,24 +3008,13 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
2943
3008
|
options.onUpdate?.(file, originalSource, nextCss);
|
|
2944
3009
|
options.debug?.("inject vite-processed css into main css asset: %s bytes=%d", file, nextCss.length);
|
|
2945
3010
|
}
|
|
2946
|
-
const removedSources = removeCoveredInjectedSourceAssets(bundle, file, nextCss, targetViteCssResults, options);
|
|
3011
|
+
const removedSources = measure("removeSources", () => removeCoveredInjectedSourceAssets(bundle, file, nextCss, targetViteCssResults, options));
|
|
2947
3012
|
if (nextCss === originalSource && removedSources === 0) continue;
|
|
2948
3013
|
injected++;
|
|
2949
3014
|
}
|
|
2950
3015
|
return injected;
|
|
2951
3016
|
}
|
|
2952
3017
|
//#endregion
|
|
2953
|
-
//#region src/bundlers/vite/generate-bundle/bundle-file-names.ts
|
|
2954
|
-
function normalizeBundleFileNameKeysForTest(bundle) {
|
|
2955
|
-
for (const [file, output] of Object.entries(bundle)) {
|
|
2956
|
-
if (!output.fileName || output.fileName === file) continue;
|
|
2957
|
-
const existing = bundle[output.fileName];
|
|
2958
|
-
if (existing != null && existing !== output) continue;
|
|
2959
|
-
bundle[output.fileName] = output;
|
|
2960
|
-
delete bundle[file];
|
|
2961
|
-
}
|
|
2962
|
-
}
|
|
2963
|
-
//#endregion
|
|
2964
3018
|
//#region src/bundlers/vite/generate-bundle/final-css-assets.ts
|
|
2965
3019
|
function readAssetSource$1(output) {
|
|
2966
3020
|
return typeof output.source === "string" ? output.source : output.source.toString();
|
|
@@ -3143,6 +3197,7 @@ async function handleUniAppXPostCssTasks(options) {
|
|
|
3143
3197
|
...cssHandlerOptions,
|
|
3144
3198
|
isMainChunk: false
|
|
3145
3199
|
},
|
|
3200
|
+
frameworkPostcssStage: "complete",
|
|
3146
3201
|
getSourceCandidatesForEntries,
|
|
3147
3202
|
styleHandler,
|
|
3148
3203
|
debug
|
|
@@ -3212,7 +3267,7 @@ function pruneLastCssResults(resultByFile, sourceHashByFile, activeFiles) {
|
|
|
3212
3267
|
}
|
|
3213
3268
|
}
|
|
3214
3269
|
//#endregion
|
|
3215
|
-
//#region src/bundlers/vite/generate-bundle/finalize.ts
|
|
3270
|
+
//#region src/bundlers/vite/generate-bundle/finalize/root-import-shell.ts
|
|
3216
3271
|
function readAssetSource(asset) {
|
|
3217
3272
|
return typeof asset.source === "string" ? asset.source : asset.source.toString();
|
|
3218
3273
|
}
|
|
@@ -3301,6 +3356,8 @@ function normalizeRootMiniProgramImportShellAssets(bundle, options) {
|
|
|
3301
3356
|
}
|
|
3302
3357
|
return updated;
|
|
3303
3358
|
}
|
|
3359
|
+
//#endregion
|
|
3360
|
+
//#region src/bundlers/vite/generate-bundle/finalize/bundle.ts
|
|
3304
3361
|
async function finalizeGenerateBundle(options) {
|
|
3305
3362
|
const { activeProcessCacheKeys, activeProcessHashKeys, activeViteCssCacheFiles, bundle, bundleFiles, cache, cssTaskFactories, cssPipelineStrategy, createCssPipelineContext, debug, defaultStyleOutputExtension, formatIteration, generatorCandidateSignature, generatorRuntime, getCssHandlerOptions, getSourceCandidateSourcesForEntries, getSourceCandidatesForEntries, getViteCssCacheStats, getViteProcessedCssAssetResults, hmrTimingRecorder, hmrTimingStartedAt, isHarmonyAppStyleTarget, isNativeAppStyleTarget, isViteProcessedCssAsset, isWebGeneratorTarget, jsAfterCss, jsTaskFactories, lastCssResultByFile, lastCssSourceHashByFile, linkedByEntry, markCssAssetProcessed, metrics, onEnd, onUpdate, opts, outDir, pendingLinkedUpdates, pruneViteCssCaches, recordCssAssetResult, recordTimingDetail, recordViteProcessedCssAssetResult, rootDir, runtime, runtimeState, shouldPreserveAppCssExtension, snapshot, sourceCandidates, sourceRoot, state, styleHandler, tasks, timingDetails, transformRuntime, transformWebTargetCss, useIncrementalMode } = options;
|
|
3306
3363
|
const tasksStart = performance.now();
|
|
@@ -3313,6 +3370,7 @@ async function finalizeGenerateBundle(options) {
|
|
|
3313
3370
|
await Promise.all(tasks);
|
|
3314
3371
|
recordTimingDetail("tasks", tasksStart);
|
|
3315
3372
|
for (const apply of pendingLinkedUpdates) apply();
|
|
3373
|
+
const uniAppXPostCssStartedAt = performance.now();
|
|
3316
3374
|
const applyStyleSources = await handleUniAppXPostCssTasks({
|
|
3317
3375
|
bundle,
|
|
3318
3376
|
debug,
|
|
@@ -3328,7 +3386,9 @@ async function finalizeGenerateBundle(options) {
|
|
|
3328
3386
|
runtimeState,
|
|
3329
3387
|
styleHandler
|
|
3330
3388
|
});
|
|
3389
|
+
recordTimingDetail("finalize.uniAppXPostCss", uniAppXPostCssStartedAt);
|
|
3331
3390
|
const syncViteProcessedCssIntoMainCssAssets = () => {
|
|
3391
|
+
const collectStartedAt = performance.now();
|
|
3332
3392
|
collectViteProcessedCssAssetResults(bundle, {
|
|
3333
3393
|
opts,
|
|
3334
3394
|
cssPipelineStrategy,
|
|
@@ -3342,7 +3402,9 @@ async function finalizeGenerateBundle(options) {
|
|
|
3342
3402
|
transformCss: transformWebTargetCss,
|
|
3343
3403
|
debug
|
|
3344
3404
|
});
|
|
3345
|
-
|
|
3405
|
+
recordTimingDetail("finalize.processedCss.collect", collectStartedAt);
|
|
3406
|
+
const injectStartedAt = performance.now();
|
|
3407
|
+
const injected = injectViteProcessedCssIntoMainCssAssets(bundle, {
|
|
3346
3408
|
opts,
|
|
3347
3409
|
cssPipelineStrategy,
|
|
3348
3410
|
createCssPipelineContext,
|
|
@@ -3356,16 +3418,22 @@ async function finalizeGenerateBundle(options) {
|
|
|
3356
3418
|
return normalizeOutputPathKey(record.file) !== targetFileKey;
|
|
3357
3419
|
},
|
|
3358
3420
|
debug,
|
|
3359
|
-
onUpdate
|
|
3421
|
+
onUpdate,
|
|
3422
|
+
recordTimingDetail
|
|
3360
3423
|
});
|
|
3424
|
+
recordTimingDetail("finalize.processedCss.inject", injectStartedAt);
|
|
3425
|
+
return injected;
|
|
3361
3426
|
};
|
|
3427
|
+
const processedCssStartedAt = performance.now();
|
|
3362
3428
|
syncViteProcessedCssIntoMainCssAssets();
|
|
3363
3429
|
if (isHarmonyAppStyleTarget && applyStyleSources.length > 0) {
|
|
3364
3430
|
if (injectUniAppXHarmonyBundleStyles(bundle, { cssSources: [...getViteProcessedCssAssetResults?.() ?? []].map(([, record]) => typeof record === "string" ? record : record.css) })) debug("uni-app-x harmony bundle styles inject after css assets");
|
|
3365
3431
|
syncViteProcessedCssIntoMainCssAssets();
|
|
3366
3432
|
}
|
|
3433
|
+
recordTimingDetail("finalize.processedCss", processedCssStartedAt);
|
|
3367
3434
|
const createFinalizeCssPipelineContext = (file = "") => createCssPipelineContext?.(file);
|
|
3368
3435
|
const finalizeCssPipelineContext = createFinalizeCssPipelineContext();
|
|
3436
|
+
const rootCssStartedAt = performance.now();
|
|
3369
3437
|
normalizeRootMiniProgramImportShellAssets(bundle, {
|
|
3370
3438
|
cssMatcher: opts.cssMatcher,
|
|
3371
3439
|
debug,
|
|
@@ -3394,6 +3462,8 @@ async function finalizeGenerateBundle(options) {
|
|
|
3394
3462
|
isWebGeneratorTarget,
|
|
3395
3463
|
outDir
|
|
3396
3464
|
}) === true) removeDuplicateUnlinkedRootCssAssetsReferencedByHtml(bundle, { debug });
|
|
3465
|
+
recordTimingDetail("finalize.rootCss", rootCssStartedAt);
|
|
3466
|
+
const finalCssAssetsStartedAt = performance.now();
|
|
3397
3467
|
await finalizeMiniProgramCssAssets(bundle, {
|
|
3398
3468
|
cssMatcher: opts.cssMatcher,
|
|
3399
3469
|
debug,
|
|
@@ -3404,6 +3474,8 @@ async function finalizeGenerateBundle(options) {
|
|
|
3404
3474
|
recordCssAssetResult,
|
|
3405
3475
|
styleHandler
|
|
3406
3476
|
});
|
|
3477
|
+
recordTimingDetail("finalize.cssAssets", finalCssAssetsStartedAt);
|
|
3478
|
+
const webCompatStartedAt = performance.now();
|
|
3407
3479
|
if (finalizeCssPipelineContext !== void 0 && cssPipelineStrategy?.shouldApplyFinalWebviewCssCompat?.({
|
|
3408
3480
|
...finalizeCssPipelineContext,
|
|
3409
3481
|
bundleFiles: Object.keys(bundle),
|
|
@@ -3415,6 +3487,7 @@ async function finalizeGenerateBundle(options) {
|
|
|
3415
3487
|
opts,
|
|
3416
3488
|
recordCssAssetResult
|
|
3417
3489
|
});
|
|
3490
|
+
recordTimingDetail("finalize.webCompat", webCompatStartedAt);
|
|
3418
3491
|
const stateUpdateStart = performance.now();
|
|
3419
3492
|
updateBundleBuildState(state, snapshot, useIncrementalMode ? linkedByEntry ?? /* @__PURE__ */ new Map() : /* @__PURE__ */ new Map(), { incremental: useIncrementalMode });
|
|
3420
3493
|
state.generatorCandidateSignature = generatorCandidateSignature;
|
|
@@ -4231,6 +4304,7 @@ async function processRememberedCssReplay(options) {
|
|
|
4231
4304
|
outputFile,
|
|
4232
4305
|
cssHandlerOptions,
|
|
4233
4306
|
cssUserHandlerOptions: getCssUserHandlerOptions(sourceFile),
|
|
4307
|
+
frameworkPostcssStage: "complete",
|
|
4234
4308
|
getSourceCandidatesForEntries: scopedSourceCandidateGetter,
|
|
4235
4309
|
generatorPlatform,
|
|
4236
4310
|
styleHandler,
|
|
@@ -4827,7 +4901,7 @@ function resolveViteWebCssCompatOptions(context) {
|
|
|
4827
4901
|
return context.currentGeneratorBranch.isWeb ? context.currentGeneratorOptions.webCompat : context.currentGeneratorOptions.webCompat ?? true;
|
|
4828
4902
|
}
|
|
4829
4903
|
//#endregion
|
|
4830
|
-
//#region src/bundlers/vite/generate-bundle.ts
|
|
4904
|
+
//#region src/bundlers/vite/generate-bundle-runtime.ts
|
|
4831
4905
|
function inferPlatformFromViteOutDir$1(outDir) {
|
|
4832
4906
|
const segment = outDir ? path.basename(path.normalize(outDir)) : void 0;
|
|
4833
4907
|
if (!segment) return;
|
|
@@ -4837,7 +4911,7 @@ function inferPlatformFromViteOutDir$1(outDir) {
|
|
|
4837
4911
|
function hasTailwindPluginDirective(source) {
|
|
4838
4912
|
return /@plugin\b/.test(source);
|
|
4839
4913
|
}
|
|
4840
|
-
function createGenerateBundleHook(context) {
|
|
4914
|
+
function createGenerateBundleHook$1(context) {
|
|
4841
4915
|
const state = createBundleBuildState();
|
|
4842
4916
|
const lastCssResultByFile = /* @__PURE__ */ new Map();
|
|
4843
4917
|
const lastCssSourceHashByFile = /* @__PURE__ */ new Map();
|
|
@@ -5146,16 +5220,16 @@ function createGenerateBundleHook(context) {
|
|
|
5146
5220
|
tailwindcssBasedir: opts.tailwindcssBasedir,
|
|
5147
5221
|
useIncrementalMode
|
|
5148
5222
|
});
|
|
5149
|
-
const createScopedGeneratorRuntime$1 = (outputFile,
|
|
5150
|
-
cssHandlerOptions,
|
|
5151
|
-
fallbackRuntime:
|
|
5223
|
+
const createScopedGeneratorRuntime$1 = (outputFile, cssHandlerOptions2, runtime2, rawSource, sourceFile) => createScopedGeneratorRuntime({
|
|
5224
|
+
cssHandlerOptions: cssHandlerOptions2,
|
|
5225
|
+
fallbackRuntime: runtime2,
|
|
5152
5226
|
getSourceCandidatesForEntries: getCombinedSourceCandidatesForEntries,
|
|
5153
5227
|
majorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
5154
5228
|
outputFile,
|
|
5155
5229
|
rawSource,
|
|
5156
5230
|
shouldExcludeSubpackageSourceCandidates,
|
|
5157
5231
|
sourceFile,
|
|
5158
|
-
scopedSourceCandidateGetter: createScopedSourceCandidateGetter(outputFile,
|
|
5232
|
+
scopedSourceCandidateGetter: createScopedSourceCandidateGetter(outputFile, cssHandlerOptions2)
|
|
5159
5233
|
});
|
|
5160
5234
|
const jsEntries = snapshot.jsEntries;
|
|
5161
5235
|
const getJsEntry = createJsEntryResolver(jsEntries);
|
|
@@ -5306,6 +5380,7 @@ function createGenerateBundleHook(context) {
|
|
|
5306
5380
|
const tasks = [];
|
|
5307
5381
|
const cssTaskFactories = [];
|
|
5308
5382
|
const jsTaskFactories = [];
|
|
5383
|
+
const entryPlanningStartedAt = performance.now();
|
|
5309
5384
|
for (const entry of snapshot.entries) {
|
|
5310
5385
|
const { file, output: originalSource, source: originalEntrySource, type } = entry;
|
|
5311
5386
|
if (processMarkupAndScripts && type === "html" && originalSource.type === "asset") {
|
|
@@ -5331,8 +5406,8 @@ function createGenerateBundleHook(context) {
|
|
|
5331
5406
|
originalEntrySource,
|
|
5332
5407
|
originalSource,
|
|
5333
5408
|
rememberProcessCacheKey,
|
|
5334
|
-
resolveCurrentSourceCandidateSource: (
|
|
5335
|
-
file,
|
|
5409
|
+
resolveCurrentSourceCandidateSource: (file2) => resolveCurrentSourceCandidateSource({
|
|
5410
|
+
file: file2,
|
|
5336
5411
|
getSourceCandidateSource,
|
|
5337
5412
|
getSourceCandidateSources,
|
|
5338
5413
|
outDir,
|
|
@@ -5352,7 +5427,7 @@ function createGenerateBundleHook(context) {
|
|
|
5352
5427
|
const assetSourceFile = resolveAssetSourceFile(originalSource, file);
|
|
5353
5428
|
const rawSource = normalizeRelativeCssConfigDirectives(originalEntrySource, assetSourceFile, outDir, opts);
|
|
5354
5429
|
const currentRawSourceHasExplicitScanContext = rawSource.includes("@source") || rawSource.includes("@config");
|
|
5355
|
-
const
|
|
5430
|
+
const cssPipelineContext2 = {
|
|
5356
5431
|
...createInitialCssPipelineContext(file),
|
|
5357
5432
|
bundle
|
|
5358
5433
|
};
|
|
@@ -5364,7 +5439,7 @@ function createGenerateBundleHook(context) {
|
|
|
5364
5439
|
isWebGeneratorTarget,
|
|
5365
5440
|
matchesCss: opts.cssMatcher(rootImportShellOutputFile) || opts.cssMatcher(file),
|
|
5366
5441
|
shouldKeep: () => context.cssPipelineStrategy?.shouldKeepRootMiniProgramStyleAsImportShell?.({
|
|
5367
|
-
...
|
|
5442
|
+
...cssPipelineContext2,
|
|
5368
5443
|
css: rawSource,
|
|
5369
5444
|
file: rootImportShellOutputFile
|
|
5370
5445
|
})
|
|
@@ -5374,16 +5449,16 @@ function createGenerateBundleHook(context) {
|
|
|
5374
5449
|
if (importedFile && isRootMiniProgramStyleOutputFile$1(importedFile)) frameworkRootImportShellTargetByFile.set(rootImportShellOutputFile, importedFile);
|
|
5375
5450
|
}
|
|
5376
5451
|
if (!rememberedFrameworkRootImportTarget && !isCurrentFrameworkRootImportShell && !isWebGeneratorTarget && isRootMiniProgramStyleOutputFile$1(rootImportShellOutputFile) && normalizeOutputPathKey(assetSourceFile) === normalizeOutputPathKey(file) && opts.mainCssChunkMatcher(rootImportShellOutputFile, opts.appType) && shouldKeepRootMiniProgramStyleAsImportShell(context.cssPipelineStrategy?.shouldKeepRootMiniProgramStyleAsImportShell?.({
|
|
5377
|
-
...
|
|
5452
|
+
...cssPipelineContext2,
|
|
5378
5453
|
css: rawSource,
|
|
5379
5454
|
file: rootImportShellOutputFile
|
|
5380
5455
|
})) && !shouldMoveRootMiniProgramStyleToImportShellOrigin(context.cssPipelineStrategy?.shouldMoveRootMiniProgramStyleToImportShellOrigin?.({
|
|
5381
|
-
...
|
|
5456
|
+
...cssPipelineContext2,
|
|
5382
5457
|
file: rootImportShellOutputFile
|
|
5383
5458
|
}))) {
|
|
5384
5459
|
const rootGeneratedTargets = /* @__PURE__ */ new Set();
|
|
5385
|
-
for (const
|
|
5386
|
-
const targetFile = resolveMatchedCssSourceOutputFile(
|
|
5460
|
+
for (const entry2 of getConfiguredTailwindV4CssSourceEntries()) {
|
|
5461
|
+
const targetFile = resolveMatchedCssSourceOutputFile(entry2.file);
|
|
5387
5462
|
if (targetFile && isRootMiniProgramStyleOutputFile$1(targetFile) && normalizeOutputPathKey(targetFile) !== normalizeOutputPathKey(rootImportShellOutputFile)) rootGeneratedTargets.add(targetFile);
|
|
5388
5463
|
}
|
|
5389
5464
|
for (const [, record] of getViteProcessedCssAssetResults?.() ?? []) {
|
|
@@ -5407,11 +5482,11 @@ function createGenerateBundleHook(context) {
|
|
|
5407
5482
|
file,
|
|
5408
5483
|
isWebGeneratorTarget,
|
|
5409
5484
|
opts,
|
|
5410
|
-
pipelineContext:
|
|
5485
|
+
pipelineContext: cssPipelineContext2,
|
|
5411
5486
|
shouldPreserveAppCssExtension
|
|
5412
5487
|
});
|
|
5413
5488
|
if (rememberedFrameworkRootImportTarget && !isWebGeneratorTarget && (opts.cssMatcher(rootImportShellOutputFile) || opts.cssMatcher(file)) && shouldKeepRootMiniProgramStyleAsImportShell(context.cssPipelineStrategy?.shouldKeepRootMiniProgramStyleAsImportShell?.({
|
|
5414
|
-
...
|
|
5489
|
+
...cssPipelineContext2,
|
|
5415
5490
|
css: rawSource,
|
|
5416
5491
|
file: rootImportShellOutputFile
|
|
5417
5492
|
}))) {
|
|
@@ -5424,7 +5499,7 @@ function createGenerateBundleHook(context) {
|
|
|
5424
5499
|
originalFileNames: originalSource.originalFileNames,
|
|
5425
5500
|
resolveOutputFileFromMatchedCssSource: resolveMatchedCssSourceOutputFile
|
|
5426
5501
|
});
|
|
5427
|
-
const configuredOriginalSourceEntry = outputFile.replace(/[?#].*$/, "").endsWith(".css") ? getConfiguredTailwindV4CssSourceEntries().find((
|
|
5502
|
+
const configuredOriginalSourceEntry = outputFile.replace(/[?#].*$/, "").endsWith(".css") ? getConfiguredTailwindV4CssSourceEntries().find((entry2) => originalSource.originalFileNames?.some((originalFile) => normalizeConfiguredTailwindV4CssEntryFileKey(originalFile) === normalizeConfiguredTailwindV4CssEntryFileKey(entry2.file)) === true) : void 0;
|
|
5428
5503
|
const configuredOriginalOutputFile = configuredOriginalSourceEntry ? resolveMatchedOutputFileForCurrentAsset(configuredOriginalSourceEntry.file) : void 0;
|
|
5429
5504
|
let resolvedFromConfiguredOriginalCssEntry = false;
|
|
5430
5505
|
if (configuredOriginalOutputFile && normalizeOutputPathKey(configuredOriginalOutputFile) !== normalizeOutputPathKey(outputFile)) {
|
|
@@ -5449,7 +5524,7 @@ function createGenerateBundleHook(context) {
|
|
|
5449
5524
|
file,
|
|
5450
5525
|
originalSource,
|
|
5451
5526
|
outputFile,
|
|
5452
|
-
pipelineContext:
|
|
5527
|
+
pipelineContext: cssPipelineContext2,
|
|
5453
5528
|
source,
|
|
5454
5529
|
viteProcessedCssAsset
|
|
5455
5530
|
});
|
|
@@ -5525,7 +5600,7 @@ function createGenerateBundleHook(context) {
|
|
|
5525
5600
|
if (!hasUsableRememberedTailwindSource) {
|
|
5526
5601
|
const configuredTailwindV4CssSourceEntries = getConfiguredTailwindV4CssSourceEntries();
|
|
5527
5602
|
const isCurrentRootMiniProgramStyleOutput = opts.cssMatcher(outputFile) && isMiniProgramStyleOutputFile(outputFile) && !normalizeOutputPathKey(outputFile.replace(/[?#].*$/, "")).includes("/");
|
|
5528
|
-
const configuredEntriesForCurrentRootMiniProgramStyle = isCurrentRootMiniProgramStyleOutput && !hasTailwindGenerationSource(rawSource) ? configuredTailwindV4CssSourceEntries.filter((
|
|
5603
|
+
const configuredEntriesForCurrentRootMiniProgramStyle = isCurrentRootMiniProgramStyleOutput && !hasTailwindGenerationSource(rawSource) ? configuredTailwindV4CssSourceEntries.filter((entry2) => hasTailwindPluginDirective(entry2.source)) : configuredTailwindV4CssSourceEntries;
|
|
5529
5604
|
if (isCurrentRootMiniProgramStyleOutput && (hasTailwindGenerationSource(rawSource) || configuredEntriesForCurrentRootMiniProgramStyle.length > 0)) {
|
|
5530
5605
|
const configuredGenerationSource = selectTailwindV4GenerationCssSourceForOutput(outputFile, configuredEntriesForCurrentRootMiniProgramStyle, rawSource, {
|
|
5531
5606
|
cwd: opts.tailwindcssBasedir,
|
|
@@ -5551,14 +5626,14 @@ function createGenerateBundleHook(context) {
|
|
|
5551
5626
|
}
|
|
5552
5627
|
}
|
|
5553
5628
|
if (!hasUsableRememberedTailwindSource) {
|
|
5554
|
-
const inferredSourceStyle = resolveSourceStyleSourceFromOutputFile(outputFile, snapshot, outDir, sourceRoot, getCssSource, getSourceCandidateSources, configuredTailwindV4CssSourceEntries.map((
|
|
5629
|
+
const inferredSourceStyle = resolveSourceStyleSourceFromOutputFile(outputFile, snapshot, outDir, sourceRoot, getCssSource, getSourceCandidateSources, configuredTailwindV4CssSourceEntries.map((entry2) => [entry2.file, entry2.source]), debug);
|
|
5555
5630
|
const inferredWebviewRootSourceEntry = inferredSourceStyle ? void 0 : selectConfiguredRootCssSourceEntry(outputFile, configuredTailwindV4CssSourceEntries, originalSource.originalFileNames);
|
|
5556
5631
|
const inferredWebviewRootSourceStyle = inferredWebviewRootSourceEntry ? {
|
|
5557
5632
|
outputFile,
|
|
5558
5633
|
rawSource: inferredWebviewRootSourceEntry.source,
|
|
5559
5634
|
sourceFile: inferredWebviewRootSourceEntry.file
|
|
5560
5635
|
} : void 0;
|
|
5561
|
-
const inferredOriginalSourceStyle = inferredSourceStyle ?? (outputFile === file ? void 0 : resolveSourceStyleSourceFromOutputFile(file, snapshot, outDir, sourceRoot, getCssSource, getSourceCandidateSources, configuredTailwindV4CssSourceEntries.map((
|
|
5636
|
+
const inferredOriginalSourceStyle = inferredSourceStyle ?? (outputFile === file ? void 0 : resolveSourceStyleSourceFromOutputFile(file, snapshot, outDir, sourceRoot, getCssSource, getSourceCandidateSources, configuredTailwindV4CssSourceEntries.map((entry2) => [entry2.file, entry2.source]), debug)) ?? inferredWebviewRootSourceStyle;
|
|
5562
5637
|
if (inferredOriginalSourceStyle) {
|
|
5563
5638
|
const matchedOutputFile = normalizeOutputPathKey(inferredOriginalSourceStyle.outputFile) === normalizeOutputPathKey(outputFile) ? outputFile : resolveMatchedOutputFileForCurrentAsset(inferredOriginalSourceStyle.sourceFile) ?? outputFile;
|
|
5564
5639
|
debug("source style output resolved: %s -> %s from %s", outputFile, matchedOutputFile, inferredOriginalSourceStyle.sourceFile);
|
|
@@ -5589,7 +5664,7 @@ function createGenerateBundleHook(context) {
|
|
|
5589
5664
|
debug("source style source inferred from temporary configured tailwind v4 css source: %s -> %s", outputFile, resolvedTemporarySource.sourceFile);
|
|
5590
5665
|
}
|
|
5591
5666
|
} else if (!isCurrentRootMiniProgramStyleOutput && hasTailwindGenerationSource(rawSource) && (originalSource.originalFileNames?.length ?? 0) === 0) {
|
|
5592
|
-
const availableConfiguredTailwindV4CssSourceEntries = configuredTailwindV4CssSourceEntries.filter((
|
|
5667
|
+
const availableConfiguredTailwindV4CssSourceEntries = configuredTailwindV4CssSourceEntries.filter((entry2) => !usedConfiguredTailwindV4CssSourceFiles.has(normalizeOutputPathKey(entry2.file)));
|
|
5593
5668
|
const configuredGenerationSource = selectTailwindV4GenerationCssSourceForOutput(outputFile, availableConfiguredTailwindV4CssSourceEntries, rawSource, {
|
|
5594
5669
|
cwd: opts.tailwindcssBasedir,
|
|
5595
5670
|
outputRoot: outDir,
|
|
@@ -5631,11 +5706,11 @@ function createGenerateBundleHook(context) {
|
|
|
5631
5706
|
}
|
|
5632
5707
|
}
|
|
5633
5708
|
if (!isWebGeneratorTarget && isRootMiniProgramStyleOutputFile$1(rootImportShellOutputFile) && isRootMiniProgramStyleOutputFile$1(outputFile) && normalizeOutputPathKey(rootImportShellOutputFile) !== normalizeOutputPathKey(outputFile) && shouldKeepRootMiniProgramStyleAsImportShell(context.cssPipelineStrategy?.shouldKeepRootMiniProgramStyleAsImportShell?.({
|
|
5634
|
-
...
|
|
5709
|
+
...cssPipelineContext2,
|
|
5635
5710
|
css: rawSource,
|
|
5636
5711
|
file: rootImportShellOutputFile
|
|
5637
5712
|
})) && !shouldMoveRootMiniProgramStyleToImportShellOrigin(context.cssPipelineStrategy?.shouldMoveRootMiniProgramStyleToImportShellOrigin?.({
|
|
5638
|
-
...
|
|
5713
|
+
...cssPipelineContext2,
|
|
5639
5714
|
file: rootImportShellOutputFile
|
|
5640
5715
|
}))) {
|
|
5641
5716
|
frameworkRootImportShellTargetByFile.set(rootImportShellOutputFile, outputFile);
|
|
@@ -5669,7 +5744,7 @@ function createGenerateBundleHook(context) {
|
|
|
5669
5744
|
usedConfiguredTailwindV4CssSourceFiles.add(normalizeOutputPathKey(generatorSourceFile));
|
|
5670
5745
|
temporaryCssAssetSourceResolver.markUsed(generatorSourceFile);
|
|
5671
5746
|
}
|
|
5672
|
-
const
|
|
5747
|
+
const cssHandlerOptions2 = vitePipelineCssAsset ? {
|
|
5673
5748
|
...getCssHandlerOptions(generatorSourceFile),
|
|
5674
5749
|
isMainChunk: resolvedFromTemporaryCssAsset ? false : outputCssHandlerOptions.isMainChunk
|
|
5675
5750
|
} : getCssHandlerOptions(file);
|
|
@@ -5678,9 +5753,9 @@ function createGenerateBundleHook(context) {
|
|
|
5678
5753
|
const shouldUsePipelineSourceAsCssEntry = !isExplicitGeneratorCssEntry && vitePipelineCssAsset && opts.cssMatcher(generatorSourceFile) && hasTailwindGenerationSource(generatorRawSource);
|
|
5679
5754
|
const generatorCssEntries = isExplicitGeneratorCssEntry || shouldUsePipelineSourceAsCssEntry ? [generatorSourceFile] : opts.cssEntries;
|
|
5680
5755
|
const generatorCssHandlerOptions = {
|
|
5681
|
-
...
|
|
5756
|
+
...cssHandlerOptions2,
|
|
5682
5757
|
sourceOptions: {
|
|
5683
|
-
...
|
|
5758
|
+
...cssHandlerOptions2.sourceOptions ?? {},
|
|
5684
5759
|
sourceFile: generatorSourceFile,
|
|
5685
5760
|
cssEntries: generatorCssEntries
|
|
5686
5761
|
}
|
|
@@ -5709,7 +5784,7 @@ function createGenerateBundleHook(context) {
|
|
|
5709
5784
|
const vitePipelineCssInjectionOutputFile = webviewRootCssInjectionTarget ?? outputFile;
|
|
5710
5785
|
const shouldRecordVitePipelineCssByOutput = normalizeOutputPathKey(vitePipelineCssInjectionOutputFile) === normalizeOutputPathKey(outputFile);
|
|
5711
5786
|
const shouldInjectVitePipelineCssIntoMain = vitePipelineCssAsset && !resolvedFromConfiguredOriginalCssEntry && outputCssHandlerOptions.isMainChunk !== true && (webviewRootCssInjectionTarget != null || shouldInjectCssIntoMainFromOutput(outputFile, generatorSourceFile, outputCssHandlerOptions));
|
|
5712
|
-
const shouldTrackGeneratorRuntime = hasStaleViteProcessedCssSource || shouldRegenerateMainPackageCssWithScopedCandidates || hasCurrentTailwindGenerationDirective || hasSameOutputRememberedTailwindGenerationSource || shouldProcessTailwindGeneration && (!useIncrementalMode ||
|
|
5787
|
+
const shouldTrackGeneratorRuntime = hasStaleViteProcessedCssSource || shouldRegenerateMainPackageCssWithScopedCandidates || hasCurrentTailwindGenerationDirective || hasSameOutputRememberedTailwindGenerationSource || shouldProcessTailwindGeneration && (!useIncrementalMode || cssHandlerOptions2.isMainChunk || processFiles.css.has(file) || runtimeLinkedCssFiles.has(file) || runtimeLinkedCssFiles.has(outputFile) || shouldRegenerateCollectedViteCss || hasRuntimeAffectingChanges && (alreadyProcessedCssAsset || vitePipelineCssAsset));
|
|
5713
5788
|
const shouldPreserveCollectedViteCssAsset = !shouldRegenerateCollectedViteCss && (state.generatorCandidateSignature === void 0 || !generatorCandidatesChanged) && (collectedBundlerGeneratedCssFiles.has(file) || hasBundlerGeneratedCssMarker(rawSource));
|
|
5714
5789
|
const strippedViteProcessedCss = stripBundlerGeneratedCssMarkers(rawSource);
|
|
5715
5790
|
const shouldPreserveStaleGeneratedCssAsset = hasStaleViteProcessedCssSource && shouldPreserveCollectedViteCssAsset && strippedViteProcessedCss.trim().length > 0 && !strippedViteProcessedCss.includes("weapp-tailwindcss generator-placeholder") && !strippedViteProcessedCss.includes("vite-placeholder") && !hasTailwindGenerationSource(strippedViteProcessedCss) && !hasTailwindApplyDirective(strippedViteProcessedCss);
|
|
@@ -5742,7 +5817,7 @@ function createGenerateBundleHook(context) {
|
|
|
5742
5817
|
}) : trackedGeneratorCandidateSignature;
|
|
5743
5818
|
const cssRuntimeSignature = createCssRuntimeSignature(runtimeSignature, scopedGeneratorCandidateSignature);
|
|
5744
5819
|
const rememberedCssRuntimeSignature = createRememberedCssRuntimeSignature(cssRuntimeSignature, cssRuntimeAffectingHash);
|
|
5745
|
-
const cssSharedCacheKey = `${cssShareScope}:${cssRuntimeSignature}:${runtimeState.tailwindRuntime.majorVersion ?? "unknown"}:${
|
|
5820
|
+
const cssSharedCacheKey = `${cssShareScope}:${cssRuntimeSignature}:${runtimeState.tailwindRuntime.majorVersion ?? "unknown"}:${cssHandlerOptions2.isMainChunk ? "1" : "0"}:${cssRuntimeAffectingHash}:${scopedGeneratorCandidateSignature}:${sourceTraceSignature}`;
|
|
5746
5821
|
const cssCacheKey = outputFile;
|
|
5747
5822
|
const cssHashKey = `${outputFile}:css:${cssRuntimeSignature}:${runtimeState.tailwindRuntime.majorVersion ?? "unknown"}`;
|
|
5748
5823
|
const cssLinkedImpactSignature = runtimeLinkedCssFiles.has(file) || runtimeLinkedCssFiles.has(outputFile) ? [...[...snapshot.runtimeAffectingChangedByType.html].sort().map((changedFile) => snapshot.runtimeAffectingSignatureByFile.get(changedFile) ?? ""), ...[...snapshot.runtimeAffectingChangedByType.js].sort().map((changedFile) => snapshot.runtimeAffectingSignatureByFile.get(changedFile) ?? "")].join(":") : "";
|
|
@@ -5807,6 +5882,7 @@ function createGenerateBundleHook(context) {
|
|
|
5807
5882
|
cssUserHandlerOptions: generatorCssUserHandlerOptions,
|
|
5808
5883
|
getSourceCandidatesForEntries: scopedSourceCandidateGetter,
|
|
5809
5884
|
sourceCandidates: scopedGeneratorRuntime,
|
|
5885
|
+
frameworkPostcssStage: "complete",
|
|
5810
5886
|
generatorPlatform,
|
|
5811
5887
|
styleHandler,
|
|
5812
5888
|
debug,
|
|
@@ -5816,24 +5892,24 @@ function createGenerateBundleHook(context) {
|
|
|
5816
5892
|
}) : void 0;
|
|
5817
5893
|
if (generated) {
|
|
5818
5894
|
const outputCss = transformWebTargetCss(generated.css);
|
|
5819
|
-
const
|
|
5895
|
+
const tracedCss2 = removeRootCoveredCssFromScopedAsset(annotateCss(outputCss));
|
|
5820
5896
|
registerGeneratorDependencies$1({ addWatchFile }, generated.dependencies);
|
|
5821
|
-
if (envFlags.debugCssDiff) debug("css diff %s: %s", generatorSourceFile, summarizeStringDiff(generatorRawSource,
|
|
5822
|
-
debug("css generated result: %s bytes=%d", file,
|
|
5897
|
+
if (envFlags.debugCssDiff) debug("css diff %s: %s", generatorSourceFile, summarizeStringDiff(generatorRawSource, tracedCss2));
|
|
5898
|
+
debug("css generated result: %s bytes=%d", file, tracedCss2.length);
|
|
5823
5899
|
for (const candidate of generated.classSet ?? []) transformRuntime.add(candidate);
|
|
5824
|
-
recordCssAssetResult?.(outputFile,
|
|
5825
|
-
if (shouldRecordVitePipelineCssByOutput) recordViteProcessedCssAssetResult?.(vitePipelineCssInjectionOutputFile,
|
|
5900
|
+
recordCssAssetResult?.(outputFile, tracedCss2);
|
|
5901
|
+
if (shouldRecordVitePipelineCssByOutput) recordViteProcessedCssAssetResult?.(vitePipelineCssInjectionOutputFile, tracedCss2, {
|
|
5826
5902
|
injectIntoMain: outputCssHandlerOptions.isMainChunk ? false : shouldInjectVitePipelineCssIntoMain,
|
|
5827
5903
|
outputFile: vitePipelineCssInjectionOutputFile
|
|
5828
5904
|
});
|
|
5829
|
-
if (vitePipelineCssAsset && shouldInjectVitePipelineCssIntoMain) recordViteProcessedCssAssetResult?.(file,
|
|
5905
|
+
if (vitePipelineCssAsset && shouldInjectVitePipelineCssIntoMain) recordViteProcessedCssAssetResult?.(file, tracedCss2, {
|
|
5830
5906
|
injectIntoMain: shouldInjectVitePipelineCssIntoMain,
|
|
5831
5907
|
outputFile: vitePipelineCssInjectionOutputFile
|
|
5832
5908
|
});
|
|
5833
5909
|
metrics.css.elapsed += measureElapsed(start);
|
|
5834
5910
|
metrics.css.transformed++;
|
|
5835
5911
|
debug("css handle via tailwind v%s engine(%s): %s", runtimeState.tailwindRuntime.majorVersion, generated.target, outputFile);
|
|
5836
|
-
return
|
|
5912
|
+
return tracedCss2;
|
|
5837
5913
|
}
|
|
5838
5914
|
if (isWebGeneratorTarget) {
|
|
5839
5915
|
const outputCss = transformWebTargetCss(rawSource);
|
|
@@ -5843,15 +5919,15 @@ function createGenerateBundleHook(context) {
|
|
|
5843
5919
|
return annotateCss(outputCss);
|
|
5844
5920
|
}
|
|
5845
5921
|
if (isPureLocalCssImportWrapper(generatorTransformRawSource)) {
|
|
5846
|
-
const
|
|
5847
|
-
recordCssAssetResult?.(outputFile,
|
|
5922
|
+
const tracedCss2 = annotateCss(generatorTransformRawSource);
|
|
5923
|
+
recordCssAssetResult?.(outputFile, tracedCss2);
|
|
5848
5924
|
metrics.css.elapsed += measureElapsed(start);
|
|
5849
5925
|
metrics.css.transformed++;
|
|
5850
5926
|
debug("css preserve mini-program import shell: %s", outputFile);
|
|
5851
|
-
return
|
|
5927
|
+
return tracedCss2;
|
|
5852
5928
|
}
|
|
5853
|
-
const { css } = await styleHandler(generatorTransformRawSource,
|
|
5854
|
-
const tracedCss = annotateCss(
|
|
5929
|
+
const { css: css2 } = await styleHandler(generatorTransformRawSource, cssHandlerOptions2);
|
|
5930
|
+
const tracedCss = annotateCss(css2);
|
|
5855
5931
|
if (envFlags.debugCssDiff) debug("css diff %s: %s", generatorSourceFile, summarizeStringDiff(generatorTransformRawSource, tracedCss));
|
|
5856
5932
|
metrics.css.elapsed += measureElapsed(start);
|
|
5857
5933
|
metrics.css.transformed++;
|
|
@@ -5902,6 +5978,8 @@ function createGenerateBundleHook(context) {
|
|
|
5902
5978
|
useIncrementalMode
|
|
5903
5979
|
});
|
|
5904
5980
|
}
|
|
5981
|
+
recordTimingDetail("entries.plan", entryPlanningStartedAt);
|
|
5982
|
+
const rememberedCssStartedAt = performance.now();
|
|
5905
5983
|
if (processStyles && (shouldProcessTailwindGeneration || useIncrementalMode || isNativeAppStyleTarget)) await processRememberedCssReplay({
|
|
5906
5984
|
addWatchFile,
|
|
5907
5985
|
activeViteCssCacheFiles,
|
|
@@ -5947,6 +6025,7 @@ function createGenerateBundleHook(context) {
|
|
|
5947
6025
|
timeTask,
|
|
5948
6026
|
useIncrementalMode
|
|
5949
6027
|
});
|
|
6028
|
+
recordTimingDetail("rememberedCss.plan", rememberedCssStartedAt);
|
|
5950
6029
|
await finalizeGenerateBundle({
|
|
5951
6030
|
activeProcessCacheKeys,
|
|
5952
6031
|
activeProcessHashKeys,
|
|
@@ -6008,7 +6087,12 @@ function createGenerateBundleHook(context) {
|
|
|
6008
6087
|
};
|
|
6009
6088
|
}
|
|
6010
6089
|
//#endregion
|
|
6011
|
-
//#region src/bundlers/vite/
|
|
6090
|
+
//#region src/bundlers/vite/generate-bundle.ts
|
|
6091
|
+
function createGenerateBundleHook(context) {
|
|
6092
|
+
return createGenerateBundleHook$1(context);
|
|
6093
|
+
}
|
|
6094
|
+
//#endregion
|
|
6095
|
+
//#region src/bundlers/vite/css-finalizer/options.ts
|
|
6012
6096
|
function inferPlatformFromViteOutDir(outDir) {
|
|
6013
6097
|
const segment = outDir ? path.basename(path.normalize(outDir)) : void 0;
|
|
6014
6098
|
if (!segment) return;
|
|
@@ -6070,6 +6154,8 @@ function finalizeWebCss(css, context, cssPipelineStrategy) {
|
|
|
6070
6154
|
shouldApplyWebCssCompat
|
|
6071
6155
|
}) ?? (shouldApplyWebCssCompat ? defaultWebCssCompat(css) : css);
|
|
6072
6156
|
}
|
|
6157
|
+
//#endregion
|
|
6158
|
+
//#region src/bundlers/vite/css-finalizer/plugin.ts
|
|
6073
6159
|
function createViteCssFinalizerOutputPlugin(context) {
|
|
6074
6160
|
return {
|
|
6075
6161
|
name: "weapp-tailwindcss:adaptor:css-finalizer",
|
|
@@ -6184,6 +6270,7 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
6184
6270
|
...harmonyCssHandlerOptions,
|
|
6185
6271
|
isMainChunk: false
|
|
6186
6272
|
},
|
|
6273
|
+
frameworkPostcssStage: "complete",
|
|
6187
6274
|
getSourceCandidatesForEntries,
|
|
6188
6275
|
generatorPlatform,
|
|
6189
6276
|
styleHandler: opts.styleHandler,
|
|
@@ -6279,6 +6366,7 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
6279
6366
|
outputFile: file,
|
|
6280
6367
|
cssHandlerOptions: generatorCssHandlerOptions,
|
|
6281
6368
|
cssUserHandlerOptions: generatorCssUserHandlerOptions,
|
|
6369
|
+
frameworkPostcssStage: "complete",
|
|
6282
6370
|
getSourceCandidatesForEntries,
|
|
6283
6371
|
generatorPlatform,
|
|
6284
6372
|
styleHandler: opts.styleHandler,
|
|
@@ -6856,7 +6944,11 @@ function createRewriteCssImportsPlugins(options) {
|
|
|
6856
6944
|
if (hasTailwindRoot) await options.onTailwindRootCss?.(id, normalizedCode);
|
|
6857
6945
|
const shouldGenerateInPreTransform = !options.shouldDeferGeneration?.(id, normalizedCode) && (hasTailwindRoot || options.shouldGenerateCss?.(id, normalizedCode));
|
|
6858
6946
|
if (options.shouldOwnTailwindGeneration && shouldGenerateInPreTransform) {
|
|
6859
|
-
const generatedCss = await options.generateTailwindCss?.(id, normalizedCode,
|
|
6947
|
+
const generatedCss = await options.generateTailwindCss?.(id, normalizedCode, {
|
|
6948
|
+
...this.addWatchFile ? { addWatchFile: this.addWatchFile.bind(this) } : {},
|
|
6949
|
+
...this.emitFile ? { emitFile: this.emitFile.bind(this) } : {},
|
|
6950
|
+
frameworkPostcssStage: "pending"
|
|
6951
|
+
});
|
|
6860
6952
|
if (generatedCss !== void 0) return {
|
|
6861
6953
|
code: generatedCss,
|
|
6862
6954
|
map: null
|
|
@@ -7071,7 +7163,11 @@ function createViteCssGenerationPlugins(options) {
|
|
|
7071
7163
|
if (!hasTailwindRootDirectives(code)) return;
|
|
7072
7164
|
if (DEFERRED_CSS_HMR_QUERY_RE.test(id)) return;
|
|
7073
7165
|
await options.onTailwindRootCss?.(id, code);
|
|
7074
|
-
const generatedCss = await options.generateCss(id, code,
|
|
7166
|
+
const generatedCss = await options.generateCss(id, code, {
|
|
7167
|
+
...this.addWatchFile ? { addWatchFile: this.addWatchFile.bind(this) } : {},
|
|
7168
|
+
...this.emitFile ? { emitFile: this.emitFile.bind(this) } : {},
|
|
7169
|
+
frameworkPostcssStage: "pending"
|
|
7170
|
+
});
|
|
7075
7171
|
if (generatedCss === void 0 || generatedCss === code) return;
|
|
7076
7172
|
return {
|
|
7077
7173
|
code: generatedCss,
|
|
@@ -7087,7 +7183,11 @@ function createViteCssGenerationPlugins(options) {
|
|
|
7087
7183
|
if (!options.shouldGenerate() || options.shouldGenerateBuild?.() === false || !isViteBuildStyleRequest(id, options.getCommand())) return;
|
|
7088
7184
|
if (!hasViteCssGenerationDirective(code)) return;
|
|
7089
7185
|
if (hasViteServeCssRootDirective(code)) await options.onTailwindRootCss?.(id, code);
|
|
7090
|
-
const generatedCss = await options.generateCss(id, code,
|
|
7186
|
+
const generatedCss = await options.generateCss(id, code, {
|
|
7187
|
+
...this.addWatchFile ? { addWatchFile: this.addWatchFile.bind(this) } : {},
|
|
7188
|
+
...this.emitFile ? { emitFile: this.emitFile.bind(this) } : {},
|
|
7189
|
+
frameworkPostcssStage: "pending"
|
|
7190
|
+
});
|
|
7091
7191
|
if (generatedCss === void 0 || generatedCss === code) return;
|
|
7092
7192
|
return {
|
|
7093
7193
|
code: generatedCss,
|
|
@@ -7105,7 +7205,11 @@ function createViteCssGenerationPlugins(options) {
|
|
|
7105
7205
|
if (!extracted) return;
|
|
7106
7206
|
if (!hasViteCssGenerationDirective(extracted.css)) return;
|
|
7107
7207
|
if (hasViteServeCssRootDirective(extracted.css)) await options.onTailwindRootCss?.(id, extracted.css);
|
|
7108
|
-
const generatedCss = await options.generateCss(id, extracted.css,
|
|
7208
|
+
const generatedCss = await options.generateCss(id, extracted.css, {
|
|
7209
|
+
...this.addWatchFile ? { addWatchFile: this.addWatchFile.bind(this) } : {},
|
|
7210
|
+
...this.emitFile ? { emitFile: this.emitFile.bind(this) } : {},
|
|
7211
|
+
frameworkPostcssStage: "complete"
|
|
7212
|
+
});
|
|
7109
7213
|
if (generatedCss === void 0 || generatedCss === extracted.css) return;
|
|
7110
7214
|
const nextCode = replaceViteCssHmrModuleCss(code, generatedCss);
|
|
7111
7215
|
if (nextCode === void 0 || nextCode === code) return;
|
|
@@ -7214,7 +7318,7 @@ function wrapViteCssPostTransform(config, transformCss) {
|
|
|
7214
7318
|
return true;
|
|
7215
7319
|
}
|
|
7216
7320
|
//#endregion
|
|
7217
|
-
//#region src/bundlers/vite/shared/create-framework-plugins.ts
|
|
7321
|
+
//#region src/bundlers/vite/shared/create-framework-plugins-runtime.ts
|
|
7218
7322
|
const debug = createDebug();
|
|
7219
7323
|
const weappTailwindcssPackageDir = resolvePackageDir("weapp-tailwindcss");
|
|
7220
7324
|
const weappTailwindcssDirPosix = slash(weappTailwindcssPackageDir);
|
|
@@ -7257,10 +7361,7 @@ function isWebOrNativeAppPlatform(platform) {
|
|
|
7257
7361
|
function isInternalUserDefinedOptions(options) {
|
|
7258
7362
|
return typeof options.onLoad === "function" && typeof options.mainCssChunkMatcher === "function" && typeof options.tailwindRuntime === "object" && typeof options.refreshTailwindcssRuntime === "function";
|
|
7259
7363
|
}
|
|
7260
|
-
|
|
7261
|
-
* Vite 各框架分支共享的组合工厂。框架分支只负责选择和拥有各自入口,公共稳定能力放在这里复用。
|
|
7262
|
-
*/
|
|
7263
|
-
function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
7364
|
+
function createViteFrameworkPlugins$1(options = {}, frameworkBranch) {
|
|
7264
7365
|
debug("create vite framework plugins framework=%s", frameworkBranch.frameworkName);
|
|
7265
7366
|
const rawOptions = options.__internalViteRawOptions ?? options;
|
|
7266
7367
|
const hasExplicitAppType = typeof options.__internalViteRawExplicitAppType === "boolean" ? options.__internalViteRawExplicitAppType : typeof options.appType === "string" && options.appType.trim().length > 0;
|
|
@@ -7356,7 +7457,7 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7356
7457
|
await sourceCandidateCollector.syncCss(id, css);
|
|
7357
7458
|
cacheCurrentSourceCandidateScan();
|
|
7358
7459
|
};
|
|
7359
|
-
const registerAutoCssSource = async (id, css,
|
|
7460
|
+
const registerAutoCssSource = async (id, css, options2 = {}) => {
|
|
7360
7461
|
if (!shouldOwnTailwindGeneration) return;
|
|
7361
7462
|
const file = cleanUrl(id);
|
|
7362
7463
|
if (!path.isAbsolute(file)) return;
|
|
@@ -7390,7 +7491,7 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7390
7491
|
})) return;
|
|
7391
7492
|
invalidateSourceCandidateScan();
|
|
7392
7493
|
debug("detected tailwindcss v4 css source from vite css module: %s", sourceFile);
|
|
7393
|
-
if (
|
|
7494
|
+
if (options2.refresh === false) return;
|
|
7394
7495
|
autoCssSourcesRefresh = (autoCssSourcesRefresh ?? Promise.resolve()).then(async () => {
|
|
7395
7496
|
await refreshRuntimeStateForAutoCssSources?.(true);
|
|
7396
7497
|
await syncSourceCandidateScan({ force: true });
|
|
@@ -7496,8 +7597,8 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7496
7597
|
recordedGeneratorCandidates = void 0;
|
|
7497
7598
|
};
|
|
7498
7599
|
const getSourceCandidates = () => sourceCandidateCollector.values();
|
|
7499
|
-
const getSourceCandidatesForEntries = (entries,
|
|
7500
|
-
const getSourceCandidateSourcesForEntries = (entries,
|
|
7600
|
+
const getSourceCandidatesForEntries = (entries, options2) => sourceCandidateCollector.valuesForEntries(entries, options2);
|
|
7601
|
+
const getSourceCandidateSourcesForEntries = (entries, options2) => sourceCandidateCollector.sourcesForEntries(entries, options2);
|
|
7501
7602
|
const isWatchBuild = () => resolvedConfig?.command === "build" && resolvedConfig.build.watch != null;
|
|
7502
7603
|
const isWatchLikeBuild = () => isWatchBuild() || resolvedConfig?.command === "serve" || process$1.env["WEAPP_TW_WATCH_REGRESSION"] === "1" || process$1.env["WEAPP_TW_HMR_TIMING"] === "1";
|
|
7503
7604
|
const isCurrentWebLikeStylePlatform = () => {
|
|
@@ -7537,10 +7638,10 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7537
7638
|
}
|
|
7538
7639
|
pendingHmrCssTargetFiles = collectPendingHmrCssTargetFiles(cssModules, fallbackCssIds);
|
|
7539
7640
|
};
|
|
7540
|
-
const createViteSourceCandidateChange = (file, change,
|
|
7641
|
+
const createViteSourceCandidateChange = (file, change, options2 = {}) => ({
|
|
7541
7642
|
...change,
|
|
7542
7643
|
file,
|
|
7543
|
-
runtimeAffecting:
|
|
7644
|
+
runtimeAffecting: options2.runtimeAffecting === true || isSourceStyleRequest(file) || hasWebHmrRuntimeAffectingDirectives(sourceCandidateCollector.source(file))
|
|
7544
7645
|
});
|
|
7545
7646
|
const clearPendingHmrCandidateChange = () => {
|
|
7546
7647
|
pendingHmrCandidateChange = void 0;
|
|
@@ -7643,8 +7744,9 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7643
7744
|
};
|
|
7644
7745
|
const cacheCurrentSourceCandidateScan = () => {
|
|
7645
7746
|
if (sourceCandidateScanSignature) {
|
|
7646
|
-
|
|
7647
|
-
|
|
7747
|
+
const snapshot = sourceCandidateCollector.snapshot();
|
|
7748
|
+
sourceCandidateScanCache.set(sourceCandidateScanSignature, snapshot);
|
|
7749
|
+
sourceCandidateScanSnapshotCache.set(sourceCandidateScanSignature, snapshot);
|
|
7648
7750
|
}
|
|
7649
7751
|
};
|
|
7650
7752
|
const shouldDiscoverAutoCssSources = () => {
|
|
@@ -7652,9 +7754,9 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7652
7754
|
if (!isWatchLikeBuild()) return true;
|
|
7653
7755
|
return sourceCandidateScanInvalidated;
|
|
7654
7756
|
};
|
|
7655
|
-
async function syncSourceCandidateScan(
|
|
7757
|
+
async function syncSourceCandidateScan(options2 = {}) {
|
|
7656
7758
|
if (!shouldOwnTailwindGeneration) return;
|
|
7657
|
-
if (!
|
|
7759
|
+
if (!options2.force && isWatchLikeBuild() && hasSourceCandidateScanState() && !sourceCandidateScanInvalidated) {
|
|
7658
7760
|
debug("reuse vite source candidate scan definition for watch rebuild");
|
|
7659
7761
|
return;
|
|
7660
7762
|
}
|
|
@@ -7697,8 +7799,9 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7697
7799
|
sourceCandidateScanSignature = nextScanSignature;
|
|
7698
7800
|
sourceCandidateScanInvalidated = false;
|
|
7699
7801
|
if (isWatchLikeBuild()) {
|
|
7700
|
-
|
|
7701
|
-
|
|
7802
|
+
const snapshot = sourceCandidateCollector.snapshot();
|
|
7803
|
+
sourceCandidateScanCache.set(nextScanSignature, snapshot);
|
|
7804
|
+
sourceCandidateScanSnapshotCache.set(nextScanSignature, snapshot);
|
|
7702
7805
|
}
|
|
7703
7806
|
}
|
|
7704
7807
|
const waitForSourceCandidateSyncs = async () => {
|
|
@@ -7740,14 +7843,14 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7740
7843
|
const recordCssAssetResult = (file, css) => {
|
|
7741
7844
|
touchMapEntry(cleanGeneratedCssByFile, normalizeVitePersistentCacheKey(file), css);
|
|
7742
7845
|
};
|
|
7743
|
-
const recordViteProcessedCssAssetResult = (file, css,
|
|
7846
|
+
const recordViteProcessedCssAssetResult = (file, css, options2 = {}) => {
|
|
7744
7847
|
const key = normalizeVitePersistentCacheKey(file);
|
|
7745
7848
|
const previous = viteProcessedCssAssetResults.get(key);
|
|
7746
|
-
const injectIntoMain = previous?.injectIntoMain === true ? true :
|
|
7849
|
+
const injectIntoMain = previous?.injectIntoMain === true ? true : options2.injectIntoMain ?? previous?.injectIntoMain;
|
|
7747
7850
|
touchMapEntry(viteProcessedCssAssetResults, key, {
|
|
7748
7851
|
css,
|
|
7749
7852
|
injectIntoMain,
|
|
7750
|
-
outputFile:
|
|
7853
|
+
outputFile: options2.outputFile ?? previous?.outputFile
|
|
7751
7854
|
});
|
|
7752
7855
|
};
|
|
7753
7856
|
const getViteProcessedCssAssetResults = () => viteProcessedCssAssetResults.entries();
|
|
@@ -7765,8 +7868,8 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7765
7868
|
pendingSourceCandidateSyncs: pendingSourceCandidateSyncs.size,
|
|
7766
7869
|
pendingSourceCandidateSyncByFile: pendingSourceCandidateSyncByFile.size
|
|
7767
7870
|
});
|
|
7768
|
-
const pruneViteCssCaches = (
|
|
7769
|
-
const activeFiles = new Set([...
|
|
7871
|
+
const pruneViteCssCaches = (options2) => {
|
|
7872
|
+
const activeFiles = new Set([...options2.activeFiles].map(normalizeVitePersistentCacheKey));
|
|
7770
7873
|
for (const key of cleanGeneratedCssByFile.keys()) if (!activeFiles.has(key)) cleanGeneratedCssByFile.delete(key);
|
|
7771
7874
|
for (const key of tracedGeneratedCssByFile.keys()) if (!activeFiles.has(key)) tracedGeneratedCssByFile.delete(key);
|
|
7772
7875
|
for (const key of generatedClassSetByFile.keys()) if (!activeFiles.has(key)) generatedClassSetByFile.delete(key);
|
|
@@ -7774,7 +7877,7 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7774
7877
|
const outputKey = typeof record.outputFile === "string" ? normalizeVitePersistentCacheKey(record.outputFile) : void 0;
|
|
7775
7878
|
if (!activeFiles.has(key) && (outputKey == null || !activeFiles.has(outputKey))) viteProcessedCssAssetResults.delete(key);
|
|
7776
7879
|
}
|
|
7777
|
-
cssMemory.prune(
|
|
7880
|
+
cssMemory.prune(options2);
|
|
7778
7881
|
};
|
|
7779
7882
|
const normalizeViteProcessedCssFile = (file) => path.resolve(cleanUrl(file));
|
|
7780
7883
|
const markViteProcessedCssSource = (file) => {
|
|
@@ -7890,7 +7993,8 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7890
7993
|
const previousTracedCss = tracedGeneratedCssByFile.get(fileKey);
|
|
7891
7994
|
if (previousTracedCss !== void 0) {
|
|
7892
7995
|
finishPendingHmrCssTargetFile(file);
|
|
7893
|
-
return `${createBundlerGeneratedCssMarker("vite", normalizeViteProcessedCssFile(file))}
|
|
7996
|
+
return `${createBundlerGeneratedCssMarker("vite", normalizeViteProcessedCssFile(file))}
|
|
7997
|
+
${previousTracedCss}`;
|
|
7894
7998
|
}
|
|
7895
7999
|
}
|
|
7896
8000
|
const sourceCssHandlerOptions = transformCssHandlerOptions.getCssHandlerOptions(requestFile);
|
|
@@ -7930,6 +8034,7 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7930
8034
|
deferEmptyScopedCssSource: shouldDeferEmptyScopedCssSource,
|
|
7931
8035
|
deferCssAdaptation: !currentGeneratorBranch.isWeb && !shouldAdaptFrameworkWatchCss(),
|
|
7932
8036
|
disableSourceScan: false,
|
|
8037
|
+
frameworkPostcssStage: hookContext?.frameworkPostcssStage,
|
|
7933
8038
|
restoreLocalCssImports: !currentGeneratorBranch.isWeb
|
|
7934
8039
|
}), {
|
|
7935
8040
|
file,
|
|
@@ -7989,7 +8094,8 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
7989
8094
|
sourceFile: requestFile
|
|
7990
8095
|
});
|
|
7991
8096
|
debug("css generated for vite postcss pipeline: %s bytes=%d", requestFile, tracedCss.length);
|
|
7992
|
-
return `${createBundlerGeneratedCssMarker("vite", normalizeViteProcessedCssFile(file))}
|
|
8097
|
+
return `${createBundlerGeneratedCssMarker("vite", normalizeViteProcessedCssFile(file))}
|
|
8098
|
+
${tracedCss}`;
|
|
7993
8099
|
};
|
|
7994
8100
|
const rewritePlugins = createRewriteCssImportsPlugins({
|
|
7995
8101
|
getAppType: () => opts.appType,
|
|
@@ -8277,14 +8383,16 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
8277
8383
|
replacement: path.join(weappTailwindcssPackageDir, "generator-placeholder.css")
|
|
8278
8384
|
}] } };
|
|
8279
8385
|
if (config.css?.postcss !== void 0) return baseConfig;
|
|
8280
|
-
return
|
|
8386
|
+
return resolvePostcssConfig(root).then((postcssConfig) => {
|
|
8281
8387
|
if (!postcssConfig) return baseConfig;
|
|
8282
|
-
|
|
8388
|
+
const plugins2 = [...postcssConfig.plugins];
|
|
8389
|
+
const removed = removeTailwindPostcssPlugins(plugins2);
|
|
8390
|
+
if (removed > 0) debug("inline filtered postcss config without official tailwind plugins in generator mode: %d", removed);
|
|
8283
8391
|
return {
|
|
8284
8392
|
...baseConfig,
|
|
8285
8393
|
css: { postcss: {
|
|
8286
8394
|
...postcssConfig.options,
|
|
8287
|
-
plugins:
|
|
8395
|
+
plugins: plugins2
|
|
8288
8396
|
} }
|
|
8289
8397
|
};
|
|
8290
8398
|
});
|
|
@@ -8329,6 +8437,7 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
8329
8437
|
}
|
|
8330
8438
|
}
|
|
8331
8439
|
}
|
|
8440
|
+
captureFrameworkPostcssOptions(opts, config.css?.postcss && typeof config.css.postcss === "object" ? config.css.postcss : void 0);
|
|
8332
8441
|
}, { emit: false });
|
|
8333
8442
|
},
|
|
8334
8443
|
generateBundle: {
|
|
@@ -8343,6 +8452,11 @@ function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
|
8343
8452
|
return plugins;
|
|
8344
8453
|
}
|
|
8345
8454
|
//#endregion
|
|
8455
|
+
//#region src/bundlers/vite/shared/create-framework-plugins.ts
|
|
8456
|
+
function createViteFrameworkPlugins(options = {}, frameworkBranch) {
|
|
8457
|
+
return createViteFrameworkPlugins$1(options, frameworkBranch);
|
|
8458
|
+
}
|
|
8459
|
+
//#endregion
|
|
8346
8460
|
//#region src/bundlers/vite/frameworks/generic/index.ts
|
|
8347
8461
|
function createGenericVitePlugins(options = {}) {
|
|
8348
8462
|
return createViteFrameworkPlugins(options, {
|