weapp-tailwindcss 5.3.6 → 5.4.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.
Files changed (92) hide show
  1. package/README.md +3 -3
  2. package/README.zh-CN.md +4 -4
  3. package/dist/bundlers/shared/framework-postcss.d.ts +3 -0
  4. package/dist/bundlers/shared/generator-css/result-helpers.d.ts +1 -1
  5. package/dist/bundlers/shared/generator-css/source-resolver/single-source.d.ts +1 -1
  6. package/dist/bundlers/shared/generator-css/types.d.ts +3 -1
  7. package/dist/bundlers/shared/source-candidates/snapshot.d.ts +19 -0
  8. package/dist/bundlers/shared/source-candidates/source-priority.d.ts +1 -0
  9. package/dist/bundlers/shared/source-candidates/types-and-cache.d.ts +1 -0
  10. package/dist/bundlers/shared/source-candidates/views.d.ts +12 -0
  11. package/dist/bundlers/shared/style-requests.d.ts +1 -0
  12. package/dist/bundlers/vite/bundle-state.d.ts +9 -1
  13. package/dist/bundlers/vite/capability-profile.d.ts +18 -0
  14. package/dist/bundlers/vite/generate-bundle/js-processing.d.ts +12 -0
  15. package/dist/bundlers/vite/hot-css-modules.d.ts +2 -2
  16. package/dist/bundlers/vite/shared/configured-css-entry-observer.d.ts +29 -0
  17. package/dist/bundlers/vite/shared/create-framework-plugins.d.ts +8 -0
  18. package/dist/bundlers/vite/shared/framework-css-generation-queue.d.ts +1 -0
  19. package/dist/bundlers/vite/shared/framework-hmr-module-version.d.ts +9 -0
  20. package/dist/bundlers/vite/shared/framework-runtime-utils.d.ts +5 -0
  21. package/dist/bundlers/vite/shared/framework-source-scan-session.d.ts +12 -2
  22. package/dist/compiler/compilation-session-pool.d.ts +1 -0
  23. package/dist/compiler/framework-compiler-session.d.ts +21 -0
  24. package/dist/compiler/index.d.ts +1 -0
  25. package/dist/{context-DTLRADfE.cjs → compiler-CDAz4SwJ.cjs} +907 -11
  26. package/dist/{context-4ittVpgt.js → compiler-DWcUgi3A.js} +813 -6
  27. package/dist/context/handlers.d.ts +1 -1
  28. package/dist/core/compiler/compiler.d.ts +2 -0
  29. package/dist/core/compiler/generation-cache.d.ts +30 -0
  30. package/dist/core/compiler/generation-state.d.ts +17 -0
  31. package/dist/core/compiler/index.d.ts +2 -0
  32. package/dist/core/compiler/root-store.d.ts +41 -0
  33. package/dist/core/compiler/snapshot.d.ts +35 -0
  34. package/dist/core/compiler/source-fingerprint.d.ts +3 -0
  35. package/dist/core/compiler/transforms.d.ts +15 -0
  36. package/dist/core/compiler/types.d.ts +75 -0
  37. package/dist/core.cjs +34 -8
  38. package/dist/core.d.ts +4 -1
  39. package/dist/core.js +3 -2
  40. package/dist/framework/index.d.ts +3 -1
  41. package/dist/framework.cjs +6 -1
  42. package/dist/framework.js +6 -1
  43. package/dist/{generator-EnTXLBlK.js → generator-BjK5PRR-.js} +28 -10
  44. package/dist/{generator-DKiYbTFR.cjs → generator-WlhrtNa3.cjs} +26 -8
  45. package/dist/generator.cjs +1 -1
  46. package/dist/generator.js +1 -1
  47. package/dist/{gulp-DwtrU4V1.js → gulp-BbMMp7vY.js} +7 -7
  48. package/dist/{gulp-CUysZjW3.cjs → gulp-CBu_waef.cjs} +14 -16
  49. package/dist/gulp.cjs +1 -1
  50. package/dist/gulp.js +1 -1
  51. package/dist/{hmr-timing-utmOgn6p.js → hmr-timing-B_4sAvsk.js} +369 -291
  52. package/dist/{hmr-timing-Cvh5UgnM.cjs → hmr-timing-CYhNto2U.cjs} +4 -4
  53. package/dist/index.cjs +4 -4
  54. package/dist/index.js +4 -4
  55. package/dist/{pipeline-helpers-CyVXL3h6.cjs → pipeline-helpers-Du8eAtMG.cjs} +6 -6
  56. package/dist/postcss.cjs +1 -1
  57. package/dist/postcss.js +1 -1
  58. package/dist/presets.cjs +2 -3
  59. package/dist/presets.js +1 -1
  60. package/dist/rspack.cjs +2 -2
  61. package/dist/rspack.js +2 -2
  62. package/dist/{source-candidate-scan-signature-BNt7NrrI.cjs → source-candidate-scan-signature-ZOm0O17V.cjs} +5 -5
  63. package/dist/{source-candidate-scan-signature-CDrLxVKu.js → source-candidate-scan-signature-wieibgE7.js} +3 -3
  64. package/dist/{tailwindcss-ChnpCv25.js → tailwindcss-9xmoCkaR.js} +1 -1
  65. package/dist/{tailwindcss-CexDJBhx.cjs → tailwindcss-D3jltF7M.cjs} +763 -5
  66. package/dist/{transform-CL-UZW1U.cjs → transform-C6k9zTQR.cjs} +12 -4
  67. package/dist/{transform-Bfi1_VgN.js → transform-DQhgAarN.js} +12 -4
  68. package/dist/typedoc.export.d.ts +1 -0
  69. package/dist/types/index.d.ts +2 -0
  70. package/dist/uni-app-x/component-local-style.d.ts +2 -0
  71. package/dist/uni-app-x/transform.d.ts +1 -0
  72. package/dist/uni-app-x/vite/asset-task.d.ts +21 -0
  73. package/dist/uni-app-x/vite/plugin-options.d.ts +8 -0
  74. package/dist/uni-app-x/vite/web-local-style.d.ts +2 -1
  75. package/dist/uni-app-x/vite.d.ts +1 -21
  76. package/dist/{v4-generation-core-Dhsu9Deu.cjs → v4-generation-core-BhYkeoZ4.cjs} +378 -300
  77. package/dist/{vite-DMX5zoID.cjs → vite-B0cvyfSY.cjs} +807 -200
  78. package/dist/{vite-DJkhb8n1.js → vite-Fu6GTjIY.js} +774 -165
  79. package/dist/vite.cjs +1 -1
  80. package/dist/vite.js +1 -1
  81. package/dist/weapp-tw-css-generation-loader.cjs +1 -1
  82. package/dist/weapp-tw-css-import-rewrite-loader.cjs +7 -7
  83. package/dist/{webpack-Cpy_yggg.cjs → webpack-Amn5lmnx.cjs} +33 -35
  84. package/dist/{webpack-CzhrD9p3.js → webpack-BKHO-WSM.js} +10 -10
  85. package/dist/webpack.cjs +1 -1
  86. package/dist/webpack.js +1 -1
  87. package/dist/wxml/utils.d.ts +1 -1
  88. package/dist/{wxml-B7OAVpXJ.js → wxml-CvKyV69S.js} +10 -2
  89. package/dist/{wxml-PrK-8ARX.cjs → wxml-o-CUulAM.cjs} +40 -32
  90. package/package.json +12 -11
  91. package/dist/options-BJrtIQbH.cjs +0 -768
  92. package/dist/style-options-DW30H5PV.cjs +0 -82
@@ -1,28 +1,52 @@
1
1
  import { resolveImplicitAppTypeFromViteRoot } from "./framework.js";
2
- import { $ as hasTailwindSourceDirectives, B as stripMiniProgramCssSpecificityPlaceholders, D as resolveTailwindcssOptions, Ft as filterUnsupportedMiniProgramTailwindV4Candidates, K as hasUserCssLayerBlocks, L as hasMiniProgramCssSpecificityPlaceholders, Ot as resolveSourceScanPath, Pt as getTailwindV4IncrementalGenerateCacheStats, Q as hasTailwindRootDirectives, S as findNearestPackageRoot, U as normalizeEmptyTailwindCustomVariants, X as hasTailwindApplyDirective, Y as hasLocalCssImport, Z as hasTailwindNonRootGenerationDirectives, _ as upsertTailwindV4CssSource, a as resolveGeneratorRuntimeBranch, b as isTailwindV4CssEntry, c as shouldUseNativeAppCssBranch, et as normalizeTailwindConfigDirectives, h as hasConfiguredTailwindV4CssRoots, i as normalizeWeappTailwindcssGeneratorOptions, it as removeTailwindSourceDirectives, kt as resolveTailwindV4CssSourceBase, l as resolveUniUtsPlatform, lt as hasTailwindGeneratedCss, m as filterTailwindV4CssSourceRoots, mt as stripGeneratorPlaceholderMarkers, nt as normalizeTailwindSourceForGenerator, q as splitUserCssLayerBlocks, rt as parseImportRequest, s as shouldUseMiniProgramCssBranch, ut as hasTailwindGeneratedCssMarkers, wt as isFileMatchedByTailwindSourceEntries, x as normalizeCssEntries } from "./generator-EnTXLBlK.js";
2
+ import { $ as hasTailwindSourceDirectives, B as stripMiniProgramCssSpecificityPlaceholders, D as resolveTailwindcssOptions, Ft as filterUnsupportedMiniProgramTailwindV4Candidates, K as hasUserCssLayerBlocks, L as hasMiniProgramCssSpecificityPlaceholders, Ot as resolveSourceScanPath, Pt as getTailwindV4IncrementalGenerateCacheStats, Q as hasTailwindRootDirectives, S as findNearestPackageRoot, U as normalizeEmptyTailwindCustomVariants, X as hasTailwindApplyDirective, Y as hasLocalCssImport, Z as hasTailwindNonRootGenerationDirectives, _ as upsertTailwindV4CssSource, a as resolveGeneratorRuntimeBranch, b as isTailwindV4CssEntry, c as shouldUseNativeAppCssBranch, et as normalizeTailwindConfigDirectives, h as hasConfiguredTailwindV4CssRoots, i as normalizeWeappTailwindcssGeneratorOptions, it as removeTailwindSourceDirectives, kt as resolveTailwindV4CssSourceBase, l as resolveUniUtsPlatform, lt as hasTailwindGeneratedCss, m as filterTailwindV4CssSourceRoots, mt as stripGeneratorPlaceholderMarkers, nt as normalizeTailwindSourceForGenerator, q as splitUserCssLayerBlocks, rt as parseImportRequest, s as shouldUseMiniProgramCssBranch, ut as hasTailwindGeneratedCssMarkers, wt as isFileMatchedByTailwindSourceEntries, x as normalizeCssEntries } from "./generator-BjK5PRR-.js";
3
3
  import { t as omitUndefined } from "./object-B-8IHefx.js";
4
- import { a as findTailwindConfig, f as resolveSourceScanEntries, g as resolveTailwindV4EntriesFromCssCached, i as resolveUniAppXOptions, l as getRuntimeClassSetSignature, m as resolveTailwindV4CssDependencies, p as discoverTailwindV4CssEntries, r as isUniAppXEnabled } from "./tailwindcss-ChnpCv25.js";
4
+ import { a as findTailwindConfig, f as resolveSourceScanEntries, g as resolveTailwindV4EntriesFromCssCached, i as resolveUniAppXOptions, l as getRuntimeClassSetSignature, m as resolveTailwindV4CssDependencies, p as discoverTailwindV4CssEntries, r as isUniAppXEnabled } from "./tailwindcss-9xmoCkaR.js";
5
5
  import "./utils-MVwpU07P.js";
6
- import { $ as AssetEmissionPlan, A as hasEmptyAtRuleBlockCandidate, C as isSourceStyleRequest, D as parseBundlerGeneratedCssMarkerBlocks, E as hasBundlerGeneratedCssMarker, F as processCachedTask, G as createRuntimeCompilationBuildState, H as finalizeCompilerShadowRun, I as createRuntimeClassSetManager, J as updateRuntimeCompilationBuildState, M as createCssSourceTraceCacheSignature, N as createCssTokenSourceMap, O as stripBundlerGeneratedCssMarkers, P as isCssSourceTraceEnabled, S as isSourcePreprocessorRequest, T as createBundlerGeneratedCssMarker, U as buildRuntimeCompilationSnapshot, X as disposeCompilerOwner, Y as createRuntimeAffectingSourceSignature, Z as beginCompilerShadowRun, a as extractMarkedUserLayerComponentsCss, ct as createSourceCandidateEligibilityMatcher, d as runWithConcurrency, f as normalizeMiniProgramGeneratorCssSource, g as captureFrameworkPostcssOptions, i as validateCandidatesByGenerator, it as createSourceCandidateCollector, j as annotateCssSourceTrace, k as finalizeMiniProgramCssStructure, m as scoreTailwindV4CssSourceFileMatch, nt as recordCompilationDependencyChanges, o as mergeMarkedUserLayerComponentsCss, ot as isSourceCandidateRequest, p as normalizeMiniProgramImportShell, r as generateTailwindV4Css, rt as createCompilationDependencyChanges, s as collectGeneratedRawSourceCandidatesFromCss, st as extractCandidatesFromSource, t as createHmrTimingRecorder, w as stripRequestQuery, z as isPureLocalCssImportWrapper } from "./hmr-timing-utmOgn6p.js";
7
- import { m as createDebug, p as replaceWxml } from "./wxml-B7OAVpXJ.js";
8
- import { a as vitePluginName, c as collectRuntimeClassSet, d as refreshTailwindRuntimeState, f as normalizeFrameworkStylePlatform, l as createTailwindRuntimeReadyPromise, n as normalizeStyleHandlerMajorVersion, o as shouldSkipJsTransform, s as toCustomAttributesEntities, t as getCompilerContext } from "./context-4ittVpgt.js";
9
- import { _ as createBuiltinViteStyleInjectorPlugins, a as createCandidateSignature, c as getSnapshotHash, d as classifyRuntimeEntry, f as resolvePackageDir, g as toAbsoluteOutputPath, h as resolveOutputSpecifier, i as createScopedGeneratorSourceTraceMap, l as hasRuntimeAffectingSourceChanges, m as normalizeOutputPathKey, n as createScopedGeneratorCandidateSignature, o as createJsHashSalt, p as resolvePluginDisabledState, r as createScopedGeneratorRuntime, s as createLinkedImpactSignature, t as createSourceCandidateScanSignature, u as summarizeStringDiff, x as resolveViteFrameworkProfile, y as viteStyleInjectorDelegates } from "./source-candidate-scan-signature-CDrLxVKu.js";
6
+ import { $ as AssetEmissionPlan, A as hasEmptyAtRuleBlockCandidate, C as isSourceStyleRequest, D as parseBundlerGeneratedCssMarkerBlocks, E as hasBundlerGeneratedCssMarker, F as processCachedTask, G as createRuntimeCompilationBuildState, H as finalizeCompilerShadowRun, I as createRuntimeClassSetManager, J as updateRuntimeCompilationBuildState, M as createCssSourceTraceCacheSignature, N as createCssTokenSourceMap, O as stripBundlerGeneratedCssMarkers, P as isCssSourceTraceEnabled, S as isSourcePreprocessorRequest, T as createBundlerGeneratedCssMarker, U as buildRuntimeCompilationSnapshot, X as disposeCompilerOwner, Y as createRuntimeAffectingSourceSignature, Z as beginCompilerShadowRun, a as extractMarkedUserLayerComponentsCss, ct as createSourceCandidateEligibilityMatcher, d as runWithConcurrency, f as normalizeMiniProgramGeneratorCssSource, g as captureFrameworkPostcssOptions, i as validateCandidatesByGenerator, it as createSourceCandidateCollector, j as annotateCssSourceTrace, k as finalizeMiniProgramCssStructure, m as scoreTailwindV4CssSourceFileMatch, nt as recordCompilationDependencyChanges, o as mergeMarkedUserLayerComponentsCss, ot as isSourceCandidateRequest, p as normalizeMiniProgramImportShell, r as generateTailwindV4Css, rt as createCompilationDependencyChanges, s as collectGeneratedRawSourceCandidatesFromCss, st as extractCandidatesFromSource, t as createHmrTimingRecorder, w as stripRequestQuery, z as isPureLocalCssImportWrapper } from "./hmr-timing-B_4sAvsk.js";
7
+ import { m as createDebug, p as replaceWxml } from "./wxml-CvKyV69S.js";
8
+ import { c as toCustomAttributesEntities, f as refreshTailwindRuntimeState, l as collectRuntimeClassSet, n as getCompilerContext, o as vitePluginName, p as normalizeFrameworkStylePlatform, r as normalizeStyleHandlerMajorVersion, s as shouldSkipJsTransform, u as createTailwindRuntimeReadyPromise } from "./compiler-DWcUgi3A.js";
9
+ import { _ as createBuiltinViteStyleInjectorPlugins, a as createCandidateSignature, c as getSnapshotHash, d as classifyRuntimeEntry, f as resolvePackageDir, g as toAbsoluteOutputPath, h as resolveOutputSpecifier, i as createScopedGeneratorSourceTraceMap, l as hasRuntimeAffectingSourceChanges, m as normalizeOutputPathKey, n as createScopedGeneratorCandidateSignature, o as createJsHashSalt, p as resolvePluginDisabledState, r as createScopedGeneratorRuntime, s as createLinkedImpactSignature, t as createSourceCandidateScanSignature, u as summarizeStringDiff, x as resolveViteFrameworkProfile, y as viteStyleInjectorDelegates } from "./source-candidate-scan-signature-wieibgE7.js";
10
10
  import { n as shouldEnableComponentLocalStyle, r as shouldEnablePageLocalStyle, t as normalizeUniAppXLocalStyleId } from "./local-style-matcher-DsiI2wIc.js";
