weapp-tailwindcss 5.0.13 → 5.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.en.md +1 -1
- package/README.md +1 -1
- package/dist/auto-Ba6hDrse.mjs +13 -0
- package/dist/auto-DtU6f3X6.js +18 -0
- package/dist/bundlers/shared/css-cleanup.d.ts +1 -1
- package/dist/bundlers/shared/generator-css/class-selectors.d.ts +2 -0
- package/dist/bundlers/shared/generator-css/directives.d.ts +2 -1
- package/dist/bundlers/shared/generator-css/generation-helpers.d.ts +10 -6
- package/dist/bundlers/shared/generator-css/local-imports.d.ts +3 -0
- package/dist/bundlers/shared/generator-css/source-resolver/apply-reference.d.ts +3 -0
- package/dist/bundlers/shared/generator-css/source-resolver/matching.d.ts +0 -1
- package/dist/bundlers/shared/generator-css/source-resolver/metadata.d.ts +1 -1
- package/dist/bundlers/shared/generator-css/source-resolver/types.d.ts +3 -3
- package/dist/bundlers/shared/generator-css/source-resolver.d.ts +2 -2
- package/dist/bundlers/shared/generator-css/types.d.ts +13 -1
- package/dist/bundlers/shared/generator-css/user-css.d.ts +5 -1
- package/dist/bundlers/shared/generator-css/validate.d.ts +1 -0
- package/dist/bundlers/shared/run-tasks.d.ts +1 -0
- package/dist/bundlers/shared/v4-generation-core.d.ts +11 -0
- package/dist/bundlers/vite/css-finalizer.d.ts +1 -1
- package/dist/bundlers/vite/css-memory.d.ts +16 -0
- package/dist/bundlers/vite/generate-bundle/candidates.d.ts +0 -1
- package/dist/bundlers/vite/generate-bundle/configured-css-sources.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/css-assets.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/css-output-helpers.d.ts +39 -0
- package/dist/bundlers/vite/generate-bundle/css-output.d.ts +1 -0
- package/dist/bundlers/vite/generate-bundle/env-flags.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/final-css-assets.d.ts +13 -0
- package/dist/bundlers/vite/generate-bundle/finalize.d.ts +7 -0
- package/dist/bundlers/vite/generate-bundle/html-processing.d.ts +26 -0
- package/dist/bundlers/vite/generate-bundle/js-processing.d.ts +4 -0
- package/dist/bundlers/vite/generate-bundle/memory-debug.d.ts +21 -18
- package/dist/bundlers/vite/generate-bundle/remembered-css-replay.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/remembered-css.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle/root-style-output.d.ts +6 -0
- package/dist/bundlers/vite/generate-bundle/runtime-linked-source-memory.d.ts +25 -0
- package/dist/bundlers/vite/generate-bundle/sfc-style-source.d.ts +3 -1
- package/dist/bundlers/vite/generate-bundle/source-candidate-scope.d.ts +1 -0
- package/dist/bundlers/vite/generate-bundle/source-candidate-source.d.ts +9 -0
- package/dist/bundlers/vite/generate-bundle/tailwind-v4-css-source.d.ts +9 -0
- package/dist/bundlers/vite/generate-bundle/transform-filter.d.ts +15 -0
- package/dist/bundlers/vite/generate-bundle/types.d.ts +2 -1
- package/dist/bundlers/vite/generate-bundle/vite-css-cache.d.ts +1 -1
- package/dist/bundlers/vite/generate-bundle.d.ts +2 -1
- package/dist/bundlers/vite/incremental-runtime-class-set/escaped-candidates.d.ts +1 -0
- package/dist/bundlers/vite/incremental-runtime-class-set.d.ts +3 -3
- package/dist/bundlers/vite/plugin-cache.d.ts +15 -0
- package/dist/bundlers/vite/rewrite-css-imports.d.ts +1 -0
- package/dist/bundlers/vite/runtime-class-set.d.ts +5 -4
- package/dist/bundlers/vite/source-candidates/script.d.ts +1 -7
- package/dist/bundlers/vite/source-candidates.d.ts +9 -2
- package/dist/bundlers/vite/source-scan/css-entries.d.ts +2 -6
- package/dist/bundlers/vite/source-scan.d.ts +2 -2
- package/dist/bundlers/vite/uni-app-x-css-options.d.ts +1 -1
- package/dist/bundlers/vite/utils.d.ts +1 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +26 -2
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/css-source-resolvers.d.ts +34 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/helpers.d.ts +48 -11
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/js-module-graph.d.ts +37 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/pipeline-helpers.d.ts +199 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/source-candidate-cache.d.ts +28 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/source-candidate-refresh.d.ts +11 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets.d.ts +1 -0
- package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +4 -2
- package/dist/bundlers/webpack/loaders/runtime-registry.d.ts +10 -1
- package/dist/bundlers/webpack/shared/css-loader-runtime.d.ts +1 -0
- package/dist/cache/index.d.ts +1 -0
- package/dist/cli/mount-options.d.ts +2 -2
- package/dist/cli.js +138 -444
- package/dist/cli.mjs +134 -440
- package/dist/context/index.d.ts +3 -3
- package/dist/context/style-options.d.ts +5 -1
- package/dist/context/tailwindcss.d.ts +1 -1
- package/dist/{precheck-B0Z8yW7E.js → context-B6hVF7dr.js} +405 -156
- package/dist/{precheck-CRI90iL1.mjs → context-DlpKD7aN.mjs} +377 -141
- package/dist/core.js +15 -12
- package/dist/core.mjs +10 -7
- package/dist/css-macro/index.d.ts +3 -7
- package/dist/css-macro.js +1 -1
- package/dist/css-macro.mjs +1 -1
- package/dist/{defaults-Bqx18S1f.mjs → defaults-BhE26nSw.mjs} +12 -13
- package/dist/{defaults-C_J_kBpw.js → defaults-CmFBmxsr.js} +11 -18
- package/dist/defaults.d.ts +2 -8
- package/dist/defaults.js +1 -2
- package/dist/defaults.mjs +2 -2
- package/dist/generator/index.d.ts +6 -7
- package/dist/generator/options.d.ts +3 -3
- package/dist/generator/types.d.ts +9 -10
- package/dist/generator-6oMJtTDO.js +170 -0
- package/dist/generator-CjzBK7h-.mjs +123 -0
- package/dist/generator.js +10 -16
- package/dist/generator.mjs +3 -3
- package/dist/{gulp-XT8Jc7lH.js → gulp-BtGq6LP9.js} +49 -87
- package/dist/{gulp-DfOQERcV.mjs → gulp-DNU10Vtc.mjs} +42 -80
- package/dist/gulp.js +1 -1
- package/dist/gulp.mjs +1 -1
- package/dist/{hmr-timing-DQIP_8qP.mjs → hmr-timing-B0KuWDjV.mjs} +1197 -858
- package/dist/{hmr-timing-BMftW7Us.js → hmr-timing-CegXR9O4.js} +1356 -927
- package/dist/index.js +4 -4
- package/dist/index.mjs +4 -4
- package/dist/js/fast-path/oxc.d.ts +4 -0
- package/dist/js/precheck.d.ts +1 -0
- package/dist/postcss.js +3 -4
- package/dist/postcss.mjs +2 -3
- package/dist/presets.js +9 -19
- package/dist/presets.mjs +8 -18
- package/dist/runtime-branch/create-branch.d.ts +2 -0
- package/dist/runtime-branch/generator-target-env.d.ts +4 -0
- package/dist/runtime-branch/index.d.ts +6 -0
- package/dist/runtime-branch/mini-program.d.ts +2 -0
- package/dist/runtime-branch/native-app.d.ts +2 -0
- package/dist/runtime-branch/platform.d.ts +6 -0
- package/dist/runtime-branch/tailwind-version.d.ts +2 -0
- package/dist/runtime-branch/types.d.ts +37 -0
- package/dist/runtime-branch/web.d.ts +2 -0
- package/dist/runtime-branch.d.ts +1 -0
- package/dist/{bundle-state-zQ2MrDdi.mjs → source-candidate-scan-signature-B5af2Ahe.mjs} +187 -17
- package/dist/{bundle-state-CKWeTEhv.js → source-candidate-scan-signature-BKYb9jxa.js} +261 -19
- package/dist/tailwindcss/candidates.d.ts +7 -0
- package/dist/tailwindcss/index.d.ts +2 -2
- package/dist/tailwindcss/runtime/cache.d.ts +6 -6
- package/dist/tailwindcss/runtime-factory.d.ts +12 -0
- package/dist/tailwindcss/runtime-options.d.ts +8 -0
- package/dist/tailwindcss/runtime-types.d.ts +87 -0
- package/dist/tailwindcss/runtime.d.ts +6 -6
- package/dist/tailwindcss/source-scan.d.ts +1 -1
- package/dist/tailwindcss/targets.d.ts +2 -2
- package/dist/tailwindcss/v4/config.d.ts +3 -3
- package/dist/tailwindcss/v4/css-entries.d.ts +1 -0
- package/dist/tailwindcss/v4/css-sources.d.ts +4 -2
- package/dist/tailwindcss/v4/index.d.ts +1 -1
- package/dist/tailwindcss/v4/multi-runtime.d.ts +2 -0
- package/dist/tailwindcss/v4/runtime-factory.d.ts +15 -0
- package/dist/tailwindcss/v4/runtime-options.d.ts +2 -0
- package/dist/tailwindcss/v4-engine/design-system.d.ts +1 -1
- package/dist/tailwindcss/v4-engine/generator/css-compat.d.ts +1 -1
- package/dist/tailwindcss/v4-engine/generator/rpx-candidates.d.ts +3 -3
- package/dist/tailwindcss/v4-engine/generator/scan-sources.d.ts +1 -1
- package/dist/tailwindcss/v4-engine/generator.d.ts +10 -3
- package/dist/tailwindcss/v4-engine/index.d.ts +1 -1
- package/dist/tailwindcss/v4-engine/miniprogram.d.ts +7 -1
- package/dist/tailwindcss/v4-engine/source.d.ts +15 -7
- package/dist/tailwindcss/v4-engine/types.d.ts +17 -10
- package/dist/tailwindcss/version.d.ts +1 -1
- package/dist/tailwindcss-B5mRo0-M.mjs +1423 -0
- package/dist/tailwindcss-dbrbY4cd.js +1528 -0
- package/dist/{transform-DfcEjsZF.mjs → transform-fRBeuuK-.mjs} +2 -2
- package/dist/{transform-YmrmxuF3.js → transform-vLwZpiTE.js} +17 -17
- package/dist/typedoc.export.d.ts +1 -1
- package/dist/types/index.d.ts +16 -17
- package/dist/types/shared.d.ts +1 -1
- package/dist/types/{typedoc-tailwindcss-patch.d.ts → typedoc-tailwindcss-runtime.d.ts} +4 -10
- package/dist/types/user-defined-options/general.d.ts +5 -3
- package/dist/types/user-defined-options/important.d.ts +2 -2
- package/dist/types/user-defined-options/matcher.d.ts +7 -0
- package/dist/uni-app-x/style-asset.d.ts +1 -0
- package/dist/v4-engine-C3qSwQ-e.mjs +2376 -0
- package/dist/v4-engine-ON_oSLfO.js +2752 -0
- package/dist/{vite-DjI09vVN.mjs → vite-CWRooooa.mjs} +1417 -540
- package/dist/{vite-CXHVsHmX.js → vite-w-RkgaTY.js} +1575 -698
- package/dist/vite.js +1 -1
- package/dist/vite.mjs +1 -1
- package/dist/weapp-tw-css-import-rewrite-loader.js +5665 -4443
- package/dist/weapp-tw-runtime-classset-loader.js +15 -4
- package/dist/webpack-8PaV1gG3.mjs +2334 -0
- package/dist/webpack-CGgBOx9l.js +2346 -0
- package/dist/webpack.js +1 -1
- package/dist/webpack.mjs +1 -1
- package/package.json +6 -7
- package/dist/auto-CTp6wE5a.js +0 -33
- package/dist/auto-Cl8_hsG6.mjs +0 -22
- package/dist/bundlers/vite/incremental-runtime-class-set/v3-candidates.d.ts +0 -13
- package/dist/bundlers/vite/source-candidates/tailwind-v3-default-extractor.d.ts +0 -1
- package/dist/context/tailwindcss/rax.d.ts +0 -2
- package/dist/generator-CzpArpCL.js +0 -92
- package/dist/generator-ITLd7PTl.mjs +0 -67
- package/dist/tailwindcss/patcher-options.d.ts +0 -8
- package/dist/tailwindcss/patcher.d.ts +0 -12
- package/dist/tailwindcss/runtime-patch.d.ts +0 -5
- package/dist/tailwindcss/v3-engine/generator/cache-key.d.ts +0 -3
- package/dist/tailwindcss/v3-engine/generator/content.d.ts +0 -10
- package/dist/tailwindcss/v3-engine/generator/runtime-ready.d.ts +0 -2
- package/dist/tailwindcss/v3-engine/generator.d.ts +0 -19
- package/dist/tailwindcss/v3-engine/index.d.ts +0 -4
- package/dist/tailwindcss/v3-engine/miniprogram.d.ts +0 -4
- package/dist/tailwindcss/v3-engine/source.d.ts +0 -5
- package/dist/tailwindcss/v3-engine/types.d.ts +0 -61
- package/dist/tailwindcss/v4/multi-patcher.d.ts +0 -2
- package/dist/tailwindcss/v4/patcher-options.d.ts +0 -2
- package/dist/tailwindcss/v4/patcher.d.ts +0 -15
- package/dist/tailwindcss/v4-engine/tailwind-v3-compatibility.d.ts +0 -1
- package/dist/tailwindcss/v4-engine/tailwind-v3-default-colors.d.ts +0 -1
- package/dist/tailwindcss-DTq3uYBK.mjs +0 -556
- package/dist/tailwindcss-DZEwT3C_.js +0 -613
- package/dist/v3-engine-2rrgylhn.js +0 -4686
- package/dist/v3-engine-C6eJ0YzK.mjs +0 -4272
- package/dist/webpack-BcPpnT90.mjs +0 -1184
- package/dist/webpack-CfkUkMXG.js +0 -1196
- /package/dist/tailwindcss/{patcher-resolve.d.ts → runtime-resolve.d.ts} +0 -0
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { resolveImplicitAppTypeFromViteRoot } from "./framework.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import { i as normalizeWeappTailwindcssGeneratorOptions } from "./generator-
|
|
4
|
-
import { _ as collectRuntimeClassSet, a as vitePluginName, b as refreshTailwindRuntimeState, g as toCustomAttributesEntities, n as getCompilerContext, p as replaceWxml, t as shouldSkipJsTransform, v as createTailwindRuntimeReadyPromise } from "./precheck-CRI90iL1.mjs";
|
|
2
|
+
import { C as hasTailwindRootDirectives, D as normalizeTailwindSourceForGenerator, F as hasTailwindGeneratedCssMarkers, G as getTailwindV4IncrementalGenerateCacheStats, O as parseImportRequest, S as hasTailwindNonRootGenerationDirectives, T as normalizeTailwindConfigDirectives, _ as resolveTailwindcssOptions, a as filterTailwindV4CssSourceRoots, b as hasLocalCssImport, d as normalizeCssEntries, f as findNearestPackageRoot, k as removeTailwindSourceDirectives, o as hasConfiguredTailwindV4CssRoots, ot as filterUnsupportedMiniProgramTailwindV4Candidates, rt as resolveTailwindV4CssSourceBase, s as upsertTailwindV4CssSource, st as omitUndefined, u as isTailwindV4CssEntry, w as hasTailwindSourceDirectives, x as hasTailwindApplyDirective } from "./v4-engine-C3qSwQ-e.mjs";
|
|
3
|
+
import { a as resolveGeneratorRuntimeBranch, c as shouldUseNativeAppCssBranch, i as normalizeWeappTailwindcssGeneratorOptions, s as shouldUseMiniProgramCssBranch } from "./generator-CjzBK7h-.mjs";
|
|
5
4
|
import { o as resolveUniUtsPlatform } from "./utils-DodxWHGz.mjs";
|
|
6
|
-
import {
|
|
7
|
-
import { _ as
|
|
8
|
-
import {
|
|
5
|
+
import { S as createDebug, _ as toCustomAttributesEntities, a as vitePluginName, l as shouldSkipJsTransform, m as replaceWxml, n as normalizeStyleHandlerMajorVersion, t as getCompilerContext, v as collectRuntimeClassSet, x as refreshTailwindRuntimeState, y as createTailwindRuntimeReadyPromise } from "./context-DlpKD7aN.mjs";
|
|
6
|
+
import { _ as resolveViteTailwindV4CssDependencies, a as findTailwindConfig, f as createViteSourceScanMatcher, g as resolveTailwindV4EntriesFromCssCached, i as resolveUniAppXOptions, l as getRuntimeClassSetSignature, m as discoverTailwindV4CssEntries, p as resolveViteSourceScanEntries, r as isUniAppXEnabled } from "./tailwindcss-B5mRo0-M.mjs";
|
|
7
|
+
import { A as hasMiniProgramCssSpecificityPlaceholders, F as createCssTokenSourceMap, L as processCachedTask, M as stripMiniProgramCssSpecificityPlaceholders, N as annotateCssSourceTrace, P as createCssSourceTraceCacheSignature, _ as isPureLocalCssImportWrapper, a as isSourceCandidateRequest, d as validateCandidatesByGenerator, g as mergeMarkedUserLayerComponentsCss, h as extractMarkedUserLayerComponentsCss, m as runWithConcurrency, r as createSourceCandidateCollector, s as createBundleRuntimeClassSetManager, t as createHmrTimingRecorder } from "./hmr-timing-B0KuWDjV.mjs";
|
|
8
|
+
import { A as isSourceStyleRequest, C as resolvePluginDisabledState, D as isHTMLRequest, E as isCSSRequest, M as normalizeOutputPathKey, O as normalizePath, P as toAbsoluteOutputPath, S as resolvePackageDir, T as formatPostcssSourceMap, _ as generateTailwindV4Css, a as createJsHashSalt, b as parseBundlerGeneratedCssMarkerBlocks, c as hasRuntimeAffectingSourceChanges, f as createBundleBuildState, g as createBundleModuleGraphOptions, h as applyLinkedResults, i as createCandidateSignature, j as stripRequestQuery, k as slash, l as summarizeStringDiff, m as createRuntimeAffectingSourceSignature, n as createScopedGeneratorCandidateSignature, o as createLinkedImpactSignature, p as updateBundleBuildState, r as createScopedGeneratorRuntime, s as getSnapshotHash, t as createSourceCandidateScanSignature, u as buildBundleSnapshot, v as createBundlerGeneratedCssMarker, w as cleanUrl, x as stripBundlerGeneratedCssMarkers, y as hasBundlerGeneratedCssMarker } from "./source-candidate-scan-signature-B5af2Ahe.mjs";
|
|
9
9
|
import { t as logger$1 } from "./logger-BNzxZbZj.mjs";
|
|
10
|
-
import fs, { existsSync } from "node:fs";
|
|
10
|
+
import fs, { existsSync, realpathSync } from "node:fs";
|
|
11
11
|
import path from "node:path";
|
|
12
12
|
import process$1 from "node:process";
|
|
13
|
-
import {
|
|
13
|
+
import { splitCandidateTokens } from "@tailwindcss-mangle/engine";
|
|
14
|
+
import { containsCssAfterMinify, filterExistingCssRules, mergeCoveredCssRuleDeclarations, mergeMiniProgramPreflightRuleDeclarations, mergeMiniProgramThemeScopeRuleDeclarations, postcss, removeTailwindPostcssPlugins, resolveFilteredPostcssConfig } from "@weapp-tailwindcss/postcss";
|
|
14
15
|
import { LRUCache } from "lru-cache";
|
|
15
|
-
import { splitCandidateTokens } from "tailwindcss-patch";
|
|
16
|
-
import { logger } from "@weapp-tailwindcss/logger";
|
|
17
16
|
import { readFile } from "node:fs/promises";
|
|
17
|
+
import micromatch from "micromatch";
|
|
18
18
|
import { Buffer } from "node:buffer";
|
|
19
|
-
import
|
|
19
|
+
import { logger } from "@weapp-tailwindcss/logger";
|
|
20
20
|
import { parse } from "comment-json";
|
|
21
21
|
//#region src/uni-app-x/harmony.ts
|
|
22
22
|
function isUniAppXHarmonyOutDir(outDir) {
|
|
@@ -353,18 +353,13 @@ function findFirstStyleObjectDecl(source) {
|
|
|
353
353
|
varName
|
|
354
354
|
};
|
|
355
355
|
}
|
|
356
|
-
function resolveCssFallbackFiles(
|
|
357
|
-
const files =
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
if (file.startsWith("assets/") && file.endsWith(".js")) {
|
|
364
|
-
const withoutAssets = file.slice(7).replace(/\.js$/, "");
|
|
365
|
-
files.push(`${withoutAssets}.wxss`, `${withoutAssets}.css`);
|
|
366
|
-
}
|
|
367
|
-
return files;
|
|
356
|
+
function resolveCssFallbackFiles(styleAssetFiles = []) {
|
|
357
|
+
const files = /* @__PURE__ */ new Set();
|
|
358
|
+
for (const assetFile of styleAssetFiles) if (assetFile) files.add(assetFile);
|
|
359
|
+
return [...files];
|
|
360
|
+
}
|
|
361
|
+
function resolveStyleAssetFilesForChunk(file, styleAssetFiles) {
|
|
362
|
+
return typeof styleAssetFiles === "function" ? styleAssetFiles(file) : styleAssetFiles;
|
|
368
363
|
}
|
|
369
364
|
function resolveSourceMapFiles(file) {
|
|
370
365
|
return [
|
|
@@ -374,7 +369,7 @@ function resolveSourceMapFiles(file) {
|
|
|
374
369
|
].filter((item) => typeof item === "string");
|
|
375
370
|
}
|
|
376
371
|
function createStyleValueFromBundleSources(file, _code, getBundleSource, options = {}) {
|
|
377
|
-
const cssStyles = mergeStyleValues(...[...options.cssSources ?? []].map((source) => source ? cssSourceToStyleValue(source) : void 0), ...resolveCssFallbackFiles(file).map((cssFile) => {
|
|
372
|
+
const cssStyles = mergeStyleValues(...[...options.cssSources ?? []].map((source) => source ? cssSourceToStyleValue(source) : void 0), ...resolveCssFallbackFiles(resolveStyleAssetFilesForChunk(file, options.styleAssetFiles)).map((cssFile) => {
|
|
378
373
|
const source = getBundleSource?.(cssFile);
|
|
379
374
|
return source ? cssSourceToStyleValue(source) : void 0;
|
|
380
375
|
}));
|
|
@@ -425,12 +420,15 @@ function injectUniAppXHarmonyGlobalStyles(file, code, getBundleSource, options =
|
|
|
425
420
|
}
|
|
426
421
|
function injectUniAppXHarmonyBundleStyles(bundle, options = {}) {
|
|
427
422
|
const getBundleSource = createUniAppXBundleAssetSourceGetter(bundle);
|
|
423
|
+
const styleAssetFilesByChunk = collectUniAppXBundleStyleAssetFilesByChunk(bundle);
|
|
424
|
+
const resolveStyleAssetFiles = typeof options.styleAssetFiles === "function" ? options.styleAssetFiles : (file) => [...options.styleAssetFiles ?? [], ...styleAssetFilesByChunk.get(file) ?? []];
|
|
428
425
|
let changed = false;
|
|
429
426
|
for (const [file, item] of Object.entries(bundle)) {
|
|
430
427
|
if (item.type !== "chunk" || !file.endsWith(".js")) continue;
|
|
431
428
|
const currentSource = item.code;
|
|
432
429
|
const nextSource = injectUniAppXHarmonyGlobalStyles(file, currentSource, getBundleSource, {
|
|
433
430
|
...options,
|
|
431
|
+
styleAssetFiles: resolveStyleAssetFiles,
|
|
434
432
|
mapSources: collectChunkMapSourcesContent(item)
|
|
435
433
|
});
|
|
436
434
|
if (nextSource !== currentSource) {
|
|
@@ -440,6 +438,41 @@ function injectUniAppXHarmonyBundleStyles(bundle, options = {}) {
|
|
|
440
438
|
}
|
|
441
439
|
return changed;
|
|
442
440
|
}
|
|
441
|
+
function collectUniAppXBundleStyleAssetFilesByChunk(bundle) {
|
|
442
|
+
const styleAssetFilesByChunk = /* @__PURE__ */ new Map();
|
|
443
|
+
const appStyleAssetFiles = /* @__PURE__ */ new Set();
|
|
444
|
+
const assetFiles = new Set(Object.entries(bundle).filter(([, item]) => item.type === "asset").map(([file]) => file).filter(isStyleAssetFile));
|
|
445
|
+
for (const [chunkFile, item] of Object.entries(bundle)) {
|
|
446
|
+
if (item.type !== "chunk") continue;
|
|
447
|
+
const chunk = item;
|
|
448
|
+
for (const cssFile of chunk.viteMetadata?.importedCss ?? []) {
|
|
449
|
+
if (!assetFiles.has(cssFile)) continue;
|
|
450
|
+
if (APP_JS_RE.test(chunk.fileName ?? chunkFile) || APP_JS_RE.test(chunkFile)) {
|
|
451
|
+
appStyleAssetFiles.add(cssFile);
|
|
452
|
+
continue;
|
|
453
|
+
}
|
|
454
|
+
let styleAssetFiles = styleAssetFilesByChunk.get(chunkFile);
|
|
455
|
+
if (!styleAssetFiles) {
|
|
456
|
+
styleAssetFiles = /* @__PURE__ */ new Set();
|
|
457
|
+
styleAssetFilesByChunk.set(chunkFile, styleAssetFiles);
|
|
458
|
+
}
|
|
459
|
+
styleAssetFiles.add(cssFile);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
if (appStyleAssetFiles.size > 0) for (const [file, item] of Object.entries(bundle)) {
|
|
463
|
+
if (item.type !== "chunk" || !file.endsWith(".js") || APP_JS_RE.test(file)) continue;
|
|
464
|
+
let styleAssetFiles = styleAssetFilesByChunk.get(file);
|
|
465
|
+
if (!styleAssetFiles) {
|
|
466
|
+
styleAssetFiles = /* @__PURE__ */ new Set();
|
|
467
|
+
styleAssetFilesByChunk.set(file, styleAssetFiles);
|
|
468
|
+
}
|
|
469
|
+
for (const appStyleAssetFile of appStyleAssetFiles) styleAssetFiles.add(appStyleAssetFile);
|
|
470
|
+
}
|
|
471
|
+
return styleAssetFilesByChunk;
|
|
472
|
+
}
|
|
473
|
+
function isStyleAssetFile(file) {
|
|
474
|
+
return /\.(?:acss|css|jxss|qss|ttss|wxss)$/i.test(file);
|
|
475
|
+
}
|
|
443
476
|
function isUniAppXHarmonyBundle(bundle) {
|
|
444
477
|
for (const file of Object.keys(bundle)) if (HARMONY_BUNDLE_MARKER_FILES.has(file)) return true;
|
|
445
478
|
return false;
|
|
@@ -476,7 +509,7 @@ function resolveUniAppXStyleIsolationEnabled(root) {
|
|
|
476
509
|
//#region src/uni-app-x/vite.ts
|
|
477
510
|
let transformUVuePromise;
|
|
478
511
|
function loadTransformUVue() {
|
|
479
|
-
transformUVuePromise ?? (transformUVuePromise = import("./transform-
|
|
512
|
+
transformUVuePromise ?? (transformUVuePromise = import("./transform-fRBeuuK-.mjs").then((mod) => mod.transformUVue));
|
|
480
513
|
return transformUVuePromise;
|
|
481
514
|
}
|
|
482
515
|
const preprocessorLangs = new Set([
|
|
@@ -711,89 +744,24 @@ function createUniAppXAssetTask(file, originalSource, outDir, options) {
|
|
|
711
744
|
};
|
|
712
745
|
}
|
|
713
746
|
//#endregion
|
|
714
|
-
//#region src/bundlers/vite/generate-bundle/candidates.ts
|
|
715
|
-
const MUSTACHE_EXPRESSION_RE = /\{\{[\s\S]*?\}\}/g;
|
|
716
|
-
const QUOTED_LITERAL_RE = /'([^']*)'|"([^"]*)"|`([^`]*)`/g;
|
|
717
|
-
const CLASS_ATTRIBUTE_RE = /\bclass\s*=\s*/g;
|
|
718
|
-
const MUSTACHE_OPEN = "{{";
|
|
719
|
-
const MUSTACHE_CLOSE = "}}";
|
|
720
|
-
function isUrlLikeCandidate(candidate) {
|
|
721
|
-
return candidate.startsWith("//") || candidate.startsWith("http://") || candidate.startsWith("https://");
|
|
722
|
-
}
|
|
723
|
-
function isArbitraryValueCandidate(candidate) {
|
|
724
|
-
return candidate.includes("[") && candidate.includes("]") && !isUrlLikeCandidate(candidate.trim());
|
|
725
|
-
}
|
|
726
|
-
function collectClassAttributeValues(source) {
|
|
727
|
-
const values = [];
|
|
728
|
-
CLASS_ATTRIBUTE_RE.lastIndex = 0;
|
|
729
|
-
let matched = CLASS_ATTRIBUTE_RE.exec(source);
|
|
730
|
-
while (matched !== null) {
|
|
731
|
-
const quoteIndex = CLASS_ATTRIBUTE_RE.lastIndex;
|
|
732
|
-
const quote = source[quoteIndex];
|
|
733
|
-
if (quote !== "\"" && quote !== "'") {
|
|
734
|
-
matched = CLASS_ATTRIBUTE_RE.exec(source);
|
|
735
|
-
continue;
|
|
736
|
-
}
|
|
737
|
-
let expressionDepth = 0;
|
|
738
|
-
for (let index = quoteIndex + 1; index < source.length; index++) {
|
|
739
|
-
if (source.startsWith(MUSTACHE_OPEN, index)) {
|
|
740
|
-
expressionDepth++;
|
|
741
|
-
index += 1;
|
|
742
|
-
continue;
|
|
743
|
-
}
|
|
744
|
-
if (expressionDepth > 0 && source.startsWith(MUSTACHE_CLOSE, index)) {
|
|
745
|
-
expressionDepth--;
|
|
746
|
-
index += 1;
|
|
747
|
-
continue;
|
|
748
|
-
}
|
|
749
|
-
if (expressionDepth === 0 && source[index] === quote) {
|
|
750
|
-
values.push(source.slice(quoteIndex + 1, index));
|
|
751
|
-
CLASS_ATTRIBUTE_RE.lastIndex = index + 1;
|
|
752
|
-
break;
|
|
753
|
-
}
|
|
754
|
-
}
|
|
755
|
-
matched = CLASS_ATTRIBUTE_RE.exec(source);
|
|
756
|
-
}
|
|
757
|
-
return values;
|
|
758
|
-
}
|
|
759
|
-
function collectUnescapedDynamicCandidates(source, allowedCandidates) {
|
|
760
|
-
const matches = /* @__PURE__ */ new Set();
|
|
761
|
-
const shouldFilterByAllowedCandidates = allowedCandidates !== void 0 && allowedCandidates.size > 0;
|
|
762
|
-
for (const classValue of collectClassAttributeValues(source)) for (const expression of classValue.match(MUSTACHE_EXPRESSION_RE) ?? []) {
|
|
763
|
-
QUOTED_LITERAL_RE.lastIndex = 0;
|
|
764
|
-
let quoted = QUOTED_LITERAL_RE.exec(expression);
|
|
765
|
-
while (quoted !== null) {
|
|
766
|
-
const literal = quoted[1] ?? quoted[2] ?? quoted[3] ?? "";
|
|
767
|
-
for (const candidate of splitCandidateTokens(literal)) {
|
|
768
|
-
const normalized = candidate.trim();
|
|
769
|
-
if (!normalized || !isArbitraryValueCandidate(normalized)) continue;
|
|
770
|
-
if (shouldFilterByAllowedCandidates && !allowedCandidates.has(normalized)) continue;
|
|
771
|
-
matches.add(normalized);
|
|
772
|
-
}
|
|
773
|
-
quoted = QUOTED_LITERAL_RE.exec(expression);
|
|
774
|
-
}
|
|
775
|
-
}
|
|
776
|
-
return [...matches];
|
|
777
|
-
}
|
|
778
|
-
function collectLegacyContainerCompatCandidates(sourceCandidates, candidates) {
|
|
779
|
-
if (candidates.has("container")) return candidates;
|
|
780
|
-
if (!sourceCandidates.has("container")) return candidates;
|
|
781
|
-
return new Set([...candidates, "container"]);
|
|
782
|
-
}
|
|
783
|
-
//#endregion
|
|
784
747
|
//#region src/bundlers/vite/generate-bundle/configured-css-sources.ts
|
|
785
748
|
function collectConfiguredTailwindV4CssSources(opts) {
|
|
786
|
-
const
|
|
787
|
-
return [...opts.tailwindcss?.v4?.cssSources ?? [], ...
|
|
749
|
+
const runtimeCssSources = opts.tailwindcssRuntimeOptions?.tailwindcss?.v4?.cssSources ?? [];
|
|
750
|
+
return filterTailwindV4CssSourceRoots([...opts.tailwindcss?.v4?.cssSources ?? [], ...runtimeCssSources]) ?? [];
|
|
788
751
|
}
|
|
789
752
|
function collectConfiguredTailwindV4CssSourceEntries(opts, fallbackBase) {
|
|
790
753
|
const entries = [];
|
|
754
|
+
const seen = /* @__PURE__ */ new Set();
|
|
791
755
|
for (const cssSource of collectConfiguredTailwindV4CssSources(opts)) {
|
|
792
756
|
if (typeof cssSource.css !== "string" || cssSource.css.length === 0) continue;
|
|
793
757
|
const base = resolveTailwindV4CssSourceBase(cssSource, fallbackBase);
|
|
794
758
|
const file = typeof cssSource.file === "string" && cssSource.file.length > 0 ? cssSource.file : path.join(base, "tailwind.css");
|
|
759
|
+
const resolvedFile = path.isAbsolute(file) ? path.resolve(file) : path.resolve(base, file);
|
|
760
|
+
const key = `${resolvedFile}\0${cssSource.css}`;
|
|
761
|
+
if (seen.has(key)) continue;
|
|
762
|
+
seen.add(key);
|
|
795
763
|
entries.push({
|
|
796
|
-
file:
|
|
764
|
+
file: resolvedFile,
|
|
797
765
|
source: cssSource.css
|
|
798
766
|
});
|
|
799
767
|
}
|
|
@@ -833,16 +801,15 @@ function registerGeneratorDependencies$1(ctx, dependencies) {
|
|
|
833
801
|
//#region src/bundlers/vite/generate-bundle/css-assets.ts
|
|
834
802
|
function createCssAssetEmitter(context) {
|
|
835
803
|
return (fileName, source) => {
|
|
836
|
-
const replayAsset = createReplayCssAsset(fileName, source);
|
|
837
804
|
if (context.emitFile) {
|
|
838
805
|
context.emitFile({
|
|
839
806
|
type: "asset",
|
|
840
807
|
fileName,
|
|
841
808
|
source
|
|
842
809
|
});
|
|
843
|
-
return
|
|
810
|
+
return;
|
|
844
811
|
}
|
|
845
|
-
return
|
|
812
|
+
return createReplayCssAsset(fileName, source);
|
|
846
813
|
};
|
|
847
814
|
}
|
|
848
815
|
function resolveAssetSourceFile(asset, fallbackFile) {
|
|
@@ -862,6 +829,23 @@ const COMMON_MINI_PROGRAM_STYLE_OUTPUT_EXTENSIONS = [
|
|
|
862
829
|
".jxss",
|
|
863
830
|
".tyss"
|
|
864
831
|
];
|
|
832
|
+
function resolveCssOutputRealPath(value) {
|
|
833
|
+
const resolved = path.resolve(value);
|
|
834
|
+
let current = resolved;
|
|
835
|
+
const pendingSegments = [];
|
|
836
|
+
while (!existsSync(current)) {
|
|
837
|
+
const parent = path.dirname(current);
|
|
838
|
+
if (parent === current) return resolved;
|
|
839
|
+
pendingSegments.unshift(path.basename(current));
|
|
840
|
+
current = parent;
|
|
841
|
+
}
|
|
842
|
+
try {
|
|
843
|
+
const realPath = realpathSync.native(current);
|
|
844
|
+
return pendingSegments.length > 0 ? path.join(realPath, ...pendingSegments) : realPath;
|
|
845
|
+
} catch {
|
|
846
|
+
return resolved;
|
|
847
|
+
}
|
|
848
|
+
}
|
|
865
849
|
function normalizeStyleOutputExtension(value) {
|
|
866
850
|
if (typeof value !== "string" || value.trim().length === 0) return;
|
|
867
851
|
const normalized = value.trim().toLowerCase();
|
|
@@ -890,11 +874,26 @@ function resolveStyleOutputExtensionFromMatcher(cssMatcher, stem) {
|
|
|
890
874
|
if (!cssMatcher || !stem) return;
|
|
891
875
|
return COMMON_MINI_PROGRAM_STYLE_OUTPUT_EXTENSIONS.find((extension) => cssMatcher(`${stem}${extension}`));
|
|
892
876
|
}
|
|
877
|
+
function resolveStyleOutputFileFromFiles(files, cssMatcher, stem) {
|
|
878
|
+
const cleanStem = normalizeOutputPathKey(stem);
|
|
879
|
+
const stemSuffix = `/${cleanStem}`;
|
|
880
|
+
const matchedFiles = /* @__PURE__ */ new Set();
|
|
881
|
+
for (const file of files ?? []) {
|
|
882
|
+
const cleanFile = normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
883
|
+
if (!cssMatcher?.(cleanFile)) continue;
|
|
884
|
+
const extension = path.extname(cleanFile);
|
|
885
|
+
if (!extension || extension === ".css") continue;
|
|
886
|
+
const outputStem = cleanFile.slice(0, -extension.length);
|
|
887
|
+
const outputStemSuffix = `/${outputStem}`;
|
|
888
|
+
if (outputStem === cleanStem || outputStem.endsWith(stemSuffix) || cleanStem.endsWith(outputStemSuffix) || cleanStem.endsWith(`/${outputStem}`)) matchedFiles.add(cleanFile);
|
|
889
|
+
}
|
|
890
|
+
return matchedFiles.size === 1 ? [...matchedFiles][0] : void 0;
|
|
891
|
+
}
|
|
893
892
|
function resolveMiniProgramStyleOutputExtension(options = {}) {
|
|
894
|
-
return resolveStyleOutputExtensionFromFiles(options.files, options.cssMatcher, options.stem) ??
|
|
893
|
+
return resolveStyleOutputExtensionFromFiles(options.files, options.cssMatcher, options.stem) ?? resolveStyleOutputExtensionFromFiles(options.files, options.cssMatcher) ?? resolveStyleOutputExtensionFromMatcher(options.cssMatcher, options.stem) ?? normalizeStyleOutputExtension(options.fallback) ?? FALLBACK_STYLE_OUTPUT_EXTENSION;
|
|
895
894
|
}
|
|
896
895
|
function resolveReplayCssOutputFile(rootDir, file) {
|
|
897
|
-
const normalizedFile = normalizeOutputPathKey(path.isAbsolute(file) ? path.relative(rootDir, file) : file);
|
|
896
|
+
const normalizedFile = normalizeOutputPathKey(path.isAbsolute(file) ? path.relative(resolveCssOutputRealPath(rootDir), resolveCssOutputRealPath(file)) : file);
|
|
898
897
|
if (normalizedFile.length === 0 || normalizedFile === "." || normalizedFile === ".." || normalizedFile.startsWith("../")) return normalizeOutputPathKey(path.basename(file));
|
|
899
898
|
return normalizedFile;
|
|
900
899
|
}
|
|
@@ -931,6 +930,21 @@ function resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTar
|
|
|
931
930
|
if (!fallbackExtension && !SOURCE_STYLE_OUTPUT_EXT_RE.test(normalizedFile)) return normalizedFile;
|
|
932
931
|
return normalizedFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, fallbackExtension ?? FALLBACK_STYLE_OUTPUT_EXTENSION);
|
|
933
932
|
}
|
|
933
|
+
function resolveViteCssPipelineOutputFileFromSourceFile(sourceFile, opts, rootDir, isWebGeneratorTarget = false, preserveCssExtension = false, sourceRoot, styleOutputExtension, styleOutputFiles) {
|
|
934
|
+
const normalizedFile = resolveReplayCssOutputFileFromSourceRoot(rootDir, sourceFile, sourceRoot);
|
|
935
|
+
const cleanFile = normalizedFile.replace(/[?#].*$/, "");
|
|
936
|
+
if (isWebGeneratorTarget || preserveCssExtension || !CSS_SOURCE_OUTPUT_EXT_RE.test(cleanFile) || !isCSSRequest(normalizedFile)) return normalizedFile;
|
|
937
|
+
const stem = cleanFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, "");
|
|
938
|
+
const matchedStyleFile = resolveStyleOutputFileFromFiles(styleOutputFiles, opts.cssMatcher, stem);
|
|
939
|
+
if (matchedStyleFile) return matchedStyleFile;
|
|
940
|
+
const styleExtension = resolveStyleOutputExtensionFromFiles(styleOutputFiles, opts.cssMatcher, stem) ?? resolveMiniProgramStyleOutputExtension({
|
|
941
|
+
cssMatcher: opts.cssMatcher,
|
|
942
|
+
fallback: styleOutputExtension,
|
|
943
|
+
files: styleOutputFiles,
|
|
944
|
+
stem
|
|
945
|
+
}) ?? normalizeStyleOutputExtension(styleOutputExtension);
|
|
946
|
+
return normalizedFile.replace(CSS_SOURCE_OUTPUT_EXT_RE, styleExtension);
|
|
947
|
+
}
|
|
934
948
|
function canProcessViteSourceStyleAsCss(source, file) {
|
|
935
949
|
if (SOURCE_STYLE_NON_CSS_SYNTAX_RE.test(source)) return false;
|
|
936
950
|
try {
|
|
@@ -950,6 +964,23 @@ function stripStyleFileExtension(file) {
|
|
|
950
964
|
}
|
|
951
965
|
//#endregion
|
|
952
966
|
//#region src/bundlers/vite/generate-bundle/style-matching.ts
|
|
967
|
+
function resolveStyleMatchingRealPath(value) {
|
|
968
|
+
const resolved = path.resolve(value);
|
|
969
|
+
let current = resolved;
|
|
970
|
+
const pendingSegments = [];
|
|
971
|
+
while (!existsSync(current)) {
|
|
972
|
+
const parent = path.dirname(current);
|
|
973
|
+
if (parent === current) return resolved;
|
|
974
|
+
pendingSegments.unshift(path.basename(current));
|
|
975
|
+
current = parent;
|
|
976
|
+
}
|
|
977
|
+
try {
|
|
978
|
+
const realPath = realpathSync.native(current);
|
|
979
|
+
return pendingSegments.length > 0 ? path.join(realPath, ...pendingSegments) : realPath;
|
|
980
|
+
} catch {
|
|
981
|
+
return resolved;
|
|
982
|
+
}
|
|
983
|
+
}
|
|
953
984
|
function isMatchingCssSourceFile(outputFile, cssSourceFile, outputRoot) {
|
|
954
985
|
return stripStyleFileExtension(path.resolve(outputRoot, outputFile)) === stripStyleFileExtension(path.resolve(cssSourceFile));
|
|
955
986
|
}
|
|
@@ -963,7 +994,7 @@ function collectStyleFileMatchBases(file, roots) {
|
|
|
963
994
|
addBase(normalizedFile);
|
|
964
995
|
const resolvedRoots = roots.filter((root) => typeof root === "string" && root.length > 0).map((root) => path.resolve(root));
|
|
965
996
|
if (path.isAbsolute(normalizedFile)) for (const root of resolvedRoots) {
|
|
966
|
-
const relative = path.relative(root, normalizedFile);
|
|
997
|
+
const relative = path.relative(resolveStyleMatchingRealPath(root), resolveStyleMatchingRealPath(normalizedFile));
|
|
967
998
|
if (relative && !relative.startsWith("..") && !path.isAbsolute(relative)) addBase(relative);
|
|
968
999
|
}
|
|
969
1000
|
else for (const root of resolvedRoots) addBase(path.resolve(root, normalizedFile));
|
|
@@ -1003,11 +1034,11 @@ function normalizeMatchedCssSourcePath(file) {
|
|
|
1003
1034
|
return path.resolve(file.replace(/[?#].*$/, ""));
|
|
1004
1035
|
}
|
|
1005
1036
|
function collectConfiguredCssEntries(opts) {
|
|
1006
|
-
const
|
|
1037
|
+
const runtimeCssEntries = opts.tailwindcssRuntimeOptions?.tailwindcss?.v4?.cssEntries ?? [];
|
|
1007
1038
|
return [
|
|
1008
1039
|
...opts.cssEntries ?? [],
|
|
1009
1040
|
...opts.tailwindcss?.v4?.cssEntries ?? [],
|
|
1010
|
-
...
|
|
1041
|
+
...runtimeCssEntries ?? []
|
|
1011
1042
|
].filter((entry) => typeof entry === "string" && entry.length > 0);
|
|
1012
1043
|
}
|
|
1013
1044
|
function collectCssConfigBaseCandidates(source, file, outputRoot, opts) {
|
|
@@ -1022,9 +1053,9 @@ function collectCssConfigBaseCandidates(source, file, outputRoot, opts) {
|
|
|
1022
1053
|
};
|
|
1023
1054
|
addCandidate(path.dirname(path.resolve(outputRoot, file.replace(/[?#].*$/, ""))));
|
|
1024
1055
|
const normalizedSource = normalizeCssSourceForCompare(source);
|
|
1025
|
-
const
|
|
1026
|
-
const sourceBaseFallback = opts.tailwindcss?.v4?.base ??
|
|
1027
|
-
const sourceRoot = opts.tailwindcssBasedir ??
|
|
1056
|
+
const runtimeProjectRoot = typeof opts.tailwindcssRuntimeOptions?.projectRoot === "string" ? opts.tailwindcssRuntimeOptions.projectRoot : void 0;
|
|
1057
|
+
const sourceBaseFallback = opts.tailwindcss?.v4?.base ?? runtimeProjectRoot ?? opts.tailwindcssBasedir ?? outputRoot;
|
|
1058
|
+
const sourceRoot = opts.tailwindcssBasedir ?? runtimeProjectRoot;
|
|
1028
1059
|
const configuredCssEntries = collectConfiguredCssEntries(opts);
|
|
1029
1060
|
for (const cssEntry of configuredCssEntries) {
|
|
1030
1061
|
const resolvedCssEntry = path.resolve(cssEntry);
|
|
@@ -1064,7 +1095,7 @@ function createCssHandlerOptionsCache(options) {
|
|
|
1064
1095
|
const appType = options.getAppType();
|
|
1065
1096
|
const isMainChunk = options.mainCssChunkMatcher(file, appType);
|
|
1066
1097
|
const outputRoot = options.getOutputRoot?.();
|
|
1067
|
-
const from = outputRoot ? path.resolve(outputRoot, file) : file;
|
|
1098
|
+
const from = path.isAbsolute(file) ? file : outputRoot ? path.resolve(outputRoot, file) : file;
|
|
1068
1099
|
const extraOptions = options.getExtraOptions?.(file) ?? {};
|
|
1069
1100
|
const cacheKey = `${majorVersion ?? "unknown"}:${appType ?? "unknown"}:${isMainChunk ? "1" : "0"}:${outputRoot ?? ""}:${file}:${JSON.stringify(extraOptions)}`;
|
|
1070
1101
|
const cached = cssHandlerOptionsCache.get(cacheKey);
|
|
@@ -1073,7 +1104,7 @@ function createCssHandlerOptionsCache(options) {
|
|
|
1073
1104
|
isMainChunk,
|
|
1074
1105
|
...extraOptions,
|
|
1075
1106
|
postcssOptions: { options: { from } },
|
|
1076
|
-
majorVersion,
|
|
1107
|
+
majorVersion: normalizeStyleHandlerMajorVersion(majorVersion),
|
|
1077
1108
|
sourceOptions: { outputRoot }
|
|
1078
1109
|
};
|
|
1079
1110
|
cssHandlerOptionsCache.set(cacheKey, created);
|
|
@@ -1098,6 +1129,91 @@ function createCssHandlerOptionsCache(options) {
|
|
|
1098
1129
|
};
|
|
1099
1130
|
}
|
|
1100
1131
|
//#endregion
|
|
1132
|
+
//#region src/bundlers/vite/generate-bundle/root-style-output.ts
|
|
1133
|
+
function isRootMiniProgramStyleOutputFile$1(file) {
|
|
1134
|
+
const normalized = normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
1135
|
+
return !normalized.includes("/") && /\.(?:wxss|acss|ttss|qss|jxss|tyss)$/i.test(normalized);
|
|
1136
|
+
}
|
|
1137
|
+
function createRelativeCssImportRequest$1(targetFile, importedFile) {
|
|
1138
|
+
const normalizedTargetFile = normalizeOutputPathKey(targetFile.replace(/[?#].*$/, ""));
|
|
1139
|
+
const normalizedImportedFile = normalizeOutputPathKey(importedFile.replace(/[?#].*$/, ""));
|
|
1140
|
+
const targetDir = path.posix.dirname(normalizedTargetFile);
|
|
1141
|
+
const baseDir = targetDir === "." ? "" : targetDir;
|
|
1142
|
+
const relative = path.posix.relative(baseDir, normalizedImportedFile);
|
|
1143
|
+
return relative.startsWith(".") ? relative : `./${relative}`;
|
|
1144
|
+
}
|
|
1145
|
+
function createCssImportShell$1(targetFile, importedFile) {
|
|
1146
|
+
return `@import "${createRelativeCssImportRequest$1(targetFile, importedFile)}";\n`;
|
|
1147
|
+
}
|
|
1148
|
+
function createRootMiniProgramOriginStyleOutputFile(file) {
|
|
1149
|
+
const normalized = normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
1150
|
+
if (/(?:^|\/)[^/]+-origin\.[^.]+$/i.test(normalized)) return normalized;
|
|
1151
|
+
return normalized.replace(/(\.[^.]+)$/, "-origin$1");
|
|
1152
|
+
}
|
|
1153
|
+
function shouldKeepRootMiniProgramStyleAsImportShell(appType) {
|
|
1154
|
+
return appType === "uni-app-vite" || appType === "uni-app-x" || appType === "taro";
|
|
1155
|
+
}
|
|
1156
|
+
function shouldMoveRootMiniProgramStyleToImportShellOrigin(appType) {
|
|
1157
|
+
return appType === "taro";
|
|
1158
|
+
}
|
|
1159
|
+
//#endregion
|
|
1160
|
+
//#region src/bundlers/vite/generate-bundle/css-output-helpers.ts
|
|
1161
|
+
function resolveCssBundleOutputFile(options) {
|
|
1162
|
+
const { bundleFiles, defaultStyleOutputExtension, file, isWebGeneratorTarget, opts, shouldPreserveAppCssExtension } = options;
|
|
1163
|
+
let outputFile = resolveViteCssOutputFile(file, opts, isWebGeneratorTarget, shouldPreserveAppCssExtension, defaultStyleOutputExtension, bundleFiles);
|
|
1164
|
+
if (outputFile === file && isRootMiniProgramStyleOutputFile$1(file) && shouldMoveRootMiniProgramStyleToImportShellOrigin(opts.appType)) outputFile = createRootMiniProgramOriginStyleOutputFile(file);
|
|
1165
|
+
return outputFile;
|
|
1166
|
+
}
|
|
1167
|
+
function shouldSkipRawSourceStyleAsset(outputFile, file, rawSource) {
|
|
1168
|
+
return rawSource.trim().length > 0 && outputFile !== file && !canProcessViteSourceStyleAsCss(rawSource, file);
|
|
1169
|
+
}
|
|
1170
|
+
function resolveOutputFileFromMatchedCssSource(options) {
|
|
1171
|
+
const { bundleFiles, defaultStyleOutputExtension, isWebGeneratorTarget, opts, rootDir, shouldPreserveAppCssExtension, sourceFile, sourceRoot } = options;
|
|
1172
|
+
if (!sourceFile) return;
|
|
1173
|
+
if (isWebGeneratorTarget) return;
|
|
1174
|
+
const outputFile = resolveViteCssPipelineOutputFileFromSourceFile(sourceFile, opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension, sourceRoot, defaultStyleOutputExtension, bundleFiles);
|
|
1175
|
+
return opts.cssMatcher(outputFile) ? outputFile : void 0;
|
|
1176
|
+
}
|
|
1177
|
+
function createMatchedCssSourceOutputResolver(options) {
|
|
1178
|
+
const { assetSourceFile, file, originalFileNames, resolveOutputFileFromMatchedCssSource } = options;
|
|
1179
|
+
return (sourceFile) => {
|
|
1180
|
+
if (!sourceFile) return;
|
|
1181
|
+
if (normalizeOutputPathKey(assetSourceFile.replace(/[?#].*$/, "")) === normalizeOutputPathKey(sourceFile.replace(/[?#].*$/, "")) || originalFileNames?.some((originalFile) => normalizeOutputPathKey(originalFile.replace(/[?#].*$/, "")) === normalizeOutputPathKey(sourceFile.replace(/[?#].*$/, "")))) return file;
|
|
1182
|
+
return resolveOutputFileFromMatchedCssSource(sourceFile);
|
|
1183
|
+
};
|
|
1184
|
+
}
|
|
1185
|
+
function hasViteProcessedCssResultForSource(sourceFile, getViteProcessedCssAssetResults) {
|
|
1186
|
+
const sourceKey = normalizeOutputPathKey(sourceFile);
|
|
1187
|
+
for (const [file] of getViteProcessedCssAssetResults?.() ?? []) if (normalizeOutputPathKey(file) === sourceKey) return true;
|
|
1188
|
+
return false;
|
|
1189
|
+
}
|
|
1190
|
+
function applyCssResultToBundle(options) {
|
|
1191
|
+
const { appType, assetSourceFile, bundle, emitOrReplayCssAsset, file, originalSource, outputFile, source, viteProcessedCssAsset } = options;
|
|
1192
|
+
if (outputFile === file) {
|
|
1193
|
+
originalSource.source = source;
|
|
1194
|
+
return;
|
|
1195
|
+
}
|
|
1196
|
+
const importShellSource = isRootMiniProgramStyleOutputFile$1(file) && isRootMiniProgramStyleOutputFile$1(outputFile) && shouldKeepRootMiniProgramStyleAsImportShell(appType) ? createCssImportShell$1(file, outputFile) : void 0;
|
|
1197
|
+
if (bundle[file] === originalSource && originalSource.originalFileNames?.includes(assetSourceFile)) {
|
|
1198
|
+
const existingOutput = bundle[outputFile];
|
|
1199
|
+
if (existingOutput?.type === "asset") existingOutput.source = source;
|
|
1200
|
+
else {
|
|
1201
|
+
const replayAsset = emitOrReplayCssAsset(outputFile, source);
|
|
1202
|
+
if (replayAsset) bundle[outputFile] = replayAsset;
|
|
1203
|
+
}
|
|
1204
|
+
originalSource.source = importShellSource ?? source;
|
|
1205
|
+
return;
|
|
1206
|
+
}
|
|
1207
|
+
const existingOutput = bundle[outputFile];
|
|
1208
|
+
if (existingOutput?.type === "asset") existingOutput.source = source;
|
|
1209
|
+
else {
|
|
1210
|
+
const replayAsset = emitOrReplayCssAsset(outputFile, source);
|
|
1211
|
+
if (replayAsset) bundle[outputFile] = replayAsset;
|
|
1212
|
+
}
|
|
1213
|
+
if (!viteProcessedCssAsset && SOURCE_STYLE_OUTPUT_EXT_RE.test(file)) delete bundle[file];
|
|
1214
|
+
else originalSource.source = importShellSource ?? "";
|
|
1215
|
+
}
|
|
1216
|
+
//#endregion
|
|
1101
1217
|
//#region src/bundlers/vite/generate-bundle/css-share-scope.ts
|
|
1102
1218
|
const CSS_URL_FUNCTION_RE = /url\((?:"([^"]*)"|'([^']*)'|([^)]*))\)/gi;
|
|
1103
1219
|
const CSS_PATH_INDEPENDENT_URL_RE = /^(?:[a-z][a-z\d+.-]*:|\/\/|\/|#)/i;
|
|
@@ -1122,7 +1238,7 @@ function createCssTransformShareScope(file, rawSource) {
|
|
|
1122
1238
|
function createCssTransformShareScopeKey(opts, file, rawSource) {
|
|
1123
1239
|
if (opts.mainCssChunkMatcher(file, opts.appType)) return `main:${normalizeOutputPathKey(file)}`;
|
|
1124
1240
|
const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(opts.generator);
|
|
1125
|
-
if (hasTailwindGeneratedCssMarkers(rawSource) || hasTailwindSourceDirectives(rawSource, { importFallback: generatorOptions.importFallback })
|
|
1241
|
+
if (hasTailwindGeneratedCssMarkers(rawSource) || hasTailwindSourceDirectives(rawSource, { importFallback: generatorOptions.importFallback })) return `source:${normalizeOutputPathKey(file)}`;
|
|
1126
1242
|
return createCssTransformShareScope(file, rawSource);
|
|
1127
1243
|
}
|
|
1128
1244
|
function createCssRuntimeSignature(runtimeSignature, generatorCandidateSignature) {
|
|
@@ -1138,12 +1254,13 @@ function hasOmittedKnownBundleFiles(currentBundleFiles, previousBundleFiles) {
|
|
|
1138
1254
|
//#endregion
|
|
1139
1255
|
//#region src/bundlers/vite/generate-bundle/env-flags.ts
|
|
1140
1256
|
function resolveGenerateBundleEnvFlags() {
|
|
1257
|
+
const slowJsAstWarnMs = Number(process$1.env["WEAPP_TW_VITE_SLOW_JS_AST_WARN_MS"] ?? 1e3);
|
|
1141
1258
|
return {
|
|
1142
1259
|
forceRuntimeRefreshByEnv: process$1.env["WEAPP_TW_VITE_FORCE_RUNTIME_REFRESH"] === "1",
|
|
1143
1260
|
disableDirtyOptimization: process$1.env["WEAPP_TW_VITE_DISABLE_DIRTY"] === "1",
|
|
1144
1261
|
disableJsPrecheck: process$1.env["WEAPP_TW_VITE_DISABLE_JS_PRECHECK"] === "1",
|
|
1145
1262
|
debugCssDiff: process$1.env["WEAPP_TW_VITE_DEBUG_CSS_DIFF"] === "1",
|
|
1146
|
-
|
|
1263
|
+
slowJsAstWarnMs: Number.isFinite(slowJsAstWarnMs) && slowJsAstWarnMs >= 0 ? slowJsAstWarnMs : 1e3
|
|
1147
1264
|
};
|
|
1148
1265
|
}
|
|
1149
1266
|
//#endregion
|
|
@@ -1615,8 +1732,13 @@ function extractSfcStyleSources(source) {
|
|
|
1615
1732
|
function hasSfcStyleSources(source) {
|
|
1616
1733
|
return extractSfcStyleSources(source).length > 0;
|
|
1617
1734
|
}
|
|
1618
|
-
function hasTailwindGenerationSource(source) {
|
|
1619
|
-
|
|
1735
|
+
function hasTailwindGenerationSource(source, options = {}) {
|
|
1736
|
+
const allowRootDirectives = options.allowRootDirectives !== false;
|
|
1737
|
+
return hasTailwindNonRootGenerationDirectives(source, { importFallback: true }) || allowRootDirectives && hasTailwindSourceDirectives(source, { importFallback: true }) || allowRootDirectives && hasTailwindRootDirectives(source, { importFallback: true }) || hasTailwindApplyDirective(source);
|
|
1738
|
+
}
|
|
1739
|
+
function hasTailwindGenerationSourceForFile(file, source) {
|
|
1740
|
+
if (isTailwindV4CssEntry(file)) return hasTailwindGenerationSource(source);
|
|
1741
|
+
return hasTailwindGenerationSource(source, { allowRootDirectives: false });
|
|
1620
1742
|
}
|
|
1621
1743
|
async function resolveSfcStyleSourceFromOutputFile(outputFile, snapshot, outputRoot, sourceRoot, cssMatcher, getSfcSource, debug) {
|
|
1622
1744
|
const sourceFile = resolveSfcStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot, sourceRoot, cssMatcher, debug);
|
|
@@ -1630,7 +1752,7 @@ async function resolveSfcStyleSourceFromOutputFile(outputFile, snapshot, outputR
|
|
|
1630
1752
|
return;
|
|
1631
1753
|
}
|
|
1632
1754
|
const rawSource = extractSfcStyleSources(source).join("\n");
|
|
1633
|
-
if (!rawSource || !
|
|
1755
|
+
if (!rawSource || !hasTailwindGenerationSourceForFile(sourceFile, rawSource)) {
|
|
1634
1756
|
debug("sfc style source infer skipped: no tailwind generation source for %s -> %s", outputFile, sourceFile);
|
|
1635
1757
|
return;
|
|
1636
1758
|
}
|
|
@@ -1644,7 +1766,7 @@ async function resolveSfcStyleSourceFromOutputFile(outputFile, snapshot, outputR
|
|
|
1644
1766
|
function normalizeSfcSourceFileForCompare(file) {
|
|
1645
1767
|
return normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
1646
1768
|
}
|
|
1647
|
-
function collectChunkModuleIds$
|
|
1769
|
+
function collectChunkModuleIds$2(output) {
|
|
1648
1770
|
const moduleIds = Array.isArray(output.moduleIds) ? output.moduleIds : [];
|
|
1649
1771
|
return [
|
|
1650
1772
|
output.facadeModuleId,
|
|
@@ -1684,7 +1806,7 @@ function resolveSfcStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot, s
|
|
|
1684
1806
|
debug("sfc style sibling chunk skipped: missing chunk for %s -> %s", outputFile, siblingJsFile);
|
|
1685
1807
|
return;
|
|
1686
1808
|
}
|
|
1687
|
-
const sourceFiles = collectChunkModuleIds$
|
|
1809
|
+
const sourceFiles = collectChunkModuleIds$2(siblingChunk.output).map(normalizeSfcModuleId).filter((file, index, files) => Boolean(file) && files.indexOf(file) === index);
|
|
1688
1810
|
if (sourceFiles.length === 0) {
|
|
1689
1811
|
debug("sfc style sibling chunk skipped: no sfc modules for %s -> %s", outputFile, siblingJsFile);
|
|
1690
1812
|
return;
|
|
@@ -1704,7 +1826,7 @@ function resolveSfcStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot, s
|
|
|
1704
1826
|
return bestSources[0]?.sourceFile;
|
|
1705
1827
|
}
|
|
1706
1828
|
function resolveSourceStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot, sourceRoot, debug) {
|
|
1707
|
-
const siblingJsFile = resolveSiblingJsChunkFile(outputFile);
|
|
1829
|
+
const siblingJsFile = resolveSiblingJsChunkFile(outputFile, void 0);
|
|
1708
1830
|
if (!siblingJsFile) {
|
|
1709
1831
|
debug("source style sibling chunk skipped: no sibling js for %s", outputFile);
|
|
1710
1832
|
return;
|
|
@@ -1715,7 +1837,7 @@ function resolveSourceStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot
|
|
|
1715
1837
|
debug("source style sibling chunk skipped: missing chunk for %s -> %s", outputFile, siblingJsFile);
|
|
1716
1838
|
return;
|
|
1717
1839
|
}
|
|
1718
|
-
const sourceFiles = collectChunkModuleIds$
|
|
1840
|
+
const sourceFiles = collectChunkModuleIds$2(siblingChunk.output).map(normalizeSourceStyleModuleId).filter((file, index, files) => Boolean(file) && files.indexOf(file) === index);
|
|
1719
1841
|
if (sourceFiles.length === 0) {
|
|
1720
1842
|
debug("source style sibling chunk skipped: no source style modules for %s -> %s", outputFile, siblingJsFile);
|
|
1721
1843
|
return;
|
|
@@ -1737,8 +1859,8 @@ function resolveSourceStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot
|
|
|
1737
1859
|
function resolveSourceStyleSourceFromOutputFile(outputFile, snapshot, outputRoot, sourceRoot, getSourceStyleSource, getSourceStyleSources, configuredSourceEntries, debug) {
|
|
1738
1860
|
let sourceFile = resolveSourceStyleFileFromSiblingChunk(outputFile, snapshot, outputRoot, sourceRoot, debug);
|
|
1739
1861
|
let rawSource = sourceFile ? getSourceStyleSource?.(sourceFile) : void 0;
|
|
1740
|
-
if (!rawSource || !
|
|
1741
|
-
const scoredSources = [...getSourceStyleSources?.() ?? [], ...configuredSourceEntries ?? []].filter(([file, source]) => CSS_SOURCE_OUTPUT_EXT_RE.test(file) &&
|
|
1862
|
+
if (!sourceFile || !rawSource || !hasTailwindGenerationSourceForFile(sourceFile, rawSource)) {
|
|
1863
|
+
const scoredSources = [...getSourceStyleSources?.() ?? [], ...configuredSourceEntries ?? []].filter(([file, source]) => CSS_SOURCE_OUTPUT_EXT_RE.test(file) && hasTailwindGenerationSourceForFile(file, source)).map(([file, source]) => ({
|
|
1742
1864
|
file,
|
|
1743
1865
|
source,
|
|
1744
1866
|
score: scoreMatchingStyleFileBase(outputFile, file, outputRoot, sourceRoot)
|
|
@@ -1752,7 +1874,7 @@ function resolveSourceStyleSourceFromOutputFile(outputFile, snapshot, outputRoot
|
|
|
1752
1874
|
}
|
|
1753
1875
|
}
|
|
1754
1876
|
if (!sourceFile || !rawSource) return;
|
|
1755
|
-
if (!
|
|
1877
|
+
if (!hasTailwindGenerationSourceForFile(sourceFile, rawSource)) {
|
|
1756
1878
|
debug("source style source infer skipped: no tailwind generation source for %s -> %s", outputFile, sourceFile);
|
|
1757
1879
|
return;
|
|
1758
1880
|
}
|
|
@@ -1812,7 +1934,7 @@ function collectMiniProgramSubpackageSourceEntries(snapshot, subpackageRoots, so
|
|
|
1812
1934
|
if (entry.output.type !== "chunk" || !isSubpackageOutputFile(entry.file, subpackageRoots)) continue;
|
|
1813
1935
|
const matchedSubpackageRoot = [...subpackageRoots].find((root) => isSubpackageOutputFile(entry.file, new Set([root])));
|
|
1814
1936
|
if (!matchedSubpackageRoot) continue;
|
|
1815
|
-
for (const moduleId of collectChunkModuleIds$
|
|
1937
|
+
for (const moduleId of collectChunkModuleIds$2(entry.output)) {
|
|
1816
1938
|
if (!path.isAbsolute(moduleId.replace(/[?#].*$/, ""))) continue;
|
|
1817
1939
|
const sourceRoot = resolveSubpackageSourceRootFromModuleId(moduleId, matchedSubpackageRoot);
|
|
1818
1940
|
if (sourceRoot) sourceRoots.add(sourceRoot);
|
|
@@ -1837,16 +1959,16 @@ const CSS_OUTPUT_FILE_RE = /\.(?:css|wxss|acss|ttss|qss|jxss|tyss)(?:$|[?#])/i;
|
|
|
1837
1959
|
function isCssOutputFile(file) {
|
|
1838
1960
|
return CSS_OUTPUT_FILE_RE.test(file);
|
|
1839
1961
|
}
|
|
1840
|
-
function getAssetFile(bundleFile, asset) {
|
|
1962
|
+
function getAssetFile$1(bundleFile, asset) {
|
|
1841
1963
|
return asset.fileName || bundleFile;
|
|
1842
1964
|
}
|
|
1843
|
-
function readAssetSource(asset) {
|
|
1965
|
+
function readAssetSource$2(asset) {
|
|
1844
1966
|
return typeof asset.source === "string" ? asset.source : asset.source.toString();
|
|
1845
1967
|
}
|
|
1846
1968
|
function clearAssetSource(asset) {
|
|
1847
1969
|
asset.source = "";
|
|
1848
1970
|
}
|
|
1849
|
-
function appendCss(baseCss, css) {
|
|
1971
|
+
function appendCss$1(baseCss, css) {
|
|
1850
1972
|
if (baseCss.length === 0) return css;
|
|
1851
1973
|
if (css.length === 0) return baseCss;
|
|
1852
1974
|
return `${baseCss}\n${css}`;
|
|
@@ -1920,9 +2042,9 @@ function collectRootStyleBundleCssSources(bundle, excludedFile) {
|
|
|
1920
2042
|
const excludedFileKey = normalizeOutputPathKey(excludedFile);
|
|
1921
2043
|
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
1922
2044
|
if (output.type !== "asset") continue;
|
|
1923
|
-
const file = normalizeOutputPathKey(getAssetFile(bundleFile, output));
|
|
2045
|
+
const file = normalizeOutputPathKey(getAssetFile$1(bundleFile, output));
|
|
1924
2046
|
if (file === excludedFileKey || !isRootStyleOutputFile(file)) continue;
|
|
1925
|
-
const source = stripBundlerGeneratedCssMarkers(readAssetSource(output)).trim();
|
|
2047
|
+
const source = stripBundlerGeneratedCssMarkers(readAssetSource$2(output)).trim();
|
|
1926
2048
|
if (source.length > 0) sources.push(source);
|
|
1927
2049
|
}
|
|
1928
2050
|
return sources;
|
|
@@ -1962,9 +2084,9 @@ function removeCssCoveredByRootStyleAssets(bundle, options) {
|
|
|
1962
2084
|
let updated = 0;
|
|
1963
2085
|
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
1964
2086
|
if (output.type !== "asset") continue;
|
|
1965
|
-
const file = getAssetFile(bundleFile, output);
|
|
2087
|
+
const file = getAssetFile$1(bundleFile, output);
|
|
1966
2088
|
if (!options.cssMatcher(file) || isRootStyleOutputFile(file) || options.isViteProcessedCssAsset?.(output, file) === true || options.subpackageRoots != null && isSubpackageOutputFile(file, options.subpackageRoots)) continue;
|
|
1967
|
-
const rawSource = readAssetSource(output);
|
|
2089
|
+
const rawSource = readAssetSource$2(output);
|
|
1968
2090
|
const nextCss = removeCssCoveredByRootStyleBundleSources(bundle, file, rawSource);
|
|
1969
2091
|
if (nextCss === rawSource) continue;
|
|
1970
2092
|
output.source = nextCss;
|
|
@@ -1985,8 +2107,29 @@ function isRootStyleOutputFile(file) {
|
|
|
1985
2107
|
const normalized = normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
1986
2108
|
return isCssOutputFile(normalized) && !normalized.includes("/");
|
|
1987
2109
|
}
|
|
2110
|
+
function isMiniProgramStyleOutputFile(file) {
|
|
2111
|
+
return /\.(?:wxss|acss|ttss|qss|jxss|tyss)(?:$|[?#])/i.test(file);
|
|
2112
|
+
}
|
|
2113
|
+
function shouldPreserveMiniProgramImportShell(opts, file, css) {
|
|
2114
|
+
return (opts.appType === "taro" || opts.appType === "uni-app-vite" || opts.appType === "uni-app-x") && isMiniProgramStyleOutputFile(file) && opts.cssMatcher(file) && isPureLocalCssImportWrapper(css);
|
|
2115
|
+
}
|
|
2116
|
+
function resolvePreservedImportShellInjectionTarget(opts, bundle, file, css) {
|
|
2117
|
+
if (opts.appType !== "taro") return;
|
|
2118
|
+
const importedStyleFiles = collectImportedStyleFiles(css, file);
|
|
2119
|
+
if (importedStyleFiles.size !== 1) return;
|
|
2120
|
+
const [importedFile] = importedStyleFiles;
|
|
2121
|
+
if (!importedFile) return;
|
|
2122
|
+
if (!isRootStyleOutputFile(importedFile)) return;
|
|
2123
|
+
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2124
|
+
if (output.type !== "asset") continue;
|
|
2125
|
+
const outputFile = getAssetFile$1(bundleFile, output);
|
|
2126
|
+
if (normalizeOutputPathKey(outputFile) === normalizeOutputPathKey(importedFile)) return outputFile;
|
|
2127
|
+
}
|
|
2128
|
+
}
|
|
1988
2129
|
function shouldUseCssAssetAsMainInjectionTarget(opts, file, records) {
|
|
1989
2130
|
const fileKey = normalizeOutputPathKey(file);
|
|
2131
|
+
if (!isRootStyleOutputFile(file) && records.some((record) => typeof record.outputFile === "string" && normalizeOutputPathKey(record.outputFile) === fileKey)) return false;
|
|
2132
|
+
if (!isRootStyleOutputFile(file)) return records.some((record) => record.injectIntoMain === true && typeof record.outputFile === "string" && normalizeOutputPathKey(record.outputFile) === fileKey);
|
|
1990
2133
|
if (records.some((record) => {
|
|
1991
2134
|
if (record.injectIntoMain !== true) return false;
|
|
1992
2135
|
return isRootStyleOutputFile(file) || typeof record.outputFile === "string" && normalizeOutputPathKey(record.outputFile) === fileKey;
|
|
@@ -1996,8 +2139,16 @@ function shouldUseCssAssetAsMainInjectionTarget(opts, file, records) {
|
|
|
1996
2139
|
return isRootStyleOutputFile(file) && records.some((record) => record.injectIntoMain === true);
|
|
1997
2140
|
}
|
|
1998
2141
|
function isViteProcessedCssResultImported(record, importedStyleFiles) {
|
|
1999
|
-
|
|
2000
|
-
|
|
2142
|
+
return importedStyleFiles.has(normalizeOutputPathKey(record.file)) || typeof record.outputFile === "string" && importedStyleFiles.has(normalizeOutputPathKey(record.outputFile));
|
|
2143
|
+
}
|
|
2144
|
+
function isViteProcessedCssResultCoveredByImportedBundleAsset(record, importedStyleFiles, assetFiles) {
|
|
2145
|
+
for (const candidate of [record.file, record.outputFile]) {
|
|
2146
|
+
if (typeof candidate !== "string" || candidate.length === 0) continue;
|
|
2147
|
+
const candidateKey = normalizeOutputPathKey(candidate);
|
|
2148
|
+
if (!importedStyleFiles.has(candidateKey)) continue;
|
|
2149
|
+
if (assetFiles.has(candidateKey)) return true;
|
|
2150
|
+
}
|
|
2151
|
+
return false;
|
|
2001
2152
|
}
|
|
2002
2153
|
function removeCssCoveredByImportedViteResults(css, importedCssSources) {
|
|
2003
2154
|
if (importedCssSources.length === 0) return css;
|
|
@@ -2011,9 +2162,9 @@ function collectImportedBundleCssSources(bundle, importedStyleFiles) {
|
|
|
2011
2162
|
const importedSources = [];
|
|
2012
2163
|
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2013
2164
|
if (output.type !== "asset") continue;
|
|
2014
|
-
const file = normalizeOutputPathKey(getAssetFile(bundleFile, output));
|
|
2165
|
+
const file = normalizeOutputPathKey(getAssetFile$1(bundleFile, output));
|
|
2015
2166
|
if (!(importedStyleFiles.has(file) || !file.includes("/") && importedFileNames.has(posix.posix.basename(file)))) continue;
|
|
2016
|
-
importedSources.push(readAssetSource(output));
|
|
2167
|
+
importedSources.push(readAssetSource$2(output));
|
|
2017
2168
|
}
|
|
2018
2169
|
return importedSources;
|
|
2019
2170
|
}
|
|
@@ -2021,7 +2172,7 @@ function collectBundleAssetFiles(bundle) {
|
|
|
2021
2172
|
const files = /* @__PURE__ */ new Set();
|
|
2022
2173
|
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2023
2174
|
if (output.type !== "asset") continue;
|
|
2024
|
-
files.add(normalizeOutputPathKey(getAssetFile(bundleFile, output)));
|
|
2175
|
+
files.add(normalizeOutputPathKey(getAssetFile$1(bundleFile, output)));
|
|
2025
2176
|
}
|
|
2026
2177
|
return files;
|
|
2027
2178
|
}
|
|
@@ -2044,14 +2195,19 @@ function isCoveredViteGeneratedSourceAsset(file, existingAssetFiles, resolveVite
|
|
|
2044
2195
|
const resolvedOutputFile = normalizeOutputPathKey(resolveViteProcessedCssOutputFile?.(file) ?? file);
|
|
2045
2196
|
return resolvedOutputFile !== normalizeOutputPathKey(file) && existingAssetFiles.has(resolvedOutputFile);
|
|
2046
2197
|
}
|
|
2198
|
+
function isSourceRootPrefixedOutputFile(file, outputFile) {
|
|
2199
|
+
const fileKey = normalizeOutputPathKey(file);
|
|
2200
|
+
const outputFileKey = normalizeOutputPathKey(outputFile);
|
|
2201
|
+
return fileKey !== outputFileKey && fileKey.endsWith(`/${outputFileKey}`);
|
|
2202
|
+
}
|
|
2047
2203
|
function collectViteProcessedCssAssetResults(bundle, options) {
|
|
2048
2204
|
let collected = 0;
|
|
2049
2205
|
const existingAssetFiles = collectBundleAssetFiles(bundle);
|
|
2050
2206
|
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2051
2207
|
if (output.type !== "asset") continue;
|
|
2052
|
-
const file = getAssetFile(bundleFile, output);
|
|
2208
|
+
const file = getAssetFile$1(bundleFile, output);
|
|
2053
2209
|
if (!isCssOutputFile(file) || !options.isViteProcessedCssAsset?.(output, file)) continue;
|
|
2054
|
-
const rawSource = readAssetSource(output);
|
|
2210
|
+
const rawSource = readAssetSource$2(output);
|
|
2055
2211
|
let nextCss = resolveViteProcessedCssAssetSource(file, rawSource, options.resolveViteProcessedCssOutputFile);
|
|
2056
2212
|
const singleMarkerFile = collectSingleViteGeneratedCssMarkerFile(rawSource);
|
|
2057
2213
|
if (singleMarkerFile && (options.subpackageRoots == null || !isSubpackageOutputFile(file, options.subpackageRoots)) && shouldFilterRootGeneratedCssMarkerForScopedAsset(file, singleMarkerFile, options.resolveViteProcessedCssOutputFile)) nextCss = removeCssCoveredByRootStyleBundleSources(bundle, file, nextCss);
|
|
@@ -2059,7 +2215,7 @@ function collectViteProcessedCssAssetResults(bundle, options) {
|
|
|
2059
2215
|
options.markCssAssetProcessed?.(output, file);
|
|
2060
2216
|
options.recordCssAssetResult?.(file, nextCss);
|
|
2061
2217
|
const resolvedOutputFile = options.resolveViteProcessedCssOutputFile?.(file) ?? file;
|
|
2062
|
-
const shouldReplayIntoMainCss = options.opts != null && (options.opts.mainCssChunkMatcher(file, options.opts.appType) ||
|
|
2218
|
+
const shouldReplayIntoMainCss = options.opts != null && (isRootStyleOutputFile(file) && options.opts.mainCssChunkMatcher(file, options.opts.appType) || isSourceRootPrefixedOutputFile(file, resolvedOutputFile) && isRootStyleOutputFile(resolvedOutputFile) && options.opts.mainCssChunkMatcher(resolvedOutputFile, options.opts.appType));
|
|
2063
2219
|
options.recordViteProcessedCssAssetResult?.(file, nextCss, {
|
|
2064
2220
|
injectIntoMain: shouldReplayIntoMainCss || void 0,
|
|
2065
2221
|
outputFile: resolvedOutputFile
|
|
@@ -2104,20 +2260,42 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
2104
2260
|
};
|
|
2105
2261
|
}).filter((record) => record.css.length > 0);
|
|
2106
2262
|
let injected = 0;
|
|
2107
|
-
for (const [bundleFile,
|
|
2263
|
+
for (const [bundleFile, bundleOutput] of Object.entries(bundle)) {
|
|
2264
|
+
let output = bundleOutput;
|
|
2108
2265
|
if (output.type !== "asset") continue;
|
|
2109
|
-
|
|
2266
|
+
let file = getAssetFile$1(bundleFile, output);
|
|
2110
2267
|
if (!options.opts.cssMatcher(file) || !shouldUseCssAssetAsMainInjectionTarget(options.opts, file, viteCssResults)) continue;
|
|
2268
|
+
let originalSource = readAssetSource$2(output);
|
|
2269
|
+
if (shouldPreserveMiniProgramImportShell(options.opts, file, originalSource)) {
|
|
2270
|
+
const importedTargetFile = resolvePreservedImportShellInjectionTarget(options.opts, bundle, file, originalSource);
|
|
2271
|
+
if (typeof importedTargetFile === "string") {
|
|
2272
|
+
options.debug?.("preserve mini-program css import shell asset: %s -> %s", file, importedTargetFile);
|
|
2273
|
+
const importedOutput = Object.entries(bundle).find(([candidateFile, candidate]) => candidate.type === "asset" && normalizeOutputPathKey(getAssetFile$1(candidateFile, candidate)) === normalizeOutputPathKey(importedTargetFile))?.[1];
|
|
2274
|
+
if (importedOutput?.type === "asset") {
|
|
2275
|
+
output = importedOutput;
|
|
2276
|
+
file = importedTargetFile;
|
|
2277
|
+
originalSource = readAssetSource$2(output);
|
|
2278
|
+
} else continue;
|
|
2279
|
+
} else {
|
|
2280
|
+
options.debug?.("preserve mini-program css import shell asset: %s", file);
|
|
2281
|
+
continue;
|
|
2282
|
+
}
|
|
2283
|
+
}
|
|
2284
|
+
const fileKey = normalizeOutputPathKey(file);
|
|
2111
2285
|
const mainFileKey = normalizeOutputPathKey(file);
|
|
2112
|
-
const originalSource = readAssetSource(output);
|
|
2113
2286
|
let nextCss = removeTailwindEntryDirectivesFromCss(originalSource);
|
|
2114
2287
|
const importedStyleFiles = collectImportedStyleFiles(nextCss, file);
|
|
2115
2288
|
const importedBundleCssSources = collectImportedBundleCssSources(bundle, importedStyleFiles);
|
|
2116
2289
|
nextCss = removeCssCoveredByImportedViteResults(nextCss, importedBundleCssSources);
|
|
2117
2290
|
const importedViteCssResults = viteCssResults.filter((record) => isViteProcessedCssResultImported(record, importedStyleFiles));
|
|
2118
|
-
const
|
|
2119
|
-
|
|
2291
|
+
const bundleAssetFiles = collectBundleAssetFiles(bundle);
|
|
2292
|
+
const uncoveredImportedViteCssResults = importedViteCssResults.filter((record) => !isViteProcessedCssResultCoveredByImportedBundleAsset(record, importedStyleFiles, bundleAssetFiles));
|
|
2293
|
+
const importedCssSources = [...importedBundleCssSources, ...uncoveredImportedViteCssResults.map((record) => record.css)];
|
|
2294
|
+
nextCss = removeCssCoveredByImportedViteResults(nextCss, uncoveredImportedViteCssResults.map((record) => record.css));
|
|
2120
2295
|
for (const record of viteCssResults) {
|
|
2296
|
+
if (!isRootStyleOutputFile(file)) {
|
|
2297
|
+
if (typeof record.outputFile !== "string" || normalizeOutputPathKey(record.outputFile) !== fileKey) continue;
|
|
2298
|
+
}
|
|
2121
2299
|
if (!shouldInjectViteProcessedCssResult(options.opts, mainFileKey, record.file, record)) continue;
|
|
2122
2300
|
if (isViteProcessedCssResultImported(record, importedStyleFiles)) continue;
|
|
2123
2301
|
let css = stripBundlerGeneratedCssMarkers(record.css).trim();
|
|
@@ -2129,6 +2307,7 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
2129
2307
|
css = extractMarkedUserLayerComponentsCss(css).rest.trim();
|
|
2130
2308
|
if (css.length === 0) continue;
|
|
2131
2309
|
}
|
|
2310
|
+
if (containsCssAfterMinify(nextCss, css) || filterExistingCssRules(nextCss, css).length === 0) continue;
|
|
2132
2311
|
if (containsCssAfterMinify(nextCss, css)) continue;
|
|
2133
2312
|
const mergedPreflightDeclarations = mergeMiniProgramPreflightRuleDeclarations(nextCss, css);
|
|
2134
2313
|
if (mergedPreflightDeclarations.changed) {
|
|
@@ -2150,7 +2329,7 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
2150
2329
|
}
|
|
2151
2330
|
const missingCss = filterExistingCssRules(nextCss, css);
|
|
2152
2331
|
if (missingCss.length === 0 || containsCssAfterMinify(nextCss, missingCss)) continue;
|
|
2153
|
-
nextCss = appendCss(nextCss, missingCss);
|
|
2332
|
+
nextCss = appendCss$1(nextCss, missingCss);
|
|
2154
2333
|
}
|
|
2155
2334
|
if (nextCss === originalSource) continue;
|
|
2156
2335
|
output.source = nextCss;
|
|
@@ -2163,9 +2342,10 @@ function injectViteProcessedCssIntoMainCssAssets(bundle, options) {
|
|
|
2163
2342
|
const recordFileKey = normalizeOutputPathKey(record.file);
|
|
2164
2343
|
for (const [candidateFile, candidateOutput] of Object.entries(bundle)) {
|
|
2165
2344
|
if (candidateOutput.type !== "asset") continue;
|
|
2166
|
-
const candidateKey = normalizeOutputPathKey(getAssetFile(candidateFile, candidateOutput));
|
|
2345
|
+
const candidateKey = normalizeOutputPathKey(getAssetFile$1(candidateFile, candidateOutput));
|
|
2167
2346
|
const isRecordFile = candidateKey === recordFileKey;
|
|
2168
|
-
const
|
|
2347
|
+
const candidateSource = readAssetSource$2(candidateOutput).trim();
|
|
2348
|
+
const isProcessedSource = candidateSource === record.css.trim() || candidateSource.length > 0 && containsCssAfterMinify(nextCss, candidateSource);
|
|
2169
2349
|
if (!isRecordFile && !isProcessedSource || candidateKey === normalizeOutputPathKey(file)) continue;
|
|
2170
2350
|
clearAssetSource(candidateOutput);
|
|
2171
2351
|
options.debug?.("remove injected vite-processed source css asset: %s -> %s", candidateKey, file);
|
|
@@ -2187,31 +2367,84 @@ function normalizeBundleFileNameKeysForTest(bundle) {
|
|
|
2187
2367
|
}
|
|
2188
2368
|
}
|
|
2189
2369
|
//#endregion
|
|
2370
|
+
//#region src/bundlers/vite/generate-bundle/final-css-assets.ts
|
|
2371
|
+
function readAssetSource$1(output) {
|
|
2372
|
+
return typeof output.source === "string" ? output.source : output.source.toString();
|
|
2373
|
+
}
|
|
2374
|
+
function shouldFinalizeMiniProgramCssAsset(source) {
|
|
2375
|
+
return source.includes(":hover") || source.includes("does-not-exist") || hasMiniProgramCssSpecificityPlaceholders(source);
|
|
2376
|
+
}
|
|
2377
|
+
async function finalizeMiniProgramCssAssets(bundle, options) {
|
|
2378
|
+
if (options.isWebGeneratorTarget) return 0;
|
|
2379
|
+
let updated = 0;
|
|
2380
|
+
for (const [bundleFile, output] of Object.entries(bundle)) {
|
|
2381
|
+
if (output.type !== "asset") continue;
|
|
2382
|
+
const file = output.fileName || bundleFile;
|
|
2383
|
+
if (!options.cssMatcher(file)) continue;
|
|
2384
|
+
const rawSource = readAssetSource$1(output);
|
|
2385
|
+
if (rawSource.trim().length === 0) continue;
|
|
2386
|
+
if (options.lastCssResultByFile?.has(file)) {
|
|
2387
|
+
const outputCss = stripMiniProgramCssSpecificityPlaceholders(rawSource);
|
|
2388
|
+
if (outputCss !== rawSource) {
|
|
2389
|
+
output.source = outputCss;
|
|
2390
|
+
options.recordCssAssetResult?.(file, outputCss);
|
|
2391
|
+
options.onUpdate(file, rawSource, outputCss);
|
|
2392
|
+
options.debug?.("strip mini-program css specificity placeholders: %s bytes=%d", file, outputCss.length);
|
|
2393
|
+
updated++;
|
|
2394
|
+
}
|
|
2395
|
+
continue;
|
|
2396
|
+
}
|
|
2397
|
+
if (!shouldFinalizeMiniProgramCssAsset(rawSource)) continue;
|
|
2398
|
+
const cssHandlerOptions = options.getCssHandlerOptions(file);
|
|
2399
|
+
const { css } = await options.styleHandler(rawSource, {
|
|
2400
|
+
...cssHandlerOptions,
|
|
2401
|
+
autoprefixer: false,
|
|
2402
|
+
cssOptions: {
|
|
2403
|
+
...cssHandlerOptions.cssOptions ?? {},
|
|
2404
|
+
autoprefixer: false,
|
|
2405
|
+
cssPresetEnv: {}
|
|
2406
|
+
},
|
|
2407
|
+
cssPresetEnv: {}
|
|
2408
|
+
});
|
|
2409
|
+
const outputCss = stripMiniProgramCssSpecificityPlaceholders(css);
|
|
2410
|
+
if (outputCss === rawSource) continue;
|
|
2411
|
+
output.source = outputCss;
|
|
2412
|
+
options.recordCssAssetResult?.(file, outputCss);
|
|
2413
|
+
options.onUpdate(file, rawSource, outputCss);
|
|
2414
|
+
options.debug?.("finalize mini-program css asset: %s bytes=%d", file, outputCss.length);
|
|
2415
|
+
updated++;
|
|
2416
|
+
}
|
|
2417
|
+
return updated;
|
|
2418
|
+
}
|
|
2419
|
+
//#endregion
|
|
2190
2420
|
//#region src/bundlers/vite/generate-bundle/memory-debug.ts
|
|
2191
|
-
function toMb(bytes) {
|
|
2421
|
+
function toMb$2(bytes) {
|
|
2192
2422
|
return Math.round(bytes / 1024 / 1024);
|
|
2193
2423
|
}
|
|
2194
|
-
function summarizeStringMapCache(map) {
|
|
2424
|
+
function summarizeStringMapCache$1(map) {
|
|
2195
2425
|
let bytes = 0;
|
|
2196
2426
|
for (const value of map.values()) bytes += value.length;
|
|
2197
2427
|
return {
|
|
2198
2428
|
bytes,
|
|
2199
|
-
mb: toMb(bytes),
|
|
2429
|
+
mb: toMb$2(bytes),
|
|
2200
2430
|
size: map.size
|
|
2201
2431
|
};
|
|
2202
2432
|
}
|
|
2203
2433
|
function resolveViteMemoryDebugStats(context) {
|
|
2204
2434
|
if (process$1.env["WEAPP_TW_HMR_MEMORY_DEBUG"] !== "1") return;
|
|
2205
2435
|
const memory = process$1.memoryUsage();
|
|
2436
|
+
const processCacheInstanceSize = context.cache.instance.size;
|
|
2437
|
+
const processCacheHashMapSize = context.cache.hashMap.size;
|
|
2206
2438
|
return {
|
|
2207
2439
|
phase: context.phase,
|
|
2208
2440
|
mode: context.useIncrementalMode ? "incremental" : "full",
|
|
2441
|
+
bundle: { hasOmittedKnownFiles: context.hasOmittedKnownFiles },
|
|
2209
2442
|
process: {
|
|
2210
|
-
rssMb: toMb(memory.rss),
|
|
2211
|
-
heapTotalMb: toMb(memory.heapTotal),
|
|
2212
|
-
heapUsedMb: toMb(memory.heapUsed),
|
|
2213
|
-
externalMb: toMb(memory.external),
|
|
2214
|
-
arrayBuffersMb: toMb(memory.arrayBuffers)
|
|
2443
|
+
rssMb: toMb$2(memory.rss),
|
|
2444
|
+
heapTotalMb: toMb$2(memory.heapTotal),
|
|
2445
|
+
heapUsedMb: toMb$2(memory.heapUsed),
|
|
2446
|
+
externalMb: toMb$2(memory.external),
|
|
2447
|
+
arrayBuffersMb: toMb$2(memory.arrayBuffers)
|
|
2215
2448
|
},
|
|
2216
2449
|
runtime: {
|
|
2217
2450
|
sourceCandidates: context.sourceCandidatesSize,
|
|
@@ -2220,19 +2453,21 @@ function resolveViteMemoryDebugStats(context) {
|
|
|
2220
2453
|
generatorRuntime: context.generatorRuntimeSize
|
|
2221
2454
|
},
|
|
2222
2455
|
processCache: {
|
|
2223
|
-
instance:
|
|
2224
|
-
hashMap:
|
|
2456
|
+
instance: processCacheInstanceSize,
|
|
2457
|
+
hashMap: processCacheHashMapSize,
|
|
2225
2458
|
activeCacheKeys: context.activeProcessCacheKeys.size,
|
|
2226
|
-
activeHashKeys: context.activeProcessHashKeys.size
|
|
2459
|
+
activeHashKeys: context.activeProcessHashKeys.size,
|
|
2460
|
+
staleCacheKeys: Math.max(0, processCacheInstanceSize - context.activeProcessCacheKeys.size),
|
|
2461
|
+
staleHashKeys: Math.max(0, processCacheHashMapSize - context.activeProcessHashKeys.size),
|
|
2462
|
+
pruned: context.processCachePruned,
|
|
2463
|
+
pruneSkipped: !context.processCachePruned,
|
|
2464
|
+
...context.processCachePruneSkipReason ? { pruneSkipReason: context.processCachePruneSkipReason } : {}
|
|
2227
2465
|
},
|
|
2228
2466
|
viteCss: {
|
|
2229
2467
|
...context.getViteCssCacheStats?.(),
|
|
2230
|
-
lastCssResultByFile: summarizeStringMapCache(context.lastCssResultByFile)
|
|
2468
|
+
lastCssResultByFile: summarizeStringMapCache$1(context.lastCssResultByFile)
|
|
2231
2469
|
},
|
|
2232
|
-
tailwind: {
|
|
2233
|
-
v3: getTailwindV3IncrementalGenerateCacheStats(),
|
|
2234
|
-
v4: getTailwindV4IncrementalGenerateCacheStats()
|
|
2235
|
-
}
|
|
2470
|
+
tailwind: { v4: getTailwindV4IncrementalGenerateCacheStats() }
|
|
2236
2471
|
};
|
|
2237
2472
|
}
|
|
2238
2473
|
//#endregion
|
|
@@ -2271,6 +2506,27 @@ function formatMs(value) {
|
|
|
2271
2506
|
}
|
|
2272
2507
|
//#endregion
|
|
2273
2508
|
//#region src/bundlers/vite/generate-bundle/uni-app-x-postprocess.ts
|
|
2509
|
+
function appendCss(baseCss, css) {
|
|
2510
|
+
if (baseCss.length === 0) return css;
|
|
2511
|
+
if (css.length === 0) return baseCss;
|
|
2512
|
+
return `${baseCss}\n${css}`;
|
|
2513
|
+
}
|
|
2514
|
+
function injectHarmonyCssIntoMainAsset(bundle, cssSources, onUpdate, debug) {
|
|
2515
|
+
const output = bundle["main.css"];
|
|
2516
|
+
if (output?.type !== "asset" || cssSources.length === 0) return false;
|
|
2517
|
+
const currentSource = String(output.source);
|
|
2518
|
+
let nextSource = currentSource;
|
|
2519
|
+
for (const css of cssSources) {
|
|
2520
|
+
const trimmedCss = css.trim();
|
|
2521
|
+
if (trimmedCss.length === 0 || nextSource.includes(trimmedCss)) continue;
|
|
2522
|
+
nextSource = appendCss(nextSource, trimmedCss);
|
|
2523
|
+
}
|
|
2524
|
+
if (nextSource === currentSource) return false;
|
|
2525
|
+
output.source = nextSource;
|
|
2526
|
+
onUpdate("main.css", currentSource, nextSource);
|
|
2527
|
+
debug("uni-app-x harmony main css inject");
|
|
2528
|
+
return true;
|
|
2529
|
+
}
|
|
2274
2530
|
async function handleUniAppXPostCssTasks(options) {
|
|
2275
2531
|
const { bundle, debug, generatorRuntime, getCssHandlerOptions, getSourceCandidateSourcesForEntries, getSourceCandidatesForEntries, getViteProcessedCssAssetResults, isHarmonyAppStyleTarget, isNativeAppStyleTarget, onUpdate, opts, runtimeState, styleHandler } = options;
|
|
2276
2532
|
const applyStyleSources = collectUniAppXHarmonyApplyStyleSources(bundle);
|
|
@@ -2281,12 +2537,13 @@ async function handleUniAppXPostCssTasks(options) {
|
|
|
2281
2537
|
if (isHarmonyAppStyleTarget && applyUtilities.size > 0 && applyStyleSources.length > 0) {
|
|
2282
2538
|
const outputFile = "uni-app-x-harmony-apply.css";
|
|
2283
2539
|
const cssHandlerOptions = getCssHandlerOptions(outputFile);
|
|
2284
|
-
const generated = await
|
|
2540
|
+
const generated = await generateTailwindV4Css({
|
|
2285
2541
|
opts,
|
|
2286
2542
|
runtimeState,
|
|
2287
2543
|
runtime: new Set([...generatorRuntime, ...applyUtilities]),
|
|
2288
2544
|
rawSource: createUniAppXHarmonyApplyGeneratorSource(applyStyleSources, applyUtilities),
|
|
2289
2545
|
file: outputFile,
|
|
2546
|
+
outputFile,
|
|
2290
2547
|
cssHandlerOptions,
|
|
2291
2548
|
cssUserHandlerOptions: {
|
|
2292
2549
|
...cssHandlerOptions,
|
|
@@ -2302,6 +2559,7 @@ async function handleUniAppXPostCssTasks(options) {
|
|
|
2302
2559
|
}));
|
|
2303
2560
|
}
|
|
2304
2561
|
if (isHarmonyAppStyleTarget && injectUniAppXHarmonyBundleStyles(bundle, { cssSources: viteProcessedCssSources })) debug("uni-app-x harmony bundle styles inject");
|
|
2562
|
+
if (isHarmonyAppStyleTarget) injectHarmonyCssIntoMainAsset(bundle, viteProcessedCssSources, onUpdate, debug);
|
|
2305
2563
|
for (const [file, item] of Object.entries(bundle)) {
|
|
2306
2564
|
if (item.type !== "asset" || !file.endsWith(".uvue.ts")) continue;
|
|
2307
2565
|
const currentSource = String(item.source);
|
|
@@ -2317,10 +2575,10 @@ async function handleUniAppXPostCssTasks(options) {
|
|
|
2317
2575
|
//#endregion
|
|
2318
2576
|
//#region src/bundlers/vite/generate-bundle/vite-css-cache.ts
|
|
2319
2577
|
const VITE_LAST_CSS_RESULT_CACHE_MAX = 64;
|
|
2320
|
-
function resolveViteCssTaskConcurrency(
|
|
2578
|
+
function resolveViteCssTaskConcurrency(_useIncrementalMode, _majorVersion) {
|
|
2321
2579
|
const configured = Number.parseInt(process$1.env["WEAPP_TW_VITE_CSS_CONCURRENCY"] ?? "", 10);
|
|
2322
2580
|
if (Number.isFinite(configured) && configured > 0) return configured;
|
|
2323
|
-
return
|
|
2581
|
+
return 1;
|
|
2324
2582
|
}
|
|
2325
2583
|
function normalizeViteCssCacheKey(file) {
|
|
2326
2584
|
return normalizeOutputPathKey(file);
|
|
@@ -2361,13 +2619,88 @@ function pruneLastCssResults(resultByFile, sourceHashByFile, activeFiles) {
|
|
|
2361
2619
|
}
|
|
2362
2620
|
//#endregion
|
|
2363
2621
|
//#region src/bundlers/vite/generate-bundle/finalize.ts
|
|
2622
|
+
function readAssetSource(asset) {
|
|
2623
|
+
return typeof asset.source === "string" ? asset.source : asset.source.toString();
|
|
2624
|
+
}
|
|
2625
|
+
function getAssetFile(bundleFile, asset) {
|
|
2626
|
+
return asset.fileName || bundleFile;
|
|
2627
|
+
}
|
|
2628
|
+
function isRootMiniProgramStyleOutputFile(file) {
|
|
2629
|
+
const normalized = normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
2630
|
+
return !normalized.includes("/") && /\.(?:wxss|acss|ttss|qss|jxss|tyss)$/i.test(normalized);
|
|
2631
|
+
}
|
|
2632
|
+
function createRelativeCssImportRequest(targetFile, importedFile) {
|
|
2633
|
+
const normalizedTargetFile = normalizeOutputPathKey(targetFile.replace(/[?#].*$/, ""));
|
|
2634
|
+
const normalizedImportedFile = normalizeOutputPathKey(importedFile.replace(/[?#].*$/, ""));
|
|
2635
|
+
const targetDir = path.posix.dirname(normalizedTargetFile);
|
|
2636
|
+
const baseDir = targetDir === "." ? "" : targetDir;
|
|
2637
|
+
const relative = path.posix.relative(baseDir, normalizedImportedFile);
|
|
2638
|
+
return relative.startsWith(".") ? relative : `./${relative}`;
|
|
2639
|
+
}
|
|
2640
|
+
function createCssImportShell(targetFile, importedFile) {
|
|
2641
|
+
return `@import "${createRelativeCssImportRequest(targetFile, importedFile)}";\n`;
|
|
2642
|
+
}
|
|
2643
|
+
function resolveRootMiniProgramOriginStyleFile(file) {
|
|
2644
|
+
const normalized = normalizeOutputPathKey(file.replace(/[?#].*$/, ""));
|
|
2645
|
+
if (!isRootMiniProgramStyleOutputFile(normalized)) return;
|
|
2646
|
+
if (/(?:^|\/)[^/]+-origin\.[^.]+$/i.test(normalized)) return;
|
|
2647
|
+
return normalized.replace(/(\.[^.]+)$/, "-origin$1");
|
|
2648
|
+
}
|
|
2649
|
+
function resolveSingleCssImportOutputFile(targetFile, css) {
|
|
2650
|
+
let importedFile;
|
|
2651
|
+
try {
|
|
2652
|
+
postcss.parse(css).walkAtRules("import", (atRule) => {
|
|
2653
|
+
if (importedFile !== void 0) return;
|
|
2654
|
+
const request = parseImportRequest(atRule.params);
|
|
2655
|
+
if (!request || /^(?:https?:)?\/\//i.test(request) || request.startsWith("data:")) return;
|
|
2656
|
+
const cleanRequest = request.replace(/[?#].*$/, "");
|
|
2657
|
+
if (!/\.(?:css|wxss|acss|ttss|qss|jxss|tyss)$/i.test(cleanRequest)) return;
|
|
2658
|
+
const targetDir = path.posix.dirname(normalizeOutputPathKey(targetFile));
|
|
2659
|
+
importedFile = normalizeOutputPathKey(path.posix.join(targetDir === "." ? "" : targetDir, cleanRequest));
|
|
2660
|
+
});
|
|
2661
|
+
} catch {}
|
|
2662
|
+
return importedFile;
|
|
2663
|
+
}
|
|
2664
|
+
function normalizeTaroRootImportShellAssets(bundle, options) {
|
|
2665
|
+
if (options.appType !== "taro") return 0;
|
|
2666
|
+
let updated = 0;
|
|
2667
|
+
for (const [rootBundleFile, rootOutput] of Object.entries(bundle)) {
|
|
2668
|
+
if (rootOutput.type !== "asset") continue;
|
|
2669
|
+
const rootFile = getAssetFile(rootBundleFile, rootOutput);
|
|
2670
|
+
if (!isRootMiniProgramStyleOutputFile(rootFile) || !options.cssMatcher(rootFile)) continue;
|
|
2671
|
+
const originFile = resolveRootMiniProgramOriginStyleFile(rootFile);
|
|
2672
|
+
if (!originFile || !options.cssMatcher(originFile)) continue;
|
|
2673
|
+
const originOutput = Object.entries(bundle).find(([bundleFile, output]) => output.type === "asset" && normalizeOutputPathKey(getAssetFile(bundleFile, output)) === normalizeOutputPathKey(originFile))?.[1];
|
|
2674
|
+
if (originOutput?.type !== "asset") continue;
|
|
2675
|
+
const rootSource = readAssetSource(rootOutput);
|
|
2676
|
+
if (isPureLocalCssImportWrapper(rootSource)) continue;
|
|
2677
|
+
const originSource = readAssetSource(originOutput);
|
|
2678
|
+
if (isPureLocalCssImportWrapper(originSource)) {
|
|
2679
|
+
const importedFile = resolveSingleCssImportOutputFile(originFile, originSource);
|
|
2680
|
+
if (importedFile && normalizeOutputPathKey(importedFile) !== normalizeOutputPathKey(rootFile)) continue;
|
|
2681
|
+
} else if (originSource.trim().length > 0 && originSource.trim() !== rootSource.trim()) continue;
|
|
2682
|
+
const nextRootSource = createCssImportShell(rootFile, originFile);
|
|
2683
|
+
if (rootSource === nextRootSource) continue;
|
|
2684
|
+
rootOutput.source = nextRootSource;
|
|
2685
|
+
originOutput.source = rootSource;
|
|
2686
|
+
options.recordCssAssetResult?.(rootFile, nextRootSource);
|
|
2687
|
+
options.recordCssAssetResult?.(originFile, rootSource);
|
|
2688
|
+
options.onUpdate?.(rootFile, rootSource, nextRootSource);
|
|
2689
|
+
options.onUpdate?.(originFile, originSource, rootSource);
|
|
2690
|
+
options.debug("normalize taro root css import shell: %s -> %s", rootFile, originFile);
|
|
2691
|
+
updated++;
|
|
2692
|
+
}
|
|
2693
|
+
return updated;
|
|
2694
|
+
}
|
|
2364
2695
|
async function finalizeGenerateBundle(options) {
|
|
2365
|
-
const { activeProcessCacheKeys, activeProcessHashKeys, activeViteCssCacheFiles, bundle, bundleFiles, cache, cssTaskFactories, debug, defaultStyleOutputExtension, formatIteration, generatorCandidateSignature, generatorRuntime, getCssHandlerOptions, getSourceCandidateSourcesForEntries, getSourceCandidatesForEntries, getViteCssCacheStats, getViteProcessedCssAssetResults, hmrTimingRecorder, hmrTimingStartedAt, isHarmonyAppStyleTarget, isNativeAppStyleTarget, isViteProcessedCssAsset, isWebGeneratorTarget, lastCssResultByFile, lastCssSourceHashByFile, linkedByEntry, markCssAssetProcessed, metrics, onEnd, onUpdate, opts, pendingLinkedUpdates, pruneViteCssCaches, recordCssAssetResult, recordTimingDetail, recordViteProcessedCssAssetResult, rootDir, runtime, runtimeState, shouldPreserveAppCssExtension, snapshot, sourceCandidates, sourceRoot, state, styleHandler, tasks, timingDetails, transformRuntime, useIncrementalMode } = options;
|
|
2696
|
+
const { activeProcessCacheKeys, activeProcessHashKeys, activeViteCssCacheFiles, bundle, bundleFiles, cache, cssTaskFactories, debug, defaultStyleOutputExtension, formatIteration, generatorCandidateSignature, generatorRuntime, getCssHandlerOptions, getSourceCandidateSourcesForEntries, getSourceCandidatesForEntries, getViteCssCacheStats, getViteProcessedCssAssetResults, hmrTimingRecorder, hmrTimingStartedAt, isHarmonyAppStyleTarget, isNativeAppStyleTarget, isViteProcessedCssAsset, isWebGeneratorTarget, jsAfterCss, jsTaskFactories, lastCssResultByFile, lastCssSourceHashByFile, linkedByEntry, markCssAssetProcessed, metrics, onEnd, onUpdate, opts, pendingLinkedUpdates, pruneViteCssCaches, recordCssAssetResult, recordTimingDetail, recordViteProcessedCssAssetResult, rootDir, runtime, runtimeState, shouldPreserveAppCssExtension, snapshot, sourceCandidates, sourceRoot, state, styleHandler, tasks, timingDetails, transformRuntime, useIncrementalMode } = options;
|
|
2697
|
+
const tasksStart = performance.now();
|
|
2366
2698
|
if (cssTaskFactories.length > 0) {
|
|
2367
|
-
const
|
|
2368
|
-
|
|
2699
|
+
const cssTask = runWithConcurrency(cssTaskFactories, resolveViteCssTaskConcurrency(useIncrementalMode, runtimeState.tailwindRuntime.majorVersion)).then(() => void 0);
|
|
2700
|
+
if (jsAfterCss) await cssTask;
|
|
2701
|
+
else tasks.push(cssTask);
|
|
2369
2702
|
}
|
|
2370
|
-
|
|
2703
|
+
if (jsTaskFactories.length > 0) tasks.push(runWithConcurrency(jsTaskFactories).then(() => void 0));
|
|
2371
2704
|
await Promise.all(tasks);
|
|
2372
2705
|
recordTimingDetail("tasks", tasksStart);
|
|
2373
2706
|
for (const apply of pendingLinkedUpdates) apply();
|
|
@@ -2402,9 +2735,10 @@ async function finalizeGenerateBundle(options) {
|
|
|
2402
2735
|
getViteProcessedCssAssetResults,
|
|
2403
2736
|
markCssAssetProcessed,
|
|
2404
2737
|
recordCssAssetResult,
|
|
2405
|
-
shouldRemoveInjectedSourceAsset: (
|
|
2406
|
-
if (record.injectIntoMain
|
|
2407
|
-
|
|
2738
|
+
shouldRemoveInjectedSourceAsset: (targetFile, record) => {
|
|
2739
|
+
if (record.injectIntoMain === false) return false;
|
|
2740
|
+
const targetFileKey = normalizeOutputPathKey(targetFile);
|
|
2741
|
+
return normalizeOutputPathKey(record.file) !== targetFileKey;
|
|
2408
2742
|
},
|
|
2409
2743
|
debug,
|
|
2410
2744
|
onUpdate
|
|
@@ -2415,6 +2749,13 @@ async function finalizeGenerateBundle(options) {
|
|
|
2415
2749
|
if (injectUniAppXHarmonyBundleStyles(bundle, { cssSources: [...getViteProcessedCssAssetResults?.() ?? []].map(([, record]) => typeof record === "string" ? record : record.css) })) debug("uni-app-x harmony bundle styles inject after css assets");
|
|
2416
2750
|
syncViteProcessedCssIntoMainCssAssets();
|
|
2417
2751
|
}
|
|
2752
|
+
normalizeTaroRootImportShellAssets(bundle, {
|
|
2753
|
+
appType: opts.appType,
|
|
2754
|
+
cssMatcher: opts.cssMatcher,
|
|
2755
|
+
debug,
|
|
2756
|
+
onUpdate,
|
|
2757
|
+
recordCssAssetResult
|
|
2758
|
+
});
|
|
2418
2759
|
normalizeBundleFileNameKeysForTest(bundle);
|
|
2419
2760
|
removeCssCoveredByRootStyleAssets(bundle, {
|
|
2420
2761
|
cssMatcher: opts.cssMatcher,
|
|
@@ -2424,18 +2765,33 @@ async function finalizeGenerateBundle(options) {
|
|
|
2424
2765
|
recordCssAssetResult,
|
|
2425
2766
|
subpackageRoots: collectMiniProgramSubpackageRoots(bundle)
|
|
2426
2767
|
});
|
|
2768
|
+
await finalizeMiniProgramCssAssets(bundle, {
|
|
2769
|
+
cssMatcher: opts.cssMatcher,
|
|
2770
|
+
debug,
|
|
2771
|
+
getCssHandlerOptions,
|
|
2772
|
+
isWebGeneratorTarget,
|
|
2773
|
+
lastCssResultByFile,
|
|
2774
|
+
onUpdate,
|
|
2775
|
+
recordCssAssetResult,
|
|
2776
|
+
styleHandler
|
|
2777
|
+
});
|
|
2427
2778
|
const stateUpdateStart = performance.now();
|
|
2428
2779
|
updateBundleBuildState(state, snapshot, useIncrementalMode ? linkedByEntry ?? /* @__PURE__ */ new Map() : /* @__PURE__ */ new Map(), { incremental: useIncrementalMode });
|
|
2429
2780
|
state.generatorCandidateSignature = generatorCandidateSignature;
|
|
2430
|
-
|
|
2781
|
+
const shouldPruneTransientCaches = !snapshot.hasOmittedKnownFiles;
|
|
2782
|
+
const processCachePruned = useIncrementalMode && shouldPruneTransientCaches && typeof cache.prune === "function";
|
|
2783
|
+
const processCachePruneSkipReason = processCachePruned ? void 0 : !useIncrementalMode ? "full-mode" : !shouldPruneTransientCaches ? "omitted-known-files" : "cache-prune-unavailable";
|
|
2784
|
+
if (processCachePruned) cache.prune?.({
|
|
2431
2785
|
cacheKeys: activeProcessCacheKeys,
|
|
2432
2786
|
hashKeys: activeProcessHashKeys
|
|
2433
2787
|
});
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2788
|
+
if (shouldPruneTransientCaches) {
|
|
2789
|
+
pruneLastCssResults(lastCssResultByFile, lastCssSourceHashByFile, activeViteCssCacheFiles);
|
|
2790
|
+
pruneViteCssCaches?.({
|
|
2791
|
+
activeFiles: activeViteCssCacheFiles,
|
|
2792
|
+
activeKnownSfcFiles: new Set([...snapshot.sourceHashByFile.keys(), ...snapshot.entries.map((entry) => entry.file)])
|
|
2793
|
+
});
|
|
2794
|
+
}
|
|
2439
2795
|
recordTimingDetail("state.update", stateUpdateStart);
|
|
2440
2796
|
debug("metrics iteration=%d runtime=%sms html(total=%d transform=%d hit=%d rate=%s elapsed=%sms) js(total=%d transform=%d hit=%d rate=%s elapsed=%sms) css(total=%d transform=%d hit=%d rate=%s elapsed=%sms)", formatIteration, formatMs(metrics.runtimeSet), metrics.html.total, metrics.html.transformed, metrics.html.cacheHits, formatCacheHitRate(metrics.html), formatMs(metrics.html.elapsed), metrics.js.total, metrics.js.transformed, metrics.js.cacheHits, formatCacheHitRate(metrics.js), formatMs(metrics.js.elapsed), metrics.css.total, metrics.css.transformed, metrics.css.cacheHits, formatCacheHitRate(metrics.css), formatMs(metrics.css.elapsed));
|
|
2441
2797
|
if (hmrTimingRecorder) {
|
|
@@ -2447,8 +2803,11 @@ async function finalizeGenerateBundle(options) {
|
|
|
2447
2803
|
cache,
|
|
2448
2804
|
generatorRuntimeSize: generatorRuntime.size,
|
|
2449
2805
|
getViteCssCacheStats,
|
|
2806
|
+
hasOmittedKnownFiles: snapshot.hasOmittedKnownFiles,
|
|
2450
2807
|
lastCssResultByFile,
|
|
2451
2808
|
phase: "generateBundle",
|
|
2809
|
+
processCachePruned,
|
|
2810
|
+
processCachePruneSkipReason,
|
|
2452
2811
|
runtimeSize: runtime.size,
|
|
2453
2812
|
sourceCandidatesSize: sourceCandidates.size,
|
|
2454
2813
|
transformRuntimeSize: transformRuntime.size,
|
|
@@ -2461,6 +2820,120 @@ async function finalizeGenerateBundle(options) {
|
|
|
2461
2820
|
debug("end");
|
|
2462
2821
|
}
|
|
2463
2822
|
//#endregion
|
|
2823
|
+
//#region src/bundlers/vite/generate-bundle/candidates.ts
|
|
2824
|
+
const MUSTACHE_EXPRESSION_RE = /\{\{[\s\S]*?\}\}/g;
|
|
2825
|
+
const QUOTED_LITERAL_RE = /'([^']*)'|"([^"]*)"|`([^`]*)`/g;
|
|
2826
|
+
const CLASS_ATTRIBUTE_RE = /\bclass\s*=\s*/g;
|
|
2827
|
+
const MUSTACHE_OPEN = "{{";
|
|
2828
|
+
const MUSTACHE_CLOSE = "}}";
|
|
2829
|
+
function isUrlLikeCandidate(candidate) {
|
|
2830
|
+
return candidate.startsWith("//") || candidate.startsWith("http://") || candidate.startsWith("https://");
|
|
2831
|
+
}
|
|
2832
|
+
function isArbitraryValueCandidate(candidate) {
|
|
2833
|
+
return candidate.includes("[") && candidate.includes("]") && !isUrlLikeCandidate(candidate.trim());
|
|
2834
|
+
}
|
|
2835
|
+
function collectClassAttributeValues(source) {
|
|
2836
|
+
const values = [];
|
|
2837
|
+
CLASS_ATTRIBUTE_RE.lastIndex = 0;
|
|
2838
|
+
let matched = CLASS_ATTRIBUTE_RE.exec(source);
|
|
2839
|
+
while (matched !== null) {
|
|
2840
|
+
const quoteIndex = CLASS_ATTRIBUTE_RE.lastIndex;
|
|
2841
|
+
const quote = source[quoteIndex];
|
|
2842
|
+
if (quote !== "\"" && quote !== "'") {
|
|
2843
|
+
matched = CLASS_ATTRIBUTE_RE.exec(source);
|
|
2844
|
+
continue;
|
|
2845
|
+
}
|
|
2846
|
+
let expressionDepth = 0;
|
|
2847
|
+
for (let index = quoteIndex + 1; index < source.length; index++) {
|
|
2848
|
+
if (source.startsWith(MUSTACHE_OPEN, index)) {
|
|
2849
|
+
expressionDepth++;
|
|
2850
|
+
index += 1;
|
|
2851
|
+
continue;
|
|
2852
|
+
}
|
|
2853
|
+
if (expressionDepth > 0 && source.startsWith(MUSTACHE_CLOSE, index)) {
|
|
2854
|
+
expressionDepth--;
|
|
2855
|
+
index += 1;
|
|
2856
|
+
continue;
|
|
2857
|
+
}
|
|
2858
|
+
if (expressionDepth === 0 && source[index] === quote) {
|
|
2859
|
+
values.push(source.slice(quoteIndex + 1, index));
|
|
2860
|
+
CLASS_ATTRIBUTE_RE.lastIndex = index + 1;
|
|
2861
|
+
break;
|
|
2862
|
+
}
|
|
2863
|
+
}
|
|
2864
|
+
matched = CLASS_ATTRIBUTE_RE.exec(source);
|
|
2865
|
+
}
|
|
2866
|
+
return values;
|
|
2867
|
+
}
|
|
2868
|
+
function collectUnescapedDynamicCandidates(source, allowedCandidates) {
|
|
2869
|
+
const matches = /* @__PURE__ */ new Set();
|
|
2870
|
+
const shouldFilterByAllowedCandidates = allowedCandidates !== void 0 && allowedCandidates.size > 0;
|
|
2871
|
+
for (const classValue of collectClassAttributeValues(source)) for (const expression of classValue.match(MUSTACHE_EXPRESSION_RE) ?? []) {
|
|
2872
|
+
QUOTED_LITERAL_RE.lastIndex = 0;
|
|
2873
|
+
let quoted = QUOTED_LITERAL_RE.exec(expression);
|
|
2874
|
+
while (quoted !== null) {
|
|
2875
|
+
const literal = quoted[1] ?? quoted[2] ?? quoted[3] ?? "";
|
|
2876
|
+
for (const candidate of splitCandidateTokens(literal)) {
|
|
2877
|
+
const normalized = candidate.trim();
|
|
2878
|
+
if (!normalized || !isArbitraryValueCandidate(normalized)) continue;
|
|
2879
|
+
if (shouldFilterByAllowedCandidates && !allowedCandidates.has(normalized)) continue;
|
|
2880
|
+
matches.add(normalized);
|
|
2881
|
+
}
|
|
2882
|
+
quoted = QUOTED_LITERAL_RE.exec(expression);
|
|
2883
|
+
}
|
|
2884
|
+
}
|
|
2885
|
+
return [...matches];
|
|
2886
|
+
}
|
|
2887
|
+
//#endregion
|
|
2888
|
+
//#region src/bundlers/vite/generate-bundle/html-processing.ts
|
|
2889
|
+
function processHtmlBundleEntry(options) {
|
|
2890
|
+
const { cache, context, debug, dynamicRetryCandidates, file, metrics, onUpdate, originalEntrySource, originalSource, rememberProcessCacheKey, resolveCurrentSourceCandidateSource, tasks, templateHandler, timeTask, transformRuntime, transformRuntimeSignature } = options;
|
|
2891
|
+
const rawSource = resolveCurrentSourceCandidateSource(file) ?? originalEntrySource;
|
|
2892
|
+
const currentRawDynamicCandidates = collectUnescapedDynamicCandidates(rawSource);
|
|
2893
|
+
const templateRuntime = currentRawDynamicCandidates.length > 0 ? new Set([...transformRuntime, ...currentRawDynamicCandidates]) : transformRuntime;
|
|
2894
|
+
const templateRuntimeSignature = templateRuntime === transformRuntime ? transformRuntimeSignature : createCandidateSignature(templateRuntime);
|
|
2895
|
+
const htmlProcessHash = `${cache.computeHash(rawSource)}:${cache.computeHash(createRuntimeAffectingSourceSignature(rawSource, "html"))}:${templateRuntimeSignature}`;
|
|
2896
|
+
const cacheKey = `${file}:html:${htmlProcessHash}`;
|
|
2897
|
+
const hashKey = cacheKey;
|
|
2898
|
+
rememberProcessCacheKey(cacheKey, hashKey);
|
|
2899
|
+
tasks.push(timeTask("html", () => processCachedTask({
|
|
2900
|
+
cache,
|
|
2901
|
+
cacheKey,
|
|
2902
|
+
hashKey,
|
|
2903
|
+
hash: htmlProcessHash,
|
|
2904
|
+
applyResult(source) {
|
|
2905
|
+
originalSource.source = source;
|
|
2906
|
+
},
|
|
2907
|
+
onCacheHit() {
|
|
2908
|
+
metrics.html.cacheHits++;
|
|
2909
|
+
debug("html cache hit: %s", file);
|
|
2910
|
+
},
|
|
2911
|
+
async transform() {
|
|
2912
|
+
const start = performance.now();
|
|
2913
|
+
let transformed = await templateHandler(rawSource, { runtimeSet: templateRuntime });
|
|
2914
|
+
let unresolvedDynamicCandidates = collectUnescapedDynamicCandidates(transformed);
|
|
2915
|
+
let retryRuntimeSet;
|
|
2916
|
+
if (unresolvedDynamicCandidates.length > 0) {
|
|
2917
|
+
const fullRuntimeSet = await context.ensureRuntimeClassSet(true);
|
|
2918
|
+
const allowedRetryCandidates = fullRuntimeSet.size === 0 ? unresolvedDynamicCandidates : unresolvedDynamicCandidates.filter((candidate) => dynamicRetryCandidates.has(candidate) || fullRuntimeSet.has(candidate));
|
|
2919
|
+
retryRuntimeSet = new Set([...fullRuntimeSet, ...allowedRetryCandidates]);
|
|
2920
|
+
unresolvedDynamicCandidates = unresolvedDynamicCandidates.filter((candidate) => retryRuntimeSet?.has(candidate) === true);
|
|
2921
|
+
}
|
|
2922
|
+
if (retryRuntimeSet && unresolvedDynamicCandidates.length > 0) {
|
|
2923
|
+
logger.warn("检测到已提取 WXML 动态类名未完成转译,已回退到完整 runtimeSet 重试: %s -> %O", file, unresolvedDynamicCandidates);
|
|
2924
|
+
transformed = await templateHandler(rawSource, { runtimeSet: retryRuntimeSet });
|
|
2925
|
+
unresolvedDynamicCandidates = collectUnescapedDynamicCandidates(transformed, retryRuntimeSet);
|
|
2926
|
+
if (unresolvedDynamicCandidates.length > 0) logger.warn("已提取 WXML 动态类名在完整 runtimeSet 重试后仍未完成转译: %s -> %O", file, unresolvedDynamicCandidates);
|
|
2927
|
+
}
|
|
2928
|
+
metrics.html.elapsed += measureElapsed(start);
|
|
2929
|
+
metrics.html.transformed++;
|
|
2930
|
+
onUpdate(file, rawSource, transformed);
|
|
2931
|
+
debug("html handle: %s", file);
|
|
2932
|
+
return { result: transformed };
|
|
2933
|
+
}
|
|
2934
|
+
})));
|
|
2935
|
+
}
|
|
2936
|
+
//#endregion
|
|
2464
2937
|
//#region src/bundlers/vite/generate-bundle/js-entries.ts
|
|
2465
2938
|
function createJsEntryResolver(jsEntries) {
|
|
2466
2939
|
const normalizedJsEntries = /* @__PURE__ */ new Map();
|
|
@@ -2475,6 +2948,7 @@ function resolveUniAppXJsTransformEnabled(uniAppX) {
|
|
|
2475
2948
|
function createJsHandlerOptionsFactory(options) {
|
|
2476
2949
|
return (absoluteFilename, extra) => ({
|
|
2477
2950
|
...extra,
|
|
2951
|
+
generateMap: false,
|
|
2478
2952
|
filename: absoluteFilename,
|
|
2479
2953
|
tailwindcssMajorVersion: options.getMajorVersion(),
|
|
2480
2954
|
moduleGraph: options.moduleGraph,
|
|
@@ -2509,62 +2983,14 @@ function createLinkedUpdateHelpers(options) {
|
|
|
2509
2983
|
function collectLinkedFileNames(linked, getJsEntry, linkedSet) {
|
|
2510
2984
|
if (!linked || !linkedSet) return;
|
|
2511
2985
|
for (const id of Object.keys(linked)) {
|
|
2512
|
-
const linkedEntry = getJsEntry(id);
|
|
2513
|
-
if (linkedEntry) linkedSet.add(linkedEntry.fileName);
|
|
2514
|
-
}
|
|
2515
|
-
}
|
|
2516
|
-
//#endregion
|
|
2517
|
-
//#region src/bundlers/vite/generate-bundle/signatures.ts
|
|
2518
|
-
function summarizeStringDiff(previous, next) {
|
|
2519
|
-
if (previous === next) return "same";
|
|
2520
|
-
const previousLength = previous.length;
|
|
2521
|
-
const nextLength = next.length;
|
|
2522
|
-
const minLength = Math.min(previousLength, nextLength);
|
|
2523
|
-
let prefixLength = 0;
|
|
2524
|
-
while (prefixLength < minLength && previous.charCodeAt(prefixLength) === next.charCodeAt(prefixLength)) prefixLength += 1;
|
|
2525
|
-
let previousSuffixCursor = previousLength - 1;
|
|
2526
|
-
let nextSuffixCursor = nextLength - 1;
|
|
2527
|
-
while (previousSuffixCursor >= prefixLength && nextSuffixCursor >= prefixLength && previous.charCodeAt(previousSuffixCursor) === next.charCodeAt(nextSuffixCursor)) {
|
|
2528
|
-
previousSuffixCursor -= 1;
|
|
2529
|
-
nextSuffixCursor -= 1;
|
|
2530
|
-
}
|
|
2531
|
-
const previousChangedLength = previousSuffixCursor >= prefixLength ? previousSuffixCursor - prefixLength + 1 : 0;
|
|
2532
|
-
const nextChangedLength = nextSuffixCursor >= prefixLength ? nextSuffixCursor - prefixLength + 1 : 0;
|
|
2533
|
-
return `changed@${prefixLength} old=${previousChangedLength} new=${nextChangedLength} len=${previousLength}->${nextLength}`;
|
|
2534
|
-
}
|
|
2535
|
-
function createLinkedImpactSignature(entry, linkedImpactsByEntry, sourceHashByFile) {
|
|
2536
|
-
const changedLinkedFiles = linkedImpactsByEntry.get(entry);
|
|
2537
|
-
if (!changedLinkedFiles || changedLinkedFiles.size === 0) return;
|
|
2538
|
-
return [...changedLinkedFiles].sort().map((file) => {
|
|
2539
|
-
return `${file}:${sourceHashByFile.get(file) ?? "missing"}`;
|
|
2540
|
-
}).join(",");
|
|
2541
|
-
}
|
|
2542
|
-
function createJsHashSalt(runtimeSignature, linkedImpactSignature) {
|
|
2543
|
-
if (!linkedImpactSignature) return runtimeSignature;
|
|
2544
|
-
return `${runtimeSignature}:linked:${linkedImpactSignature}`;
|
|
2545
|
-
}
|
|
2546
|
-
function createStableTextSignature(input) {
|
|
2547
|
-
let hash = 2166136261;
|
|
2548
|
-
for (let i = 0; i < input.length; i++) {
|
|
2549
|
-
hash ^= input.charCodeAt(i);
|
|
2550
|
-
hash = Math.imul(hash, 16777619);
|
|
2986
|
+
const linkedEntry = getJsEntry(id);
|
|
2987
|
+
if (linkedEntry) linkedSet.add(linkedEntry.fileName);
|
|
2551
2988
|
}
|
|
2552
|
-
return (hash >>> 0).toString(36);
|
|
2553
|
-
}
|
|
2554
|
-
function createCandidateSignature(candidates) {
|
|
2555
|
-
if (candidates.size === 0) return "empty";
|
|
2556
|
-
return createStableTextSignature([...candidates].sort().join("\n"));
|
|
2557
|
-
}
|
|
2558
|
-
function getSnapshotHash(snapshotMap, file, fallback) {
|
|
2559
|
-
return snapshotMap.get(file) ?? fallback;
|
|
2560
|
-
}
|
|
2561
|
-
function hasRuntimeAffectingSourceChanges(changedByType) {
|
|
2562
|
-
return changedByType.html.size > 0 || changedByType.js.size > 0;
|
|
2563
2989
|
}
|
|
2564
2990
|
//#endregion
|
|
2565
2991
|
//#region src/bundlers/vite/generate-bundle/js-processing.ts
|
|
2566
2992
|
function processJsBundleEntry(options) {
|
|
2567
|
-
const { applyLinkedUpdates, bundle, cache, createHandlerOptions, debug, disableJsPrecheck, entry, getJsEntry, jsHandler, jsTaskFactories, linkedByEntry, metrics, onUpdate, outDir, processFiles, rememberProcessCacheKey, runtimeSignature, snapshot, timeTask, transformRuntime, uniAppX, useIncrementalMode } = options;
|
|
2993
|
+
const { applyLinkedUpdates, bundle, cache, createHandlerOptions, debug, disableJsPrecheck, entry, getJsEntry, jsHandler, jsTaskFactories, linkedByEntry, metrics, onUpdate, outDir, processFiles, rememberProcessCacheKey, runtimeSignature, snapshot, shouldSkipAstTransform, slowJsAstWarnMs, timeTask, transformRuntime, transformRuntimeSignature, transformFilterSignature, uniAppX, useIncrementalMode } = options;
|
|
2568
2994
|
const { file, output: originalSource, source: originalEntrySource } = entry;
|
|
2569
2995
|
metrics.js.total++;
|
|
2570
2996
|
const shouldTransformJs = !useIncrementalMode || processFiles.js.has(file);
|
|
@@ -2574,16 +3000,27 @@ function processJsBundleEntry(options) {
|
|
|
2574
3000
|
const initialRawSource = originalEntrySource;
|
|
2575
3001
|
const linkedSet = useIncrementalMode ? /* @__PURE__ */ new Set() : void 0;
|
|
2576
3002
|
if (linkedByEntry && linkedSet) linkedByEntry.set(file, linkedSet);
|
|
3003
|
+
const linkedImpactSignature = useIncrementalMode ? createLinkedImpactSignature(file, snapshot.linkedImpactsByEntry, snapshot.sourceHashByFile) : void 0;
|
|
3004
|
+
const hashSalt = createJsHashSalt(`${transformRuntimeSignature}:transform-filter:${transformFilterSignature}`, linkedImpactSignature);
|
|
3005
|
+
const hashKey = `${file}:js`;
|
|
3006
|
+
const processHash = `${getSnapshotHash(snapshot.sourceHashByFile, file, initialRawSource)}:${hashSalt}`;
|
|
3007
|
+
rememberProcessCacheKey(file, hashKey);
|
|
3008
|
+
if (useIncrementalMode && !shouldTransformJs) {
|
|
3009
|
+
const cachedCode = cache.getHashValue(hashKey)?.hash === processHash ? cache.get(file) : void 0;
|
|
3010
|
+
if (cachedCode !== void 0) {
|
|
3011
|
+
originalSource.code = cachedCode;
|
|
3012
|
+
metrics.js.cacheHits++;
|
|
3013
|
+
debug("js direct replay hit: %s", file);
|
|
3014
|
+
return;
|
|
3015
|
+
}
|
|
3016
|
+
}
|
|
2577
3017
|
jsTaskFactories.push(async () => {
|
|
2578
3018
|
await timeTask("js", async () => {
|
|
2579
|
-
const hashSalt = createJsHashSalt(runtimeSignature, useIncrementalMode ? createLinkedImpactSignature(file, snapshot.linkedImpactsByEntry, snapshot.sourceHashByFile) : void 0);
|
|
2580
|
-
const hashKey = `${file}:js`;
|
|
2581
|
-
rememberProcessCacheKey(file, hashKey);
|
|
2582
3019
|
await processCachedTask({
|
|
2583
3020
|
cache,
|
|
2584
3021
|
cacheKey: file,
|
|
2585
3022
|
hashKey,
|
|
2586
|
-
hash:
|
|
3023
|
+
hash: processHash,
|
|
2587
3024
|
applyResult(source) {
|
|
2588
3025
|
originalSource.code = source;
|
|
2589
3026
|
},
|
|
@@ -2595,15 +3032,24 @@ function processJsBundleEntry(options) {
|
|
|
2595
3032
|
const start = performance.now();
|
|
2596
3033
|
const rawSource = originalSource.code;
|
|
2597
3034
|
if (!shouldTransformJs) debug("js cache replay miss, fallback transform: %s", file);
|
|
3035
|
+
if (shouldSkipAstTransform?.(originalSource)) {
|
|
3036
|
+
metrics.js.elapsed += measureElapsed(start);
|
|
3037
|
+
metrics.js.transformed++;
|
|
3038
|
+
debug("js skip ast transform (filtered): %s", file);
|
|
3039
|
+
return { result: rawSource };
|
|
3040
|
+
}
|
|
2598
3041
|
const handlerOptions = createHandlerOptions(absoluteFile);
|
|
2599
3042
|
if (!disableJsPrecheck && shouldSkipJsTransform(rawSource, handlerOptions)) {
|
|
2600
3043
|
metrics.js.elapsed += measureElapsed(start);
|
|
2601
3044
|
metrics.js.transformed++;
|
|
2602
3045
|
return { result: rawSource };
|
|
2603
3046
|
}
|
|
3047
|
+
const handlerStart = performance.now();
|
|
2604
3048
|
const { code, linked } = await jsHandler(rawSource, transformRuntime, handlerOptions);
|
|
3049
|
+
const handlerElapsed = measureElapsed(handlerStart);
|
|
2605
3050
|
metrics.js.elapsed += measureElapsed(start);
|
|
2606
3051
|
metrics.js.transformed++;
|
|
3052
|
+
if (handlerElapsed >= slowJsAstWarnMs) logger$1.warn("JS AST 转译耗时较长: %s 用时 %sms,源码约 %d bytes。若这是大型生成 TS/JS chunk,请配置 weapp-tailwindcss 的 transform.exclude 排除 generated/openapi 等目录。", file, handlerElapsed.toFixed(1), rawSource.length);
|
|
2607
3053
|
onUpdate(file, rawSource, code);
|
|
2608
3054
|
debug("js handle: %s", file);
|
|
2609
3055
|
collectLinkedFileNames(linked, getJsEntry, linkedSet);
|
|
@@ -2730,7 +3176,8 @@ function mergeRememberedCssSources(sources, outputFile) {
|
|
|
2730
3176
|
function collectRememberedCssReplayGroups(sources, opts, rootDir, isWebGeneratorTarget, preserveCssExtension, sourceRoot, styleOutputExtension, styleOutputFiles) {
|
|
2731
3177
|
const groups = /* @__PURE__ */ new Map();
|
|
2732
3178
|
for (const [key, remembered] of sources ?? []) {
|
|
2733
|
-
const
|
|
3179
|
+
const cleanSourceFile = remembered.sourceFile.replace(/[?#].*$/, "");
|
|
3180
|
+
const outputKey = normalizeOutputPathKey(CSS_SOURCE_OUTPUT_EXT_RE.test(cleanSourceFile) ? resolveViteCssPipelineOutputFileFromSourceFile(remembered.sourceFile, opts, rootDir, isWebGeneratorTarget, preserveCssExtension, sourceRoot, styleOutputExtension, styleOutputFiles) : resolveViteCssPipelineOutputFileFromSourceFile(remembered.outputFile, opts, rootDir, isWebGeneratorTarget, preserveCssExtension, sourceRoot, styleOutputExtension, styleOutputFiles));
|
|
2734
3181
|
const group = groups.get(outputKey) ?? [];
|
|
2735
3182
|
group.push({
|
|
2736
3183
|
key,
|
|
@@ -2741,40 +3188,17 @@ function collectRememberedCssReplayGroups(sources, opts, rootDir, isWebGenerator
|
|
|
2741
3188
|
return groups;
|
|
2742
3189
|
}
|
|
2743
3190
|
//#endregion
|
|
2744
|
-
//#region src/bundlers/vite/generate-bundle/scoped-generator.ts
|
|
2745
|
-
function hasOwnSourceDirectives(rawSource) {
|
|
2746
|
-
return rawSource.includes("@source") || rawSource.includes("@config");
|
|
2747
|
-
}
|
|
2748
|
-
async function createScopedGeneratorCandidateSignature(rawSource, sourceFile, fallbackSignature, getSourceCandidatesForEntries, options = {}) {
|
|
2749
|
-
if (!getSourceCandidatesForEntries || !hasOwnSourceDirectives(rawSource)) return fallbackSignature;
|
|
2750
|
-
const sourceBase = path.dirname(path.resolve(sourceFile.replace(/[?#].*$/, "")));
|
|
2751
|
-
const resolved = options.majorVersion === 3 ? await resolveTailwindConfigEntriesFromCssCached(rawSource, sourceBase) : await resolveTailwindV4EntriesFromCssCached(rawSource, sourceBase);
|
|
2752
|
-
if (resolved?.entries === void 0) return fallbackSignature;
|
|
2753
|
-
const scopedSignature = createCandidateSignature(getSourceCandidatesForEntries(resolved.entries));
|
|
2754
|
-
return options.includeFallbackSignature === true ? `${scopedSignature}:${fallbackSignature}` : scopedSignature;
|
|
2755
|
-
}
|
|
2756
|
-
async function createScopedGeneratorRuntime(options) {
|
|
2757
|
-
const { cssHandlerOptions, fallbackRuntime, getSourceCandidatesForEntries, majorVersion, outputFile, rawSource, shouldExcludeSubpackageSourceCandidates, sourceFile, scopedSourceCandidateGetter } = options;
|
|
2758
|
-
if (getSourceCandidatesForEntries && rawSource && sourceFile) {
|
|
2759
|
-
const sourceBase = path.dirname(path.resolve(sourceFile.replace(/[?#].*$/, "")));
|
|
2760
|
-
const resolved = majorVersion === 3 ? await resolveTailwindConfigEntriesFromCssCached(rawSource, sourceBase) : await resolveTailwindV4EntriesFromCssCached(rawSource, sourceBase);
|
|
2761
|
-
if (resolved?.entries !== void 0 && (resolved.entries.length > 0 || hasOwnSourceDirectives(rawSource))) return scopedSourceCandidateGetter?.(resolved.entries) ?? getSourceCandidatesForEntries(resolved.entries);
|
|
2762
|
-
}
|
|
2763
|
-
const scopedCandidates = scopedSourceCandidateGetter?.(void 0);
|
|
2764
|
-
if (scopedCandidates && (scopedCandidates.size > 0 || shouldExcludeSubpackageSourceCandidates(outputFile, cssHandlerOptions))) return scopedCandidates;
|
|
2765
|
-
if (!shouldExcludeSubpackageSourceCandidates(outputFile, cssHandlerOptions)) return fallbackRuntime;
|
|
2766
|
-
return fallbackRuntime;
|
|
2767
|
-
}
|
|
2768
|
-
//#endregion
|
|
2769
3191
|
//#region src/bundlers/vite/generate-bundle/remembered-css-replay.ts
|
|
2770
3192
|
async function processRememberedCssReplay(options) {
|
|
2771
3193
|
const { addWatchFile, activeViteCssCacheFiles, bundleFiles, cache, createScopedGeneratorRuntime, createScopedSourceCandidateGetter, createScopedSourceCandidateSourceGetter, cssTaskFactories, debug, defaultStyleOutputExtension, emitOrReplayCssAsset, generatorRuntime, getCssHandlerOptions, getCssUserHandlerOptions, getRememberedCssSignature, getRememberedCssSources, isNativeAppStyleTarget, isWebGeneratorTarget, lastCssResultByFile, lastCssSourceHashByFile, markCssAssetProcessed, metrics, normalizeViteCssCacheKey, onUpdate, opts, recordCssAssetResult, recordViteProcessedCssAssetResult, refreshRememberedCssSource, rootDir, runtimeState, setRememberedCssSignature, shouldInjectCssIntoMainFromOutput, shouldPreserveAppCssExtension, sourceRoot, styleHandler, timeTask, useIncrementalMode } = options;
|
|
2772
3194
|
const rememberedReplayGroups = collectRememberedCssReplayGroups(getRememberedCssSources?.(), opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension, sourceRoot, defaultStyleOutputExtension, bundleFiles);
|
|
2773
3195
|
for (const [outputFile, rememberedGroup] of rememberedReplayGroups) {
|
|
3196
|
+
if (isHTMLRequest(outputFile) || options.opts.htmlMatcher(outputFile)) continue;
|
|
2774
3197
|
const refreshedRememberedGroup = await Promise.all(rememberedGroup.map(async (item) => ({
|
|
2775
3198
|
key: item.key,
|
|
2776
3199
|
remembered: await refreshRememberedCssSource?.(item.remembered) ?? item.remembered
|
|
2777
3200
|
})));
|
|
3201
|
+
const rememberedKeys = refreshedRememberedGroup.map((item) => item.key);
|
|
2778
3202
|
const rememberedCssSource = mergeRememberedCssSources(refreshedRememberedGroup.map((item) => item.remembered), outputFile);
|
|
2779
3203
|
if (!rememberedCssSource) continue;
|
|
2780
3204
|
const { rawSource, sourceFile } = rememberedCssSource;
|
|
@@ -2787,33 +3211,33 @@ async function processRememberedCssReplay(options) {
|
|
|
2787
3211
|
};
|
|
2788
3212
|
const scopedSourceCandidateGetter = createScopedSourceCandidateGetter(outputFile, cssHandlerOptions);
|
|
2789
3213
|
const scopedSourceCandidateSourceGetter = createScopedSourceCandidateSourceGetter(outputFile, cssHandlerOptions);
|
|
2790
|
-
const sourceTraceTokenSources = scopedSourceCandidateSourceGetter ? createCssTokenSourceMap(scopedSourceCandidateSourceGetter(void 0), opts) : void 0;
|
|
2791
|
-
const annotateCss = (css) => annotateCssSourceTrace(css, {
|
|
2792
|
-
opts,
|
|
2793
|
-
tokenSources: sourceTraceTokenSources
|
|
2794
|
-
});
|
|
2795
3214
|
const scopedGeneratorRuntime = await createScopedGeneratorRuntime(outputFile, cssHandlerOptions, generatorRuntime, rawSource, sourceFile);
|
|
2796
3215
|
const cssRuntimeSignature = createCssRuntimeSignature(createCandidateSignature(scopedGeneratorRuntime), await createScopedGeneratorCandidateSignature(rawSource, sourceFile, createCandidateSignature(scopedGeneratorRuntime), scopedSourceCandidateGetter, {
|
|
2797
3216
|
includeFallbackSignature: cssHandlerOptions.isMainChunk,
|
|
2798
|
-
majorVersion: runtimeState.
|
|
3217
|
+
majorVersion: runtimeState.tailwindRuntime.majorVersion
|
|
2799
3218
|
}));
|
|
2800
3219
|
const cssRuntimeAffectingHash = cache.computeHash(createRuntimeAffectingSourceSignature(rawSource, "css"));
|
|
2801
3220
|
const rememberedCssRuntimeSignature = createRememberedCssRuntimeSignature(cssRuntimeSignature, cssRuntimeAffectingHash);
|
|
2802
3221
|
const previousCss = useIncrementalMode && getLastCssSourceHash(lastCssSourceHashByFile, outputFile) === cssRuntimeAffectingHash ? getLastCssResult(lastCssResultByFile, outputFile) : void 0;
|
|
2803
|
-
const rememberedKeys = refreshedRememberedGroup.map((item) => item.key);
|
|
2804
3222
|
const allRememberedSignaturesFresh = rememberedKeys.length > 0 && rememberedKeys.every((key) => getRememberedCssSignature?.(key) === rememberedCssRuntimeSignature);
|
|
2805
3223
|
if (bundleFiles.includes(outputFile) || bundleFiles.includes(sourceFile) || allRememberedSignaturesFresh) continue;
|
|
3224
|
+
const sourceTraceTokenSources = scopedSourceCandidateSourceGetter ? createCssTokenSourceMap(scopedSourceCandidateSourceGetter(void 0), opts) : void 0;
|
|
3225
|
+
const annotateCss = (css) => annotateCssSourceTrace(css, {
|
|
3226
|
+
opts,
|
|
3227
|
+
tokenSources: sourceTraceTokenSources
|
|
3228
|
+
});
|
|
2806
3229
|
const shouldRecordRememberedReplayCss = useIncrementalMode || isNativeAppStyleTarget;
|
|
2807
3230
|
const shouldEmitRememberedReplayCssAsset = shouldRecordRememberedReplayCss;
|
|
2808
3231
|
if (!shouldRecordRememberedReplayCss) continue;
|
|
2809
3232
|
cssTaskFactories.push(() => timeTask("css.replay", async () => {
|
|
2810
3233
|
const start = performance.now();
|
|
2811
|
-
const generated = await
|
|
3234
|
+
const generated = await generateTailwindV4Css({
|
|
2812
3235
|
opts,
|
|
2813
3236
|
runtimeState,
|
|
2814
3237
|
runtime: scopedGeneratorRuntime,
|
|
2815
3238
|
rawSource,
|
|
2816
3239
|
file: sourceFile,
|
|
3240
|
+
outputFile,
|
|
2817
3241
|
cssHandlerOptions,
|
|
2818
3242
|
cssUserHandlerOptions: getCssUserHandlerOptions(sourceFile),
|
|
2819
3243
|
getSourceCandidatesForEntries: scopedSourceCandidateGetter,
|
|
@@ -2836,7 +3260,7 @@ async function processRememberedCssReplay(options) {
|
|
|
2836
3260
|
}
|
|
2837
3261
|
if (shouldEmitRememberedReplayCssAsset) {
|
|
2838
3262
|
const replayAsset = emitOrReplayCssAsset(outputFile, css);
|
|
2839
|
-
markCssAssetProcessed?.(replayAsset, outputFile);
|
|
3263
|
+
if (replayAsset) markCssAssetProcessed?.(replayAsset, outputFile);
|
|
2840
3264
|
}
|
|
2841
3265
|
metrics.css.elapsed += measureElapsed(start);
|
|
2842
3266
|
metrics.css.transformed++;
|
|
@@ -2891,6 +3315,26 @@ function collectJsImportedCssFiles(snapshot) {
|
|
|
2891
3315
|
return files;
|
|
2892
3316
|
}
|
|
2893
3317
|
//#endregion
|
|
3318
|
+
//#region src/bundlers/vite/generate-bundle/runtime-linked-source-memory.ts
|
|
3319
|
+
function rememberRuntimeLinkedCssSources(options) {
|
|
3320
|
+
const { bundleFiles, defaultStyleOutputExtension, debug, getConfiguredTailwindV4CssSourceEntries, getSourceCandidateSource, getSourceCandidateSources, isWebGeneratorTarget, jsImportedCssFiles, opts, outDir, rememberCssSource, rootDir, runtimeLinkedCssFiles, shouldPreserveAppCssExtension, snapshot, sourceRoot } = options;
|
|
3321
|
+
for (const file of runtimeLinkedCssFiles) {
|
|
3322
|
+
if (snapshot.sourceHashByFile.has(file)) {
|
|
3323
|
+
snapshot.processFiles.css.add(file);
|
|
3324
|
+
continue;
|
|
3325
|
+
}
|
|
3326
|
+
const outputFile = resolveViteCssPipelineOutputFile(file, opts, rootDir, isWebGeneratorTarget, shouldPreserveAppCssExtension, sourceRoot, defaultStyleOutputExtension, bundleFiles);
|
|
3327
|
+
const inferredSourceStyle = resolveSourceStyleSourceFromOutputFile(outputFile, snapshot, outDir, sourceRoot, getSourceCandidateSource, jsImportedCssFiles.has(file) ? getSourceCandidateSources : void 0, getConfiguredTailwindV4CssSourceEntries().map((entry) => [entry.file, entry.source]), debug);
|
|
3328
|
+
const rawSource = inferredSourceStyle?.rawSource ?? getSourceCandidateSource?.(path.resolve(outDir, file)) ?? getSourceCandidateSource?.(file);
|
|
3329
|
+
if (rawSource === void 0 || !hasTailwindGenerationSource(rawSource)) continue;
|
|
3330
|
+
rememberCssSource?.({
|
|
3331
|
+
outputFile,
|
|
3332
|
+
rawSource,
|
|
3333
|
+
sourceFile: inferredSourceStyle?.sourceFile ?? path.resolve(outDir, file)
|
|
3334
|
+
});
|
|
3335
|
+
}
|
|
3336
|
+
}
|
|
3337
|
+
//#endregion
|
|
2894
3338
|
//#region src/bundlers/vite/generate-bundle/source-candidate-scope.ts
|
|
2895
3339
|
function intersectCandidateSets(left, right) {
|
|
2896
3340
|
if (left.size === 0 || right.size === 0) return /* @__PURE__ */ new Set();
|
|
@@ -2905,11 +3349,43 @@ function intersectCandidateSourceMaps(left, right) {
|
|
|
2905
3349
|
for (const [candidate, sources] of left) if (right.has(candidate)) matched.set(candidate, sources);
|
|
2906
3350
|
return matched;
|
|
2907
3351
|
}
|
|
3352
|
+
function normalizeSourceFile(file) {
|
|
3353
|
+
return path.resolve(file.replace(/[?#].*$/, ""));
|
|
3354
|
+
}
|
|
3355
|
+
function resolveSubpackageSourceRootFromFile(file, subpackageRoot) {
|
|
3356
|
+
const normalizedFile = normalizeSourceFile(file).split(path.sep).join("/");
|
|
3357
|
+
const normalizedRoot = subpackageRoot.replace(/\\/g, "/").replace(/^\/+|\/+$/g, "");
|
|
3358
|
+
if (!normalizedRoot) return;
|
|
3359
|
+
const rootSegment = `/${normalizedRoot}/`;
|
|
3360
|
+
const rootIndex = normalizedFile.lastIndexOf(rootSegment);
|
|
3361
|
+
if (rootIndex < 0) return;
|
|
3362
|
+
return normalizedFile.slice(0, rootIndex);
|
|
3363
|
+
}
|
|
3364
|
+
function collectSubpackageSourceRootsFromCssSources(cssSourceFiles, subpackageRoots) {
|
|
3365
|
+
const sourceRootsByPackageRoot = /* @__PURE__ */ new Map();
|
|
3366
|
+
if (!cssSourceFiles || !subpackageRoots) return sourceRootsByPackageRoot;
|
|
3367
|
+
for (const file of cssSourceFiles) {
|
|
3368
|
+
if (typeof file !== "string" || file.length === 0) continue;
|
|
3369
|
+
for (const root of subpackageRoots) {
|
|
3370
|
+
const sourceRoot = resolveSubpackageSourceRootFromFile(file, root);
|
|
3371
|
+
if (!sourceRoot) continue;
|
|
3372
|
+
const roots = sourceRootsByPackageRoot.get(root) ?? /* @__PURE__ */ new Set();
|
|
3373
|
+
roots.add(sourceRoot);
|
|
3374
|
+
sourceRootsByPackageRoot.set(root, roots);
|
|
3375
|
+
}
|
|
3376
|
+
}
|
|
3377
|
+
return sourceRootsByPackageRoot;
|
|
3378
|
+
}
|
|
3379
|
+
function flattenSourceRoots(sourceRootsByPackageRoot) {
|
|
3380
|
+
return [...new Set([...sourceRootsByPackageRoot.values()].flatMap((roots) => [...roots]))];
|
|
3381
|
+
}
|
|
2908
3382
|
function createSubpackageSourceCandidateScope(options) {
|
|
3383
|
+
const cssSourceRootsByPackageRoot = collectSubpackageSourceRootsFromCssSources(options.cssSourceFiles, options.subpackageRoots);
|
|
2909
3384
|
const subpackageSourceExcludeEntries = options.subpackageRoots ? collectMiniProgramSubpackageSourceEntries(options.snapshot, options.subpackageRoots, [
|
|
2910
3385
|
options.rootDir,
|
|
2911
3386
|
options.tailwindcssBasedir,
|
|
2912
|
-
options.projectRoot
|
|
3387
|
+
options.projectRoot,
|
|
3388
|
+
...flattenSourceRoots(cssSourceRootsByPackageRoot)
|
|
2913
3389
|
]) : [];
|
|
2914
3390
|
const isMainPackageStyleOutputFile = (file) => options.subpackageRoots != null && !isSubpackageOutputFile(file, options.subpackageRoots);
|
|
2915
3391
|
const resolveSubpackageOutputSourceEntries = (outputFile) => {
|
|
@@ -2918,6 +3394,12 @@ function createSubpackageSourceCandidateScope(options) {
|
|
|
2918
3394
|
if (matchedRoots.length !== 1) return;
|
|
2919
3395
|
const root = matchedRoots[0];
|
|
2920
3396
|
if (!root) return;
|
|
3397
|
+
const configuredSourceRoots = cssSourceRootsByPackageRoot.get(root);
|
|
3398
|
+
if (configuredSourceRoots?.size === 1) return [{
|
|
3399
|
+
base: [...configuredSourceRoots][0],
|
|
3400
|
+
negated: false,
|
|
3401
|
+
pattern: `${root}/**/*`
|
|
3402
|
+
}];
|
|
2921
3403
|
return options.sourceRoot ? [{
|
|
2922
3404
|
base: options.sourceRoot,
|
|
2923
3405
|
negated: false,
|
|
@@ -2969,7 +3451,7 @@ function createSubpackageSourceCandidateScope(options) {
|
|
|
2969
3451
|
excludeEntries: [...filterOptions?.excludeEntries ?? [], ...subpackageSourceExcludeEntries]
|
|
2970
3452
|
}) ?? /* @__PURE__ */ new Map();
|
|
2971
3453
|
};
|
|
2972
|
-
const shouldInjectCssIntoMainFromOutput = (outputFile, _sourceFile, outputCssHandlerOptions) => outputCssHandlerOptions.isMainChunk === true || options.useIncrementalMode && isMainPackageStyleOutputFile(outputFile);
|
|
3454
|
+
const shouldInjectCssIntoMainFromOutput = (outputFile, _sourceFile, outputCssHandlerOptions) => outputCssHandlerOptions.isMainChunk === true && !outputFile.replace(/[?#].*$/, "").includes("/") || options.useIncrementalMode && isMainPackageStyleOutputFile(outputFile);
|
|
2973
3455
|
return {
|
|
2974
3456
|
createScopedSourceCandidateGetter,
|
|
2975
3457
|
createScopedSourceCandidateSourceGetter,
|
|
@@ -2978,6 +3460,111 @@ function createSubpackageSourceCandidateScope(options) {
|
|
|
2978
3460
|
};
|
|
2979
3461
|
}
|
|
2980
3462
|
//#endregion
|
|
3463
|
+
//#region src/bundlers/vite/generate-bundle/source-candidate-source.ts
|
|
3464
|
+
function normalizeSourceCandidatePathKey(file) {
|
|
3465
|
+
return normalizeOutputPathKey(path.resolve(file));
|
|
3466
|
+
}
|
|
3467
|
+
function resolveCurrentSourceCandidateSource(options) {
|
|
3468
|
+
const { file, getSourceCandidateSource, getSourceCandidateSources, outDir, rootDir, sourceRoot } = options;
|
|
3469
|
+
const cleanedFile = file.replace(/[?#].*$/, "");
|
|
3470
|
+
const normalizedFile = normalizeOutputPathKey(cleanedFile);
|
|
3471
|
+
const absoluteFile = path.isAbsolute(cleanedFile) ? cleanedFile : path.resolve(rootDir, cleanedFile);
|
|
3472
|
+
const relativeFromOutDir = normalizeOutputPathKey(path.relative(outDir, absoluteFile));
|
|
3473
|
+
const sourceCandidates = [
|
|
3474
|
+
sourceRoot ? path.resolve(sourceRoot, file) : void 0,
|
|
3475
|
+
path.resolve(rootDir, file),
|
|
3476
|
+
path.resolve(path.dirname(outDir), file),
|
|
3477
|
+
path.resolve(outDir, file),
|
|
3478
|
+
!path.isAbsolute(relativeFromOutDir) && !relativeFromOutDir.startsWith("../") ? path.resolve(rootDir, relativeFromOutDir) : void 0,
|
|
3479
|
+
!path.isAbsolute(relativeFromOutDir) && !relativeFromOutDir.startsWith("../") ? path.resolve(path.dirname(outDir), relativeFromOutDir) : void 0,
|
|
3480
|
+
file
|
|
3481
|
+
];
|
|
3482
|
+
const explicitSource = sourceCandidates.reduce((source, candidate) => {
|
|
3483
|
+
if (source || !candidate) return source;
|
|
3484
|
+
return getSourceCandidateSource?.(candidate);
|
|
3485
|
+
}, void 0);
|
|
3486
|
+
if (explicitSource) return explicitSource;
|
|
3487
|
+
const normalizedSourceCandidates = sourceCandidates.filter((candidate) => Boolean(candidate)).map((candidate) => ({
|
|
3488
|
+
absolute: path.isAbsolute(candidate),
|
|
3489
|
+
key: normalizeSourceCandidatePathKey(candidate)
|
|
3490
|
+
}));
|
|
3491
|
+
let bestSource;
|
|
3492
|
+
for (const [sourceFile, source] of getSourceCandidateSources?.() ?? []) {
|
|
3493
|
+
const normalizedSourceFile = normalizeSourceCandidatePathKey(sourceFile);
|
|
3494
|
+
let score = 0;
|
|
3495
|
+
for (const candidate of normalizedSourceCandidates) if (normalizedSourceFile === candidate.key) {
|
|
3496
|
+
score = Math.max(score, candidate.absolute ? 100 : 80);
|
|
3497
|
+
continue;
|
|
3498
|
+
}
|
|
3499
|
+
if (normalizedSourceFile.endsWith(`/${normalizedFile}`)) score = Math.max(score, 20);
|
|
3500
|
+
if (score > (bestSource?.score ?? 0)) bestSource = {
|
|
3501
|
+
score,
|
|
3502
|
+
source
|
|
3503
|
+
};
|
|
3504
|
+
}
|
|
3505
|
+
return bestSource?.source;
|
|
3506
|
+
}
|
|
3507
|
+
//#endregion
|
|
3508
|
+
//#region src/bundlers/vite/generate-bundle/tailwind-v4-css-source.ts
|
|
3509
|
+
function collectTailwindV4SourceFingerprint(source) {
|
|
3510
|
+
const tokens = /* @__PURE__ */ new Set();
|
|
3511
|
+
const add = (prefix, value) => {
|
|
3512
|
+
tokens.add(`${prefix}:${value.trim()}`);
|
|
3513
|
+
};
|
|
3514
|
+
for (const match of source.matchAll(/@config\s+(["'])(.+?)\1\s*;?/g)) {
|
|
3515
|
+
const configRequest = match[2];
|
|
3516
|
+
add("config", path.basename(configRequest));
|
|
3517
|
+
add("config-request", configRequest.replace(/\\/g, "/"));
|
|
3518
|
+
}
|
|
3519
|
+
for (const match of source.matchAll(/@source\s+(not\s+)?(["'])(.+?)\2\s*;?/g)) add(match[1] ? "source:not" : "source", match[3]);
|
|
3520
|
+
for (const match of source.matchAll(/@custom-variant\s+([^{\s]+)/g)) add("custom-variant", match[1]);
|
|
3521
|
+
for (const match of source.matchAll(/@(?:theme|utility|variant|layer)\s+([^{;\s]+)/g)) add("directive", match[1]);
|
|
3522
|
+
for (const match of source.matchAll(/--[\w-]+(?=\s*:)/g)) add("theme-token", match[0]);
|
|
3523
|
+
for (const match of source.matchAll(/\.([_a-z][\w-]*)\s*[{,]/gi)) add("selector", match[1]);
|
|
3524
|
+
return tokens;
|
|
3525
|
+
}
|
|
3526
|
+
function scoreConfiguredTailwindV4SourceForRawSource(rawSource, entrySource) {
|
|
3527
|
+
if (!rawSource) return 0;
|
|
3528
|
+
const rawTokens = collectTailwindV4SourceFingerprint(rawSource);
|
|
3529
|
+
if (rawTokens.size === 0) return 0;
|
|
3530
|
+
const entryTokens = collectTailwindV4SourceFingerprint(entrySource);
|
|
3531
|
+
let score = 0;
|
|
3532
|
+
for (const token of entryTokens) if (rawTokens.has(token)) score += token.startsWith("config:") ? 100 : 1;
|
|
3533
|
+
return score;
|
|
3534
|
+
}
|
|
3535
|
+
function resolveSubpackageRootForFile(file, subpackageRoots) {
|
|
3536
|
+
if (!file || !subpackageRoots) return;
|
|
3537
|
+
return [...subpackageRoots].find((root) => isSubpackageOutputFile(file, new Set([root])));
|
|
3538
|
+
}
|
|
3539
|
+
function isSameSubpackageScope(outputFile, sourceFile, subpackageRoots) {
|
|
3540
|
+
return resolveSubpackageRootForFile(outputFile, subpackageRoots) === resolveSubpackageRootForFile(sourceFile, subpackageRoots);
|
|
3541
|
+
}
|
|
3542
|
+
function selectTailwindV4GenerationCssSourceForOutput(outputFile, entries, rawSource, subpackageRoots) {
|
|
3543
|
+
const generationSources = entries.filter((entry) => hasTailwindGenerationSource(entry.source));
|
|
3544
|
+
if (generationSources.length <= 1) return generationSources[0];
|
|
3545
|
+
const selectByRawSourceFingerprint = (candidates) => {
|
|
3546
|
+
const scoredSources = candidates.map((entry) => ({
|
|
3547
|
+
entry,
|
|
3548
|
+
score: scoreConfiguredTailwindV4SourceForRawSource(rawSource, entry.source)
|
|
3549
|
+
})).filter((item) => item.score > 0).sort((a, b) => b.score - a.score);
|
|
3550
|
+
const bestScore = scoredSources[0]?.score;
|
|
3551
|
+
const bestSources = bestScore ? scoredSources.filter((item) => item.score === bestScore) : [];
|
|
3552
|
+
return bestSources.length === 1 ? bestSources[0]?.entry : void 0;
|
|
3553
|
+
};
|
|
3554
|
+
const rawSourceMatched = selectByRawSourceFingerprint(generationSources);
|
|
3555
|
+
if (rawSourceMatched) return rawSourceMatched;
|
|
3556
|
+
const scopedSources = subpackageRoots ? generationSources.filter((entry) => {
|
|
3557
|
+
const outputMatchesSubpackage = isSubpackageOutputFile(outputFile, subpackageRoots);
|
|
3558
|
+
const sourceMatchesSubpackage = isSubpackageOutputFile(entry.file, subpackageRoots);
|
|
3559
|
+
if (!outputMatchesSubpackage) return !sourceMatchesSubpackage;
|
|
3560
|
+
return sourceMatchesSubpackage && [...subpackageRoots].some((root) => isSubpackageOutputFile(outputFile, new Set([root])) && isSubpackageOutputFile(entry.file, new Set([root])));
|
|
3561
|
+
}) : generationSources;
|
|
3562
|
+
const explicitSources = scopedSources.filter((entry) => /@(?:config|source|plugin|custom-variant|theme|utility|variant|apply)\b/.test(entry.source));
|
|
3563
|
+
const candidates = explicitSources.length === 1 ? explicitSources : scopedSources;
|
|
3564
|
+
if (candidates.length === 1) return candidates[0];
|
|
3565
|
+
return selectByRawSourceFingerprint(candidates);
|
|
3566
|
+
}
|
|
3567
|
+
//#endregion
|
|
2981
3568
|
//#region src/bundlers/vite/generate-bundle/timing.ts
|
|
2982
3569
|
function createBundleTaskTimer(recordTimingDetail) {
|
|
2983
3570
|
return async (name, task) => {
|
|
@@ -2990,9 +3577,116 @@ function createBundleTaskTimer(recordTimingDetail) {
|
|
|
2990
3577
|
};
|
|
2991
3578
|
}
|
|
2992
3579
|
//#endregion
|
|
3580
|
+
//#region src/bundlers/vite/generate-bundle/transform-filter.ts
|
|
3581
|
+
function toArray(value) {
|
|
3582
|
+
return Array.isArray(value) ? value : value === void 0 ? [] : [value];
|
|
3583
|
+
}
|
|
3584
|
+
function normalizeSourceId(id) {
|
|
3585
|
+
const file = cleanUrl(id);
|
|
3586
|
+
return path.isAbsolute(file) ? path.resolve(file) : void 0;
|
|
3587
|
+
}
|
|
3588
|
+
function collectChunkModuleIds$1(chunk) {
|
|
3589
|
+
const ids = /* @__PURE__ */ new Set();
|
|
3590
|
+
for (const id of chunk.moduleIds ?? []) {
|
|
3591
|
+
const normalized = normalizeSourceId(id);
|
|
3592
|
+
if (normalized) ids.add(normalized);
|
|
3593
|
+
}
|
|
3594
|
+
for (const id of Object.keys(chunk.modules ?? {})) {
|
|
3595
|
+
const normalized = normalizeSourceId(id);
|
|
3596
|
+
if (normalized) ids.add(normalized);
|
|
3597
|
+
}
|
|
3598
|
+
return ids;
|
|
3599
|
+
}
|
|
3600
|
+
function collectAssetSourceIds(asset, fallbackFile, rootDir) {
|
|
3601
|
+
const ids = /* @__PURE__ */ new Set();
|
|
3602
|
+
const sourceCandidates = [asset.originalFileName, ...asset.originalFileNames ?? []].filter((candidate) => typeof candidate === "string" && candidate.length > 0);
|
|
3603
|
+
const candidates = sourceCandidates.length > 0 ? sourceCandidates : [fallbackFile];
|
|
3604
|
+
for (const candidate of candidates) {
|
|
3605
|
+
if (typeof candidate !== "string" || candidate.length === 0) continue;
|
|
3606
|
+
const cleanCandidate = cleanUrl(candidate);
|
|
3607
|
+
const resolved = path.isAbsolute(cleanCandidate) ? path.resolve(cleanCandidate) : path.resolve(rootDir, cleanCandidate);
|
|
3608
|
+
ids.add(resolved);
|
|
3609
|
+
}
|
|
3610
|
+
return ids;
|
|
3611
|
+
}
|
|
3612
|
+
function isStringRuleMatched(rule, id, rootDir) {
|
|
3613
|
+
const normalizedId = slash(id);
|
|
3614
|
+
const normalizedRule = slash(rule);
|
|
3615
|
+
if (path.isAbsolute(rule)) return micromatch.isMatch(normalizedId, normalizedRule);
|
|
3616
|
+
const relative = slash(path.relative(rootDir, id));
|
|
3617
|
+
return relative.length > 0 && !relative.startsWith("../") && !path.isAbsolute(relative) && micromatch.isMatch(relative, normalizedRule);
|
|
3618
|
+
}
|
|
3619
|
+
function isRuleMatched(rule, id, rootDir) {
|
|
3620
|
+
if (typeof rule === "string") return isStringRuleMatched(rule, id, rootDir);
|
|
3621
|
+
if (rule instanceof RegExp) {
|
|
3622
|
+
rule.lastIndex = 0;
|
|
3623
|
+
return rule.test(slash(id));
|
|
3624
|
+
}
|
|
3625
|
+
return rule(id) === true;
|
|
3626
|
+
}
|
|
3627
|
+
function createTransformMatcher(rules, rootDir) {
|
|
3628
|
+
const normalizedRules = toArray(rules);
|
|
3629
|
+
if (normalizedRules.length === 0) return;
|
|
3630
|
+
return (id) => normalizedRules.some((rule) => isRuleMatched(rule, id, rootDir));
|
|
3631
|
+
}
|
|
3632
|
+
function shouldSkipSourceIds(sourceIds, filter) {
|
|
3633
|
+
if (sourceIds.size === 0) return false;
|
|
3634
|
+
if (filter.exclude) {
|
|
3635
|
+
let excluded = true;
|
|
3636
|
+
for (const id of sourceIds) if (!filter.exclude(id)) {
|
|
3637
|
+
excluded = false;
|
|
3638
|
+
break;
|
|
3639
|
+
}
|
|
3640
|
+
if (excluded) return true;
|
|
3641
|
+
}
|
|
3642
|
+
if (filter.include) {
|
|
3643
|
+
for (const id of sourceIds) if (filter.include(id)) return false;
|
|
3644
|
+
return true;
|
|
3645
|
+
}
|
|
3646
|
+
return false;
|
|
3647
|
+
}
|
|
3648
|
+
function createTransformFilter(options, rootDir) {
|
|
3649
|
+
const include = createTransformMatcher(options?.include, rootDir);
|
|
3650
|
+
const exclude = createTransformMatcher(options?.exclude, rootDir);
|
|
3651
|
+
if (!include && !exclude) return;
|
|
3652
|
+
return {
|
|
3653
|
+
include,
|
|
3654
|
+
exclude
|
|
3655
|
+
};
|
|
3656
|
+
}
|
|
3657
|
+
function shouldSkipViteJsChunkTransform(chunk, filter) {
|
|
3658
|
+
if (!filter) return false;
|
|
3659
|
+
return shouldSkipSourceIds(collectChunkModuleIds$1(chunk), filter);
|
|
3660
|
+
}
|
|
3661
|
+
function shouldSkipViteAssetTransform(asset, file, rootDir, filter) {
|
|
3662
|
+
if (!filter) return false;
|
|
3663
|
+
return shouldSkipSourceIds(collectAssetSourceIds(asset, file, rootDir), filter);
|
|
3664
|
+
}
|
|
3665
|
+
function createRuleSignature(rules) {
|
|
3666
|
+
return toArray(rules).map((rule) => {
|
|
3667
|
+
if (typeof rule === "string") return `s:${rule}`;
|
|
3668
|
+
if (rule instanceof RegExp) return `r:${rule.source}/${rule.flags}`;
|
|
3669
|
+
return "f";
|
|
3670
|
+
}).join("|") || "none";
|
|
3671
|
+
}
|
|
3672
|
+
function createTransformFilterSignature(options) {
|
|
3673
|
+
return [`include:${createRuleSignature(options?.include)}`, `exclude:${createRuleSignature(options?.exclude)}`].join(";");
|
|
3674
|
+
}
|
|
3675
|
+
//#endregion
|
|
2993
3676
|
//#region src/bundlers/vite/uni-app-x-css-options.ts
|
|
2994
3677
|
function resolveUniAppXNativeCssHandlerOptions(opts) {
|
|
2995
|
-
|
|
3678
|
+
const uniUtsPlatform = resolveUniUtsPlatform();
|
|
3679
|
+
if (!shouldUseNativeAppCssBranch(resolveGeneratorRuntimeBranch(normalizeWeappTailwindcssGeneratorOptions(opts.generator, {
|
|
3680
|
+
appType: opts.appType,
|
|
3681
|
+
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
3682
|
+
uniAppX: resolveUniAppXOptions(opts.uniAppX),
|
|
3683
|
+
uniUtsPlatform
|
|
3684
|
+
}), {
|
|
3685
|
+
appType: opts.appType,
|
|
3686
|
+
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
3687
|
+
uniAppX: resolveUniAppXOptions(opts.uniAppX),
|
|
3688
|
+
uniUtsPlatform
|
|
3689
|
+
})) || !isUniAppXEnabled(opts.uniAppX)) return {};
|
|
2996
3690
|
return {
|
|
2997
3691
|
uniAppX: true,
|
|
2998
3692
|
uniAppXCssTarget: "uvue",
|
|
@@ -3011,7 +3705,7 @@ function resolveWeappViteSourceRoot(config, _appType) {
|
|
|
3011
3705
|
const root = typeof viteConfig?.root === "string" && viteConfig.root.length > 0 ? path.resolve(viteConfig.root) : process$1.cwd();
|
|
3012
3706
|
const configuredSrcRoot = resolveSourceRootCandidate(root, viteConfig?.weapp?.srcRoot);
|
|
3013
3707
|
if (configuredSrcRoot) return configuredSrcRoot;
|
|
3014
|
-
const envSrcRoot = resolveSourceRootCandidate(root, process$1.env
|
|
3708
|
+
const envSrcRoot = resolveSourceRootCandidate(root, process$1.env["UNI_INPUT_DIR"]) ?? resolveSourceRootCandidate(root, process$1.env["UNI_INPUT_ROOT"]) ?? resolveSourceRootCandidate(root, process$1.env["UNI_APP_INPUT_DIR"]);
|
|
3015
3709
|
if (envSrcRoot) return envSrcRoot;
|
|
3016
3710
|
}
|
|
3017
3711
|
function stripFileExtension(file) {
|
|
@@ -3064,7 +3758,7 @@ function createGenerateBundleHook(context) {
|
|
|
3064
3758
|
const cssHandlerOptions = createCssHandlerOptionsCache({
|
|
3065
3759
|
getAppType: () => context.opts.appType,
|
|
3066
3760
|
mainCssChunkMatcher: context.opts.mainCssChunkMatcher,
|
|
3067
|
-
getMajorVersion: () => context.runtimeState.
|
|
3761
|
+
getMajorVersion: () => context.runtimeState.tailwindRuntime.majorVersion,
|
|
3068
3762
|
getOutputRoot: () => currentOutDir,
|
|
3069
3763
|
getExtraOptions: (file) => ({
|
|
3070
3764
|
...resolveViteCssHandlerExtraOptions(file),
|
|
@@ -3081,15 +3775,27 @@ function createGenerateBundleHook(context) {
|
|
|
3081
3775
|
};
|
|
3082
3776
|
const getSfcSource = (sourceFile) => getBundlerSfcSource(sourceFile) ?? getKnownSfcSource?.(sourceFile);
|
|
3083
3777
|
const { cache, onEnd, onStart, onUpdate, styleHandler, templateHandler, jsHandler, uniAppX } = opts;
|
|
3084
|
-
const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(opts.generator);
|
|
3085
|
-
const isWebGeneratorTarget = generatorOptions.target === "web";
|
|
3086
3778
|
const resolvedConfig = getResolvedConfig();
|
|
3087
3779
|
const uniUtsPlatform = resolveUniUtsPlatform();
|
|
3780
|
+
const generatorBranch = resolveGeneratorRuntimeBranch(normalizeWeappTailwindcssGeneratorOptions(opts.generator, {
|
|
3781
|
+
appType: opts.appType,
|
|
3782
|
+
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
3783
|
+
tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
3784
|
+
uniAppX,
|
|
3785
|
+
uniUtsPlatform
|
|
3786
|
+
}), {
|
|
3787
|
+
appType: opts.appType,
|
|
3788
|
+
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
3789
|
+
tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
3790
|
+
uniAppX,
|
|
3791
|
+
uniUtsPlatform
|
|
3792
|
+
});
|
|
3793
|
+
const isWebGeneratorTarget = generatorBranch.isWeb;
|
|
3088
3794
|
const isNativeAppStyleTarget = uniUtsPlatform.isApp;
|
|
3089
3795
|
const canInferHarmonyAppStyleTarget = !uniUtsPlatform.normalized || uniUtsPlatform.isApp;
|
|
3090
3796
|
const isHarmonyAppStyleTarget = uniUtsPlatform.isAppHarmony || canInferHarmonyAppStyleTarget && (isUniAppXHarmonyBundle(bundle) || isUniAppXHarmonyOutDir(resolvedConfig?.build?.outDir));
|
|
3091
3797
|
const shouldPreserveAppCssExtension = isNativeAppStyleTarget || isHarmonyAppStyleTarget;
|
|
3092
|
-
const shouldGenerateWebCssByGenerator = isWebGeneratorTarget
|
|
3798
|
+
const shouldGenerateWebCssByGenerator = isWebGeneratorTarget;
|
|
3093
3799
|
const { getCssHandlerOptions, getCssUserHandlerOptions } = cssHandlerOptions;
|
|
3094
3800
|
const rootDir = resolvedConfig?.root ? path.resolve(resolvedConfig.root) : process$1.cwd();
|
|
3095
3801
|
const sourceRoot = resolveWeappViteSourceRoot(resolvedConfig, opts.appType) ?? resolveSourceRootFromBundleGraph(resolvedConfig, bundle);
|
|
@@ -3122,7 +3828,28 @@ function createGenerateBundleHook(context) {
|
|
|
3122
3828
|
const envFlags = resolveGenerateBundleEnvFlags();
|
|
3123
3829
|
const bundleFiles = Object.keys(bundle);
|
|
3124
3830
|
const activeViteCssCacheFiles = new Set(bundleFiles.map(normalizeViteCssCacheKey));
|
|
3125
|
-
const
|
|
3831
|
+
const getConfiguredTailwindV4CssSourceEntries = () => collectConfiguredTailwindV4CssSourceEntries({
|
|
3832
|
+
...opts,
|
|
3833
|
+
tailwindcssRuntimeOptions: {
|
|
3834
|
+
...opts.tailwindcssRuntimeOptions ?? {},
|
|
3835
|
+
tailwindcss: {
|
|
3836
|
+
...resolveTailwindcssOptions(opts.tailwindcssRuntimeOptions) ?? {},
|
|
3837
|
+
...resolveTailwindcssOptions(runtimeState.tailwindRuntime.options) ?? {}
|
|
3838
|
+
}
|
|
3839
|
+
}
|
|
3840
|
+
}, opts.tailwindcssBasedir ?? rootDir);
|
|
3841
|
+
const normalizeGeneratorUserRawSource = (source, sourceFile, fallbackFile) => normalizeRelativeCssConfigDirectives(source, sourceFile || fallbackFile, outDir, opts);
|
|
3842
|
+
const resolveMatchedCssSourceOutputFile = (sourceFile) => resolveOutputFileFromMatchedCssSource({
|
|
3843
|
+
bundleFiles,
|
|
3844
|
+
defaultStyleOutputExtension,
|
|
3845
|
+
isWebGeneratorTarget,
|
|
3846
|
+
opts,
|
|
3847
|
+
rootDir,
|
|
3848
|
+
shouldPreserveAppCssExtension: false,
|
|
3849
|
+
sourceFile,
|
|
3850
|
+
sourceRoot
|
|
3851
|
+
});
|
|
3852
|
+
const usedConfiguredTailwindV4CssSourceFiles = /* @__PURE__ */ new Set();
|
|
3126
3853
|
const buildCommand = resolvedConfig?.command === "build";
|
|
3127
3854
|
const hasPreviousBundleState = state.iteration > 0 || state.sourceHashByFile.size > 0;
|
|
3128
3855
|
const hasOmittedKnownFiles = hasOmittedKnownBundleFiles(bundleFiles, state.sourceHashByFile.keys());
|
|
@@ -3130,10 +3857,13 @@ function createGenerateBundleHook(context) {
|
|
|
3130
3857
|
currentOutDir = outDir;
|
|
3131
3858
|
const snapshotStart = performance.now();
|
|
3132
3859
|
const snapshot = buildBundleSnapshot(bundle, opts, outDir, state, envFlags.disableDirtyOptimization || !useIncrementalMode, { hasOmittedKnownFiles });
|
|
3860
|
+
const configuredTailwindV4CssSourceEntriesForScope = getConfiguredTailwindV4CssSourceEntries();
|
|
3861
|
+
const configuredTailwindV4CssSourceFileKeysForScope = new Set(configuredTailwindV4CssSourceEntriesForScope.map((entry) => normalizeOutputPathKey(entry.file.replace(/[?#].*$/, ""))));
|
|
3133
3862
|
const { createScopedSourceCandidateGetter, createScopedSourceCandidateSourceGetter, shouldExcludeSubpackageSourceCandidates, shouldInjectCssIntoMainFromOutput } = createSubpackageSourceCandidateScope({
|
|
3863
|
+
cssSourceFiles: configuredTailwindV4CssSourceEntriesForScope.map((entry) => entry.file),
|
|
3134
3864
|
getSourceCandidateSourcesForEntries,
|
|
3135
3865
|
getSourceCandidatesForEntries,
|
|
3136
|
-
projectRoot: opts.
|
|
3866
|
+
projectRoot: opts.tailwindcssRuntimeOptions?.projectRoot,
|
|
3137
3867
|
rootDir,
|
|
3138
3868
|
snapshot,
|
|
3139
3869
|
sourceRoot,
|
|
@@ -3142,7 +3872,7 @@ function createGenerateBundleHook(context) {
|
|
|
3142
3872
|
useIncrementalMode
|
|
3143
3873
|
});
|
|
3144
3874
|
recordTimingDetail("snapshot", snapshotStart);
|
|
3145
|
-
const useBundleRuntimeClassSet = !isWebGeneratorTarget
|
|
3875
|
+
const useBundleRuntimeClassSet = !isWebGeneratorTarget;
|
|
3146
3876
|
const forceRuntimeRefreshBySource = useIncrementalMode && hasRuntimeAffectingSourceChanges(snapshot.runtimeAffectingChangedByType);
|
|
3147
3877
|
const processFiles = snapshot.processFiles;
|
|
3148
3878
|
logBundleProcessPlan({
|
|
@@ -3159,7 +3889,7 @@ function createGenerateBundleHook(context) {
|
|
|
3159
3889
|
cssHandlerOptions,
|
|
3160
3890
|
fallbackRuntime: runtime,
|
|
3161
3891
|
getSourceCandidatesForEntries,
|
|
3162
|
-
majorVersion: runtimeState.
|
|
3892
|
+
majorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
3163
3893
|
outputFile,
|
|
3164
3894
|
rawSource,
|
|
3165
3895
|
shouldExcludeSubpackageSourceCandidates,
|
|
@@ -3168,63 +3898,46 @@ function createGenerateBundleHook(context) {
|
|
|
3168
3898
|
});
|
|
3169
3899
|
const jsEntries = snapshot.jsEntries;
|
|
3170
3900
|
const getJsEntry = createJsEntryResolver(jsEntries);
|
|
3901
|
+
const transformFilter = createTransformFilter(opts.transform, rootDir);
|
|
3902
|
+
const transformFilterSignature = createTransformFilterSignature(opts.transform);
|
|
3171
3903
|
const moduleGraphOptions = createBundleModuleGraphOptions(outDir, jsEntries);
|
|
3172
|
-
const hasCssAssetEntry = snapshot.entries.some((entry) => entry.type === "css" && entry.output.type === "asset");
|
|
3173
3904
|
const hasRuntimeAffectingChanges = hasRuntimeAffectingSourceChanges(snapshot.runtimeAffectingChangedByType);
|
|
3174
|
-
const useV3OxideSourceRuntime = runtimeState.twPatcher.majorVersion === 3 && sourceCandidates.size > 0 && hasCssAssetEntry && !envFlags.forceRuntimeRefreshByEnv && !envFlags.disableV3OxideSourceRuntime;
|
|
3175
3905
|
const runtimeStart = performance.now();
|
|
3176
|
-
const
|
|
3177
|
-
const
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
if (useV3OxideSourceRuntime) debug("[tailwindcss:v3] use oxide source candidates as runtime input, candidates=%d", sourceCandidates.size);
|
|
3183
|
-
const shouldFilterTailwindV4MiniProgramCandidates = runtimeState.twPatcher.majorVersion === 4 && generatorOptions.target === "weapp";
|
|
3906
|
+
const forceV4RuntimeRefreshBySource = forceRuntimeRefreshBySource;
|
|
3907
|
+
const runtime = isWebGeneratorTarget ? /* @__PURE__ */ new Set() : useBundleRuntimeClassSet ? await ensureBundleRuntimeClassSet(snapshot, envFlags.forceRuntimeRefreshByEnv, {
|
|
3908
|
+
allowBaselineOnlyInitialSync: buildCommand,
|
|
3909
|
+
refreshBySource: forceV4RuntimeRefreshBySource
|
|
3910
|
+
}) : await context.ensureRuntimeClassSet(envFlags.forceRuntimeRefreshByEnv);
|
|
3911
|
+
const shouldFilterTailwindV4MiniProgramCandidates = shouldUseMiniProgramCssBranch(generatorBranch);
|
|
3184
3912
|
const collectedGeneratorCandidates = new Set([...runtime, ...sourceCandidates]);
|
|
3185
3913
|
const filteredGeneratorCandidates = shouldFilterTailwindV4MiniProgramCandidates ? filterUnsupportedMiniProgramTailwindV4Candidates(collectedGeneratorCandidates) : collectedGeneratorCandidates;
|
|
3186
|
-
|
|
3187
|
-
|
|
3188
|
-
|
|
3189
|
-
generatorRuntime = await context.ensureRuntimeClassSet(envFlags.forceRuntimeRefreshByEnv);
|
|
3190
|
-
transformRuntime = generatorRuntime;
|
|
3191
|
-
}
|
|
3914
|
+
const filteredSourceCandidates = shouldFilterTailwindV4MiniProgramCandidates ? filterUnsupportedMiniProgramTailwindV4Candidates(sourceCandidates) : sourceCandidates;
|
|
3915
|
+
const transformRuntime = shouldFilterTailwindV4MiniProgramCandidates ? new Set(runtime) : new Set(filteredGeneratorCandidates);
|
|
3916
|
+
const generatorRuntime = filteredGeneratorCandidates;
|
|
3192
3917
|
const cssEntries = snapshot.entries.filter((entry) => entry.type === "css" && entry.output.type === "asset");
|
|
3193
|
-
|
|
3194
|
-
|
|
3195
|
-
if (mainCssEntry) {
|
|
3196
|
-
const validatedSourceRuntime = await validateCandidatesByGenerator({
|
|
3197
|
-
opts,
|
|
3198
|
-
runtimeState,
|
|
3199
|
-
candidates: filteredGeneratorCandidates,
|
|
3200
|
-
rawSource: mainCssEntry.source,
|
|
3201
|
-
file: mainCssEntry.file,
|
|
3202
|
-
cssHandlerOptions: getCssHandlerOptions(mainCssEntry.file),
|
|
3203
|
-
cssUserHandlerOptions: getCssUserHandlerOptions(mainCssEntry.file),
|
|
3204
|
-
styleHandler,
|
|
3205
|
-
debug,
|
|
3206
|
-
skipGenerateFallback: true
|
|
3207
|
-
});
|
|
3208
|
-
if (validatedSourceRuntime.size > 0) transformRuntime = new Set([...transformRuntime, ...validatedSourceRuntime]);
|
|
3209
|
-
}
|
|
3210
|
-
}
|
|
3211
|
-
if (runtimeState.twPatcher.majorVersion === 3 && useV3OxideSourceRuntime && generatorRuntime.size > 0 && (state.iteration === 0 || !hasRuntimeAffectingChanges) && cssEntries.length <= 1) {
|
|
3918
|
+
const hasMultipleConfiguredCssEntries = (opts.cssEntries?.length ?? 0) > 1;
|
|
3919
|
+
if (sourceCandidates.size > 0 && !hasMultipleConfiguredCssEntries) {
|
|
3212
3920
|
const mainCssEntry = cssEntries.find((entry) => getCssHandlerOptions(entry.file).isMainChunk) ?? cssEntries[0];
|
|
3213
3921
|
if (mainCssEntry) {
|
|
3214
|
-
const
|
|
3215
|
-
|
|
3216
|
-
|
|
3217
|
-
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
|
|
3221
|
-
|
|
3222
|
-
|
|
3223
|
-
|
|
3224
|
-
|
|
3225
|
-
|
|
3226
|
-
|
|
3227
|
-
|
|
3922
|
+
const mainCssRawSource = typeof mainCssEntry.output.source === "string" ? mainCssEntry.output.source : Buffer.from(mainCssEntry.output.source).toString();
|
|
3923
|
+
if (!hasTailwindApplyDirective(mainCssRawSource)) {
|
|
3924
|
+
const generatedCssSources = /* @__PURE__ */ new Set();
|
|
3925
|
+
for (const [, record] of getViteProcessedCssAssetResults?.() ?? []) if (typeof record === "string") generatedCssSources.add(record);
|
|
3926
|
+
else if (typeof record?.css === "string") generatedCssSources.add(record.css);
|
|
3927
|
+
const validatedSourceRuntime = await validateCandidatesByGenerator({
|
|
3928
|
+
opts,
|
|
3929
|
+
runtimeState,
|
|
3930
|
+
candidates: filteredSourceCandidates,
|
|
3931
|
+
rawSource: mainCssRawSource,
|
|
3932
|
+
generatedCssSources,
|
|
3933
|
+
file: mainCssEntry.file,
|
|
3934
|
+
cssHandlerOptions: getCssHandlerOptions(mainCssEntry.file),
|
|
3935
|
+
cssUserHandlerOptions: getCssUserHandlerOptions(mainCssEntry.file),
|
|
3936
|
+
styleHandler,
|
|
3937
|
+
debug,
|
|
3938
|
+
skipGenerateFallback: false
|
|
3939
|
+
});
|
|
3940
|
+
if (validatedSourceRuntime.size > 0) for (const candidate of validatedSourceRuntime) transformRuntime.add(candidate);
|
|
3228
3941
|
}
|
|
3229
3942
|
}
|
|
3230
3943
|
}
|
|
@@ -3233,33 +3946,36 @@ function createGenerateBundleHook(context) {
|
|
|
3233
3946
|
const cssExtensionByStem = collectCssExtensionByStem(bundleFiles, opts.cssMatcher);
|
|
3234
3947
|
const jsImportedCssFiles = collectJsImportedCssFiles(snapshot);
|
|
3235
3948
|
const runtimeLinkedCssFiles = new Set([...collectRuntimeLinkedCssFiles(snapshot, cssExtensionByStem, defaultStyleOutputExtension), ...jsImportedCssFiles]);
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
|
|
3243
|
-
|
|
3244
|
-
|
|
3245
|
-
|
|
3246
|
-
|
|
3247
|
-
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
|
|
3949
|
+
rememberRuntimeLinkedCssSources({
|
|
3950
|
+
bundleFiles,
|
|
3951
|
+
debug,
|
|
3952
|
+
defaultStyleOutputExtension,
|
|
3953
|
+
getConfiguredTailwindV4CssSourceEntries,
|
|
3954
|
+
getSourceCandidateSource,
|
|
3955
|
+
getSourceCandidateSources,
|
|
3956
|
+
isWebGeneratorTarget,
|
|
3957
|
+
jsImportedCssFiles,
|
|
3958
|
+
opts,
|
|
3959
|
+
outDir,
|
|
3960
|
+
rememberCssSource,
|
|
3961
|
+
rootDir,
|
|
3962
|
+
runtimeLinkedCssFiles,
|
|
3963
|
+
shouldPreserveAppCssExtension,
|
|
3964
|
+
snapshot,
|
|
3965
|
+
sourceRoot
|
|
3966
|
+
});
|
|
3251
3967
|
recordGeneratorCandidates?.(generatorRuntime);
|
|
3252
3968
|
const dynamicRetryCandidates = new Set([
|
|
3253
3969
|
...sourceCandidates,
|
|
3254
3970
|
...generatorRuntime,
|
|
3255
3971
|
...transformRuntime
|
|
3256
3972
|
]);
|
|
3257
|
-
const defaultTemplateHandlerOptions = { runtimeSet: transformRuntime };
|
|
3258
3973
|
metrics.runtimeSet = measureElapsed(runtimeStart);
|
|
3259
3974
|
timingDetails["runtime"] = metrics.runtimeSet;
|
|
3260
3975
|
if (forceRuntimeRefreshBySource) debug("runtimeSet forced refresh due to source changes: html=%d js=%d", snapshot.runtimeAffectingChangedByType.html.size, snapshot.runtimeAffectingChangedByType.js.size);
|
|
3261
3976
|
debug("get runtimeSet, class count: %d, transform class count: %d", runtime.size, transformRuntime.size);
|
|
3262
|
-
const runtimeSignature = getRuntimeClassSetSignature(runtimeState.
|
|
3977
|
+
const runtimeSignature = getRuntimeClassSetSignature(runtimeState.tailwindRuntime) ?? "runtime:missing";
|
|
3978
|
+
const transformRuntimeSignature = createCandidateSignature(transformRuntime);
|
|
3263
3979
|
const shouldProcessTailwindGeneration = !useIncrementalMode || hasRuntimeAffectingChanges || generatorCandidatesChanged || snapshot.processFiles.css.size > 0;
|
|
3264
3980
|
const { applyLinkedUpdates, pendingLinkedUpdates } = createLinkedUpdateHelpers({
|
|
3265
3981
|
jsEntries,
|
|
@@ -3267,7 +3983,7 @@ function createGenerateBundleHook(context) {
|
|
|
3267
3983
|
debug
|
|
3268
3984
|
});
|
|
3269
3985
|
const createHandlerOptions = createJsHandlerOptionsFactory({
|
|
3270
|
-
getMajorVersion: () => runtimeState.
|
|
3986
|
+
getMajorVersion: () => runtimeState.tailwindRuntime.majorVersion,
|
|
3271
3987
|
moduleGraph: moduleGraphOptions
|
|
3272
3988
|
});
|
|
3273
3989
|
const linkedByEntry = useIncrementalMode ? /* @__PURE__ */ new Map() : void 0;
|
|
@@ -3289,69 +4005,86 @@ function createGenerateBundleHook(context) {
|
|
|
3289
4005
|
debug("html skip web target: %s", file);
|
|
3290
4006
|
continue;
|
|
3291
4007
|
}
|
|
4008
|
+
if (shouldSkipViteAssetTransform(originalSource, file, rootDir, transformFilter)) {
|
|
4009
|
+
metrics.html.transformed++;
|
|
4010
|
+
debug("html skip transform (filtered): %s", file);
|
|
4011
|
+
continue;
|
|
4012
|
+
}
|
|
3292
4013
|
if (!processFiles.html.has(file)) continue;
|
|
3293
|
-
|
|
3294
|
-
const cacheKey = file;
|
|
3295
|
-
const hashKey = `${file}:html:${runtimeSignature}`;
|
|
3296
|
-
rememberProcessCacheKey(cacheKey, hashKey);
|
|
3297
|
-
tasks.push(timeTask("html", () => processCachedTask({
|
|
4014
|
+
processHtmlBundleEntry({
|
|
3298
4015
|
cache,
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
|
|
3308
|
-
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
|
|
3313
|
-
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
|
|
3318
|
-
|
|
3319
|
-
|
|
3320
|
-
|
|
3321
|
-
|
|
3322
|
-
transformed = await templateHandler(rawSource, { runtimeSet: retryRuntimeSet });
|
|
3323
|
-
unresolvedDynamicCandidates = collectUnescapedDynamicCandidates(transformed, retryRuntimeSet);
|
|
3324
|
-
if (unresolvedDynamicCandidates.length > 0) logger.warn("已提取 WXML 动态类名在完整 runtimeSet 重试后仍未完成转译: %s -> %O", file, unresolvedDynamicCandidates);
|
|
3325
|
-
}
|
|
3326
|
-
metrics.html.elapsed += measureElapsed(start);
|
|
3327
|
-
metrics.html.transformed++;
|
|
3328
|
-
onUpdate(file, rawSource, transformed);
|
|
3329
|
-
debug("html handle: %s", file);
|
|
3330
|
-
return { result: transformed };
|
|
3331
|
-
}
|
|
3332
|
-
})));
|
|
4016
|
+
context,
|
|
4017
|
+
debug,
|
|
4018
|
+
dynamicRetryCandidates,
|
|
4019
|
+
file,
|
|
4020
|
+
metrics,
|
|
4021
|
+
onUpdate,
|
|
4022
|
+
originalEntrySource,
|
|
4023
|
+
originalSource,
|
|
4024
|
+
rememberProcessCacheKey,
|
|
4025
|
+
resolveCurrentSourceCandidateSource: (file) => resolveCurrentSourceCandidateSource({
|
|
4026
|
+
file,
|
|
4027
|
+
getSourceCandidateSource,
|
|
4028
|
+
getSourceCandidateSources,
|
|
4029
|
+
outDir,
|
|
4030
|
+
rootDir,
|
|
4031
|
+
sourceRoot
|
|
4032
|
+
}),
|
|
4033
|
+
tasks,
|
|
4034
|
+
templateHandler,
|
|
4035
|
+
timeTask,
|
|
4036
|
+
transformRuntime,
|
|
4037
|
+
transformRuntimeSignature
|
|
4038
|
+
});
|
|
3333
4039
|
continue;
|
|
3334
4040
|
}
|
|
3335
4041
|
if (type === "css" && originalSource.type === "asset") {
|
|
3336
4042
|
metrics.css.total++;
|
|
3337
4043
|
const assetSourceFile = resolveAssetSourceFile(originalSource, file);
|
|
3338
4044
|
const rawSource = normalizeRelativeCssConfigDirectives(originalEntrySource, assetSourceFile, outDir, opts);
|
|
3339
|
-
|
|
4045
|
+
let outputFile = resolveCssBundleOutputFile({
|
|
4046
|
+
bundleFiles,
|
|
4047
|
+
defaultStyleOutputExtension,
|
|
4048
|
+
file,
|
|
4049
|
+
isWebGeneratorTarget,
|
|
4050
|
+
opts,
|
|
4051
|
+
shouldPreserveAppCssExtension
|
|
4052
|
+
});
|
|
4053
|
+
const resolveMatchedOutputFileForCurrentAsset = createMatchedCssSourceOutputResolver({
|
|
4054
|
+
assetSourceFile,
|
|
4055
|
+
file,
|
|
4056
|
+
originalFileNames: originalSource.originalFileNames,
|
|
4057
|
+
resolveOutputFileFromMatchedCssSource: resolveMatchedCssSourceOutputFile
|
|
4058
|
+
});
|
|
3340
4059
|
activeViteCssCacheFiles.add(normalizeViteCssCacheKey(outputFile));
|
|
3341
|
-
if (outputFile
|
|
4060
|
+
if (shouldSkipRawSourceStyleAsset(outputFile, file, rawSource)) {
|
|
3342
4061
|
delete bundle[file];
|
|
3343
4062
|
debug("css skip raw source style asset: %s -> %s", file, outputFile);
|
|
3344
4063
|
continue;
|
|
3345
4064
|
}
|
|
4065
|
+
const hasViteProcessedCssRecord = getViteProcessedCssAssetResult?.(file) != null;
|
|
4066
|
+
const viteProcessedCssAsset = isViteProcessedCssAsset?.(originalSource, file) === true || hasViteProcessedCssRecord;
|
|
3346
4067
|
const applyCssResult = (source) => {
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
|
|
3353
|
-
|
|
4068
|
+
applyCssResultToBundle({
|
|
4069
|
+
appType: opts.appType,
|
|
4070
|
+
assetSourceFile,
|
|
4071
|
+
bundle,
|
|
4072
|
+
emitOrReplayCssAsset,
|
|
4073
|
+
file,
|
|
4074
|
+
originalSource,
|
|
4075
|
+
outputFile,
|
|
4076
|
+
source,
|
|
4077
|
+
viteProcessedCssAsset
|
|
4078
|
+
});
|
|
3354
4079
|
};
|
|
4080
|
+
if (shouldSkipViteAssetTransform(originalSource, file, rootDir, transformFilter)) {
|
|
4081
|
+
applyCssResult(rawSource);
|
|
4082
|
+
markCssAssetProcessed?.(originalSource, outputFile);
|
|
4083
|
+
onUpdate(outputFile, rawSource, rawSource);
|
|
4084
|
+
metrics.css.transformed++;
|
|
4085
|
+
debug("css skip transform (filtered): %s", outputFile);
|
|
4086
|
+
continue;
|
|
4087
|
+
}
|
|
3355
4088
|
if (isWebGeneratorTarget && !shouldGenerateWebCssByGenerator) {
|
|
3356
4089
|
applyCssResult(rawSource);
|
|
3357
4090
|
markCssAssetProcessed?.(originalSource, outputFile);
|
|
@@ -3359,24 +4092,65 @@ function createGenerateBundleHook(context) {
|
|
|
3359
4092
|
debug("css skip web target: %s", outputFile);
|
|
3360
4093
|
continue;
|
|
3361
4094
|
}
|
|
3362
|
-
const hasViteProcessedCssRecord = getViteProcessedCssAssetResult?.(file) != null;
|
|
3363
|
-
const viteProcessedCssAsset = isViteProcessedCssAsset?.(originalSource, file) === true || hasViteProcessedCssRecord;
|
|
3364
4095
|
const cssAssetProcessed = isCssAssetProcessed?.(originalSource, file) === true;
|
|
3365
4096
|
const alreadyProcessedCssAsset = viteProcessedCssAsset || cssAssetProcessed;
|
|
3366
4097
|
let rememberedCssSources = findRememberedCssSources(getRememberedCssSources?.(), outputFile, file, originalSource, outDir, opts.tailwindcssBasedir);
|
|
3367
|
-
if (rememberedCssSources.length > 0) rememberedCssSources = await Promise.all(rememberedCssSources.map(async (remembered) =>
|
|
3368
|
-
|
|
4098
|
+
if (rememberedCssSources.length > 0) rememberedCssSources = await Promise.all(rememberedCssSources.map(async (remembered) => {
|
|
4099
|
+
return await refreshRememberedCssSource?.(remembered) ?? remembered;
|
|
4100
|
+
}));
|
|
4101
|
+
let hasUsableRememberedTailwindSource = rememberedCssSources.some((remembered) => hasTailwindGenerationSource(remembered.rawSource) && normalizeOutputPathKey(remembered.sourceFile.replace(/[?#].*$/, "")) !== normalizeOutputPathKey(file));
|
|
3369
4102
|
const inferredSfcStyleSource = await resolveSfcStyleSourceFromOutputFile(outputFile, snapshot, outDir, opts.tailwindcssBasedir, opts.cssMatcher, getSfcSource, debug);
|
|
3370
4103
|
if (inferredSfcStyleSource) {
|
|
3371
4104
|
const inferredSourceFile = normalizeSfcSourceFileForCompare(inferredSfcStyleSource.sourceFile);
|
|
3372
4105
|
const rememberedSourcesBelongToInferredSfc = rememberedCssSources.length > 0 && rememberedCssSources.every((remembered) => normalizeSfcSourceFileForCompare(remembered.sourceFile) === inferredSourceFile);
|
|
3373
4106
|
if (!hasUsableRememberedTailwindSource || rememberedSourcesBelongToInferredSfc) rememberedCssSources = [inferredSfcStyleSource];
|
|
3374
4107
|
}
|
|
3375
|
-
|
|
3376
|
-
|
|
3377
|
-
|
|
4108
|
+
let outputCssHandlerOptions = getCssHandlerOptions(outputFile);
|
|
4109
|
+
if (currentSubpackageRoots && rememberedCssSources.length > 0 && rememberedCssSources.some((remembered) => configuredTailwindV4CssSourceFileKeysForScope.has(normalizeOutputPathKey(remembered.sourceFile.replace(/[?#].*$/, ""))) && !isSameSubpackageScope(outputFile, remembered.sourceFile, currentSubpackageRoots))) {
|
|
4110
|
+
rememberedCssSources = [];
|
|
4111
|
+
hasUsableRememberedTailwindSource = false;
|
|
4112
|
+
}
|
|
4113
|
+
if (!hasUsableRememberedTailwindSource) {
|
|
4114
|
+
const configuredTailwindV4CssSourceEntries = getConfiguredTailwindV4CssSourceEntries();
|
|
4115
|
+
const inferredOriginalSourceStyle = resolveSourceStyleSourceFromOutputFile(outputFile, snapshot, outDir, sourceRoot, getSourceCandidateSource, getSourceCandidateSources, configuredTailwindV4CssSourceEntries.map((entry) => [entry.file, entry.source]), debug) ?? (outputFile === file ? void 0 : resolveSourceStyleSourceFromOutputFile(file, snapshot, outDir, sourceRoot, getSourceCandidateSource, getSourceCandidateSources, configuredTailwindV4CssSourceEntries.map((entry) => [entry.file, entry.source]), debug));
|
|
4116
|
+
if (inferredOriginalSourceStyle) {
|
|
4117
|
+
outputFile = resolveMatchedOutputFileForCurrentAsset(inferredOriginalSourceStyle.sourceFile) ?? outputFile;
|
|
4118
|
+
activeViteCssCacheFiles.add(normalizeViteCssCacheKey(outputFile));
|
|
4119
|
+
outputCssHandlerOptions = getCssHandlerOptions(outputFile);
|
|
4120
|
+
rememberedCssSources = [{
|
|
4121
|
+
...inferredOriginalSourceStyle,
|
|
4122
|
+
outputFile
|
|
4123
|
+
}];
|
|
4124
|
+
} else if (hasTailwindGenerationSource(rawSource) && (originalSource.originalFileNames?.length ?? 0) === 0) {
|
|
4125
|
+
const availableConfiguredTailwindV4CssSourceEntries = configuredTailwindV4CssSourceEntries.filter((entry) => !usedConfiguredTailwindV4CssSourceFiles.has(normalizeOutputPathKey(entry.file)));
|
|
4126
|
+
const configuredGenerationSource = selectTailwindV4GenerationCssSourceForOutput(outputFile, availableConfiguredTailwindV4CssSourceEntries, rawSource, currentSubpackageRoots);
|
|
4127
|
+
if (configuredGenerationSource && !hasViteProcessedCssResultForSource(configuredGenerationSource.file, getViteProcessedCssAssetResults)) {
|
|
4128
|
+
outputFile = resolveMatchedOutputFileForCurrentAsset(configuredGenerationSource.file) ?? outputFile;
|
|
4129
|
+
activeViteCssCacheFiles.add(normalizeViteCssCacheKey(outputFile));
|
|
4130
|
+
outputCssHandlerOptions = getCssHandlerOptions(outputFile);
|
|
4131
|
+
usedConfiguredTailwindV4CssSourceFiles.add(normalizeOutputPathKey(configuredGenerationSource.file));
|
|
4132
|
+
rememberedCssSources = [{
|
|
4133
|
+
outputFile,
|
|
4134
|
+
rawSource: configuredGenerationSource.source,
|
|
4135
|
+
sourceFile: configuredGenerationSource.file
|
|
4136
|
+
}];
|
|
4137
|
+
debug("source style source inferred from scoped configured tailwind v4 css source: %s -> %s", outputFile, configuredGenerationSource.file);
|
|
4138
|
+
}
|
|
4139
|
+
}
|
|
4140
|
+
}
|
|
4141
|
+
let rememberedCssSource = mergeRememberedCssSources(rememberedCssSources, outputFile);
|
|
4142
|
+
if (rememberedCssSource && viteProcessedCssAsset && outputCssHandlerOptions.isMainChunk !== true && configuredTailwindV4CssSourceFileKeysForScope.has(normalizeOutputPathKey(rememberedCssSource.sourceFile.replace(/[?#].*$/, "")))) {
|
|
4143
|
+
const matchedOutputFile = resolveMatchedOutputFileForCurrentAsset(rememberedCssSource.sourceFile);
|
|
4144
|
+
if (matchedOutputFile && normalizeOutputPathKey(matchedOutputFile) !== normalizeOutputPathKey(outputFile)) {
|
|
4145
|
+
outputFile = matchedOutputFile;
|
|
4146
|
+
activeViteCssCacheFiles.add(normalizeViteCssCacheKey(outputFile));
|
|
4147
|
+
outputCssHandlerOptions = getCssHandlerOptions(outputFile);
|
|
4148
|
+
rememberedCssSource = {
|
|
4149
|
+
...rememberedCssSource,
|
|
4150
|
+
outputFile
|
|
4151
|
+
};
|
|
4152
|
+
}
|
|
3378
4153
|
}
|
|
3379
|
-
const rememberedCssSource = mergeRememberedCssSources(rememberedCssSources, outputFile);
|
|
3380
4154
|
const shouldKeepImportedCssShell = isCssImportOnlyBundleAsset(bundle, file, rawSource);
|
|
3381
4155
|
const useRememberedCssSource = !shouldKeepImportedCssShell && rememberedCssSource != null && (normalizeOutputPathKey(rememberedCssSource.sourceFile) !== normalizeOutputPathKey(file) || !hasTailwindGenerationSource(rawSource) && hasTailwindGenerationSource(rememberedCssSource.rawSource));
|
|
3382
4156
|
const vitePipelineCssAsset = viteProcessedCssAsset || useRememberedCssSource;
|
|
@@ -3394,35 +4168,46 @@ function createGenerateBundleHook(context) {
|
|
|
3394
4168
|
}
|
|
3395
4169
|
const hasRememberedApplyDirective = rememberedCssSource != null && hasTailwindApplyDirective(rememberedCssSource.rawSource);
|
|
3396
4170
|
const hasRememberedTailwindGenerationSource = rememberedCssSource != null && hasTailwindGenerationSource(rememberedCssSource.rawSource);
|
|
4171
|
+
const usesConfiguredTailwindV4FallbackSource = rememberedCssSource != null && normalizeOutputPathKey(rememberedCssSource.outputFile) === normalizeOutputPathKey(outputFile) && normalizeOutputPathKey(rememberedCssSource.sourceFile.replace(/[?#].*$/, "")) !== normalizeOutputPathKey(file);
|
|
3397
4172
|
const hasSameOutputRememberedTailwindGenerationSource = hasRememberedTailwindGenerationSource && rememberedCssSource != null && normalizeOutputPathKey(rememberedCssSource.outputFile) === normalizeOutputPathKey(outputFile);
|
|
3398
|
-
const hasStaleViteProcessedCssSource = vitePipelineCssAsset && hasDifferentRememberedCssSource && (hasCurrentTailwindGenerationDirective || hasRememberedApplyDirective ||
|
|
4173
|
+
const hasStaleViteProcessedCssSource = vitePipelineCssAsset && hasDifferentRememberedCssSource && (hasCurrentTailwindGenerationDirective || hasRememberedApplyDirective || hasRememberedTailwindGenerationSource);
|
|
3399
4174
|
const generatorSourceFile = vitePipelineCssAsset ? rememberedCssSource?.sourceFile ?? assetSourceFile : assetSourceFile;
|
|
3400
|
-
|
|
4175
|
+
if (vitePipelineCssAsset && outputCssHandlerOptions.isMainChunk !== true && configuredTailwindV4CssSourceFileKeysForScope.has(normalizeOutputPathKey(generatorSourceFile.replace(/[?#].*$/, "")))) usedConfiguredTailwindV4CssSourceFiles.add(normalizeOutputPathKey(generatorSourceFile));
|
|
3401
4176
|
const cssHandlerOptions = vitePipelineCssAsset ? {
|
|
3402
4177
|
...getCssHandlerOptions(generatorSourceFile),
|
|
3403
4178
|
isMainChunk: outputCssHandlerOptions.isMainChunk
|
|
3404
4179
|
} : getCssHandlerOptions(file);
|
|
3405
|
-
const
|
|
3406
|
-
|
|
4180
|
+
const generatorCssHandlerOptions = {
|
|
4181
|
+
...cssHandlerOptions,
|
|
4182
|
+
sourceOptions: {
|
|
4183
|
+
...cssHandlerOptions.sourceOptions ?? {},
|
|
4184
|
+
sourceFile: generatorSourceFile,
|
|
4185
|
+
cssEntries: opts.cssEntries
|
|
4186
|
+
}
|
|
4187
|
+
};
|
|
4188
|
+
const scopedSourceCandidateGetter = createScopedSourceCandidateGetter(outputFile, generatorCssHandlerOptions);
|
|
4189
|
+
const scopedSourceCandidateSourceGetter = createScopedSourceCandidateSourceGetter(outputFile, generatorCssHandlerOptions);
|
|
3407
4190
|
const sourceTraceTokenSources = scopedSourceCandidateSourceGetter ? createCssTokenSourceMap(scopedSourceCandidateSourceGetter(void 0), opts) : void 0;
|
|
3408
4191
|
const sourceTraceSignature = createCssSourceTraceCacheSignature(sourceTraceTokenSources, opts);
|
|
3409
|
-
const scopedGeneratorRuntime = await createScopedGeneratorRuntime$1(outputFile,
|
|
4192
|
+
const scopedGeneratorRuntime = await createScopedGeneratorRuntime$1(outputFile, generatorCssHandlerOptions, generatorRuntime, generatorRawSource, generatorSourceFile);
|
|
3410
4193
|
const annotateCss = (css) => annotateCssSourceTrace(css, {
|
|
3411
4194
|
opts,
|
|
3412
4195
|
tokenSources: sourceTraceTokenSources
|
|
3413
4196
|
});
|
|
3414
|
-
const shouldRegenerateMainPackageCssWithScopedCandidates = vitePipelineCssAsset && shouldExcludeSubpackageSourceCandidates(outputFile,
|
|
4197
|
+
const shouldRegenerateMainPackageCssWithScopedCandidates = vitePipelineCssAsset && shouldExcludeSubpackageSourceCandidates(outputFile, generatorCssHandlerOptions);
|
|
3415
4198
|
const generatorCssUserHandlerOptions = getCssUserHandlerOptions(generatorSourceFile);
|
|
3416
4199
|
const cssRuntimeAffectingSignature = vitePipelineCssAsset ? createRuntimeAffectingSourceSignature(generatorRawSource, "css") : snapshot.runtimeAffectingSignatureByFile.get(file) ?? createRuntimeAffectingSourceSignature(generatorRawSource, "css");
|
|
3417
4200
|
const cssRuntimeAffectingHash = vitePipelineCssAsset ? cache.computeHash(cssRuntimeAffectingSignature) : snapshot.runtimeAffectingHashByFile.get(file) ?? cache.computeHash(cssRuntimeAffectingSignature);
|
|
3418
|
-
const cssShareScope = createCssTransformShareScopeKey(opts,
|
|
4201
|
+
const cssShareScope = createCssTransformShareScopeKey(opts, outputFile, generatorRawSource);
|
|
3419
4202
|
const shouldRegenerateCollectedViteCss = viteProcessedCssAsset && useIncrementalMode && state.generatorCandidateSignature !== void 0 && generatorCandidatesChanged && (hasTailwindGenerationSource(generatorRawSource) || hasBundlerGeneratedCssMarker(rawSource) || rememberedCssSource != null && hasTailwindGenerationSource(rememberedCssSource.rawSource));
|
|
3420
4203
|
const shouldRefreshViteProcessedCssByCandidates = viteProcessedCssAsset && useIncrementalMode && state.generatorCandidateSignature !== void 0 && generatorCandidatesChanged;
|
|
3421
4204
|
const shouldInjectVitePipelineCssIntoMain = vitePipelineCssAsset && outputCssHandlerOptions.isMainChunk !== true && shouldInjectCssIntoMainFromOutput(outputFile, generatorSourceFile, outputCssHandlerOptions);
|
|
3422
4205
|
const shouldTrackGeneratorRuntime = hasStaleViteProcessedCssSource || shouldRegenerateMainPackageCssWithScopedCandidates || hasCurrentTailwindGenerationDirective || hasSameOutputRememberedTailwindGenerationSource || shouldProcessTailwindGeneration && (!useIncrementalMode || cssHandlerOptions.isMainChunk || processFiles.css.has(file) || runtimeLinkedCssFiles.has(file) || runtimeLinkedCssFiles.has(outputFile) || shouldRegenerateCollectedViteCss || hasRuntimeAffectingChanges && (alreadyProcessedCssAsset || vitePipelineCssAsset));
|
|
3423
4206
|
const shouldPreserveCollectedViteCssAsset = !shouldRegenerateCollectedViteCss && (state.generatorCandidateSignature === void 0 || !generatorCandidatesChanged) && (collectedBundlerGeneratedCssFiles.has(file) || hasBundlerGeneratedCssMarker(rawSource));
|
|
3424
|
-
|
|
3425
|
-
|
|
4207
|
+
const strippedViteProcessedCss = stripBundlerGeneratedCssMarkers(rawSource);
|
|
4208
|
+
const shouldPreserveStaleGeneratedCssAsset = hasStaleViteProcessedCssSource && shouldPreserveCollectedViteCssAsset && strippedViteProcessedCss.trim().length > 0 && !strippedViteProcessedCss.includes("weapp-tailwindcss generator-placeholder") && !strippedViteProcessedCss.includes("vite-placeholder") && !hasTailwindGenerationSource(strippedViteProcessedCss) && !hasTailwindApplyDirective(strippedViteProcessedCss);
|
|
4209
|
+
if (alreadyProcessedCssAsset && !shouldRefreshViteProcessedCssByCandidates && (!hasStaleViteProcessedCssSource || shouldPreserveStaleGeneratedCssAsset) && !hasRememberedApplySource && !shouldRegenerateMainPackageCssWithScopedCandidates && (!shouldTrackGeneratorRuntime || shouldPreserveCollectedViteCssAsset)) {
|
|
4210
|
+
const nextCss = strippedViteProcessedCss;
|
|
3426
4211
|
applyCssResult(nextCss);
|
|
3427
4212
|
markCssAssetProcessed?.(originalSource, outputFile);
|
|
3428
4213
|
recordCssAssetResult?.(outputFile, nextCss);
|
|
@@ -3436,14 +4221,14 @@ function createGenerateBundleHook(context) {
|
|
|
3436
4221
|
}
|
|
3437
4222
|
const trackedGeneratorCandidateSignature = shouldTrackGeneratorRuntime ? createCandidateSignature(scopedGeneratorRuntime) : "generator:stable";
|
|
3438
4223
|
const scopedGeneratorCandidateSignature = shouldTrackGeneratorRuntime ? await createScopedGeneratorCandidateSignature(generatorRawSource, generatorSourceFile, trackedGeneratorCandidateSignature, scopedSourceCandidateGetter, {
|
|
3439
|
-
includeFallbackSignature:
|
|
3440
|
-
majorVersion: runtimeState.
|
|
4224
|
+
includeFallbackSignature: generatorCssHandlerOptions.isMainChunk,
|
|
4225
|
+
majorVersion: runtimeState.tailwindRuntime.majorVersion
|
|
3441
4226
|
}) : trackedGeneratorCandidateSignature;
|
|
3442
4227
|
const cssRuntimeSignature = createCssRuntimeSignature(runtimeSignature, scopedGeneratorCandidateSignature);
|
|
3443
4228
|
const rememberedCssRuntimeSignature = createRememberedCssRuntimeSignature(cssRuntimeSignature, cssRuntimeAffectingHash);
|
|
3444
|
-
const cssSharedCacheKey = `${cssShareScope}:${cssRuntimeSignature}:${runtimeState.
|
|
3445
|
-
const cssCacheKey =
|
|
3446
|
-
const cssHashKey = `${
|
|
4229
|
+
const cssSharedCacheKey = `${cssShareScope}:${cssRuntimeSignature}:${runtimeState.tailwindRuntime.majorVersion ?? "unknown"}:${cssHandlerOptions.isMainChunk ? "1" : "0"}:${cssRuntimeAffectingHash}:${scopedGeneratorCandidateSignature}:${sourceTraceSignature}`;
|
|
4230
|
+
const cssCacheKey = outputFile;
|
|
4231
|
+
const cssHashKey = `${outputFile}:css:${cssRuntimeSignature}:${runtimeState.tailwindRuntime.majorVersion ?? "unknown"}`;
|
|
3447
4232
|
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(":") : "";
|
|
3448
4233
|
if (!shouldTrackGeneratorRuntime && !runtimeLinkedCssFiles.has(file) && !runtimeLinkedCssFiles.has(outputFile)) {
|
|
3449
4234
|
const lastCss = getLastCssResult(lastCssResultByFile, outputFile, file);
|
|
@@ -3489,24 +4274,30 @@ function createGenerateBundleHook(context) {
|
|
|
3489
4274
|
const runTransform = async () => {
|
|
3490
4275
|
const start = performance.now();
|
|
3491
4276
|
await runtimeState.readyPromise;
|
|
3492
|
-
const
|
|
4277
|
+
const previousCss = !vitePipelineCssAsset && useIncrementalMode && !hasRuntimeAffectingChanges && !snapshot.changedByType.css.has(file) ? getLastCssResult(lastCssResultByFile, outputFile, file) : void 0;
|
|
4278
|
+
const generated = hasTailwindGenerationSource(generatorRawSource) || hasBundlerGeneratedCssMarker(rawSource) ? await generateTailwindV4Css({
|
|
3493
4279
|
opts,
|
|
3494
4280
|
runtimeState,
|
|
3495
4281
|
runtime: scopedGeneratorRuntime,
|
|
3496
4282
|
rawSource: generatorRawSource,
|
|
3497
4283
|
file: generatorSourceFile,
|
|
3498
|
-
|
|
4284
|
+
outputFile,
|
|
4285
|
+
cssHandlerOptions: generatorCssHandlerOptions,
|
|
3499
4286
|
cssUserHandlerOptions: generatorCssUserHandlerOptions,
|
|
3500
4287
|
getSourceCandidatesForEntries: scopedSourceCandidateGetter,
|
|
4288
|
+
sourceCandidates: scopedGeneratorRuntime,
|
|
3501
4289
|
styleHandler,
|
|
3502
4290
|
debug,
|
|
3503
|
-
previousCss
|
|
3504
|
-
|
|
4291
|
+
previousCss,
|
|
4292
|
+
...vitePipelineCssAsset && !hasBundlerGeneratedCssMarker(rawSource) && normalizeCssSourceForCompare(rawSource) !== normalizeCssSourceForCompare(generatorRawSource) ? { userRawSource: normalizeGeneratorUserRawSource(rawSource, generatorSourceFile, assetSourceFile) } : {},
|
|
4293
|
+
...usesConfiguredTailwindV4FallbackSource ? { restoreLocalCssImports: false } : {}
|
|
4294
|
+
}) : void 0;
|
|
3505
4295
|
if (generated) {
|
|
3506
4296
|
const tracedCss = annotateCss(generated.css);
|
|
3507
4297
|
registerGeneratorDependencies$1({ addWatchFile }, generated.dependencies);
|
|
3508
4298
|
if (envFlags.debugCssDiff) debug("css diff %s: %s", generatorSourceFile, summarizeStringDiff(generatorRawSource, tracedCss));
|
|
3509
4299
|
debug("css generated result: %s bytes=%d", file, tracedCss.length);
|
|
4300
|
+
for (const candidate of generated.classSet ?? []) transformRuntime.add(candidate);
|
|
3510
4301
|
recordCssAssetResult?.(outputFile, tracedCss);
|
|
3511
4302
|
recordViteProcessedCssAssetResult?.(outputFile, tracedCss, {
|
|
3512
4303
|
injectIntoMain: outputCssHandlerOptions.isMainChunk ? false : shouldInjectVitePipelineCssIntoMain,
|
|
@@ -3518,7 +4309,7 @@ function createGenerateBundleHook(context) {
|
|
|
3518
4309
|
});
|
|
3519
4310
|
metrics.css.elapsed += measureElapsed(start);
|
|
3520
4311
|
metrics.css.transformed++;
|
|
3521
|
-
debug("css handle via tailwind v%s engine(%s): %s", runtimeState.
|
|
4312
|
+
debug("css handle via tailwind v%s engine(%s): %s", runtimeState.tailwindRuntime.majorVersion, generated.target, outputFile);
|
|
3522
4313
|
return tracedCss;
|
|
3523
4314
|
}
|
|
3524
4315
|
if (isWebGeneratorTarget) {
|
|
@@ -3568,8 +4359,12 @@ function createGenerateBundleHook(context) {
|
|
|
3568
4359
|
rememberProcessCacheKey,
|
|
3569
4360
|
runtimeSignature,
|
|
3570
4361
|
snapshot,
|
|
4362
|
+
transformFilterSignature,
|
|
4363
|
+
shouldSkipAstTransform: transformFilter ? (chunk) => shouldSkipViteJsChunkTransform(chunk, transformFilter) : void 0,
|
|
4364
|
+
slowJsAstWarnMs: envFlags.slowJsAstWarnMs,
|
|
3571
4365
|
timeTask,
|
|
3572
4366
|
transformRuntime,
|
|
4367
|
+
transformRuntimeSignature,
|
|
3573
4368
|
uniAppX,
|
|
3574
4369
|
useIncrementalMode
|
|
3575
4370
|
});
|
|
@@ -3580,10 +4375,10 @@ function createGenerateBundleHook(context) {
|
|
|
3580
4375
|
bundle,
|
|
3581
4376
|
bundleFiles,
|
|
3582
4377
|
cache,
|
|
4378
|
+
cssTaskFactories,
|
|
3583
4379
|
createScopedGeneratorRuntime: createScopedGeneratorRuntime$1,
|
|
3584
4380
|
createScopedSourceCandidateGetter,
|
|
3585
4381
|
createScopedSourceCandidateSourceGetter,
|
|
3586
|
-
cssTaskFactories,
|
|
3587
4382
|
debug,
|
|
3588
4383
|
defaultStyleOutputExtension,
|
|
3589
4384
|
emitOrReplayCssAsset,
|
|
@@ -3614,7 +4409,6 @@ function createGenerateBundleHook(context) {
|
|
|
3614
4409
|
timeTask,
|
|
3615
4410
|
useIncrementalMode
|
|
3616
4411
|
});
|
|
3617
|
-
pushConcurrentTaskFactories(tasks, jsTaskFactories);
|
|
3618
4412
|
await finalizeGenerateBundle({
|
|
3619
4413
|
activeProcessCacheKeys,
|
|
3620
4414
|
activeProcessHashKeys,
|
|
@@ -3639,6 +4433,8 @@ function createGenerateBundleHook(context) {
|
|
|
3639
4433
|
isNativeAppStyleTarget,
|
|
3640
4434
|
isViteProcessedCssAsset,
|
|
3641
4435
|
isWebGeneratorTarget,
|
|
4436
|
+
jsAfterCss: shouldFilterTailwindV4MiniProgramCandidates && cssTaskFactories.length > 0,
|
|
4437
|
+
jsTaskFactories,
|
|
3642
4438
|
lastCssResultByFile,
|
|
3643
4439
|
lastCssSourceHashByFile,
|
|
3644
4440
|
linkedByEntry,
|
|
@@ -3692,15 +4488,19 @@ function createCssHandlerOptions(opts, majorVersion, file) {
|
|
|
3692
4488
|
...resolveUniAppXNativeCssHandlerOptions(opts),
|
|
3693
4489
|
isMainChunk: opts.mainCssChunkMatcher(file, opts.appType),
|
|
3694
4490
|
postcssOptions: { options: { from: file } },
|
|
3695
|
-
...majorVersion === void 0 ? {} : { majorVersion }
|
|
4491
|
+
...normalizeStyleHandlerMajorVersion(majorVersion) === void 0 ? {} : { majorVersion: 4 }
|
|
3696
4492
|
};
|
|
3697
4493
|
}
|
|
3698
|
-
function shouldGenerateCssByGenerator(opts, file, rawSource, processed) {
|
|
3699
|
-
const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(opts.generator
|
|
4494
|
+
function shouldGenerateCssByGenerator(opts, majorVersion, file, rawSource, processed) {
|
|
4495
|
+
const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(opts.generator, {
|
|
4496
|
+
appType: opts.appType,
|
|
4497
|
+
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
4498
|
+
tailwindcssMajorVersion: majorVersion,
|
|
4499
|
+
uniAppX: opts.uniAppX
|
|
4500
|
+
});
|
|
3700
4501
|
if (hasLocalCssImport(rawSource)) return false;
|
|
3701
4502
|
if (hasTailwindGeneratedCssMarkers(rawSource)) return true;
|
|
3702
4503
|
if (hasTailwindRootDirectives(rawSource, { importFallback: generatorOptions.importFallback })) return true;
|
|
3703
|
-
if (opts.twPatcher.majorVersion === 3) return false;
|
|
3704
4504
|
return processed && hasTailwindApplyDirective(rawSource) && shouldFinalizeProcessedCssAsset(opts, file);
|
|
3705
4505
|
}
|
|
3706
4506
|
function shouldFinalizeProcessedCssAsset(opts, file) {
|
|
@@ -3718,9 +4518,21 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
3718
4518
|
async handler(_options, bundle) {
|
|
3719
4519
|
const { opts, runtimeState, ensureRuntimeClassSet, isCssAssetProcessed, markCssAssetProcessed, debug, getResolvedConfig, recordCssAssetResult, recordViteProcessedCssAssetResult, getViteProcessedCssAssetResults, getRecordedGeneratorCandidates, getSourceCandidates, getSourceCandidatesForEntries, getSourceCandidateSourcesForEntries, waitForSourceCandidateSyncs, rememberMainCssSource, getRememberedMainCssSource, isViteProcessedCssAsset } = context;
|
|
3720
4520
|
const resolvedConfig = getResolvedConfig();
|
|
3721
|
-
const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(opts.generator);
|
|
3722
|
-
const isWebGeneratorTarget = generatorOptions.target === "web";
|
|
3723
4521
|
const uniUtsPlatform = resolveUniUtsPlatform();
|
|
4522
|
+
const generatorBranch = resolveGeneratorRuntimeBranch(normalizeWeappTailwindcssGeneratorOptions(opts.generator, {
|
|
4523
|
+
appType: opts.appType,
|
|
4524
|
+
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
4525
|
+
tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
4526
|
+
uniAppX: opts.uniAppX,
|
|
4527
|
+
uniUtsPlatform
|
|
4528
|
+
}), {
|
|
4529
|
+
appType: opts.appType,
|
|
4530
|
+
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
4531
|
+
tailwindcssMajorVersion: runtimeState.tailwindRuntime.majorVersion,
|
|
4532
|
+
uniAppX: opts.uniAppX,
|
|
4533
|
+
uniUtsPlatform
|
|
4534
|
+
});
|
|
4535
|
+
const isWebGeneratorTarget = generatorBranch.isWeb;
|
|
3724
4536
|
const canInferHarmonyAppStyleTarget = !uniUtsPlatform.normalized || uniUtsPlatform.isApp;
|
|
3725
4537
|
const isHarmonyAppStyleTarget = uniUtsPlatform.isAppHarmony || canInferHarmonyAppStyleTarget && (isUniAppXHarmonyBundle(bundle) || isUniAppXHarmonyOutDir(resolvedConfig?.build?.outDir));
|
|
3726
4538
|
const isNativeAppStyleTarget = uniUtsPlatform.isApp || isHarmonyAppStyleTarget;
|
|
@@ -3760,13 +4572,14 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
3760
4572
|
const applyStyleSources = collectUniAppXHarmonyApplyStyleSources(bundle);
|
|
3761
4573
|
if (applyUtilities.size === 0 || applyStyleSources.length === 0) return cssSources;
|
|
3762
4574
|
const harmonyRuntime = new Set([...runtime, ...applyUtilities]);
|
|
3763
|
-
const harmonyCssHandlerOptions = createCssHandlerOptions(opts, runtimeState.
|
|
3764
|
-
const generated = await
|
|
4575
|
+
const harmonyCssHandlerOptions = createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, "uni-app-x-harmony-apply.css");
|
|
4576
|
+
const generated = await generateTailwindV4Css({
|
|
3765
4577
|
opts,
|
|
3766
4578
|
runtimeState,
|
|
3767
4579
|
runtime: harmonyRuntime,
|
|
3768
4580
|
rawSource: createUniAppXHarmonyApplyGeneratorSource(applyStyleSources, applyUtilities),
|
|
3769
4581
|
file: "uni-app-x-harmony-apply.css",
|
|
4582
|
+
outputFile: "uni-app-x-harmony-apply.css",
|
|
3770
4583
|
cssHandlerOptions: harmonyCssHandlerOptions,
|
|
3771
4584
|
cssUserHandlerOptions: {
|
|
3772
4585
|
...harmonyCssHandlerOptions,
|
|
@@ -3784,21 +4597,29 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
3784
4597
|
if (injectUniAppXHarmonyBundleStyles(bundle, { cssSources: await createHarmonyBundleStyleSources(runtime) })) debug("uni-app-x harmony bundle styles inject");
|
|
3785
4598
|
};
|
|
3786
4599
|
const isCssOutputAssetEntry = (entry) => {
|
|
3787
|
-
const [, output] = entry;
|
|
3788
|
-
|
|
4600
|
+
const [bundleFile, output] = entry;
|
|
4601
|
+
const fileName = output.fileName || bundleFile;
|
|
4602
|
+
return output.type === "asset" && opts.cssMatcher(fileName) && !opts.htmlMatcher(fileName) && !isHTMLRequest(fileName) && !isCssAssetProcessed(output, fileName);
|
|
3789
4603
|
};
|
|
3790
4604
|
const entries = Object.entries(bundle).filter(isCssOutputAssetEntry);
|
|
3791
4605
|
if (entries.length === 0) {
|
|
3792
4606
|
await injectHarmonyBundleStyles(getRecordedGeneratorCandidates?.() ?? getSourceCandidates?.() ?? await ensureRuntimeClassSet());
|
|
3793
4607
|
collectViteProcessedCssAssets();
|
|
3794
4608
|
injectViteProcessedCssIntoMainCss();
|
|
4609
|
+
normalizeTaroRootImportShellAssets(bundle, {
|
|
4610
|
+
appType: opts.appType,
|
|
4611
|
+
cssMatcher: opts.cssMatcher,
|
|
4612
|
+
debug,
|
|
4613
|
+
onUpdate: opts.onUpdate,
|
|
4614
|
+
recordCssAssetResult
|
|
4615
|
+
});
|
|
3795
4616
|
return;
|
|
3796
4617
|
}
|
|
3797
4618
|
await runtimeState.readyPromise;
|
|
3798
4619
|
await waitForSourceCandidateSyncs?.();
|
|
3799
4620
|
const runtime = getRecordedGeneratorCandidates?.() ?? getSourceCandidates?.() ?? await ensureRuntimeClassSet();
|
|
3800
4621
|
const collectedGeneratorCandidates = new Set([...runtime, ...getSourceCandidates?.() ?? []]);
|
|
3801
|
-
const generatorRuntime =
|
|
4622
|
+
const generatorRuntime = shouldUseMiniProgramCssBranch(generatorBranch) ? filterUnsupportedMiniProgramTailwindV4Candidates(collectedGeneratorCandidates) : collectedGeneratorCandidates;
|
|
3802
4623
|
await Promise.all(entries.map(async ([bundleFile, output]) => {
|
|
3803
4624
|
const file = output.fileName || bundleFile;
|
|
3804
4625
|
const rawSource = output.source.toString();
|
|
@@ -3810,7 +4631,7 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
3810
4631
|
debug("css finalizer skip vite-processed css: %s", file);
|
|
3811
4632
|
return;
|
|
3812
4633
|
}
|
|
3813
|
-
const cssHandlerOptions = createCssHandlerOptions(opts, runtimeState.
|
|
4634
|
+
const cssHandlerOptions = createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, file);
|
|
3814
4635
|
const cssUserHandlerOptions = {
|
|
3815
4636
|
...cssHandlerOptions,
|
|
3816
4637
|
isMainChunk: false
|
|
@@ -3819,24 +4640,25 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
3819
4640
|
const rememberedMainCssSource = processed && cssHandlerOptions.isMainChunk ? getRememberedMainCssSource?.(file) : void 0;
|
|
3820
4641
|
const generatorRawSource = rememberedMainCssSource?.rawSource ?? rawSource;
|
|
3821
4642
|
const generatorSourceFile = rememberedMainCssSource?.sourceFile ?? file;
|
|
3822
|
-
const generatorCssHandlerOptions = rememberedMainCssSource ? createCssHandlerOptions(opts, runtimeState.
|
|
4643
|
+
const generatorCssHandlerOptions = rememberedMainCssSource ? createCssHandlerOptions(opts, runtimeState.tailwindRuntime.majorVersion, generatorSourceFile) : cssHandlerOptions;
|
|
3823
4644
|
const generatorCssUserHandlerOptions = rememberedMainCssSource ? {
|
|
3824
4645
|
...generatorCssHandlerOptions,
|
|
3825
4646
|
isMainChunk: false
|
|
3826
4647
|
} : cssUserHandlerOptions;
|
|
3827
|
-
const generated = shouldGenerateCssByGenerator(opts, file, generatorRawSource, processed) ? await
|
|
4648
|
+
const generated = shouldGenerateCssByGenerator(opts, runtimeState.tailwindRuntime.majorVersion, file, generatorRawSource, processed) ? await generateTailwindV4Css({
|
|
3828
4649
|
opts,
|
|
3829
4650
|
runtimeState,
|
|
3830
4651
|
runtime: generatorRuntime,
|
|
3831
4652
|
rawSource: generatorRawSource,
|
|
3832
4653
|
file: generatorSourceFile,
|
|
4654
|
+
outputFile: file,
|
|
3833
4655
|
cssHandlerOptions: generatorCssHandlerOptions,
|
|
3834
4656
|
cssUserHandlerOptions: generatorCssUserHandlerOptions,
|
|
3835
4657
|
getSourceCandidatesForEntries,
|
|
3836
4658
|
styleHandler: opts.styleHandler,
|
|
3837
4659
|
debug
|
|
3838
4660
|
}) : void 0;
|
|
3839
|
-
const nextCss = annotateCss(generated?.css ?? (
|
|
4661
|
+
const nextCss = annotateCss(generated?.css ?? (generatorBranch.isWeb ? rawSource : (await opts.styleHandler(rawSource, cssHandlerOptions)).css));
|
|
3840
4662
|
if (generated) {
|
|
3841
4663
|
registerGeneratorDependencies(this, generated.dependencies);
|
|
3842
4664
|
debug("css finalizer generated result: %s bytes=%d", file, nextCss.length);
|
|
@@ -3851,6 +4673,13 @@ function createViteCssFinalizerOutputPlugin(context) {
|
|
|
3851
4673
|
await injectHarmonyBundleStyles(generatorRuntime);
|
|
3852
4674
|
collectViteProcessedCssAssets();
|
|
3853
4675
|
injectViteProcessedCssIntoMainCss();
|
|
4676
|
+
normalizeTaroRootImportShellAssets(bundle, {
|
|
4677
|
+
appType: opts.appType,
|
|
4678
|
+
cssMatcher: opts.cssMatcher,
|
|
4679
|
+
debug,
|
|
4680
|
+
onUpdate: opts.onUpdate,
|
|
4681
|
+
recordCssAssetResult
|
|
4682
|
+
});
|
|
3854
4683
|
}
|
|
3855
4684
|
}
|
|
3856
4685
|
};
|
|
@@ -3875,6 +4704,27 @@ const VITE_REMEMBERED_CSS_CACHE_MAX = 96;
|
|
|
3875
4704
|
const VITE_KNOWN_SFC_SOURCE_CACHE_MAX = 128;
|
|
3876
4705
|
const SFC_STYLE_BLOCK_RE = /<style\b[^>]*>([\s\S]*?)<\/style>/gi;
|
|
3877
4706
|
const SFC_COMPONENT_FILE_RE = /\.(?:vue|uvue|nvue|svelte|mpx)$/i;
|
|
4707
|
+
function toMb$1(bytes) {
|
|
4708
|
+
return Math.round(bytes / 1024 / 1024);
|
|
4709
|
+
}
|
|
4710
|
+
function summarizeStringMapCache(map) {
|
|
4711
|
+
let bytes = 0;
|
|
4712
|
+
for (const value of map.values()) bytes += value.length;
|
|
4713
|
+
return {
|
|
4714
|
+
bytes,
|
|
4715
|
+
mb: toMb$1(bytes),
|
|
4716
|
+
size: map.size
|
|
4717
|
+
};
|
|
4718
|
+
}
|
|
4719
|
+
function summarizeRememberedCssSources(map) {
|
|
4720
|
+
let bytes = 0;
|
|
4721
|
+
for (const value of map.values()) bytes += value.rawSource.length;
|
|
4722
|
+
return {
|
|
4723
|
+
bytes,
|
|
4724
|
+
mb: toMb$1(bytes),
|
|
4725
|
+
size: map.size
|
|
4726
|
+
};
|
|
4727
|
+
}
|
|
3878
4728
|
function stripSourceHash(sourceFile) {
|
|
3879
4729
|
const hashIndex = sourceFile.indexOf("#");
|
|
3880
4730
|
return hashIndex === -1 ? sourceFile : sourceFile.slice(0, hashIndex);
|
|
@@ -3923,6 +4773,7 @@ function shouldCollectTransformedSourceCandidates(id) {
|
|
|
3923
4773
|
function createViteCssMemory(options) {
|
|
3924
4774
|
const rememberedCssSources = /* @__PURE__ */ new Map();
|
|
3925
4775
|
const rememberedCssSignatureByFile = /* @__PURE__ */ new Map();
|
|
4776
|
+
const knownCssSources = /* @__PURE__ */ new Map();
|
|
3926
4777
|
const knownSfcSources = /* @__PURE__ */ new Map();
|
|
3927
4778
|
const rememberKnownSfcSource = (id, code) => {
|
|
3928
4779
|
if (id.search(/[?#]/) >= 0) return;
|
|
@@ -3974,6 +4825,7 @@ function createViteCssMemory(options) {
|
|
|
3974
4825
|
return nextRemembered;
|
|
3975
4826
|
};
|
|
3976
4827
|
const refreshRememberedCssSourceBySourceFile = (sourceFile, rawSource) => {
|
|
4828
|
+
touchMapEntry(knownCssSources, normalizeCssSourceIdentity(sourceFile), rawSource);
|
|
3977
4829
|
const normalizedSourceFile = normalizeCssSourceIdentity(sourceFile);
|
|
3978
4830
|
const relatedRememberedEntries = [...rememberedCssSources].filter(([, remembered]) => normalizeCssSourceIdentity(remembered.sourceFile) === normalizedSourceFile);
|
|
3979
4831
|
for (const [rememberedKey, remembered] of relatedRememberedEntries) refreshRememberedCssSourceEntry(rememberedKey, remembered, sourceFile, rawSource);
|
|
@@ -3983,12 +4835,28 @@ function createViteCssMemory(options) {
|
|
|
3983
4835
|
if (SFC_COMPONENT_FILE_RE.test(file)) return getKnownSfcSource(file);
|
|
3984
4836
|
if (isSourceStyleRequest(file)) return options.getSourceCandidateSource(file);
|
|
3985
4837
|
};
|
|
4838
|
+
const resolveCurrentStyleSource = async (sourceFile) => {
|
|
4839
|
+
const cached = resolveCachedStyleSource(sourceFile);
|
|
4840
|
+
if (cached != null) return cached;
|
|
4841
|
+
const file = cleanUrl(stripRequestQuery(sourceFile));
|
|
4842
|
+
const knownSource = knownCssSources.get(normalizeCssSourceIdentity(sourceFile));
|
|
4843
|
+
if (knownSource != null) return knownSource;
|
|
4844
|
+
const candidateSource = options.getSourceCandidateSource(file);
|
|
4845
|
+
if (candidateSource != null) return candidateSource;
|
|
4846
|
+
if (!isSourceStyleRequest(file)) return;
|
|
4847
|
+
try {
|
|
4848
|
+
return await readFile(file, "utf8");
|
|
4849
|
+
} catch (error) {
|
|
4850
|
+
options.debug("refresh remembered css source read failed: %s %O", file, error);
|
|
4851
|
+
return;
|
|
4852
|
+
}
|
|
4853
|
+
};
|
|
3986
4854
|
const refreshRememberedCssSourceByCurrentFile = async (sourceFile) => {
|
|
3987
4855
|
const file = cleanUrl(sourceFile);
|
|
3988
4856
|
const normalizedSourceFile = normalizeOutputPathKey(file);
|
|
3989
4857
|
const matchedRememberedSources = [...rememberedCssSources.values()].filter((remembered) => normalizeOutputPathKey(stripRequestQuery(cleanUrl(remembered.sourceFile))) === normalizedSourceFile);
|
|
3990
4858
|
if (matchedRememberedSources.length === 0) return;
|
|
3991
|
-
const source =
|
|
4859
|
+
const source = await resolveCurrentStyleSource(file);
|
|
3992
4860
|
if (source == null) {
|
|
3993
4861
|
options.debug("refresh remembered css source skipped: missing cached source for %s", file);
|
|
3994
4862
|
return;
|
|
@@ -4007,7 +4875,7 @@ function createViteCssMemory(options) {
|
|
|
4007
4875
|
const file = cleanUrl(stripRequestQuery(remembered.sourceFile));
|
|
4008
4876
|
const rememberedKey = [...rememberedCssSources.entries()].find(([, entry]) => entry === remembered)?.[0];
|
|
4009
4877
|
if (!rememberedKey || !path.isAbsolute(file)) return;
|
|
4010
|
-
const source =
|
|
4878
|
+
const source = await resolveCurrentStyleSource(file);
|
|
4011
4879
|
if (source == null) {
|
|
4012
4880
|
options.debug("refresh remembered css source before bundle replay skipped: missing cached source for %s", file);
|
|
4013
4881
|
return;
|
|
@@ -4036,6 +4904,7 @@ function createViteCssMemory(options) {
|
|
|
4036
4904
|
pruneMapToMaxSize(rememberedCssSources, VITE_REMEMBERED_CSS_CACHE_MAX, (rememberedKey) => {
|
|
4037
4905
|
rememberedCssSignatureByFile.delete(String(rememberedKey));
|
|
4038
4906
|
});
|
|
4907
|
+
pruneMapToMaxSize(knownCssSources, VITE_REMEMBERED_CSS_CACHE_MAX);
|
|
4039
4908
|
pruneMapToMaxSize(knownSfcSources, VITE_KNOWN_SFC_SOURCE_CACHE_MAX);
|
|
4040
4909
|
};
|
|
4041
4910
|
return {
|
|
@@ -4045,8 +4914,12 @@ function createViteCssMemory(options) {
|
|
|
4045
4914
|
getRememberedCssSources: () => rememberedCssSources,
|
|
4046
4915
|
getStats: () => ({
|
|
4047
4916
|
rememberedCssSources: rememberedCssSources.size,
|
|
4917
|
+
rememberedCssSourcesRaw: summarizeRememberedCssSources(rememberedCssSources),
|
|
4048
4918
|
rememberedCssSignatureByFile: rememberedCssSignatureByFile.size,
|
|
4049
|
-
|
|
4919
|
+
knownCssSources: knownCssSources.size,
|
|
4920
|
+
knownCssSourcesRaw: summarizeStringMapCache(knownCssSources),
|
|
4921
|
+
knownSfcSources: knownSfcSources.size,
|
|
4922
|
+
knownSfcSourcesRaw: summarizeStringMapCache(knownSfcSources)
|
|
4050
4923
|
}),
|
|
4051
4924
|
rememberCssSource,
|
|
4052
4925
|
rememberKnownSfcSource,
|
|
@@ -4171,6 +5044,35 @@ function disableAndRemoveTailwindVitePlugins(plugins) {
|
|
|
4171
5044
|
return removed;
|
|
4172
5045
|
}
|
|
4173
5046
|
//#endregion
|
|
5047
|
+
//#region src/bundlers/vite/plugin-cache.ts
|
|
5048
|
+
function isMissingInternalCssSource(file, packageDir) {
|
|
5049
|
+
return !existsSync(file) && path.resolve(file).startsWith(`${packageDir}${path.sep}`);
|
|
5050
|
+
}
|
|
5051
|
+
function normalizeVitePersistentCacheKey(file) {
|
|
5052
|
+
return normalizeOutputPathKey(file);
|
|
5053
|
+
}
|
|
5054
|
+
function toMb(bytes) {
|
|
5055
|
+
return Math.round(bytes / 1024 / 1024);
|
|
5056
|
+
}
|
|
5057
|
+
function summarizeStringCache(map) {
|
|
5058
|
+
let bytes = 0;
|
|
5059
|
+
for (const value of map.values()) bytes += value.length;
|
|
5060
|
+
return {
|
|
5061
|
+
bytes,
|
|
5062
|
+
mb: toMb(bytes),
|
|
5063
|
+
size: map.size
|
|
5064
|
+
};
|
|
5065
|
+
}
|
|
5066
|
+
function summarizeViteProcessedCssResults(map) {
|
|
5067
|
+
let bytes = 0;
|
|
5068
|
+
for (const record of map.values()) bytes += record.css.length;
|
|
5069
|
+
return {
|
|
5070
|
+
bytes,
|
|
5071
|
+
mb: toMb(bytes),
|
|
5072
|
+
size: map.size
|
|
5073
|
+
};
|
|
5074
|
+
}
|
|
5075
|
+
//#endregion
|
|
4174
5076
|
//#region src/bundlers/shared/css-imports.ts
|
|
4175
5077
|
const tailwindcssImportRE = /^(?:tailwindcss|weapp-tailwindcss)(?:\/.*)?$/;
|
|
4176
5078
|
const tailwindcssCssImportStatementRE = /(@import\s+(?:url\(\s*)?)(["'])((?:tailwindcss|weapp-tailwindcss)(?:\/[^"']*)?\$?)(\2\s*\)?)/gi;
|
|
@@ -4233,18 +5135,25 @@ function createRewriteCssImportsPlugins(options) {
|
|
|
4233
5135
|
async transform(code, id) {
|
|
4234
5136
|
if (!isCSSRequest(id)) return null;
|
|
4235
5137
|
const file = cleanUrl(id);
|
|
4236
|
-
const normalizedCode = hasTailwindRootDirectives(code) ? normalizeTailwindConfigDirectives(code, path.dirname(file)) : code;
|
|
5138
|
+
const normalizedCode = hasTailwindRootDirectives(code) || code.includes("@config") ? normalizeTailwindConfigDirectives(code, path.dirname(file)) : code;
|
|
4237
5139
|
await options.onCssSourceTransform?.(id, normalizedCode);
|
|
4238
5140
|
const hasTailwindRoot = hasTailwindRootDirectives(normalizedCode);
|
|
4239
5141
|
if (hasTailwindRoot) await options.onTailwindRootCss?.(id, normalizedCode);
|
|
4240
|
-
|
|
5142
|
+
const shouldGenerateInPreTransform = !options.shouldDeferGeneration?.(id, normalizedCode) && (hasTailwindRoot || options.shouldGenerateCss?.(id, normalizedCode));
|
|
5143
|
+
if (options.shouldOwnTailwindGeneration && shouldGenerateInPreTransform) {
|
|
4241
5144
|
const generatedCss = await options.generateTailwindCss?.(id, normalizedCode, this);
|
|
4242
5145
|
if (generatedCss !== void 0) return {
|
|
4243
5146
|
code: generatedCss,
|
|
4244
5147
|
map: null
|
|
4245
5148
|
};
|
|
4246
5149
|
}
|
|
4247
|
-
if (!options.shouldRewrite)
|
|
5150
|
+
if (!options.shouldRewrite) {
|
|
5151
|
+
if (normalizedCode !== code) return {
|
|
5152
|
+
code: normalizedCode,
|
|
5153
|
+
map: null
|
|
5154
|
+
};
|
|
5155
|
+
return null;
|
|
5156
|
+
}
|
|
4248
5157
|
const rewritten = rewriteTailwindcssImportsInCode(normalizedCode, weappTailwindcssDirPosix, {
|
|
4249
5158
|
join: joinPosixPath,
|
|
4250
5159
|
appType: resolveAppType(),
|
|
@@ -4265,11 +5174,11 @@ function hasVitePipelineTailwindGenerationDirective(code) {
|
|
|
4265
5174
|
//#endregion
|
|
4266
5175
|
//#region src/bundlers/vite/runtime-class-set.ts
|
|
4267
5176
|
function createViteRuntimeClassSet(options) {
|
|
4268
|
-
const { opts,
|
|
5177
|
+
const { opts, initialTailwindRuntime, refreshTailwindcssRuntime, uniAppXEnabled, customAttributesEntities, disabledDefaultTemplateHandler, debug } = options;
|
|
4269
5178
|
const runtimeState = {
|
|
4270
|
-
|
|
4271
|
-
readyPromise: createTailwindRuntimeReadyPromise(
|
|
4272
|
-
|
|
5179
|
+
tailwindRuntime: initialTailwindRuntime,
|
|
5180
|
+
readyPromise: createTailwindRuntimeReadyPromise(initialTailwindRuntime),
|
|
5181
|
+
refreshTailwindcssRuntime
|
|
4273
5182
|
};
|
|
4274
5183
|
const bundleRuntimeClassSetManager = createBundleRuntimeClassSetManager({
|
|
4275
5184
|
bareArbitraryValues: opts.arbitraryValues?.bareArbitraryValues,
|
|
@@ -4284,8 +5193,8 @@ function createViteRuntimeClassSet(options) {
|
|
|
4284
5193
|
let runtimeRefreshSignature;
|
|
4285
5194
|
let runtimeRefreshOptionsKey;
|
|
4286
5195
|
function resolveRuntimeRefreshOptions() {
|
|
4287
|
-
const configPath = resolveTailwindcssOptions(runtimeState.
|
|
4288
|
-
const signature = getRuntimeClassSetSignature(runtimeState.
|
|
5196
|
+
const configPath = resolveTailwindcssOptions(runtimeState.tailwindRuntime.options)?.config;
|
|
5197
|
+
const signature = getRuntimeClassSetSignature(runtimeState.tailwindRuntime);
|
|
4289
5198
|
const optionsKey = JSON.stringify({
|
|
4290
5199
|
appType: opts.appType,
|
|
4291
5200
|
uniAppX: uniAppXEnabled,
|
|
@@ -4321,7 +5230,7 @@ function createViteRuntimeClassSet(options) {
|
|
|
4321
5230
|
if (!forceRuntimeRefresh && runtimeSet) return runtimeSet;
|
|
4322
5231
|
if (forceRuntimeRefresh || !runtimeSetPromise) {
|
|
4323
5232
|
const invalidation = resolveRuntimeRefreshOptions();
|
|
4324
|
-
runtimeSetPromise = collectRuntimeClassSet(runtimeState.
|
|
5233
|
+
runtimeSetPromise = collectRuntimeClassSet(runtimeState.tailwindRuntime, {
|
|
4325
5234
|
force: forceRuntimeRefresh || invalidation.changed,
|
|
4326
5235
|
skipRefresh: forceRuntimeRefresh,
|
|
4327
5236
|
clearCache: forceRuntimeRefresh || invalidation.changed
|
|
@@ -4338,51 +5247,33 @@ function createViteRuntimeClassSet(options) {
|
|
|
4338
5247
|
async function ensureBundleRuntimeClassSet(snapshot, forceRefresh = false, options = {}) {
|
|
4339
5248
|
const forceRuntimeRefresh = forceRefresh || process$1.env["WEAPP_TW_VITE_FORCE_RUNTIME_REFRESH"] === "1";
|
|
4340
5249
|
const invalidation = resolveRuntimeRefreshOptions();
|
|
4341
|
-
const
|
|
5250
|
+
const shouldRefreshRuntime = forceRuntimeRefresh || invalidation.changed;
|
|
4342
5251
|
const forceCollectBySource = snapshot.runtimeAffectingChangedByType.html.size > 0 || snapshot.runtimeAffectingChangedByType.js.size > 0;
|
|
4343
|
-
await refreshRuntimeState(
|
|
5252
|
+
await refreshRuntimeState(shouldRefreshRuntime);
|
|
4344
5253
|
await runtimeState.readyPromise;
|
|
4345
|
-
if (
|
|
5254
|
+
if (shouldRefreshRuntime) {
|
|
4346
5255
|
runtimeSet = void 0;
|
|
4347
5256
|
runtimeSetPromise = void 0;
|
|
4348
5257
|
await bundleRuntimeClassSetManager.reset();
|
|
4349
5258
|
await transformRuntimeClassSetManager.reset();
|
|
4350
5259
|
}
|
|
4351
|
-
if (
|
|
4352
|
-
const
|
|
5260
|
+
if (!forceRuntimeRefresh) try {
|
|
5261
|
+
const baseClassSet = options.baseClassSet ?? runtimeSet ?? await collectRuntimeClassSet(runtimeState.tailwindRuntime, {
|
|
5262
|
+
force: invalidation.changed,
|
|
5263
|
+
clearCache: invalidation.changed
|
|
5264
|
+
});
|
|
5265
|
+
const nextRuntimeSet = await bundleRuntimeClassSetManager.sync(runtimeState.tailwindRuntime, snapshot, {
|
|
5266
|
+
baseClassSet,
|
|
5267
|
+
skipInitialFullScanWithBase: options.allowBaselineOnlyInitialSync
|
|
5268
|
+
});
|
|
4353
5269
|
runtimeSet = nextRuntimeSet;
|
|
4354
5270
|
return nextRuntimeSet;
|
|
4355
5271
|
} catch (error) {
|
|
4356
5272
|
debug("incremental runtime set sync failed, fallback to full collect: %O", error);
|
|
4357
5273
|
await bundleRuntimeClassSetManager.reset();
|
|
4358
5274
|
}
|
|
4359
|
-
if (runtimeState.twPatcher.majorVersion === 3 && !forceRuntimeRefresh) {
|
|
4360
|
-
if (options.transformOnly) try {
|
|
4361
|
-
return await transformRuntimeClassSetManager.sync(runtimeState.twPatcher, snapshot);
|
|
4362
|
-
} catch (error) {
|
|
4363
|
-
debug("incremental transform runtime set sync failed, fallback to full collect: %O", error);
|
|
4364
|
-
await transformRuntimeClassSetManager.reset();
|
|
4365
|
-
}
|
|
4366
|
-
try {
|
|
4367
|
-
let baseClassSet = options.baseClassSet;
|
|
4368
|
-
if (!baseClassSet && (!runtimeSet || shouldRefreshPatcher)) baseClassSet = await collectRuntimeClassSet(runtimeState.twPatcher, {
|
|
4369
|
-
force: true,
|
|
4370
|
-
skipRefresh: shouldRefreshPatcher,
|
|
4371
|
-
clearCache: shouldRefreshPatcher
|
|
4372
|
-
});
|
|
4373
|
-
const nextRuntimeSet = await bundleRuntimeClassSetManager.sync(runtimeState.twPatcher, snapshot, {
|
|
4374
|
-
baseClassSet: baseClassSet ?? (options.allowBaselineOnlyInitialSync === true ? runtimeSet : void 0),
|
|
4375
|
-
skipInitialFullScanWithBase: options.allowBaselineOnlyInitialSync === true && Boolean(runtimeSet)
|
|
4376
|
-
});
|
|
4377
|
-
runtimeSet = nextRuntimeSet;
|
|
4378
|
-
return nextRuntimeSet;
|
|
4379
|
-
} catch (error) {
|
|
4380
|
-
debug("incremental runtime set sync failed, fallback to full collect: %O", error);
|
|
4381
|
-
await bundleRuntimeClassSetManager.reset();
|
|
4382
|
-
}
|
|
4383
|
-
}
|
|
4384
5275
|
if (!forceRuntimeRefresh && !invalidation.changed && !forceCollectBySource && runtimeSet) return runtimeSet;
|
|
4385
|
-
const task = collectRuntimeClassSet(runtimeState.
|
|
5276
|
+
const task = collectRuntimeClassSet(runtimeState.tailwindRuntime, {
|
|
4386
5277
|
force: forceRuntimeRefresh || invalidation.changed || forceCollectBySource,
|
|
4387
5278
|
skipRefresh: forceRuntimeRefresh,
|
|
4388
5279
|
clearCache: forceRuntimeRefresh || invalidation.changed
|
|
@@ -4480,35 +5371,6 @@ function createViteServeCssGenerationPlugins(options) {
|
|
|
4480
5371
|
}];
|
|
4481
5372
|
}
|
|
4482
5373
|
//#endregion
|
|
4483
|
-
//#region src/bundlers/vite/source-candidate-scan-signature.ts
|
|
4484
|
-
function normalizeSignaturePath(value) {
|
|
4485
|
-
return slash(path.resolve(value));
|
|
4486
|
-
}
|
|
4487
|
-
function serializeInlineCandidates(inlineCandidates) {
|
|
4488
|
-
return {
|
|
4489
|
-
excluded: [...inlineCandidates?.excluded ?? []].sort(),
|
|
4490
|
-
included: [...inlineCandidates?.included ?? []].sort()
|
|
4491
|
-
};
|
|
4492
|
-
}
|
|
4493
|
-
function serializeSourceEntries(entries) {
|
|
4494
|
-
return (entries ?? []).map((entry) => ({
|
|
4495
|
-
base: normalizeSignaturePath(entry.base),
|
|
4496
|
-
negated: entry.negated,
|
|
4497
|
-
pattern: entry.pattern
|
|
4498
|
-
})).sort((a, b) => `${a.base}\0${a.pattern}\0${a.negated}`.localeCompare(`${b.base}\0${b.pattern}\0${b.negated}`));
|
|
4499
|
-
}
|
|
4500
|
-
function createSourceCandidateScanSignature(input) {
|
|
4501
|
-
return JSON.stringify({
|
|
4502
|
-
inlineCandidates: serializeInlineCandidates(input.inlineCandidates),
|
|
4503
|
-
outDir: input.outDir ? normalizeSignaturePath(input.outDir) : void 0,
|
|
4504
|
-
roots: input.roots.map((root) => ({
|
|
4505
|
-
entries: serializeSourceEntries(root.entries),
|
|
4506
|
-
root: normalizeSignaturePath(root.root)
|
|
4507
|
-
})),
|
|
4508
|
-
scanAllSources: input.scanAllSources ?? false
|
|
4509
|
-
});
|
|
4510
|
-
}
|
|
4511
|
-
//#endregion
|
|
4512
5374
|
//#region src/bundlers/vite/tailwind-basedir.ts
|
|
4513
5375
|
const PACKAGE_JSON_FILE = "package.json";
|
|
4514
5376
|
function resolveImplicitTailwindcssBasedirFromViteRoot(root) {
|
|
@@ -4535,9 +5397,6 @@ const weappTailwindcssPackageDir = resolvePackageDir("weapp-tailwindcss");
|
|
|
4535
5397
|
const weappTailwindcssDirPosix = slash(weappTailwindcssPackageDir);
|
|
4536
5398
|
const SOURCE_CANDIDATE_SCAN_CACHE_MAX = 8;
|
|
4537
5399
|
const sourceCandidateScanSnapshotCache = new LRUCache({ max: SOURCE_CANDIDATE_SCAN_CACHE_MAX });
|
|
4538
|
-
function normalizeVitePersistentCacheKey(file) {
|
|
4539
|
-
return normalizeOutputPathKey(file);
|
|
4540
|
-
}
|
|
4541
5400
|
/**
|
|
4542
5401
|
* @name WeappTailwindcss
|
|
4543
5402
|
* @description uni-app vite / uni-app-x 版本插件
|
|
@@ -4558,14 +5417,28 @@ function WeappTailwindcss(options = {}) {
|
|
|
4558
5417
|
(_opts$tailwindcss = opts.tailwindcss).v4 ?? (_opts$tailwindcss.v4 = {});
|
|
4559
5418
|
(_opts$tailwindcss$v = opts.tailwindcss.v4).cssEntries ?? (_opts$tailwindcss$v.cssEntries = opts.cssEntries);
|
|
4560
5419
|
}
|
|
4561
|
-
const { disabled, customAttributes, onLoad, mainCssChunkMatcher, styleHandler, jsHandler,
|
|
5420
|
+
const { disabled, customAttributes, onLoad, mainCssChunkMatcher, styleHandler, jsHandler, tailwindRuntime, refreshTailwindcssRuntime, uniAppX, disabledDefaultTemplateHandler } = opts;
|
|
5421
|
+
const initialTailwindRuntime = tailwindRuntime;
|
|
5422
|
+
const refreshTailwindRuntime = refreshTailwindcssRuntime;
|
|
4562
5423
|
const uniAppXEnabled = isUniAppXEnabled(uniAppX);
|
|
4563
5424
|
const disabledOptions = resolvePluginDisabledState(disabled);
|
|
4564
|
-
const tailwindcssMajorVersion =
|
|
5425
|
+
const tailwindcssMajorVersion = initialTailwindRuntime.majorVersion ?? 0;
|
|
5426
|
+
if (!disabledOptions.plugin && tailwindcssMajorVersion !== 4) throw new Error("weapp-tailwindcss/vite 新生成管线仅支持 Tailwind CSS v4,请升级 tailwindcss 或停留在旧版 weapp-tailwindcss。");
|
|
4565
5427
|
const shouldOwnTailwindGeneration = !disabledOptions.plugin;
|
|
4566
|
-
const shouldRewriteCssImports =
|
|
4567
|
-
const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(opts.generator
|
|
4568
|
-
|
|
5428
|
+
const shouldRewriteCssImports = opts.rewriteCssImports === true;
|
|
5429
|
+
const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(opts.generator, {
|
|
5430
|
+
appType: opts.appType,
|
|
5431
|
+
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
5432
|
+
tailwindcssMajorVersion,
|
|
5433
|
+
uniAppX
|
|
5434
|
+
});
|
|
5435
|
+
const generatorBranch = resolveGeneratorRuntimeBranch(generatorOptions, {
|
|
5436
|
+
appType: opts.appType,
|
|
5437
|
+
platform: opts.cssOptions?.platform ?? opts.platform,
|
|
5438
|
+
tailwindcssMajorVersion,
|
|
5439
|
+
uniAppX
|
|
5440
|
+
});
|
|
5441
|
+
const shouldInferAppType = !hasExplicitAppType && !generatorBranch.isWeb;
|
|
4569
5442
|
const hasInitialTailwindCssRoots = hasConfiguredTailwindV4CssRoots({
|
|
4570
5443
|
...options,
|
|
4571
5444
|
cssEntries: opts.cssEntries ?? options.cssEntries
|
|
@@ -4576,13 +5449,16 @@ function WeappTailwindcss(options = {}) {
|
|
|
4576
5449
|
let autoCssSourcesRefresh;
|
|
4577
5450
|
let autoCssSourcesDiscovered = false;
|
|
4578
5451
|
const syncTailwindCssSourceCandidates = async (id, css) => {
|
|
5452
|
+
if (tailwindcssMajorVersion === 4 && isMissingInternalCssSource(cleanUrl(id), weappTailwindcssPackageDir)) return;
|
|
4579
5453
|
await sourceCandidateCollector.syncCss(id, css);
|
|
4580
5454
|
cacheCurrentSourceCandidateScan();
|
|
4581
5455
|
};
|
|
4582
5456
|
const registerAutoCssSource = async (id, css, options = {}) => {
|
|
4583
|
-
if (
|
|
5457
|
+
if (!shouldOwnTailwindGeneration) return;
|
|
4584
5458
|
const file = cleanUrl(id);
|
|
4585
5459
|
if (!path.isAbsolute(file)) return;
|
|
5460
|
+
if (!isTailwindV4CssEntry(file)) return;
|
|
5461
|
+
if (isMissingInternalCssSource(file, weappTailwindcssPackageDir)) return;
|
|
4586
5462
|
const sourceFile = path.normalize(file);
|
|
4587
5463
|
const sourceBase = path.dirname(sourceFile);
|
|
4588
5464
|
const sourceCss = normalizeTailwindSourceForGenerator(normalizeTailwindConfigDirectives(css, sourceBase), { importFallback: true });
|
|
@@ -4618,7 +5494,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
4618
5494
|
await autoCssSourcesRefresh;
|
|
4619
5495
|
};
|
|
4620
5496
|
const discoverAndRegisterAutoCssSources = async () => {
|
|
4621
|
-
if (
|
|
5497
|
+
if (!shouldOwnTailwindGeneration || hasInitialTailwindCssRoots || !resolvedConfig?.root) return;
|
|
4622
5498
|
const cssEntries = await discoverTailwindV4CssEntries(resolvedConfig.root, resolvedConfig.build?.outDir);
|
|
4623
5499
|
autoCssSourcesDiscovered = true;
|
|
4624
5500
|
let changed = false;
|
|
@@ -4643,11 +5519,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
4643
5519
|
const customAttributesEntities = toCustomAttributesEntities(customAttributes);
|
|
4644
5520
|
let resolvedConfig;
|
|
4645
5521
|
let recordedGeneratorCandidates;
|
|
4646
|
-
const
|
|
4647
|
-
const sourceCandidateCollector = createSourceCandidateCollector({
|
|
4648
|
-
bareArbitraryValues: opts.arbitraryValues?.bareArbitraryValues,
|
|
4649
|
-
extractor: sourceCandidateExtractor
|
|
4650
|
-
});
|
|
5522
|
+
const sourceCandidateCollector = createSourceCandidateCollector({ bareArbitraryValues: opts.arbitraryValues?.bareArbitraryValues });
|
|
4651
5523
|
const sourceCandidateScanCache = new LRUCache({ max: SOURCE_CANDIDATE_SCAN_CACHE_MAX });
|
|
4652
5524
|
let sourceScanEntries;
|
|
4653
5525
|
let sourceScanMatcher;
|
|
@@ -4668,8 +5540,8 @@ function WeappTailwindcss(options = {}) {
|
|
|
4668
5540
|
const tailwindRootCssModuleIds = /* @__PURE__ */ new Set();
|
|
4669
5541
|
const { runtimeState, refreshRuntimeState, ensureRuntimeClassSet, ensureBundleRuntimeClassSet } = createViteRuntimeClassSet({
|
|
4670
5542
|
opts,
|
|
4671
|
-
|
|
4672
|
-
|
|
5543
|
+
initialTailwindRuntime,
|
|
5544
|
+
refreshTailwindcssRuntime: refreshTailwindRuntime,
|
|
4673
5545
|
uniAppXEnabled,
|
|
4674
5546
|
customAttributesEntities,
|
|
4675
5547
|
disabledDefaultTemplateHandler,
|
|
@@ -4697,7 +5569,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
4697
5569
|
recordedGeneratorCandidates = void 0;
|
|
4698
5570
|
};
|
|
4699
5571
|
const getSourceCandidates = () => sourceCandidateCollector.values();
|
|
4700
|
-
const getSourceCandidatesForEntries = (entries) => sourceCandidateCollector.valuesForEntries(entries);
|
|
5572
|
+
const getSourceCandidatesForEntries = (entries, options) => sourceCandidateCollector.valuesForEntries(entries, options);
|
|
4701
5573
|
const getSourceCandidateSourcesForEntries = (entries, options) => sourceCandidateCollector.sourcesForEntries(entries, options);
|
|
4702
5574
|
const isWatchBuild = () => resolvedConfig?.command === "build" && resolvedConfig.build.watch != null;
|
|
4703
5575
|
const isWatchLikeBuild = () => isWatchBuild() || resolvedConfig?.command === "serve" || process$1.env["WEAPP_TW_WATCH_REGRESSION"] === "1" || process$1.env["WEAPP_TW_HMR_TIMING"] === "1";
|
|
@@ -4726,6 +5598,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
4726
5598
|
seenRoots.add(basedir);
|
|
4727
5599
|
}
|
|
4728
5600
|
for (const cssEntry of opts.tailwindcss?.v4?.cssEntries ?? []) {
|
|
5601
|
+
if (!isTailwindV4CssEntry(cssEntry)) continue;
|
|
4729
5602
|
const cssEntryRoot = path.dirname(path.resolve(cssEntry));
|
|
4730
5603
|
if (seenRoots.has(cssEntryRoot)) continue;
|
|
4731
5604
|
roots.push({ root: cssEntryRoot });
|
|
@@ -4760,7 +5633,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
4760
5633
|
}
|
|
4761
5634
|
const root = resolvedConfig?.root ?? process$1.cwd();
|
|
4762
5635
|
const outDir = resolvedConfig?.build?.outDir;
|
|
4763
|
-
const sourceScan = await resolveViteSourceScanEntries(opts, runtimeState.
|
|
5636
|
+
const sourceScan = await resolveViteSourceScanEntries(opts, runtimeState.tailwindRuntime, {
|
|
4764
5637
|
outDir,
|
|
4765
5638
|
root
|
|
4766
5639
|
});
|
|
@@ -4811,6 +5684,9 @@ function WeappTailwindcss(options = {}) {
|
|
|
4811
5684
|
if (sourceScanMatcher && !sourceScanMatcher(file)) {
|
|
4812
5685
|
sourceCandidateCollector.remove(file);
|
|
4813
5686
|
cacheCurrentSourceCandidateScan();
|
|
5687
|
+
if (isSourceStyleRequest(file)) return readFile(file, "utf8").then((source) => cssMemory.refreshRememberedCssSourceBySourceFile(file, source)).catch((error) => {
|
|
5688
|
+
if ((typeof error === "object" && error !== null && "code" in error ? error.code : void 0) !== "ENOENT") debug("remembered css source watch refresh failed: %s %O", file, error);
|
|
5689
|
+
}).then(() => cssMemory.refreshRememberedCssSourceByCurrentFile(file)).then(() => void 0);
|
|
4814
5690
|
return cssMemory.refreshRememberedCssSourceByCurrentFile(file);
|
|
4815
5691
|
}
|
|
4816
5692
|
const existingTask = pendingSourceCandidateSyncByFile.get(file);
|
|
@@ -4843,7 +5719,9 @@ function WeappTailwindcss(options = {}) {
|
|
|
4843
5719
|
const getViteProcessedCssAssetResult = (file) => viteProcessedCssAssetResults.get(normalizeVitePersistentCacheKey(file));
|
|
4844
5720
|
const getViteCssCacheStats = () => ({
|
|
4845
5721
|
viteGeneratedCssByFile: viteGeneratedCssByFile.size,
|
|
5722
|
+
viteGeneratedCssByFileRaw: summarizeStringCache(viteGeneratedCssByFile),
|
|
4846
5723
|
viteProcessedCssAssetResults: viteProcessedCssAssetResults.size,
|
|
5724
|
+
viteProcessedCssAssetResultsRaw: summarizeViteProcessedCssResults(viteProcessedCssAssetResults),
|
|
4847
5725
|
...cssMemory.getStats(),
|
|
4848
5726
|
sourceCandidateScanCache: sourceCandidateScanCache.size,
|
|
4849
5727
|
pendingSourceCandidateSyncs: pendingSourceCandidateSyncs.size,
|
|
@@ -4889,7 +5767,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
4889
5767
|
const transformCssHandlerOptions = createCssHandlerOptionsCache({
|
|
4890
5768
|
getAppType: () => opts.appType,
|
|
4891
5769
|
mainCssChunkMatcher,
|
|
4892
|
-
getMajorVersion: () => runtimeState.
|
|
5770
|
+
getMajorVersion: () => runtimeState.tailwindRuntime.majorVersion,
|
|
4893
5771
|
getOutputRoot: () => resolvedConfig?.build?.outDir ? path.resolve(resolvedConfig.root, resolvedConfig.build.outDir) : resolvedConfig?.root,
|
|
4894
5772
|
getExtraOptions: (file) => ({
|
|
4895
5773
|
...resolveViteCssHandlerExtraOptions(file),
|
|
@@ -4901,11 +5779,13 @@ function WeappTailwindcss(options = {}) {
|
|
|
4901
5779
|
await runtimeState.readyPromise;
|
|
4902
5780
|
await waitForSourceCandidateSyncs();
|
|
4903
5781
|
const file = cleanUrl(id);
|
|
5782
|
+
const requestFile = isCSSRequest(id) ? id : file;
|
|
5783
|
+
if (!isCSSRequest(requestFile) || opts.htmlMatcher(file) || isHTMLRequest(file)) return;
|
|
4904
5784
|
const rootDir = resolvedConfig?.root ? path.resolve(resolvedConfig.root) : process$1.cwd();
|
|
4905
5785
|
const isHarmonyAppStyleTarget = isHarmonyAppBuildTarget();
|
|
4906
5786
|
const isNativeAppStyleTarget = resolveUniUtsPlatform().isApp || isHarmonyAppStyleTarget;
|
|
4907
5787
|
const sourceRoot = resolveWeappViteSourceRoot(resolvedConfig, opts.appType);
|
|
4908
|
-
const outputFile = resolveViteCssPipelineOutputFile(
|
|
5788
|
+
const outputFile = resolveViteCssPipelineOutputFile(requestFile, opts, rootDir, generatorBranch.isWeb, isNativeAppStyleTarget, sourceRoot);
|
|
4909
5789
|
const runtime = getRecordedGeneratorCandidates() ?? getSourceCandidates() ?? await ensureRuntimeClassSet();
|
|
4910
5790
|
const outputCssHandlerOptions = transformCssHandlerOptions.getCssHandlerOptions(outputFile);
|
|
4911
5791
|
const cssHandlerOptions = {
|
|
@@ -4914,12 +5794,13 @@ function WeappTailwindcss(options = {}) {
|
|
|
4914
5794
|
};
|
|
4915
5795
|
const transientCssSource = transientAutoCssSources.get(file);
|
|
4916
5796
|
const shouldDeferEmptyScopedCssSource = transientCssSource == null && !(opts.appType === "uni-app-x" && !cssHandlerOptions.isMainChunk && hasTailwindApplyDirective(code));
|
|
4917
|
-
const generated = await
|
|
5797
|
+
const generated = await generateTailwindV4Css({
|
|
4918
5798
|
opts,
|
|
4919
5799
|
runtimeState,
|
|
4920
5800
|
runtime,
|
|
4921
5801
|
rawSource: code,
|
|
4922
5802
|
file,
|
|
5803
|
+
outputFile,
|
|
4923
5804
|
cssHandlerOptions,
|
|
4924
5805
|
cssUserHandlerOptions: transformCssHandlerOptions.getCssUserHandlerOptions(file),
|
|
4925
5806
|
cssSources: transientCssSource ? [transientCssSource] : void 0,
|
|
@@ -4968,6 +5849,7 @@ function WeappTailwindcss(options = {}) {
|
|
|
4968
5849
|
onTailwindRootCss: (id, code) => registerAutoCssSource(id, code),
|
|
4969
5850
|
onCssSourceTransform: (id, code) => cssMemory.refreshRememberedCssSourceBySourceFile(id, code),
|
|
4970
5851
|
shouldGenerateCss: (_id, code) => hasVitePipelineTailwindGenerationDirective(code),
|
|
5852
|
+
shouldDeferGeneration: (_id, code) => !shouldRewriteCssImports && hasTailwindRootDirectives(code, { importFallback: generatorOptions.importFallback }),
|
|
4971
5853
|
shouldOwnTailwindGeneration,
|
|
4972
5854
|
shouldRewrite: shouldRewriteCssImports,
|
|
4973
5855
|
weappTailwindcssDirPosix
|
|
@@ -5167,11 +6049,6 @@ function WeappTailwindcss(options = {}) {
|
|
|
5167
6049
|
const removed = removeTailwindPostcssPlugins(postcssPlugins);
|
|
5168
6050
|
if (removed > 0) debug("remove official tailwind postcss plugins in generator mode: %d", removed);
|
|
5169
6051
|
}
|
|
5170
|
-
const idx = postcssPlugins.findIndex((x) => getPostcssPluginName(x) === "postcss-html-transform");
|
|
5171
|
-
if (idx > -1) {
|
|
5172
|
-
postcssPlugins.splice(idx, 1, postcssHtmlTransform());
|
|
5173
|
-
debug("remove postcss-html-transform plugin from vite config");
|
|
5174
|
-
}
|
|
5175
6052
|
}
|
|
5176
6053
|
}, { emit: false });
|
|
5177
6054
|
},
|