11
11
  import { t as logger$1 } from "./logger-BNzxZbZj.js";
12
12
  import fs, { existsSync, readFileSync, realpathSync } from "node:fs";
13
13
  import path from "node:path";
14
14
  import process$1 from "node:process";
15
15
  import { splitCandidateTokens } from "@tailwindcss-mangle/engine";
16
- import { collectCssImportRequestsRoot, compileCssMacroConditionalComments, containsCssAfterMinify, filterExistingCssRules, isMiniProgramLocalCssImportRequest, mergeCoveredCssRuleDeclarations, mergeMiniProgramPreflightRuleDeclarations, mergeMiniProgramThemeScopeRuleDeclarations, normalizeTailwindcssV4InfinityCalcCss, parseTailwindCssDirectiveRequest, postcss, removeTailwindPostcssPlugins, removeTailwindSourceDirectivesRoot, removeUnsupportedMiniProgramCssImportsRoot, resolvePostcssConfig, transformWebCssCompat, transformWebCssSafeSelectors, unwrapUnsupportedCascadeLayers } from "@weapp-tailwindcss/postcss";
16
+ import { collectCssImportRequestsRoot, compileCssMacroConditionalComments, containsCssAfterMinify, filterExistingCssRules, isMiniProgramLocalCssImportRequest, mergeCoveredCssRuleDeclarations, mergeMiniProgramPreflightRuleDeclarations, mergeMiniProgramThemeScopeRuleDeclarations, normalizeTailwindcssV4InfinityCalcCss, normalizeUniAppXImportantApplyForSass, parseTailwindCssDirectiveRequest, postcss, removeTailwindPostcssPlugins, removeTailwindSourceDirectivesRoot, removeUnsupportedMiniProgramCssImportsRoot, resolvePostcssConfig, restoreUniAppXImportantApplyMarker, transformWebCssCompat, transformWebCssSafeSelectors, unwrapUnsupportedCascadeLayers } from "@weapp-tailwindcss/postcss";
17
17
  import { LRUCache } from "lru-cache";
18
18
  import { readFile } from "node:fs/promises";
19
19
  import micromatch from "micromatch";
20
20
  import { cleanUrl as cleanUrl$1, ensurePosix } from "@weapp-tailwindcss/shared";
21
+ import { Buffer } from "node:buffer";
21
22
  import { logger } from "@weapp-tailwindcss/logger";
22
23
  import { fileURLToPath } from "node:url";
23
- import { Buffer } from "node:buffer";
24
24
  import { AsyncLocalStorage } from "node:async_hooks";
25
25
  import { parse } from "comment-json";
26
+ //#region src/bundlers/vite/capability-profile.ts
27
+ const frameworkViteCapabilityProfile = {
28
+ name: "framework",
29
+ frameworkName: "generic",
30
+ generatorTarget: void 0,
31
+ platformFamily: "unknown",
32
+ sourceCandidates: true,
33
+ frameworkExtras: true,
34
+ serveJsTransform: true,
35
+ styleInjector: true
36
+ };
37
+ function createGenericWebViteCapabilityProfile(options) {
38
+ return {
39
+ name: "generic-web",
40
+ frameworkName: "generic",
41
+ generatorTarget: "web",
42
+ platformFamily: "web",
43
+ sourceCandidates: options.cssSourceTrace === true || typeof options.cssSourceTrace === "object",
44
+ frameworkExtras: false,
45
+ serveJsTransform: false,
46
+ styleInjector: options.styleInjector !== void 0
47
+ };
48
+ }
49
+ //#endregion
26
50
  //#region src/bundlers/vite/source-output-relations.ts
27
51
  const activeRelationOwnerStorage = new AsyncLocalStorage();
28
52
  function normalizeSourceFile$1(sourceFile) {
@@ -234,6 +258,7 @@ const STRING_LITERAL_RE = /(['"`])((?:\\.|(?!\1)[\s\S])*?)\1/g;
234
258
  const SFC_STYLE_BLOCK_RE$2 = /<style\b[^>]*>([\s\S]*?)<\/style>/gi;
235
259
  const STYLE_EXPORT_PREFIX_RE = /^\s*export\s+default\s+/;
236
260
  const CLASS_SELECTOR_PREFIX_RE = /^\.((?:\\[^\n\r\f]|[\w-])+)(?=$|[.:#[])/;
261
+ const STRING_STYLE_PROPERTIES = /* @__PURE__ */ new Set(["lineHeight"]);
237
262
  function cloneStyleEntry(entry) {
238
263
  return Object.fromEntries(Object.entries(entry).map(([state, declarations]) => [state, { ...declarations }]));
239
264
  }
@@ -251,14 +276,14 @@ function cloneStyleValue(style) {
251
276
  function toCamelCase(prop) {
252
277
  return prop.replace(/-([a-z])/g, (_, char) => char.toUpperCase());
253
278
  }
254
- function normalizeValue(value) {
279
+ function normalizeValue(prop, value) {
255
280
  const trimmed = value.trim();
256
- if (/^-?\d+(?:\.\d+)?px$/.test(trimmed)) return Number(trimmed.slice(0, -2));
281
+ if (!STRING_STYLE_PROPERTIES.has(toCamelCase(prop)) && /^-?\d+(?:\.\d+)?px$/.test(trimmed)) return Number(trimmed.slice(0, -2));
257
282
  return trimmed.replace(/\s*,\s*/g, ",");
258
283
  }
259
- function normalizeStyleValue(value) {
260
- if (typeof value === "number") return value;
261
- return normalizeValue(value);
284
+ function normalizeStyleValue(prop, value) {
285
+ if (typeof value === "number") return STRING_STYLE_PROPERTIES.has(toCamelCase(prop)) ? String(value) : value;
286
+ return normalizeValue(prop, value);
262
287
  }
263
288
  function unescapeCssClassSelector(className) {
264
289
  return className.replace(/\\([^\n\r\f0-9a-f])/gi, "$1");
@@ -293,7 +318,7 @@ function styleExportToUtsMap(styleExport) {
293
318
  const declarations = styleStates[""];
294
319
  if (!declarations || Object.keys(declarations).length === 0) continue;
295
320
  const declarationEntries = Object.entries(declarations).map(([prop, value]) => {
296
- return `[${JSON.stringify(toCamelCase(prop))}, ${JSON.stringify(normalizeStyleValue(value))}]`;
321
+ return `[${JSON.stringify(toCamelCase(prop))}, ${JSON.stringify(normalizeStyleValue(prop, value))}]`;
297
322
  });
298
323
  if (declarationEntries.length === 0) continue;
299
324
  classEntries.push(`[${JSON.stringify(className)}, _pS(_uM([${declarationEntries.join(", ")}]))]`);
@@ -353,7 +378,7 @@ function cssToStyleExport(source) {
353
378
  if (!match?.[1]) continue;
354
379
  const declarations = {};
355
380
  rule.walkDecls((decl) => {
356
- declarations[toCamelCase(decl.prop)] = normalizeValue(decl.value);
381
+ declarations[toCamelCase(decl.prop)] = normalizeValue(decl.prop, decl.value);
357
382
  });
358
383
  if (Object.keys(declarations).length > 0) {
359
384
  result[match[1]] = { "": declarations };
@@ -881,7 +906,10 @@ function runWithRemovedBundleFiles(removedFiles, run) {
881
906
  return removedBundleFilesStorage.run(removedFiles, run);
882
907
  }
883
908
  function createBundleBuildState() {
884
- return createRuntimeCompilationBuildState();
909
+ return {
910
+ ...createRuntimeCompilationBuildState(),
911
+ entryMetadataByFile: /* @__PURE__ */ new Map()
912
+ };
885
913
  }
886
914
  function readEntrySource(output) {
887
915
  if (output.type === "chunk") return output.code;
@@ -899,18 +927,24 @@ function collectJsEntry(fileName, output, outDir, store) {
899
927
  const absolute = toAbsoluteOutputPath(fileName, outDir);
900
928
  store.set(absolute, entry);
901
929
  }
902
- function collectBundleEntries(bundle, opts, outDir) {
930
+ function collectBundleEntries(bundle, opts, outDir, metadataByFile) {
903
931
  const jsEntries = /* @__PURE__ */ new Map();
904
932
  const entries = [];
905
933
  for (const [file, output] of Object.entries(bundle)) {
906
- const type = classifyBundleEntry(file, opts);
934
+ const cachedMetadata = metadataByFile?.get(file);
935
+ const type = cachedMetadata?.outputType === output.type ? cachedMetadata.type : classifyBundleEntry(file, opts);
907
936
  const entry = {
908
937
  file,
909
938
  output,
910
939
  source: readEntrySource(output),
911
940
  type
912
941
  };
913
- entry.runtimeCandidate = isRuntimeCandidateBundleEntry(entry);
942
+ entry.runtimeCandidate = cachedMetadata?.outputType === output.type ? cachedMetadata.runtimeCandidate : isRuntimeCandidateBundleEntry(entry);
943
+ metadataByFile?.set(file, {
944
+ outputType: output.type,
945
+ runtimeCandidate: entry.runtimeCandidate === true,
946
+ type
947
+ });
914
948
  collectJsEntry(file, output, outDir, jsEntries);
915
949
  entries.push(entry);
916
950
  }
@@ -920,7 +954,7 @@ function collectBundleEntries(bundle, opts, outDir) {
920
954
  };
921
955
  }
922
956
  function buildBundleSnapshot(bundle, opts, outDir, state, forceAll = false, options = {}) {
923
- const { entries, jsEntries } = collectBundleEntries(bundle, opts, outDir);
957
+ const { entries, jsEntries } = collectBundleEntries(bundle, opts, outDir, state.entryMetadataByFile);
924
958
  return {
925
959
  ...buildRuntimeCompilationSnapshot(entries, state, {
926
960
  computeHash: (source) => opts.cache.computeHash(source),
@@ -934,6 +968,11 @@ function buildBundleSnapshot(bundle, opts, outDir, state, forceAll = false, opti
934
968
  }
935
969
  function updateBundleBuildState(state, snapshot, linkedByEntry, options = {}) {
936
970
  updateRuntimeCompilationBuildState(state, snapshot, linkedByEntry, options);
971
+ for (const file of snapshot.removedFiles) state.entryMetadataByFile.delete(file);
972
+ if (!snapshot.hasOmittedKnownFiles) {
973
+ const activeFiles = new Set(snapshot.entries.map((entry) => entry.file));
974
+ for (const file of state.entryMetadataByFile.keys()) if (!activeFiles.has(file)) state.entryMetadataByFile.delete(file);
975
+ }
937
976
  }
938
977
  //#endregion
939
978
  //#region ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs
@@ -6015,7 +6054,7 @@ async function resolveHotModulesByIds(ctx, ids, acceptModule) {
6015
6054
  }
6016
6055
  return modules;
6017
6056
  }
6018
- async function resolveHotTailwindCssModules(ctx, tailwindRootCssModuleIds) {
6057
+ async function resolveHotTailwindCssModules(ctx, tailwindRootCssModuleIds, selectModules) {
6019
6058
  const root = ctx.server.config?.root ?? process$1.cwd();
6020
6059
  const outDir = ctx.server.config?.build?.outDir ? resolveViteModuleIdentity(ctx.server.config.build.outDir, root) : void 0;
6021
6060
  const isHotSourceStyleModule = (id) => {
@@ -6040,8 +6079,9 @@ async function resolveHotTailwindCssModules(ctx, tailwindRootCssModuleIds) {
6040
6079
  modules.push(importer);
6041
6080
  }
6042
6081
  }
6043
- for (const mod of modules) ctx.server.moduleGraph.invalidateModule(mod);
6044
- return modules;
6082
+ const selectedModules = selectModules?.(modules) ?? modules;
6083
+ for (const mod of selectedModules) ctx.server.moduleGraph.invalidateModule(mod);
6084
+ return selectedModules;
6045
6085
  }
6046
6086
  async function resolveHotSourceModulesByIds(ctx, ids) {
6047
6087
  const root = ctx.server.config?.root ?? process$1.cwd();
@@ -6134,6 +6174,13 @@ function includesHotModule(modules, target, root) {
6134
6174
  ].some((moduleIdentity) => hasSameViteModuleIdentity(targetIdentity, moduleIdentity, root)));
6135
6175
  });
6136
6176
  }
6177
+ function includesHotId(modules, targetId, root) {
6178
+ return modules.some((mod) => [
6179
+ mod.id,
6180
+ mod.url,
6181
+ mod.file
6182
+ ].some((moduleId) => hasSameViteModuleIdentity(targetId, moduleId, root)));
6183
+ }
6137
6184
  function createSupplementalHotUpdate(hotUrl, timestamp) {
6138
6185
  return {
6139
6186
  type: "js-update",
@@ -6150,25 +6197,26 @@ function hasSelfAcceptingNonStyleHotModule(modules) {
6150
6197
  return !isSourceStyleRequest(modId) && mod.isSelfAccepting === true;
6151
6198
  });
6152
6199
  }
6153
- function sendSupplementalCssHotUpdates(ctx, cssModules, fallbackCssIds = [], fallbackSourceIds = []) {
6200
+ function sendSupplementalCssHotUpdates(ctx, cssModules, fallbackCssIds = [], fallbackSourceIds = [], handledModules = ctx.modules) {
6154
6201
  const seenUrls = /* @__PURE__ */ new Set();
6155
6202
  const root = ctx.server.config?.root ?? process$1.cwd();
6156
6203
  const updates = [];
6157
6204
  for (const id of fallbackSourceIds) {
6205
+ if (includesHotId(handledModules, id, root)) continue;
6158
6206
  const hotUrl = resolveCssHotUrl(id, root);
6159
6207
  if (!hotUrl || seenUrls.has(hotUrl)) continue;
6160
6208
  seenUrls.add(hotUrl);
6161
6209
  updates.push(createSupplementalHotUpdate(hotUrl, ctx.timestamp));
6162
6210
  }
6163
6211
  for (const id of fallbackCssIds) {
6164
- if (!isSourceStyleRequest(id)) continue;
6212
+ if (!isSourceStyleRequest(id) || includesHotId(handledModules, id, root)) continue;
6165
6213
  const hotUrl = resolveCssHotUrl(id, root);
6166
6214
  if (!hotUrl || seenUrls.has(hotUrl)) continue;
6167
6215
  seenUrls.add(hotUrl);
6168
6216
  updates.push(createSupplementalHotUpdate(hotUrl, ctx.timestamp));
6169
6217
  }
6170
6218
  for (const mod of cssModules) {
6171
- if (includesHotModule(ctx.modules, mod, root)) continue;
6219
+ if (includesHotModule(handledModules, mod, root)) continue;
6172
6220
  const moduleHotUrl = resolveModuleHotUrl(mod);
6173
6221
  const hotUrl = moduleHotUrl ? resolveCssHotUrl(moduleHotUrl, root) : void 0;
6174
6222
  if (!hotUrl || seenUrls.has(hotUrl)) continue;
@@ -6245,7 +6293,7 @@ function createUniAppXNativeBuildTargetResolver(getResolvedConfig) {
6245
6293
  const UVUE_NVUE_RE$1 = /\.(?:uvue|nvue)$/;
6246
6294
  const CSS_MODULE_EXPORT_RE = /^\s*export\s+default\s+(?:\{|\w|\[\])/;
6247
6295
  const RELATIVE_REFERENCE_RE = /@reference\s+(["'])(\.\.?[\\/][^"']+)\1\s*;?/g;
6248
- const WINDOWS_ABSOLUTE_PATH_RE = /^[a-z]:[\\/]/i;
6296
+ const WINDOWS_ABSOLUTE_PATH_RE$1 = /^[a-z]:[\\/]/i;
6249
6297
  function isPreprocessorRequest(id, lang) {
6250
6298
  return isSourcePreprocessorRequest(id, lang);
6251
6299
  }
@@ -6258,7 +6306,7 @@ function isCssModuleExport(code) {
6258
6306
  function normalizeRelativeTailwindReferences(code, id) {
6259
6307
  if (!code.includes("@reference")) return code;
6260
6308
  const sourceFile = cleanUrl$1(id);
6261
- const pathApi = WINDOWS_ABSOLUTE_PATH_RE.test(sourceFile) ? path.win32 : path;
6309
+ const pathApi = WINDOWS_ABSOLUTE_PATH_RE$1.test(sourceFile) ? path.win32 : path;
6262
6310
  const sourceDir = pathApi.dirname(sourceFile);
6263
6311
  return code.replace(RELATIVE_REFERENCE_RE, (_full, quote, request) => {
6264
6312
  return `@reference ${quote}${pathApi.resolve(sourceDir, request).replace(/\\/g, "/")}${quote};`;
@@ -6281,7 +6329,7 @@ function isStyleModule(mod) {
6281
6329
  const request = mod.id ?? mod.url;
6282
6330
  return typeof request === "string" && /[?&](?:vue&)?type=style(?:&|$)/.test(request);
6283
6331
  }
6284
- function createUniAppXWebLocalStyleBridge(isEnabled) {
6332
+ function createUniAppXWebLocalStyleBridge(isEnabled, hmrCssModuleVersions) {
6285
6333
  const rulesByFile = /* @__PURE__ */ new Map();
6286
6334
  return {
6287
6335
  appendToStyle(code, id) {
@@ -6291,10 +6339,16 @@ function createUniAppXWebLocalStyleBridge(isEnabled) {
6291
6339
  },
6292
6340
  handleHotUpdate(ctx) {
6293
6341
  if (!isEnabled() || !/\.(?:uvue|nvue)$/i.test(cleanUrl$1(ctx.file))) return;
6294
- const styleModules = [...ctx.server.moduleGraph.getModulesByFile?.(ctx.file) ?? []].filter(isStyleModule);
6295
- if (styleModules.length === 0) return;
6342
+ const root = ctx.server.config?.root ?? process$1.cwd();
6343
+ const sourceModules = ctx.modules.filter((mod) => !isStyleModule(mod));
6344
+ const contextStyleModules = ctx.modules.filter(isStyleModule);
6345
+ const currentContextStyleModules = hmrCssModuleVersions?.filterModules(contextStyleModules, ctx.timestamp, root) ?? contextStyleModules;
6346
+ const resolvedStyleModules = [...ctx.server.moduleGraph.getModulesByFile?.(ctx.file) ?? []].filter(isStyleModule);
6347
+ const currentResolvedStyleModules = hmrCssModuleVersions?.filterModules(resolvedStyleModules, ctx.timestamp, root) ?? resolvedStyleModules;
6348
+ const styleModules = [.../* @__PURE__ */ new Set([...currentContextStyleModules, ...currentResolvedStyleModules])];
6349
+ if (styleModules.length === 0 && sourceModules.length === ctx.modules.length) return;
6296
6350
  for (const mod of styleModules) ctx.server.moduleGraph.invalidateModule(mod);
6297
- return [.../* @__PURE__ */ new Set([...ctx.modules, ...styleModules])];
6351
+ return [.../* @__PURE__ */ new Set([...sourceModules, ...styleModules])];
6298
6352
  },
6299
6353
  remember(id, rules) {
6300
6354
  rulesByFile.set(cleanUrl$1(id), rules);
@@ -6302,25 +6356,67 @@ function createUniAppXWebLocalStyleBridge(isEnabled) {
6302
6356
  };
6303
6357
  }
6304
6358
  //#endregion
6359
+ //#region src/uni-app-x/vite/asset-task.ts
6360
+ function resolveUniAppXJsTransformEnabled(uniAppX) {
6361
+ return uniAppX === void 0 ? true : isUniAppXEnabled(uniAppX);
6362
+ }
6363
+ function createUniAppXAssetTask(file, originalSource, outDir, options) {
6364
+ return async () => {
6365
+ const { cache, hashKey, createHandlerOptions, debug, getAssetSource, getCssSources, injectStylePlaceholder = true, jsHandler, onUpdate, runtimeSet, applyLinkedResults } = options;
6366
+ const absoluteFile = toAbsoluteOutputPath(file, outDir);
6367
+ const rawSource = originalSource.source.toString();
6368
+ const rawHashSource = options.hashSalt ? `${rawSource}\n/*${options.hashSalt}*/` : rawSource;
6369
+ await processCachedTask({
6370
+ cache,
6371
+ cacheKey: file,
6372
+ hashKey,
6373
+ rawSource: rawHashSource,
6374
+ applyResult(source) {
6375
+ originalSource.source = source;
6376
+ },
6377
+ onCacheHit() {
6378
+ debug("js cache hit: %s", file);
6379
+ },
6380
+ async transform() {
6381
+ const currentSource = originalSource.source.toString();
6382
+ const { code, linked } = await jsHandler(currentSource, runtimeSet, createHandlerOptions(absoluteFile, {
6383
+ uniAppX: resolveUniAppXJsTransformEnabled(options.uniAppX),
6384
+ babelParserOptions: {
6385
+ plugins: ["typescript"],
6386
+ sourceType: "unambiguous"
6387
+ }
6388
+ }));
6389
+ const nextCode = injectStylePlaceholder ? injectUniAppXStylePlaceholder(file, code, getAssetSource, getCssSources?.()) : code;
6390
+ onUpdate(file, currentSource, nextCode);
6391
+ debug("js handle: %s", file);
6392
+ applyLinkedResults(linked);
6393
+ return { result: nextCode };
6394
+ }
6395
+ });
6396
+ };
6397
+ }
6398
+ //#endregion
6305
6399
  //#region src/uni-app-x/vite.ts
6306
6400
  let transformUVuePromise;
6307
6401
  function loadTransformUVue() {
6308
- transformUVuePromise ?? (transformUVuePromise = import("./transform-Bfi1_VgN.js").then((mod) => mod.transformUVue));
6402
+ transformUVuePromise ?? (transformUVuePromise = import("./transform-DQhgAarN.js").then((mod) => mod.transformUVue));
6309
6403
  return transformUVuePromise;
6310
6404
  }
6311
6405
  const UVUE_NVUE_QUERY_RE = /\.(?:uvue|nvue)(?:\?.*)?$/;
6312
6406
  const UVUE_NVUE_RE = /\.(?:uvue|nvue)$/;
6313
- function resolveUniAppXJsTransformEnabled(uniAppX) {
6314
- return uniAppX === void 0 ? true : isUniAppXEnabled(uniAppX);
6407
+ function hasUniAppXImportantApply(source) {
6408
+ return extractSfcStyleBlocks(source).some((style) => normalizeUniAppXImportantApplyForSass(style.source) !== style.source);
6315
6409
  }
6316
6410
  function createUniAppXPlugins(options) {
6317
- const { appType, customAttributesEntities, disabledDefaultTemplateHandler, isIosPlatform: providedIosPlatform, mainCssChunkMatcher, registerModuleGraphCandidates, runtimeState, styleHandler, syncSourceCandidatesForHotUpdate, tailwindRootCssModuleIds = [], generateCss, jsHandler, ensureRuntimeClassSet, getResolvedConfig, isEnabled = () => true, isNativeAppStyleTarget = () => false, isWebGeneratorTarget = () => resolveUniUtsPlatform().isWeb, uniAppX, viteProcessedCssSourceFiles = [] } = options;
6411
+ const { appType, customAttributesEntities, disabledDefaultTemplateHandler, isIosPlatform: providedIosPlatform, mainCssChunkMatcher, registerModuleGraphCandidates, runtimeState, styleHandler, syncSourceCandidatesForHotUpdate, tailwindRootCssModuleIds = [], generateCss, hmrCssModuleVersions, jsHandler, ensureRuntimeClassSet, getResolvedConfig, isEnabled = () => true, isNativeAppStyleTarget = () => false, isWebGeneratorTarget = () => resolveUniUtsPlatform().isWeb, uniAppX, viteProcessedCssSourceFiles = [], webCssEntryDiagnostics } = options;
6318
6412
  const resolvedUniAppXOptions = resolveUniAppXOptions(uniAppX);
6319
6413
  const utsPlatform = resolveUniUtsPlatform();
6320
6414
  const isIosPlatform = providedIosPlatform ?? utsPlatform.isAppIos;
6321
6415
  const cssHandlerOptionsCache = /* @__PURE__ */ new Map();
6322
6416
  const nativeLocalStyleModuleIds = /* @__PURE__ */ new Set();
6323
- const webLocalStyle = createUniAppXWebLocalStyleBridge(isWebGeneratorTarget);
6417
+ const knownSfcSources = /* @__PURE__ */ new Map();
6418
+ const pendingSfcTransforms = /* @__PURE__ */ new Map();
6419
+ const webLocalStyle = createUniAppXWebLocalStyleBridge(isWebGeneratorTarget, hmrCssModuleVersions);
6324
6420
  let componentLocalStyleEnabled;
6325
6421
  const isNativeAppBuildTarget = createUniAppXNativeBuildTargetResolver(getResolvedConfig);
6326
6422
  const nativeHmrReloader = createUniAppXNativeHmrReloader({
@@ -6384,7 +6480,7 @@ function createUniAppXPlugins(options) {
6384
6480
  const parsed = query ?? parseVueRequest(id).query;
6385
6481
  if (isCSSRequest(id) || parsed.vue && parsed.type === "style") {
6386
6482
  if (isCssModuleExport(code)) return;
6387
- const sourceCode = normalizeRelativeTailwindReferences(code, id);
6483
+ const sourceCode = normalizeRelativeTailwindReferences(restoreUniAppXImportantApplyMarker(code), id);
6388
6484
  const hasTailwindRoot = hasTailwindRootDirectives(sourceCode, { importFallback: true });
6389
6485
  const hasTailwindApply = hasTailwindApplyDirective(sourceCode);
6390
6486
  const shouldGenerateCss = hasTailwindRoot || hasTailwindApply;
@@ -6428,23 +6524,42 @@ function createUniAppXPlugins(options) {
6428
6524
  }, {
6429
6525
  name: "weapp-tailwindcss:uni-app-x:css:pre",
6430
6526
  enforce: "pre",
6527
+ load: {
6528
+ order: "pre",
6529
+ async handler(id) {
6530
+ const { filename, query } = parseVueRequest(id);
6531
+ if (!query.vue || query.type !== "style" || !UVUE_NVUE_RE.test(filename)) return;
6532
+ const source = knownSfcSources.get(filename);
6533
+ const style = source ? extractSfcStyleBlocks(source)[query.index ?? 0] : void 0;
6534
+ if (!style) return;
6535
+ const normalized = normalizeUniAppXImportantApplyForSass(style.source);
6536
+ return normalized === style.source ? void 0 : {
6537
+ code: normalized,
6538
+ map: null
6539
+ };
6540
+ }
6541
+ },
6431
6542
  async transform(code, id) {
6432
6543
  if (!isEnabled()) return;
6433
6544
  await runtimeState.readyPromise;
6434
- const { query } = parseVueRequest(id);
6545
+ const { filename, query } = parseVueRequest(id);
6546
+ if (query.vue && query.type === "style") await pendingSfcTransforms.get(cleanUrl$1(filename));
6435
6547
  const styleCode = query.vue && query.type === "style" ? webLocalStyle.appendToStyle(code, id) : code;
6436
- const preprocessor = resolvePreprocessorTransform(styleCode, id, query.lang, {
6548
+ const preprocessorCode = query.vue && query.type === "style" ? normalizeUniAppXImportantApplyForSass(styleCode) : styleCode;
6549
+ const preprocessor = resolvePreprocessorTransform(preprocessorCode, id, query.lang, {
6437
6550
  isIosPlatform,
6438
6551
  isNativeAppStyleTarget: isNativeAppStyleTarget()
6439
6552
  });
6440
- if (preprocessor) return preprocessor.result ?? (styleCode !== code ? {
6441
- code: styleCode,
6553
+ if (preprocessor) return preprocessor.result ?? (preprocessorCode !== code ? {
6554
+ code: preprocessorCode,
6442
6555
  map: null
6443
6556
  } : void 0);
6444
- return transformStyle(styleCode, id, query, this);
6557
+ return transformStyle(preprocessorCode, id, query, this);
6445
6558
  }
6446
6559
  }];
6447
6560
  async function transformSfc(code, id, context) {
6561
+ knownSfcSources.set(cleanUrl$1(id), code);
6562
+ if (isWebGeneratorTarget()) for (const style of extractSfcStyleBlocks(code)) webCssEntryDiagnostics?.observeSourceImports(style.source, id);
6448
6563
  if (isNativeAppBuildTarget(id)) {
6449
6564
  nativeLocalStyleModuleIds.add(id);
6450
6565
  nativeLocalStyleModuleIds.add(cleanUrl$1(id));
@@ -6465,9 +6580,13 @@ function createUniAppXPlugins(options) {
6465
6580
  ...disabledDefaultTemplateHandler ? { disabledDefaultTemplateHandler } : {},
6466
6581
  ...enableComponentLocalStyle ? { enableComponentLocalStyle } : {},
6467
6582
  ...enablePageLocalStyle ? { enablePageLocalStyle } : {},
6583
+ native: true,
6468
6584
  pageMatcher: resolvedUniAppXOptions.componentLocalStyles.pageMatcher,
6469
6585
  ...isWebGeneratorTarget() && customAttributesEntities.length > 0 ? { webCustomAttributeDeep: true } : {},
6470
- ...isWebGeneratorTarget() ? { onWebLocalStyleRules: (rules) => webLocalStyle.remember(id, rules) } : {}
6586
+ ...isWebGeneratorTarget() ? { onWebLocalStyleRules: (rules) => {
6587
+ webLocalStyle.remember(id, rules);
6588
+ webCssEntryDiagnostics?.requestCheck();
6589
+ } } : {}
6471
6590
  });
6472
6591
  const result = Object.keys(transformOptions).length > 0 ? transformUVue(code, id, jsHandler, currentRuntimeSet, transformOptions) : transformUVue(code, id, jsHandler, currentRuntimeSet);
6473
6592
  if (!result?.code) return result;
@@ -6478,6 +6597,15 @@ function createUniAppXPlugins(options) {
6478
6597
  map: null
6479
6598
  };
6480
6599
  }
6600
+ function runTransformSfc(code, id, context) {
6601
+ const file = cleanUrl$1(id);
6602
+ const pending = transformSfc(code, id, context);
6603
+ pendingSfcTransforms.set(file, pending);
6604
+ pending.finally(() => {
6605
+ if (pendingSfcTransforms.get(file) === pending) pendingSfcTransforms.delete(file);
6606
+ });
6607
+ return pending;
6608
+ }
6481
6609
  const nvuePlugin = {
6482
6610
  name: "weapp-tailwindcss:uni-app-x:nvue",
6483
6611
  enforce: "pre",
@@ -6490,7 +6618,7 @@ function createUniAppXPlugins(options) {
6490
6618
  async handler(code, id) {
6491
6619
  if (!isEnabled()) return;
6492
6620
  if (!UVUE_NVUE_QUERY_RE.test(id)) return;
6493
- return transformSfc(code, id, this);
6621
+ return runTransformSfc(code, id, this);
6494
6622
  }
6495
6623
  },
6496
6624
  handleHotUpdate: {
@@ -6498,7 +6626,17 @@ function createUniAppXPlugins(options) {
6498
6626
  async handler(ctx) {
6499
6627
  if (!isEnabled() || getResolvedConfig()?.command !== "serve") return;
6500
6628
  if (!UVUE_NVUE_RE.test(ctx.file) && !isCSSRequest(ctx.file)) return;
6501
- if (isWebGeneratorTarget() && UVUE_NVUE_RE.test(ctx.file) && typeof ctx.read === "function") await transformSfc(await ctx.read(), ctx.file, this);
6629
+ if (isWebGeneratorTarget() && UVUE_NVUE_RE.test(ctx.file) && typeof ctx.read === "function") {
6630
+ const source = await ctx.read();
6631
+ if (hasUniAppXImportantApply(source)) {
6632
+ ctx.server.ws.send({
6633
+ type: "full-reload",
6634
+ path: ctx.file
6635
+ });
6636
+ return [];
6637
+ }
6638
+ await runTransformSfc(source, ctx.file, this);
6639
+ }
6502
6640
  return webLocalStyle.handleHotUpdate(ctx) ?? nativeHmrReloader.handleHotUpdate(ctx);
6503
6641
  }
6504
6642
  },
@@ -6508,6 +6646,12 @@ function createUniAppXPlugins(options) {
6508
6646
  if (resolvedConfig?.command !== "build" || !resolvedConfig.build?.watch) return;
6509
6647
  if (!UVUE_NVUE_QUERY_RE.test(id)) return;
6510
6648
  await ensureRuntimeClassSet(true);
6649
+ },
6650
+ buildEnd() {
6651
+ if (isWebGeneratorTarget()) webCssEntryDiagnostics?.flush();
6652
+ },
6653
+ closeBundle() {
6654
+ webCssEntryDiagnostics?.dispose();
6511
6655
  }
6512
6656
  };
6513
6657
  const stylePlaceholderPlugin = {
@@ -6557,43 +6701,23 @@ function createUniAppXPlugins(options) {
6557
6701
  stylePlaceholderPlugin
6558
6702
  ];
6559
6703
  }
6560
- function createUniAppXAssetTask(file, originalSource, outDir, options) {
6561
- return async () => {
6562
- const { cache, hashKey, createHandlerOptions, debug, getAssetSource, getCssSources, injectStylePlaceholder = true, jsHandler, onUpdate, runtimeSet, applyLinkedResults } = options;
6563
- const absoluteFile = toAbsoluteOutputPath(file, outDir);
6564
- const rawSource = originalSource.source.toString();
6565
- const rawHashSource = options.hashSalt ? `${rawSource}\n/*${options.hashSalt}*/` : rawSource;
6566
- await processCachedTask({
6567
- cache,
6568
- cacheKey: file,
6569
- hashKey,
6570
- rawSource: rawHashSource,
6571
- applyResult(source) {
6572
- originalSource.source = source;
6573
- },
6574
- onCacheHit() {
6575
- debug("js cache hit: %s", file);
6576
- },
6577
- async transform() {
6578
- const currentSource = originalSource.source.toString();
6579
- const { code, linked } = await jsHandler(currentSource, runtimeSet, createHandlerOptions(absoluteFile, {
6580
- uniAppX: resolveUniAppXJsTransformEnabled(options.uniAppX),
6581
- babelParserOptions: {
6582
- plugins: ["typescript"],
6583
- sourceType: "unambiguous"
6584
- }
6585
- }));
6586
- const nextCode = injectStylePlaceholder ? injectUniAppXStylePlaceholder(file, code, getAssetSource, getCssSources?.()) : code;
6587
- onUpdate(file, currentSource, nextCode);
6588
- debug("js handle: %s", file);
6589
- applyLinkedResults(linked);
6590
- return { result: nextCode };
6591
- }
6592
- });
6593
- };
6594
- }
6595
6704
  //#endregion
6596
6705
  //#region src/bundlers/vite/generate-bundle/js-processing.ts
6706
+ /** 在增量构建中直接回放 clean chunk,避免创建完整 JS 处理任务。 */
6707
+ function replayCleanJsBundleEntry(options) {
6708
+ const { cache, debug, entry, metrics, rememberProcessCacheKey, snapshot, transformFilterSignature, transformRuntimeSignature, useIncrementalMode } = options;
6709
+ if (!useIncrementalMode || entry.output.type !== "chunk" || snapshot.processFiles.js.has(entry.file)) return false;
6710
+ const hashKey = `${entry.file}:js`;
6711
+ const processHash = `${snapshot.sourceHashByFile.get(entry.file) ?? cache.computeHash(entry.source)}:${transformRuntimeSignature}:transform-filter:${transformFilterSignature}`;
6712
+ rememberProcessCacheKey(entry.file, hashKey);
6713
+ const cachedCode = cache.getHashValue(hashKey)?.hash === processHash ? cache.get(entry.file) : void 0;
6714
+ if (cachedCode === void 0) return false;
6715
+ entry.output.code = cachedCode;
6716
+ metrics.js.total++;
6717
+ metrics.js.cacheHits++;
6718
+ debug("js direct replay hit (planned clean): %s", entry.file);
6719
+ return true;
6720
+ }
6597
6721
  function processJsBundleEntry(options) {
6598
6722
  const { applyLinkedUpdates, bundle, cache, createHandlerOptions, debug, disableJsPrecheck, entry, getJsEntry, deferUniAppXStylePlaceholder, jsHandler, jsTaskFactories, linkedByEntry, metrics, onUpdate, outDir, processFiles, rememberProcessCacheKey, runtimeSignature, snapshot, shouldSkipAstTransform, slowJsAstWarnMs, timeTask, transformRuntime, transformRuntimeSignature, transformFilterSignature, uniAppX, useIncrementalMode } = options;
6599
6723
  const { file, output: originalSource, source: originalEntrySource } = entry;
@@ -7962,6 +8086,17 @@ function createGenerateBundleHook$1(context) {
7962
8086
  debug("js skip web target: %s", file);
7963
8087
  continue;
7964
8088
  }
8089
+ if (replayCleanJsBundleEntry({
8090
+ cache,
8091
+ debug,
8092
+ entry,
8093
+ metrics,
8094
+ rememberProcessCacheKey,
8095
+ snapshot,
8096
+ transformFilterSignature,
8097
+ transformRuntimeSignature,
8098
+ useIncrementalMode
8099
+ })) continue;
7965
8100
  processJsBundleEntry({
7966
8101
  applyLinkedUpdates,
7967
8102
  bundle,
@@ -9015,7 +9150,7 @@ function createRewriteCssImportsPlugins(options) {
9015
9150
  async transform(code, id) {
9016
9151
  if (!isCSSRequest(id)) return null;
9017
9152
  const file = cleanUrl$1(id);
9018
- const normalizedCode = hasTailwindRootDirectives(code) || code.includes("@config") ? normalizeTailwindConfigDirectives(code, path.dirname(file)) : code;
9153
+ const normalizedCode = !isSfcStyleSourceFile(file) && (hasTailwindRootDirectives(code) || code.includes("@config")) ? normalizeTailwindConfigDirectives(code, path.dirname(file)) : code;
9019
9154
  await options.onCssSourceTransform?.(id, normalizedCode);
9020
9155
  const hasTailwindRoot = hasTailwindRootDirectives(normalizedCode, { importFallback: true });
9021
9156
  if (hasTailwindRoot) await options.onTailwindRootCss?.(id, normalizedCode);
@@ -9376,6 +9511,96 @@ function wrapViteCssPostTransform(config, transformCss) {
9376
9511
  return true;
9377
9512
  }
9378
9513
  //#endregion
9514
+ //#region src/bundlers/vite/shared/configured-css-entry-observer.ts
9515
+ const WINDOWS_ABSOLUTE_PATH_RE = /^[a-z]:[\\/]/i;
9516
+ function createConfiguredCssEntryObserver(options) {
9517
+ const observedEntries = /* @__PURE__ */ new Set();
9518
+ let checkRequested = false;
9519
+ let timer;
9520
+ let warned = false;
9521
+ const resolveEntry = (entry) => resolveViteModuleIdentity(entry, options.getRoot()).key;
9522
+ const observeImport = (request, sourceId) => {
9523
+ if (!request.startsWith(".") && !path.isAbsolute(request) && !WINDOWS_ABSOLUTE_PATH_RE.test(request)) return;
9524
+ const sourceFile = resolveViteModuleIdentity(sourceId, options.getRoot()).file;
9525
+ if (!sourceFile) return;
9526
+ const pathApi = WINDOWS_ABSOLUTE_PATH_RE.test(sourceFile) ? path.win32 : path;
9527
+ observedEntries.add(resolveEntry(pathApi.resolve(pathApi.dirname(sourceFile), request)));
9528
+ };
9529
+ const clearTimer = () => {
9530
+ if (timer !== void 0) {
9531
+ clearTimeout(timer);
9532
+ timer = void 0;
9533
+ }
9534
+ };
9535
+ const missingEntries = () => options.getEntries()?.filter((entry) => !observedEntries.has(resolveEntry(entry))) ?? [];
9536
+ const check = () => {
9537
+ clearTimer();
9538
+ if (!checkRequested || warned) return;
9539
+ const missing = missingEntries();
9540
+ if (missing.length === 0) return;
9541
+ warned = true;
9542
+ options.onMissing(missing);
9543
+ };
9544
+ return {
9545
+ dispose() {
9546
+ clearTimer();
9547
+ },
9548
+ flush: check,
9549
+ observe(id) {
9550
+ observedEntries.add(resolveEntry(id));
9551
+ if (checkRequested && missingEntries().length === 0) clearTimer();
9552
+ },
9553
+ observeSourceImports(source, sourceId) {
9554
+ if (!source.includes("@import")) return;
9555
+ try {
9556
+ postcss.parse(source).walkAtRules("import", (rule) => {
9557
+ const request = parseTailwindCssDirectiveRequest(rule.params);
9558
+ if (request) observeImport(request, sourceId);
9559
+ });
9560
+ } catch {}
9561
+ },
9562
+ requestCheck() {
9563
+ if (warned) return;
9564
+ checkRequested = true;
9565
+ clearTimer();
9566
+ timer = setTimeout(check, options.delayMs ?? 1e3);
9567
+ }
9568
+ };
9569
+ }
9570
+ function createConfiguredCssEntryDiagnostics(options) {
9571
+ const observer = createConfiguredCssEntryObserver({
9572
+ getEntries: options.getEntries,
9573
+ getRoot: options.getRoot,
9574
+ onMissing(entries) {
9575
+ logger.warn("[uni-app-x Web] cssEntries 中的 Tailwind CSS 入口未进入 Web 样式构建链路:%s。componentLocalStyles 已生成 wtu-* 局部类,但入口中的 @theme/CSS 变量不会投递到浏览器。请在 App.uvue 或应用入口中显式 import 这些 CSS 文件。", entries.join(", "));
9576
+ }
9577
+ });
9578
+ return {
9579
+ observer,
9580
+ plugin: {
9581
+ name: "weapp-tailwindcss:configured-css-entry-observer",
9582
+ transform(_code, id) {
9583
+ if (options.isWeb() && isSourceStyleRequest(id)) observer.observe(id);
9584
+ }
9585
+ }
9586
+ };
9587
+ }
9588
+ //#endregion
9589
+ //#region src/bundlers/vite/shared/framework-css-generation-queue.ts
9590
+ function createFrameworkCssGenerationQueue(normalizeId, generate) {
9591
+ const pendingByFile = /* @__PURE__ */ new Map();
9592
+ return (id, ...args) => {
9593
+ const fileKey = normalizeId(id);
9594
+ const task = (pendingByFile.get(fileKey) ?? Promise.resolve()).then(() => generate(id, ...args));
9595
+ const tail = task.then(() => void 0, () => void 0);
9596
+ pendingByFile.set(fileKey, tail);
9597
+ tail.then(() => {
9598
+ if (pendingByFile.get(fileKey) === tail) pendingByFile.delete(fileKey);
9599
+ });
9600
+ return task;
9601
+ };
9602
+ }
9603
+ //#endregion
9379
9604
  //#region src/bundlers/vite/shared/framework-hmr-candidate-state.ts
9380
9605
  function createViteHmrCandidateState(options) {
9381
9606
  let pendingChange;
@@ -9516,6 +9741,70 @@ function createViteHmrCandidateState(options) {
9516
9741
  };
9517
9742
  }
9518
9743
  //#endregion
9744
+ //#region src/bundlers/vite/shared/framework-hmr-module-version.ts
9745
+ function acceptVersion(versions, keys, timestamp) {
9746
+ if (keys.some((key) => (versions.get(key) ?? 0) > timestamp)) return false;
9747
+ for (const key of keys) versions.set(key, Math.max(versions.get(key) ?? 0, timestamp));
9748
+ return true;
9749
+ }
9750
+ function createViteHmrCssModuleVersionTracker() {
9751
+ const versions = /* @__PURE__ */ new Map();
9752
+ const keysForId = (id, root) => [resolveViteModuleIdentity(id, root).key];
9753
+ const keysForModule = (mod, root) => [...new Set([
9754
+ mod.id,
9755
+ mod.url,
9756
+ mod.file
9757
+ ].filter((id) => typeof id === "string" && id.length > 0).flatMap((id) => keysForId(id, root)))];
9758
+ return {
9759
+ clear() {
9760
+ versions.clear();
9761
+ },
9762
+ filterIds(ids, timestamp, root) {
9763
+ return [...ids].filter((id) => acceptVersion(versions, keysForId(id, root), timestamp));
9764
+ },
9765
+ filterModules(modules, timestamp, root) {
9766
+ return modules.filter((mod) => {
9767
+ const keys = keysForModule(mod, root);
9768
+ return keys.length === 0 || acceptVersion(versions, keys, timestamp);
9769
+ });
9770
+ },
9771
+ reserveRefreshTimestamp(modules, timestamp, root) {
9772
+ const moduleKeys = modules.flatMap((mod) => keysForModule(mod, root));
9773
+ const latestTimestamp = moduleKeys.reduce((latest, key) => Math.max(latest, versions.get(key) ?? 0), 0);
9774
+ const refreshTimestamp = Math.max(Date.now(), timestamp + 1, latestTimestamp + 1);
9775
+ for (const key of moduleKeys) versions.set(key, refreshTimestamp);
9776
+ return refreshTimestamp;
9777
+ }
9778
+ };
9779
+ }
9780
+ function createViteHmrCssModuleVersionFilterPlugin(tracker) {
9781
+ return {
9782
+ name: "weapp-tailwindcss:hmr-css-module-version",
9783
+ enforce: "post",
9784
+ handleHotUpdate: {
9785
+ order: "post",
9786
+ handler(ctx) {
9787
+ const styleModules = ctx.modules.filter((mod) => {
9788
+ const request = mod.id ?? mod.url;
9789
+ return isSourceStyleRequest(request);
9790
+ });
9791
+ if (styleModules.length === 0) return;
9792
+ const root = ctx.server.config?.root ?? process$1.cwd();
9793
+ const currentStyleModules = tracker.filterModules(styleModules, ctx.timestamp, root);
9794
+ if (currentStyleModules.length === styleModules.length) return;
9795
+ const droppedStyleModules = styleModules.filter((mod) => !currentStyleModules.includes(mod));
9796
+ for (const mod of droppedStyleModules) ctx.server.moduleGraph.invalidateModule(mod);
9797
+ const refreshTimestamp = tracker.reserveRefreshTimestamp(droppedStyleModules, ctx.timestamp, root);
9798
+ sendSupplementalCssHotUpdates({
9799
+ ...ctx,
9800
+ timestamp: refreshTimestamp
9801
+ }, droppedStyleModules, [], [], []);
9802
+ return [...ctx.modules.filter((mod) => !styleModules.includes(mod)), ...currentStyleModules];
9803
+ }
9804
+ }
9805
+ };
9806
+ }
9807
+ //#endregion
9519
9808
  //#region src/bundlers/vite/shared/framework-module-candidates.ts
9520
9809
  function createFrameworkModuleCandidateRegistrar(options) {
9521
9810
  return async (id, source) => {
@@ -9672,7 +9961,7 @@ function createFrameworkPostPlugin(options) {
9672
9961
  }
9673
9962
  }
9674
9963
  if (options.shouldInferAppType && resolvedRoot) {
9675
- const nextAppType = resolveImplicitAppTypeFromViteRoot(resolvedRoot);
9964
+ const nextAppType = resolveImplicitAppTypeFromViteRoot(resolvedRoot, { searchUp: false });
9676
9965
  if (nextAppType && options.opts.appType !== nextAppType) {
9677
9966
  const previousAppType = options.opts.appType;
9678
9967
  options.opts.appType = nextAppType;
@@ -9681,6 +9970,16 @@ function createFrameworkPostPlugin(options) {
9681
9970
  shouldRefreshRuntime = true;
9682
9971
  }
9683
9972
  }
9973
+ if (options.frameworkName === "generic" && !options.hasExplicitGeneratorTarget && options.opts.generator !== false && options.opts.appType === void 0 && options.opts.platform === void 0 && options.opts.cssOptions?.platform === void 0 && !options.resolveViteStylePlatform()) {
9974
+ const generator = options.opts.generator && typeof options.opts.generator === "object" ? options.opts.generator : {};
9975
+ options.opts.generator = {
9976
+ ...generator,
9977
+ target: "web"
9978
+ };
9979
+ logger.info("Generic Vite 项目未指定目标,自动使用 generator.target -> web");
9980
+ options.debug("default generic vite generator target to web after configResolved");
9981
+ shouldRefreshRuntime = true;
9982
+ }
9684
9983
  if (shouldRefreshRuntime) await options.refreshRuntimeState(true);
9685
9984
  if (typeof config.css.postcss === "object" && Array.isArray(config.css.postcss.plugins)) {
9686
9985
  const postcssPlugins = config.css.postcss.plugins;
@@ -9753,6 +10052,36 @@ function sameStringList(first, second) {
9753
10052
  return first.every((item, index) => item === second[index]);
9754
10053
  }
9755
10054
  //#endregion
10055
+ //#region src/bundlers/vite/shared/framework-runtime-utils.ts
10056
+ function collectConfiguredCssEntries(options) {
10057
+ const runtimeCssEntries = options.tailwindcssRuntimeOptions?.tailwindcss?.v4?.cssEntries;
10058
+ const entries = [
10059
+ ...Array.isArray(options.cssEntries) ? options.cssEntries : [],
10060
+ ...Array.isArray(options.tailwindcss?.v4?.cssEntries) ? options.tailwindcss.v4.cssEntries : [],
10061
+ ...Array.isArray(runtimeCssEntries) ? runtimeCssEntries : []
10062
+ ].filter((item) => typeof item === "string" && item.length > 0);
10063
+ return entries.length > 0 ? [...new Set(entries)] : void 0;
10064
+ }
10065
+ function inferPlatformFromOutDir(outDir) {
10066
+ const segment = outDir ? path.basename(path.normalize(outDir)) : void 0;
10067
+ if (!segment) return;
10068
+ const normalized = segment.trim().toLowerCase();
10069
+ if (normalized === "h5" || normalized === "web" || normalized === "app" || normalized === "app-plus" || normalized.startsWith("app-") || normalized.startsWith("mp-") || normalized.startsWith("quickapp-webview")) return normalized;
10070
+ }
10071
+ function isWebOrNativeAppPlatform(platform) {
10072
+ return platform === "h5" || platform === "web" || platform?.startsWith("web-") === true || platform === "app" || platform === "app-plus" || platform?.startsWith("app-") === true;
10073
+ }
10074
+ function isInternalUserDefinedOptions(options) {
10075
+ return typeof options.onLoad === "function" && typeof options.mainCssChunkMatcher === "function" && typeof options.tailwindRuntime === "object" && typeof options.refreshTailwindcssRuntime === "function";
10076
+ }
10077
+ function isNuxtPageHotModule(id) {
10078
+ if (typeof id !== "string") return false;
10079
+ const cleanId = cleanUrl$1(id).replace(/%2F/gi, "/");
10080
+ if (cleanId.includes("virtual:nuxt:") && /(?:^|\/)routes\.mjs$/.test(cleanId)) return true;
10081
+ if (!/[?&]macro=true(?:&|$)/.test(id)) return false;
10082
+ return cleanId.includes("/pages/") && /\.(?:vue|tsx?|jsx?)$/.test(cleanId);
10083
+ }
10084
+ //#endregion
9756
10085
  //#region src/bundlers/vite/shared/framework-source-candidates-plugin.ts
9757
10086
  function createFrameworkSourceCandidatesPlugin(options, apply) {
9758
10087
  const hasDifferentHotModules = (left, right) => left.length !== right.length || left.some((mod, index) => mod !== right[index]);
@@ -9809,7 +10138,7 @@ function createFrameworkSourceCandidatesPlugin(options, apply) {
9809
10138
  options.cssMemory.rememberKnownSfcSource(id, transformedCode);
9810
10139
  if (isCSSRequest(id) && hasTailwindRootDirectives(transformedCode, { importFallback: options.resolveCurrentGeneratorOptions().importFallback })) options.rememberTailwindRootCssModule(id);
9811
10140
  }
9812
- if (!options.shouldOwnTailwindGeneration || !isSourceCandidateRequest(id) || !shouldCollectTransformedSourceCandidates(id)) return shouldReturnTransformedCode ? {
10141
+ if (!options.shouldOwnTailwindGeneration || options.collectSourceCandidates === false || !isSourceCandidateRequest(id) || !shouldCollectTransformedSourceCandidates(id)) return shouldReturnTransformedCode ? {
9813
10142
  code: transformedCode,
9814
10143
  map: null
9815
10144
  } : void 0;
@@ -9836,13 +10165,21 @@ function createFrameworkSourceCandidatesPlugin(options, apply) {
9836
10165
  async watchChange(id, change) {
9837
10166
  recordCompilationDependencyChanges(options.runtimeState, createCompilationDependencyChanges([path.resolve(cleanUrl$1(id))]));
9838
10167
  await options.hmrTimingRecorder.measure("sourceCandidates.watchChange", async () => {
9839
- if (options.shouldOwnTailwindGeneration && isSourceCandidateRequest(id)) options.invalidateRecordedGeneratorCandidates();
10168
+ if (options.shouldOwnTailwindGeneration && options.collectSourceCandidates !== false && isSourceCandidateRequest(id)) options.invalidateRecordedGeneratorCandidates();
9840
10169
  if (options.sourceScanSession.isDependency(id)) options.sourceScanSession.invalidate();
9841
10170
  if (change.event === "delete") {
9842
10171
  const file = cleanUrl$1(id);
9843
- const sourceCandidateChange = options.sourceCandidateCollector.remove(file);
9844
- options.sourceScanSession.cacheCurrent();
9845
- options.hmrCandidateState.apply(options.hmrCandidateState.createChange(file, sourceCandidateChange, { runtimeAffecting: options.sourceScanSession.isDependency(file) }));
10172
+ if (typeof options.sourceScanSession.queueChangedFile === "function") {
10173
+ options.sourceScanSession.queueChangedFile({
10174
+ event: "delete",
10175
+ id: file
10176
+ });
10177
+ queueMicrotask(() => void options.sourceScanSession.flushChangedFiles());
10178
+ } else {
10179
+ const sourceCandidateChange = options.sourceCandidateCollector.remove(file);
10180
+ options.sourceScanSession.cacheCurrent();
10181
+ options.hmrCandidateState.apply(options.hmrCandidateState.createChange(file, sourceCandidateChange, { runtimeAffecting: options.sourceScanSession.isDependency(file) }));
10182
+ }
9846
10183
  return;
9847
10184
  }
9848
10185
  const changedSource = options.shouldOwnTailwindGeneration && isSourceCandidateRequest(id) && isCSSRequest(id) ? await readFile(cleanUrl$1(id), "utf8").catch(() => void 0) : void 0;
@@ -9850,7 +10187,14 @@ function createFrameworkSourceCandidatesPlugin(options, apply) {
9850
10187
  options.rememberOriginalCssLayerSource(id, changedSource);
9851
10188
  await options.refreshTailwindRootCssSource(id, changedSource);
9852
10189
  }
9853
- await options.sourceScanSession.syncChangedFile(id, changedSource);
10190
+ if (typeof options.sourceScanSession.queueChangedFile === "function") {
10191
+ options.sourceScanSession.queueChangedFile({
10192
+ event: change.event === "create" ? "create" : "update",
10193
+ id,
10194
+ source: changedSource
10195
+ });
10196
+ queueMicrotask(() => void options.sourceScanSession.flushChangedFiles());
10197
+ } else await options.sourceScanSession.syncChangedFile(id, changedSource);
9854
10198
  }, { emit: false });
9855
10199
  },
9856
10200
  handleHotUpdate: {
@@ -9858,7 +10202,7 @@ function createFrameworkSourceCandidatesPlugin(options, apply) {
9858
10202
  async handler(ctx) {
9859
10203
  recordCompilationDependencyChanges(options.runtimeState, createCompilationDependencyChanges([path.resolve(cleanUrl$1(ctx.file))]));
9860
10204
  return options.hmrTimingRecorder.measure("sourceCandidates.handleHotUpdate", async () => {
9861
- const isSourceCandidateHotUpdate = options.shouldOwnTailwindGeneration && isSourceCandidateRequest(ctx.file);
10205
+ const isSourceCandidateHotUpdate = options.shouldOwnTailwindGeneration && options.collectSourceCandidates !== false && isSourceCandidateRequest(ctx.file);
9862
10206
  if (isSourceCandidateHotUpdate && isSourceStyleRequest(ctx.file)) {
9863
10207
  for (const mod of ctx.modules) for (const id of [
9864
10208
  mod.id,
@@ -9871,7 +10215,11 @@ function createFrameworkSourceCandidatesPlugin(options, apply) {
9871
10215
  options.rememberOriginalCssLayerSource(ctx.file, hotSource);
9872
10216
  await options.refreshTailwindRootCssSource(ctx.file, hotSource);
9873
10217
  }
9874
- const sourceCandidateChange = await options.sourceScanSession.syncChangedFile(ctx.file, hotSource);
10218
+ const sourceCandidateChange = typeof options.sourceScanSession.queueChangedFile === "function" ? (options.sourceScanSession.queueChangedFile({
10219
+ event: "update",
10220
+ id: ctx.file,
10221
+ source: hotSource
10222
+ }), await options.sourceScanSession.flushChangedFiles()).get(cleanUrl$1(ctx.file)) : await options.sourceScanSession.syncChangedFile(ctx.file, hotSource);
9875
10223
  options.sourceScanSession.consumeHotUpdateChange(ctx.file);
9876
10224
  const isWebLikeHotUpdate = options.isCurrentWebLikeStylePlatform();
9877
10225
  let canUseHmrCandidateAppend = false;
@@ -9892,8 +10240,9 @@ function createFrameworkSourceCandidatesPlugin(options, apply) {
9892
10240
  }
9893
10241
  if (isSourceCandidateHotUpdate) await options.sourceScanSession.waitForPendingSyncs();
9894
10242
  if (isSourceCandidateHotUpdate && !isSourceStyleRequest(ctx.file)) options.hmrCandidateState.reconcileRuntimeCandidates(ctx.file, options.sourceCandidateCollector.values(), options.tailwindRootCssModuleIds);
9895
- const cssModules = await resolveHotTailwindCssModules(ctx, isSourceStyleRequest(ctx.file) ? [ctx.file] : options.tailwindRootCssModuleIds);
10243
+ const hotTailwindCssModuleIds = isSourceStyleRequest(ctx.file) ? [ctx.file] : options.tailwindRootCssModuleIds;
9896
10244
  const hotRoot = ctx.server.config?.root ?? process$1.cwd();
10245
+ const cssModules = await resolveHotTailwindCssModules(ctx, hotTailwindCssModuleIds, options.hmrCssModuleVersions ? (modules) => options.hmrCssModuleVersions.filterModules(modules, ctx.timestamp, hotRoot) : void 0);
9897
10246
  const sourceModules = isSourceCandidateHotUpdate && !isSourceStyleRequest(ctx.file) ? await resolveHotSourceModules(ctx) : ctx.modules;
9898
10247
  if (isWebLikeHotUpdate && isSourceCandidateHotUpdate && !isSourceStyleRequest(ctx.file)) {
9899
10248
  if (!/\.(?:uvue|nvue)$/i.test(cleanUrl$1(ctx.file))) sendSupplementalSourceHotUpdates(ctx, sourceModules);
@@ -9920,14 +10269,18 @@ function createFrameworkSourceCandidatesPlugin(options, apply) {
9920
10269
  }
9921
10270
  const shouldSendSupplementalCssHotUpdates = !(isWebLikeHotUpdate && isSourceCandidateHotUpdate && !isSourceStyleRequest(ctx.file) && sourceCandidateChange !== void 0 && options.resolveCurrentGeneratorOptions().hmr.preserveDeletedCss && !sourceCandidateChange.runtimeAffecting && sourceCandidateChange.addedCandidates.size === 0 && sourceCandidateChange.removedCandidates.size > 0);
9922
10271
  const supplementalCssFallbackIds = /* @__PURE__ */ new Set([...options.tailwindRootCssModuleIds, ...options.viteProcessedCssSourceFiles]);
9923
- if (options.hmrCandidateState.hasPendingChange()) options.hmrCandidateState.armTargets(cssModules, supplementalCssFallbackIds);
9924
- if (shouldSendSupplementalCssHotUpdates) sendSupplementalCssHotUpdates(ctx, cssModules, supplementalCssFallbackIds);
10272
+ const currentSupplementalCssFallbackIds = options.hmrCssModuleVersions?.filterIds(supplementalCssFallbackIds, ctx.timestamp, hotRoot) ?? supplementalCssFallbackIds;
10273
+ if (options.hmrCandidateState.hasPendingChange()) options.hmrCandidateState.armTargets(cssModules, currentSupplementalCssFallbackIds);
10274
+ if (shouldSendSupplementalCssHotUpdates && cssModules.length === 0) sendSupplementalCssHotUpdates(ctx, [], currentSupplementalCssFallbackIds);
9925
10275
  if (isWebLikeHotUpdate && isSourceCandidateHotUpdate && !isSourceStyleRequest(ctx.file)) return cssModules.length > 0 ? mergeHotModulesByIdentity(hotRoot, sourceModules, cssModules) : hasDifferentHotModules(sourceModules, ctx.modules) ? sourceModules : void 0;
9926
10276
  if (isSourceCandidateHotUpdate && !isSourceStyleRequest(ctx.file) && cssModules.length > 0) return mergeHotModulesByIdentity(hotRoot, sourceModules, cssModules);
9927
10277
  return cssModules.length > 0 ? mergeHotModulesByIdentity(hotRoot, ctx.modules, cssModules) : void 0;
9928
10278
  }, { emit: false });
9929
10279
  }
9930
10280
  },
10281
+ closeBundle() {
10282
+ options.hmrCssModuleVersions?.clear();
10283
+ },
9931
10284
  async buildStart() {
9932
10285
  await options.hmrTimingRecorder.measure("sourceCandidates.buildStart", options.prepareTailwindGeneration, { emit: false });
9933
10286
  },
@@ -9970,6 +10323,11 @@ function createFrameworkSourceScanSession(options) {
9970
10323
  const pendingSourceCandidateSyncs = /* @__PURE__ */ new Set();
9971
10324
  const pendingSourceCandidateSyncByFile = /* @__PURE__ */ new Map();
9972
10325
  const pendingHotUpdateChangeByFile = /* @__PURE__ */ new Map();
10326
+ const pendingChangedFiles = /* @__PURE__ */ new Map();
10327
+ let pendingChangedFilesFlush;
10328
+ let isFlushingChangedFiles = false;
10329
+ let cacheDirty = false;
10330
+ let cachedCollectorRevision;
9973
10331
  const normalizeDependency = (file) => path.normalize(path.resolve(cleanUrl$1(file)));
9974
10332
  const isDependency = (file) => sourceScanDependencies.has(normalizeDependency(file));
9975
10333
  const invalidate = () => {
@@ -10005,12 +10363,20 @@ function createFrameworkSourceScanSession(options) {
10005
10363
  };
10006
10364
  const cacheCurrent = () => {
10007
10365
  if (!sourceCandidateScanSignature) return;
10366
+ if (isFlushingChangedFiles) {
10367
+ cacheDirty = true;
10368
+ return;
10369
+ }
10370
+ const collectorRevision = options.sourceCandidateCollector.getRevision?.();
10371
+ if (!cacheDirty && cachedCollectorRevision !== void 0 && collectorRevision === cachedCollectorRevision) return;
10008
10372
  const entry = {
10009
10373
  eligibleFiles: [...sourceScanEligibleFiles],
10010
10374
  snapshot: options.sourceCandidateCollector.snapshot()
10011
10375
  };
10012
10376
  sourceCandidateScanCache.set(sourceCandidateScanSignature, entry);
10013
10377
  sourceCandidateScanSnapshotCache.set(sourceCandidateScanSignature, entry);
10378
+ cachedCollectorRevision = collectorRevision;
10379
+ cacheDirty = false;
10014
10380
  };
10015
10381
  const updateSourceScanMatchers = (eligibleFiles) => {
10016
10382
  sourceScanEligibleFiles = new Set(eligibleFiles);
@@ -10096,7 +10462,12 @@ function createFrameworkSourceScanSession(options) {
10096
10462
  if (options.isWatchLikeBuild()) cacheCurrent();
10097
10463
  };
10098
10464
  const waitForPendingSyncs = async () => {
10099
- while (pendingSourceCandidateSyncs.size > 0) await Promise.all(pendingSourceCandidateSyncs);
10465
+ while (true) {
10466
+ if (!pendingChangedFilesFlush && pendingChangedFiles.size === 0 && pendingSourceCandidateSyncs.size === 0) break;
10467
+ await pendingChangedFilesFlush;
10468
+ if (pendingChangedFiles.size > 0) await flushChangedFiles();
10469
+ if (pendingSourceCandidateSyncs.size > 0) await Promise.all(pendingSourceCandidateSyncs);
10470
+ }
10100
10471
  };
10101
10472
  const rememberHotUpdateChange = (change) => {
10102
10473
  if (!change) return;
@@ -10118,7 +10489,7 @@ function createFrameworkSourceScanSession(options) {
10118
10489
  previous.runtimeAffecting || (previous.runtimeAffecting = change.runtimeAffecting);
10119
10490
  return previous;
10120
10491
  };
10121
- const syncChangedFile = async (id, sourceOverride) => {
10492
+ const syncChangedFileNow = async (id, sourceOverride, event = "update") => {
10122
10493
  if (!options.shouldOwnTailwindGeneration || !options.isCandidateRequest(id)) return;
10123
10494
  const file = cleanUrl$1(id);
10124
10495
  const runtimeAffectingByDependency = isDependency(file);
@@ -10141,10 +10512,17 @@ function createFrameworkSourceScanSession(options) {
10141
10512
  return syncChangedFile(id, sourceOverride);
10142
10513
  }
10143
10514
  const previousSource = options.sourceCandidateCollector.source(file);
10515
+ if (event === "delete") {
10516
+ const change = options.sourceCandidateCollector.remove(file);
10517
+ cacheDirty = true;
10518
+ const appliedChange = options.hmrCandidateState.apply(options.hmrCandidateState.createChange(file, change, { runtimeAffecting: runtimeAffectingByDependency }));
10519
+ return rememberHotUpdateChange(appliedChange);
10520
+ }
10144
10521
  const task = (sourceOverride === void 0 ? options.sourceCandidateCollector.syncCurrentFile(id) : options.sourceCandidateCollector.syncCurrentSource(id, sourceOverride)).catch((error) => {
10145
10522
  options.debug("source candidate watch sync failed: %s %O", id, error);
10146
10523
  }).then((change) => {
10147
- cacheCurrent();
10524
+ cacheDirty = true;
10525
+ if (!isFlushingChangedFiles) cacheCurrent();
10148
10526
  const runtimeAffectingBySource = hasFrameworkHmrRuntimeSourceChange(file, previousSource, options.sourceCandidateCollector.source(file));
10149
10527
  const appliedChange = change ? options.hmrCandidateState.apply(options.hmrCandidateState.createChange(file, change, { runtimeAffecting: runtimeAffectingByDependency || runtimeAffectingBySource })) : void 0;
10150
10528
  return rememberHotUpdateChange(appliedChange) ?? pendingHotUpdateChangeByFile.get(file);
@@ -10159,18 +10537,59 @@ function createFrameworkSourceScanSession(options) {
10159
10537
  return change;
10160
10538
  });
10161
10539
  };
10540
+ const queueChangedFile = (change) => {
10541
+ const file = cleanUrl$1(change.id);
10542
+ const previous = pendingChangedFiles.get(file);
10543
+ if (!previous) {
10544
+ pendingChangedFiles.set(file, {
10545
+ ...change,
10546
+ file
10547
+ });
10548
+ return;
10549
+ }
10550
+ previous.event = change.event;
10551
+ if (change.source !== void 0) previous.source = change.source;
10552
+ };
10553
+ const flushChangedFiles = async () => {
10554
+ if (pendingChangedFilesFlush) {
10555
+ const result = await pendingChangedFilesFlush;
10556
+ return pendingChangedFiles.size > 0 ? flushChangedFiles() : result;
10557
+ }
10558
+ if (pendingChangedFiles.size === 0) return /* @__PURE__ */ new Map();
10559
+ const changes = [...pendingChangedFiles.values()];
10560
+ pendingChangedFiles.clear();
10561
+ isFlushingChangedFiles = true;
10562
+ pendingChangedFilesFlush = Promise.all(changes.map(async (change) => [change.file, await syncChangedFileNow(change.file, change.source, change.event)])).then((entries) => new Map(entries)).finally(() => {
10563
+ isFlushingChangedFiles = false;
10564
+ pendingChangedFilesFlush = void 0;
10565
+ cacheCurrent();
10566
+ });
10567
+ return pendingChangedFilesFlush;
10568
+ };
10569
+ const syncChangedFile = async (id, sourceOverride) => {
10570
+ const file = cleanUrl$1(id);
10571
+ const existingTask = pendingSourceCandidateSyncByFile.get(file);
10572
+ if (existingTask) {
10573
+ await existingTask;
10574
+ return syncChangedFile(id, sourceOverride);
10575
+ }
10576
+ return syncChangedFileNow(file, sourceOverride);
10577
+ };
10162
10578
  return {
10163
10579
  cacheCurrent,
10164
10580
  consumeHotUpdateChange: (id) => pendingHotUpdateChangeByFile.delete(cleanUrl$1(id)),
10165
10581
  getStats: () => ({
10166
10582
  pendingSourceCandidateSyncByFile: pendingSourceCandidateSyncByFile.size,
10167
10583
  pendingSourceCandidateSyncs: pendingSourceCandidateSyncs.size,
10584
+ pendingChangedFiles: pendingChangedFiles.size,
10168
10585
  pendingHotUpdateChangeByFile: pendingHotUpdateChangeByFile.size,
10169
10586
  sourceCandidateScanCache: sourceCandidateScanCache.size
10170
10587
  }),
10171
10588
  invalidate,
10172
10589
  isDependency,
10173
10590
  matches: (file) => sourceScanMatcher?.(file) ?? true,
10591
+ queueChangedFile,
10592
+ flushChangedFiles,
10174
10593
  shouldDiscoverAutoCssSources,
10175
10594
  sync,
10176
10595
  syncChangedFile,
@@ -10223,29 +10642,9 @@ const ENV_PLATFORM_KEYS = [
10223
10642
  "MPX_CURRENT_TARGET_MODE",
10224
10643
  "MPX_CLI_MODE"
10225
10644
  ];
10226
- function collectConfiguredCssEntries(options) {
10227
- const runtimeCssEntries = options.tailwindcssRuntimeOptions?.tailwindcss?.v4?.cssEntries;
10228
- const entries = [
10229
- ...Array.isArray(options.cssEntries) ? options.cssEntries : [],
10230
- ...Array.isArray(options.tailwindcss?.v4?.cssEntries) ? options.tailwindcss.v4.cssEntries : [],
10231
- ...Array.isArray(runtimeCssEntries) ? runtimeCssEntries : []
10232
- ].filter((item) => typeof item === "string" && item.length > 0);
10233
- return entries.length > 0 ? [...new Set(entries)] : void 0;
10234
- }
10235
- function inferPlatformFromOutDir(outDir) {
10236
- const segment = outDir ? path.basename(path.normalize(outDir)) : void 0;
10237
- if (!segment) return;
10238
- const normalized = segment.trim().toLowerCase();
10239
- if (normalized === "h5" || normalized === "web" || normalized === "app" || normalized === "app-plus" || normalized.startsWith("app-") || normalized.startsWith("mp-") || normalized.startsWith("quickapp-webview")) return normalized;
10240
- }
10241
- function isWebOrNativeAppPlatform(platform) {
10242
- return platform === "h5" || platform === "web" || platform?.startsWith("web-") === true || platform === "app" || platform === "app-plus" || platform?.startsWith("app-") === true;
10243
- }
10244
- function isInternalUserDefinedOptions(options) {
10245
- return typeof options.onLoad === "function" && typeof options.mainCssChunkMatcher === "function" && typeof options.tailwindRuntime === "object" && typeof options.refreshTailwindcssRuntime === "function";
10246
- }
10247
10645
  function createViteFrameworkPlugins$1(options = {}, frameworkBranch) {
10248
10646
  debug("create vite framework plugins framework=%s", frameworkBranch.frameworkName);
10647
+ const capability = options.__internalViteCapabilityProfile ?? frameworkViteCapabilityProfile;
10249
10648
  const rawOptions = options.__internalViteRawOptions ?? options;
10250
10649
  const hasExplicitAppType = typeof options.__internalViteRawExplicitAppType === "boolean" ? options.__internalViteRawExplicitAppType : typeof options.appType === "string" && options.appType.trim().length > 0;
10251
10650
  const hasExplicitTailwindcssBasedir = typeof options.__internalViteRawExplicitTailwindcssBasedir === "boolean" ? options.__internalViteRawExplicitTailwindcssBasedir : typeof options.tailwindcssBasedir === "string" && options.tailwindcssBasedir.trim().length > 0;
@@ -10273,12 +10672,18 @@ function createViteFrameworkPlugins$1(options = {}, frameworkBranch) {
10273
10672
  const refreshTailwindRuntime = refreshTailwindcssRuntime;
10274
10673
  const frameworkCssPipelineStrategy = frameworkBranch.cssPipelineStrategy;
10275
10674
  const uniAppXEnabled = frameworkBranch.isRuntimeClassSetFeatureEnabled?.({ uniAppX }) === true;
10276
- const shouldEnableFrameworkExtraPlugins = () => frameworkBranch.createExtraPlugins !== void 0;
10675
+ const shouldEnableFrameworkExtraPlugins = () => capability.frameworkExtras && frameworkBranch.createExtraPlugins !== void 0;
10277
10676
  const disabledOptions = resolvePluginDisabledState(disabled);
10278
10677
  const tailwindcssMajorVersion = initialTailwindRuntime.majorVersion ?? 0;
10279
10678
  if (!disabledOptions.plugin && tailwindcssMajorVersion !== 4) throw new Error("weapp-tailwindcss/vite 新生成管线仅支持 Tailwind CSS v4,请升级 tailwindcss 或停留在旧版 weapp-tailwindcss。");
10280
10679
  const shouldRewriteCssImports = opts.rewriteCssImports === true;
10281
10680
  let resolvedConfig;
10681
+ const { observer: webCssEntryDiagnostics, plugin: webCssEntryObserverPlugin } = createConfiguredCssEntryDiagnostics({
10682
+ getEntries: () => opts.cssEntries,
10683
+ getRoot: () => resolvedConfig?.root,
10684
+ isWeb: () => resolveCurrentGeneratorBranch().isWeb
10685
+ });
10686
+ const hmrCssModuleVersions = createViteHmrCssModuleVersionTracker();
10282
10687
  const resolveViteStylePlatform = () => {
10283
10688
  const explicit = normalizeFrameworkStylePlatform(opts.cssOptions?.platform ?? opts.platform, opts.appType);
10284
10689
  if (explicit) return explicit;
@@ -10477,13 +10882,6 @@ function createViteFrameworkPlugins$1(options = {}, frameworkBranch) {
10477
10882
  const platform = resolveViteStylePlatform();
10478
10883
  return platform ? isWebOrNativeAppPlatform(platform) : resolveCurrentGeneratorBranch().isWeb;
10479
10884
  };
10480
- const isNuxtPageHotModule = (id) => {
10481
- if (typeof id !== "string") return false;
10482
- const cleanId = cleanUrl$1(id).replace(/%2F/gi, "/");
10483
- if (cleanId.includes("virtual:nuxt:") && /(?:^|\/)routes\.mjs$/.test(cleanId)) return true;
10484
- if (!/[?&]macro=true(?:&|$)/.test(id)) return false;
10485
- return cleanId.includes("/pages/") && /\.(?:vue|tsx?|jsx?)$/.test(cleanId);
10486
- };
10487
10885
  const normalizeGeneratedCssCacheFile = (file) => normalizeVitePersistentCacheKey(cleanUrl$1(file));
10488
10886
  const hmrCandidateState = createViteHmrCandidateState({
10489
10887
  cleanGeneratedCssByFile,
@@ -10574,7 +10972,7 @@ function createViteFrameworkPlugins$1(options = {}, frameworkBranch) {
10574
10972
  platform
10575
10973
  });
10576
10974
  };
10577
- const generateTailwindCssForVitePipeline = async (id, code, hookContext) => {
10975
+ const generateTailwindCssForVitePipelineNow = async (id, code, hookContext) => {
10578
10976
  if (!shouldOwnTailwindGeneration) return;
10579
10977
  await runtimeState.readyPromise;
10580
10978
  await sourceScanSession.waitForPendingSyncs();
@@ -10599,7 +10997,13 @@ function createViteFrameworkPlugins$1(options = {}, frameworkBranch) {
10599
10997
  const transient = hookContext?.transient === true;
10600
10998
  const pendingHmrChange = transient ? void 0 : hmrCandidateState.resolve(generatorCode, file);
10601
10999
  const forceFullHmrCssRegeneration = hmrCandidateState.shouldForceFullRegeneration(file, pendingHmrChange !== void 0);
10602
- const runtime = hookContext?.sourceCandidates === void 0 ? fullRuntime : new Set(hookContext.sourceCandidates);
11000
+ const runtime = hookContext?.sourceCandidates === void 0 ? new Set(fullRuntime) : new Set(hookContext.sourceCandidates);
11001
+ if (pendingHmrChange) for (const candidate of pendingHmrChange.addedCandidates) runtime.add(candidate);
11002
+ const getGenerationSourceCandidatesForEntries = pendingHmrChange ? (entries, options2) => {
11003
+ const candidates = new Set(getSourceCandidatesForEntries(entries, options2));
11004
+ for (const candidate of pendingHmrChange.addedCandidates) candidates.add(candidate);
11005
+ return candidates;
11006
+ } : getSourceCandidatesForEntries;
10603
11007
  const importShellCss = resolveViteServeRootMiniProgramImportShell({
10604
11008
  css: generatorTransformCode,
10605
11009
  cssPipelineContext,
@@ -10665,7 +11069,7 @@ ${previousTracedCss}`;
10665
11069
  cssHandlerOptions,
10666
11070
  cssUserHandlerOptions: transformCssHandlerOptions.getCssUserHandlerOptions(requestFile),
10667
11071
  cssSources: transientCssSource ? [transientCssSource] : void 0,
10668
- getSourceCandidatesForEntries,
11072
+ getSourceCandidatesForEntries: getGenerationSourceCandidatesForEntries,
10669
11073
  generatorPlatform: resolveGeneratorPlatform(),
10670
11074
  styleHandler,
10671
11075
  debug,
@@ -10740,6 +11144,7 @@ ${previousTracedCss}`;
10740
11144
  return `${createBundlerGeneratedCssMarker("vite", normalizeViteProcessedCssFile(file))}
10741
11145
  ${tracedCss}`;
10742
11146
  };
11147
+ const generateTailwindCssForVitePipeline = createFrameworkCssGenerationQueue(normalizeGeneratedCssCacheFile, generateTailwindCssForVitePipelineNow);
10743
11148
  const shouldDeferFrameworkPreTransformGeneration = (id, code) => frameworkCssPipelineStrategy?.shouldDeferPreTransformTailwindGeneration?.({
10744
11149
  ...createCssPipelineContext(),
10745
11150
  code,
@@ -10862,12 +11267,13 @@ ${tracedCss}`;
10862
11267
  if (sourceScanSession.shouldDiscoverAutoCssSources(autoCssSourcesDiscovered)) await discoverAndRegisterAutoCssSources();
10863
11268
  await sourceScanSession.sync();
10864
11269
  };
10865
- const extraPlugins = frameworkBranch.createExtraPlugins?.({
11270
+ const extraPlugins = capability.frameworkExtras ? frameworkBranch.createExtraPlugins?.({
10866
11271
  customAttributesEntities,
10867
11272
  disabledDefaultTemplateHandler,
10868
11273
  ensureRuntimeClassSet,
10869
11274
  generateCss: generateTailwindCssForVitePipeline,
10870
11275
  getResolvedConfig,
11276
+ hmrCssModuleVersions,
10871
11277
  isEnabled: shouldEnableFrameworkExtraPlugins,
10872
11278
  isIosPlatform: extraPluginPlatform.isIosPlatform === true,
10873
11279
  isNativeAppStyleTarget: () => frameworkCssPipelineStrategy?.isNativeAppStyleTarget?.(createCssPipelineContext()) === true,
@@ -10880,8 +11286,9 @@ ${tracedCss}`;
10880
11286
  syncSourceCandidatesForHotUpdate,
10881
11287
  tailwindRootCssModuleIds,
10882
11288
  uniAppX,
10883
- viteProcessedCssSourceFiles: processedCssRegistry.sourceFiles
10884
- }) ?? [];
11289
+ viteProcessedCssSourceFiles: processedCssRegistry.sourceFiles,
11290
+ webCssEntryDiagnostics
11291
+ }) ?? [] : [];
10885
11292
  const installFrameworkWatchCssCacheAdapter = async (config) => {
10886
11293
  if (!shouldAdaptFrameworkWatchCss()) return;
10887
11294
  if (wrapViteCssPostTransform(config, async (css, id) => {
@@ -10901,6 +11308,7 @@ ${tracedCss}`;
10901
11308
  cssMemory,
10902
11309
  hasUserCssLayerBlocks,
10903
11310
  hmrCandidateState,
11311
+ hmrCssModuleVersions,
10904
11312
  hmrTimingRecorder,
10905
11313
  invalidateRecordedGeneratorCandidates,
10906
11314
  isCurrentWebLikeStylePlatform,
@@ -10922,7 +11330,8 @@ ${tracedCss}`;
10922
11330
  sourceScanSession,
10923
11331
  tailwindRootCssModuleIds,
10924
11332
  transformEarlyMiniProgramCss,
10925
- viteProcessedCssSourceFiles: processedCssRegistry.sourceFiles
11333
+ viteProcessedCssSourceFiles: processedCssRegistry.sourceFiles,
11334
+ collectSourceCandidates: capability.sourceCandidates
10926
11335
  }, createGenericWebProductionSourceCandidatesApply({
10927
11336
  frameworkName: frameworkBranch.frameworkName,
10928
11337
  getIsWebGeneratorTarget: () => resolveCurrentGeneratorBranch().isWeb,
@@ -10940,8 +11349,11 @@ ${tracedCss}`;
10940
11349
  generateBundleHook,
10941
11350
  generatorPlaceholderCssFile,
10942
11351
  hasExplicitTailwindcssBasedir,
11352
+ hasExplicitGeneratorTarget: typeof options.__internalViteRawExplicitGeneratorTarget === "boolean" ? options.__internalViteRawExplicitGeneratorTarget : false,
11353
+ frameworkName: frameworkBranch.frameworkName,
10943
11354
  hmrTimingRecorder,
10944
11355
  opts,
11356
+ resolveViteStylePlatform,
10945
11357
  refreshRuntimeState,
10946
11358
  setResolvedConfig: (config) => {
10947
11359
  resolvedConfig = config;
@@ -10950,8 +11362,20 @@ ${tracedCss}`;
10950
11362
  shouldOwnTailwindGeneration,
10951
11363
  syncCssEntriesFromAnchor
10952
11364
  });
11365
+ const sourceAndRewritePlugins = orderFrameworkSourceCandidatePlugins(extraPlugins, rewritePlugins, sourceCandidatesPlugin, frameworkBranch.sourceCandidatesBeforeExtraPlugin);
11366
+ const serveJsPlugin = capability.serveJsTransform ? createViteServeJsTransformPlugin({
11367
+ createHandlerOptions: (file) => serveJsHandlerOptions(file, frameworkCssPipelineStrategy?.getServeJsHandlerOptions?.({
11368
+ ...createCssPipelineContext(),
11369
+ file
11370
+ })),
11371
+ getCommand: () => resolvedConfig?.command,
11372
+ jsHandler,
11373
+ shouldTransform: () => shouldOwnTailwindGeneration && (frameworkCssPipelineStrategy?.shouldTransformServeJs?.(createCssPipelineContext()) ?? !resolveCurrentGeneratorBranch().isWeb),
11374
+ transformRuntime: ensureRuntimeClassSet
11375
+ }) : void 0;
10953
11376
  const plugins = [
10954
- ...orderFrameworkSourceCandidatePlugins(extraPlugins, rewritePlugins, sourceCandidatesPlugin, frameworkBranch.sourceCandidatesBeforeExtraPlugin),
11377
+ ...sourceAndRewritePlugins,
11378
+ webCssEntryObserverPlugin,
10955
11379
  ...createViteCssGenerationPlugins({
10956
11380
  generateCss: generateTailwindCssForVitePipeline,
10957
11381
  getCommand: () => resolvedConfig?.command,
@@ -10960,16 +11384,7 @@ ${tracedCss}`;
10960
11384
  shouldGenerate: () => shouldOwnTailwindGeneration,
10961
11385
  shouldGenerateBuild: () => resolveCurrentGeneratorBranch().isWeb
10962
11386
  }),
10963
- createViteServeJsTransformPlugin({
10964
- createHandlerOptions: (file) => serveJsHandlerOptions(file, frameworkCssPipelineStrategy?.getServeJsHandlerOptions?.({
10965
- ...createCssPipelineContext(),
10966
- file
10967
- })),
10968
- getCommand: () => resolvedConfig?.command,
10969
- jsHandler,
10970
- shouldTransform: () => shouldOwnTailwindGeneration && (frameworkCssPipelineStrategy?.shouldTransformServeJs?.(createCssPipelineContext()) ?? !resolveCurrentGeneratorBranch().isWeb),
10971
- transformRuntime: ensureRuntimeClassSet
10972
- }),
11387
+ ...serveJsPlugin ? [serveJsPlugin] : [],
10973
11388
  {
10974
11389
  name: `${vitePluginName}:watch-css-cache`,
10975
11390
  configResolved: {
@@ -10980,7 +11395,8 @@ ${tracedCss}`;
10980
11395
  postPlugin
10981
11396
  ];
10982
11397
  plugins.push(cssFinalizerOutputPlugin);
10983
- plugins.push(...createBuiltinViteStyleInjectorPlugins(styleInjector, () => frameworkBranch.styleInjectorDelegate));
11398
+ plugins.push(createViteHmrCssModuleVersionFilterPlugin(hmrCssModuleVersions));
11399
+ if (capability.styleInjector) plugins.push(...createBuiltinViteStyleInjectorPlugins(styleInjector, () => frameworkBranch.styleInjectorDelegate));
10984
11400
  return plugins;
10985
11401
  }
10986
11402
  //#endregion
@@ -11294,6 +11710,7 @@ function createUniAppXVitePlugins(options = {}) {
11294
11710
  ensureRuntimeClassSet: context.ensureRuntimeClassSet,
11295
11711
  generateCss: context.generateCss,
11296
11712
  getResolvedConfig: context.getResolvedConfig,
11713
+ hmrCssModuleVersions: context.hmrCssModuleVersions,
11297
11714
  isEnabled: context.isEnabled,
11298
11715
  isIosPlatform: context.isIosPlatform,
11299
11716
  isNativeAppStyleTarget: context.isNativeAppStyleTarget,
@@ -11306,7 +11723,8 @@ function createUniAppXVitePlugins(options = {}) {
11306
11723
  syncSourceCandidatesForHotUpdate: context.syncSourceCandidatesForHotUpdate,
11307
11724
  tailwindRootCssModuleIds: context.tailwindRootCssModuleIds,
11308
11725
  uniAppX: context.uniAppX,
11309
- viteProcessedCssSourceFiles: context.viteProcessedCssSourceFiles
11726
+ viteProcessedCssSourceFiles: context.viteProcessedCssSourceFiles,
11727
+ webCssEntryDiagnostics: context.webCssEntryDiagnostics
11310
11728
  })
11311
11729
  });
11312
11730
  }
@@ -11320,34 +11738,225 @@ function createWeappVitePlugins(options = {}) {
11320
11738
  }
11321
11739
  //#endregion
11322
11740
  //#region src/bundlers/vite/index.ts
11323
- /**
11324
- * @name WeappTailwindcss
11325
- * @description Vite 入口只负责早期识别框架分支,具体插件组合由各 framework 目录拥有。
11326
- * @link https://tw.icebreaker.top/docs/quick-start/frameworks/uni-app-vite
11327
- */
11328
- function WeappTailwindcss(options = {}) {
11329
- const hasExplicitAppType = typeof options.appType === "string" && options.appType.trim().length > 0;
11330
- const hasExplicitTailwindcssBasedir = typeof options.tailwindcssBasedir === "string" && options.tailwindcssBasedir.trim().length > 0;
11741
+ const hookNames = [
11742
+ "config",
11743
+ "configResolved",
11744
+ "buildStart",
11745
+ "buildEnd",
11746
+ "resolveId",
11747
+ "load",
11748
+ "transform",
11749
+ "configureServer",
11750
+ "handleHotUpdate",
11751
+ "watchChange",
11752
+ "generateBundle",
11753
+ "writeBundle",
11754
+ "closeBundle"
11755
+ ];
11756
+ function platformFamily(platform) {
11757
+ const value = platform?.trim().toLowerCase();
11758
+ if (!value) return "unknown";
11759
+ if (value === "h5" || value === "web" || value.startsWith("web-")) return "web";
11760
+ if (value === "app" || value === "app-plus" || value.startsWith("app-")) return "native-app";
11761
+ if (value.startsWith("mp-") || [
11762
+ "weapp",
11763
+ "wechat",
11764
+ "wx",
11765
+ "alipay",
11766
+ "tt",
11767
+ "baidu",
11768
+ "qq",
11769
+ "jd",
11770
+ "swan"
11771
+ ].includes(value)) return "mini-program";
11772
+ return "unknown";
11773
+ }
11774
+ function resolveEnvironmentName(context) {
11775
+ const name = context?.environment?.name;
11776
+ return typeof name === "string" && name.length > 0 ? name : "default";
11777
+ }
11778
+ function resolveViteProfile(options, config, environmentName) {
11779
+ const rawTarget = options.generator && typeof options.generator === "object" ? options.generator.target : void 0;
11780
+ const explicitPlatform = options.cssOptions?.platform ?? options.platform;
11781
+ const envPlatform = process$1.env["UNI_PLATFORM"] ?? process$1.env["UNI_UTS_PLATFORM"];
11782
+ const selectedPlatform = explicitPlatform ?? envPlatform;
11783
+ const explicitAppType = options.appType;
11784
+ const root = config.root ? path.resolve(config.root) : process$1.cwd();
11785
+ let frameworkName = "generic";
11786
+ let appType = explicitAppType;
11787
+ if (explicitAppType) frameworkName = resolveViteFrameworkProfile({
11788
+ appType: explicitAppType,
11789
+ uniAppX: options.uniAppX
11790
+ }).frameworkName;
11791
+ else {
11792
+ const detected = resolveViteFrameworkProfile({
11793
+ detectEnv: true,
11794
+ env: process$1.env,
11795
+ root,
11796
+ searchUp: false,
11797
+ uniAppX: options.uniAppX
11798
+ });
11799
+ frameworkName = detected.frameworkName;
11800
+ appType = detected.appType;
11801
+ if (frameworkName === "generic" && platformFamily(selectedPlatform) !== "web") {
11802
+ appType = resolveImplicitAppTypeFromViteRoot(root, { searchUp: false });
11803
+ frameworkName = resolveViteFrameworkProfile({
11804
+ appType,
11805
+ uniAppX: options.uniAppX
11806
+ }).frameworkName;
11807
+ }
11808
+ }
11809
+ const family = platformFamily(selectedPlatform ?? (config.build?.outDir ? path.basename(path.normalize(config.build.outDir)) : void 0));
11810
+ if (!explicitAppType && !(rawTarget !== "web" && family !== "web")) appType = void 0;
11811
+ const isGenericWeb = frameworkName === "generic" && !explicitAppType && rawTarget !== "weapp" && rawTarget !== "app" && !(Array.isArray(options.cssEntries) && options.cssEntries.length > 0) && family !== "mini-program";
11812
+ const capability = isGenericWeb ? {
11813
+ ...createGenericWebViteCapabilityProfile(options),
11814
+ sourceCandidates: options.generator && typeof options.generator === "object" && options.generator.target === "web" ? true : createGenericWebViteCapabilityProfile(options).sourceCandidates
11815
+ } : {
11816
+ ...frameworkViteCapabilityProfile,
11817
+ frameworkName,
11818
+ generatorTarget: rawTarget,
11819
+ platformFamily: family
11820
+ };
11821
+ capability.command = config.command;
11822
+ capability.watch = config.build?.watch != null;
11823
+ capability.ssr = Boolean(config.build?.ssr);
11824
+ capability.environmentName = environmentName;
11825
+ return {
11826
+ frameworkName,
11827
+ appType,
11828
+ capability,
11829
+ isGenericWeb
11830
+ };
11831
+ }
11832
+ function invokeHook(plugin, hookName, thisArg, args) {
11833
+ const hook = plugin?.[hookName];
11834
+ if (typeof hook === "function") return hook.apply(thisArg, args);
11835
+ if (hook && typeof hook === "object" && "handler" in hook && typeof hook.handler === "function") return hook.handler.apply(thisArg, args);
11836
+ }
11837
+ function createDispatcher(options) {
11331
11838
  const opts = getCompilerContext({
11332
11839
  ...options,
11333
11840
  __internalDeferMissingCssEntriesWarning: true
11334
11841
  });
11335
11842
  opts.__internalViteRawOptions = options;
11336
- opts.__internalViteRawExplicitAppType = hasExplicitAppType;
11337
- opts.__internalViteRawExplicitTailwindcssBasedir = hasExplicitTailwindcssBasedir;
11338
- switch (resolveViteFrameworkProfile({
11843
+ opts.__internalViteRawExplicitAppType = typeof options.appType === "string" && options.appType.trim().length > 0;
11844
+ opts.__internalViteRawExplicitTailwindcssBasedir = typeof options.tailwindcssBasedir === "string" && options.tailwindcssBasedir.trim().length > 0;
11845
+ opts.__internalViteRawExplicitGeneratorTarget = Boolean(options.generator && typeof options.generator === "object" && Object.hasOwn(options.generator, "target"));
11846
+ const initialProfile = resolveViteFrameworkProfile({
11339
11847
  appType: opts.appType,
11340
11848
  detectEnv: true,
11341
11849
  env: process$1.env,
11342
- root: opts.tailwindcssBasedir ?? process$1.cwd(),
11850
+ root: typeof options.tailwindcssBasedir === "string" && options.tailwindcssBasedir.trim().length > 0 ? path.resolve(options.tailwindcssBasedir) : void 0,
11851
+ searchUp: false,
11343
11852
  uniAppX: opts.uniAppX
11344
- }).frameworkName) {
11345
- case "taro": return createTaroVitePlugins(opts);
11346
- case "uni-app": return createUniAppVitePlugins(opts);
11347
- case "uni-app-x": return createUniAppXVitePlugins(opts);
11348
- case "weapp-vite": return createWeappVitePlugins(opts);
11349
- default: return createGenericVitePlugins(opts);
11350
- }
11853
+ });
11854
+ const initialFramework = initialProfile.frameworkName;
11855
+ opts.__internalViteCapabilityProfile = { ...frameworkViteCapabilityProfile };
11856
+ const initialFactory = {
11857
+ "generic": createGenericVitePlugins,
11858
+ "taro": createTaroVitePlugins,
11859
+ "uni-app": createUniAppVitePlugins,
11860
+ "uni-app-x": createUniAppXVitePlugins,
11861
+ "weapp-vite": createWeappVitePlugins
11862
+ }[initialFramework];
11863
+ const initialPlugins = initialFactory(opts);
11864
+ if (!initialPlugins) return;
11865
+ if (opts.__internalViteRawExplicitTailwindcssBasedir && initialFramework !== "generic") return initialPlugins;
11866
+ const knownFrameworkPlugins = [
11867
+ {
11868
+ name: "weapp-tailwindcss:taro-alipay-browserslist-asset",
11869
+ enforce: "pre",
11870
+ generateBundle() {}
11871
+ },
11872
+ {
11873
+ name: "weapp-tailwindcss:uni-app-x:css:pre",
11874
+ enforce: "pre",
11875
+ transform() {}
11876
+ },
11877
+ {
11878
+ name: "weapp-tailwindcss:uni-app-x:css",
11879
+ transform() {}
11880
+ },
11881
+ {
11882
+ name: "weapp-tailwindcss:uni-app-x:nvue",
11883
+ enforce: "pre",
11884
+ buildStart() {},
11885
+ transform: {
11886
+ order: "pre",
11887
+ handler() {}
11888
+ },
11889
+ handleHotUpdate: {
11890
+ order: "post",
11891
+ handler() {}
11892
+ },
11893
+ watchChange() {}
11894
+ },
11895
+ {
11896
+ name: "weapp-tailwindcss:uni-app-x:style-placeholder",
11897
+ enforce: "post",
11898
+ generateBundle: {
11899
+ order: "post",
11900
+ handler() {}
11901
+ }
11902
+ }
11903
+ ];
11904
+ const initialNames = new Set(initialPlugins.map((plugin) => plugin.name));
11905
+ const pluginTemplates = [...initialPlugins, ...initialFramework === "generic" && !opts.appType && initialPlugins.length > 1 ? knownFrameworkPlugins.filter((plugin) => !initialNames.has(plugin.name)) : []];
11906
+ let activePlugins = initialPlugins;
11907
+ let resolved = false;
11908
+ const ensureBranch = (config, context) => {
11909
+ if (resolved) return;
11910
+ resolved = true;
11911
+ const environmentName = resolveEnvironmentName(context);
11912
+ const effectiveGenerator = options.generator ?? opts.generator;
11913
+ const effectiveAppType = options.appType ?? (effectiveGenerator && typeof effectiveGenerator === "object" && effectiveGenerator.target === "web" ? void 0 : opts.appType);
11914
+ const profile = resolveViteProfile({
11915
+ ...options,
11916
+ appType: effectiveAppType,
11917
+ generator: effectiveGenerator,
11918
+ platform: options.platform ?? opts.platform,
11919
+ cssOptions: options.cssOptions ?? opts.cssOptions,
11920
+ uniAppX: options.uniAppX ?? opts.uniAppX
11921
+ }, config, environmentName);
11922
+ if (profile.appType && profile.appType !== initialProfile.appType && !options.appType && effectiveAppType === void 0) {
11923
+ opts.appType = profile.appType;
11924
+ logger.info("根据 Vite 项目根目录自动推断 appType -> %s", profile.appType);
11925
+ }
11926
+ if (profile.isGenericWeb && !opts.generator && opts.generator !== false && !options.platform && !options.cssOptions?.platform && !process$1.env["UNI_PLATFORM"] && !process$1.env["UNI_UTS_PLATFORM"]) opts.generator = { target: "web" };
11927
+ const capability = opts.__internalViteCapabilityProfile;
11928
+ if (capability) Object.assign(capability, profile.capability);
11929
+ else opts.__internalViteCapabilityProfile = profile.capability;
11930
+ const factory = {
11931
+ "generic": createGenericVitePlugins,
11932
+ "taro": createTaroVitePlugins,
11933
+ "uni-app": createUniAppVitePlugins,
11934
+ "uni-app-x": createUniAppXVitePlugins,
11935
+ "weapp-vite": createWeappVitePlugins
11936
+ }[profile.frameworkName];
11937
+ if (profile.frameworkName !== initialFramework) activePlugins = factory(opts) ?? [];
11938
+ };
11939
+ const byName = (name) => activePlugins.find((plugin) => plugin.name === name);
11940
+ return pluginTemplates.map((template) => {
11941
+ const proxy = { ...template };
11942
+ for (const hookName of hookNames) {
11943
+ if (!(hookName in template)) continue;
11944
+ const originalHook = template[hookName];
11945
+ const handler = function(...args) {
11946
+ if (hookName === "configResolved") ensureBranch(args[0], this);
11947
+ return invokeHook(byName(template.name), hookName, this, args);
11948
+ };
11949
+ proxy[hookName] = originalHook && typeof originalHook === "object" ? {
11950
+ ...originalHook,
11951
+ handler
11952
+ } : handler;
11953
+ }
11954
+ return proxy;
11955
+ });
11956
+ }
11957
+ /** Vite 单一入口。框架分支在 Vite 完成配置解析后选择,保持原有导入和注册方式。 */
11958
+ function WeappTailwindcss(options = {}) {
11959
+ return createDispatcher(options);
11351
11960
  }
11352
11961
  //#endregion
11353
11962
  export { WeappTailwindcss as t };