weapp-tailwindcss 5.0.12 → 5.1.0

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 (205) hide show
  1. package/README.en.md +1 -1
  2. package/README.md +1 -1
  3. package/dist/auto-Ba6hDrse.mjs +13 -0
  4. package/dist/auto-DtU6f3X6.js +18 -0
  5. package/dist/bundlers/shared/css-cleanup.d.ts +1 -1
  6. package/dist/bundlers/shared/generator-css/directives.d.ts +2 -1
  7. package/dist/bundlers/shared/generator-css/generation-helpers.d.ts +27 -10
  8. package/dist/bundlers/shared/generator-css/local-imports.d.ts +3 -0
  9. package/dist/bundlers/shared/generator-css/source-files.d.ts +1 -0
  10. package/dist/bundlers/shared/generator-css/source-resolver/apply-reference.d.ts +6 -0
  11. package/dist/bundlers/shared/generator-css/source-resolver/config.d.ts +7 -0
  12. package/dist/bundlers/shared/generator-css/source-resolver/matching.d.ts +3 -0
  13. package/dist/bundlers/shared/generator-css/source-resolver/metadata.d.ts +15 -0
  14. package/dist/bundlers/shared/generator-css/source-resolver/postcss-source.d.ts +12 -0
  15. package/dist/bundlers/shared/generator-css/source-resolver/types.d.ts +22 -0
  16. package/dist/bundlers/shared/generator-css/source-resolver.d.ts +6 -23
  17. package/dist/bundlers/shared/generator-css/types.d.ts +15 -1
  18. package/dist/bundlers/shared/generator-css/user-css.d.ts +5 -1
  19. package/dist/bundlers/shared/generator-css/validate.d.ts +1 -0
  20. package/dist/bundlers/shared/run-tasks.d.ts +1 -0
  21. package/dist/bundlers/shared/v4-generation-core.d.ts +11 -0
  22. package/dist/bundlers/vite/css-finalizer.d.ts +1 -1
  23. package/dist/bundlers/vite/css-memory.d.ts +37 -0
  24. package/dist/bundlers/vite/generate-bundle/bundle-file-names.d.ts +2 -0
  25. package/dist/bundlers/vite/generate-bundle/candidates.d.ts +0 -1
  26. package/dist/bundlers/vite/generate-bundle/configured-css-sources.d.ts +8 -0
  27. package/dist/bundlers/vite/generate-bundle/css-assets.d.ts +4 -0
  28. package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +5 -0
  29. package/dist/bundlers/vite/generate-bundle/css-output.d.ts +9 -7
  30. package/dist/bundlers/vite/generate-bundle/env-flags.d.ts +6 -0
  31. package/dist/bundlers/vite/generate-bundle/final-css-assets.d.ts +12 -0
  32. package/dist/bundlers/vite/generate-bundle/finalize.d.ts +63 -0
  33. package/dist/bundlers/vite/generate-bundle/js-processing.d.ts +31 -0
  34. package/dist/bundlers/vite/generate-bundle/memory-debug.d.ts +80 -0
  35. package/dist/bundlers/vite/generate-bundle/remembered-css-replay.d.ts +53 -0
  36. package/dist/bundlers/vite/generate-bundle/remembered-css.d.ts +1 -1
  37. package/dist/bundlers/vite/generate-bundle/runtime-linked-css.d.ts +4 -0
  38. package/dist/bundlers/vite/generate-bundle/scoped-generator.d.ts +21 -0
  39. package/dist/bundlers/vite/generate-bundle/sfc-style-source.d.ts +5 -2
  40. package/dist/bundlers/vite/generate-bundle/source-candidate-scope.d.ts +30 -0
  41. package/dist/bundlers/vite/generate-bundle/timing.d.ts +1 -0
  42. package/dist/bundlers/vite/generate-bundle/types.d.ts +3 -1
  43. package/dist/bundlers/vite/generate-bundle/uni-app-x-postprocess.d.ts +20 -0
  44. package/dist/bundlers/vite/generate-bundle/vite-css-cache.d.ts +6 -0
  45. package/dist/bundlers/vite/generate-bundle.d.ts +4 -1
  46. package/dist/bundlers/vite/hot-css-modules.d.ts +5 -0
  47. package/dist/bundlers/vite/incremental-runtime-class-set/escaped-candidates.d.ts +1 -0
  48. package/dist/bundlers/vite/incremental-runtime-class-set.d.ts +3 -3
  49. package/dist/bundlers/vite/map-cache.d.ts +2 -0
  50. package/dist/bundlers/vite/processed-css-assets.d.ts +16 -0
  51. package/dist/bundlers/vite/resolve-app-type.d.ts +1 -2
  52. package/dist/bundlers/vite/rewrite-css-imports.d.ts +1 -0
  53. package/dist/bundlers/vite/runtime-class-set.d.ts +5 -5
  54. package/dist/bundlers/vite/source-candidate-scan-signature.d.ts +13 -0
  55. package/dist/bundlers/vite/source-candidates/script.d.ts +1 -7
  56. package/dist/bundlers/vite/source-candidates.d.ts +12 -2
  57. package/dist/bundlers/vite/source-scan/css-entries.d.ts +3 -6
  58. package/dist/bundlers/vite/source-scan.d.ts +3 -3
  59. package/dist/bundlers/vite/uni-app-x-css-options.d.ts +1 -1
  60. package/dist/bundlers/vite/utils.d.ts +1 -0
  61. package/dist/bundlers/vite/weapp-vite-config.d.ts +3 -1
  62. package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +24 -0
  63. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/helpers.d.ts +48 -10
  64. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets/source-candidate-cache.d.ts +28 -0
  65. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +5 -1
  66. package/dist/bundlers/webpack/loaders/runtime-registry.d.ts +15 -1
  67. package/dist/bundlers/webpack/shared/css-loader-runtime.d.ts +1 -0
  68. package/dist/cache/index.d.ts +1 -0
  69. package/dist/cli/mount-options.d.ts +2 -2
  70. package/dist/cli.js +126 -439
  71. package/dist/cli.mjs +121 -434
  72. package/dist/context/index.d.ts +3 -3
  73. package/dist/context/style-options.d.ts +4 -1
  74. package/dist/context/tailwindcss.d.ts +1 -1
  75. package/dist/{precheck-30zNPRlI.js → context-BHxLe743.js} +484 -175
  76. package/dist/{precheck-CsFr1q2l.mjs → context-Mbzkek1q.mjs} +461 -159
  77. package/dist/core.js +15 -12
  78. package/dist/core.mjs +10 -7
  79. package/dist/css-macro.js +2 -2
  80. package/dist/css-macro.mjs +2 -2
  81. package/dist/{defaults-Boc26eel.js → defaults-CVcKbXBG.js} +6 -50
  82. package/dist/{defaults-DH0ZQRhy.mjs → defaults-ZElj1zKc.mjs} +7 -45
  83. package/dist/defaults.d.ts +1 -7
  84. package/dist/defaults.js +1 -2
  85. package/dist/defaults.mjs +2 -2
  86. package/dist/framework/index.d.ts +59 -0
  87. package/dist/framework.d.ts +1 -0
  88. package/dist/framework.js +198 -0
  89. package/dist/framework.mjs +180 -0
  90. package/dist/generator/index.d.ts +6 -7
  91. package/dist/generator/options.d.ts +3 -3
  92. package/dist/generator/types.d.ts +9 -10
  93. package/dist/generator-9rUz4Hcb.js +170 -0
  94. package/dist/generator-Dc4qaPmT.mjs +123 -0
  95. package/dist/generator.js +10 -16
  96. package/dist/generator.mjs +3 -3
  97. package/dist/{gulp-CxGZU0-v.js → gulp-B_sdP6dx.js} +80 -92
  98. package/dist/{gulp-BfZpaYSQ.mjs → gulp-uM36oIJs.mjs} +73 -85
  99. package/dist/gulp.js +1 -1
  100. package/dist/gulp.mjs +1 -1
  101. package/dist/{hmr-timing-DNjF8bWA.mjs → hmr-timing-BXMLsF4b.mjs} +1289 -909
  102. package/dist/{hmr-timing-DFR51wgo.js → hmr-timing-CogqkFaF.js} +1397 -939
  103. package/dist/index.d.ts +1 -0
  104. package/dist/index.js +20 -4
  105. package/dist/index.mjs +6 -5
  106. package/dist/js/fast-path/oxc.d.ts +4 -0
  107. package/dist/js/precheck.d.ts +1 -0
  108. package/dist/postcss.js +3 -4
  109. package/dist/postcss.mjs +2 -3
  110. package/dist/presets.js +10 -20
  111. package/dist/presets.mjs +9 -19
  112. package/dist/runtime-branch/create-branch.d.ts +2 -0
  113. package/dist/runtime-branch/generator-target-env.d.ts +4 -0
  114. package/dist/runtime-branch/index.d.ts +6 -0
  115. package/dist/runtime-branch/mini-program.d.ts +2 -0
  116. package/dist/runtime-branch/native-app.d.ts +2 -0
  117. package/dist/runtime-branch/platform.d.ts +6 -0
  118. package/dist/runtime-branch/tailwind-version.d.ts +2 -0
  119. package/dist/runtime-branch/types.d.ts +37 -0
  120. package/dist/runtime-branch/web.d.ts +2 -0
  121. package/dist/runtime-branch.d.ts +1 -0
  122. package/dist/{bundle-state-DU2ATDhw.js → source-candidate-scan-signature-2ybpptAK.js} +262 -20
  123. package/dist/{bundle-state-BxMNKjBV.mjs → source-candidate-scan-signature-Cvb5z1ha.mjs} +187 -17
  124. package/dist/tailwindcss/candidates.d.ts +7 -0
  125. package/dist/tailwindcss/index.d.ts +2 -2
  126. package/dist/tailwindcss/runtime/cache.d.ts +6 -6
  127. package/dist/tailwindcss/runtime-factory.d.ts +12 -0
  128. package/dist/tailwindcss/runtime-options.d.ts +8 -0
  129. package/dist/tailwindcss/runtime-types.d.ts +86 -0
  130. package/dist/tailwindcss/runtime.d.ts +6 -6
  131. package/dist/tailwindcss/source-scan.d.ts +1 -1
  132. package/dist/tailwindcss/targets.d.ts +2 -2
  133. package/dist/tailwindcss/v4/config.d.ts +3 -3
  134. package/dist/tailwindcss/v4/css-entries.d.ts +1 -0
  135. package/dist/tailwindcss/v4/css-sources.d.ts +4 -2
  136. package/dist/tailwindcss/v4/index.d.ts +1 -1
  137. package/dist/tailwindcss/v4/multi-runtime.d.ts +2 -0
  138. package/dist/tailwindcss/v4/runtime-factory.d.ts +15 -0
  139. package/dist/tailwindcss/v4/runtime-options.d.ts +2 -0
  140. package/dist/tailwindcss/v4-engine/design-system.d.ts +1 -1
  141. package/dist/tailwindcss/v4-engine/generator/css-compat.d.ts +1 -1
  142. package/dist/tailwindcss/v4-engine/generator/rpx-candidates.d.ts +3 -3
  143. package/dist/tailwindcss/v4-engine/generator/scan-sources.d.ts +1 -1
  144. package/dist/tailwindcss/v4-engine/generator.d.ts +10 -3
  145. package/dist/tailwindcss/v4-engine/index.d.ts +1 -1
  146. package/dist/tailwindcss/v4-engine/miniprogram.d.ts +7 -1
  147. package/dist/tailwindcss/v4-engine/source.d.ts +23 -6
  148. package/dist/tailwindcss/v4-engine/types.d.ts +8 -9
  149. package/dist/tailwindcss/version.d.ts +1 -1
  150. package/dist/tailwindcss-DHIYcqXT.js +1523 -0
  151. package/dist/tailwindcss-wyUHrfil.mjs +1418 -0
  152. package/dist/{transform-CaVEBOuR.js → transform-CQVOgmzM.js} +45 -37
  153. package/dist/{transform-Cju08-aJ.mjs → transform-tExdt40m.mjs} +30 -22
  154. package/dist/typedoc.export.d.ts +1 -1
  155. package/dist/types/index.d.ts +16 -17
  156. package/dist/types/shared.d.ts +1 -1
  157. package/dist/types/{typedoc-tailwindcss-patch.d.ts → typedoc-tailwindcss-runtime.d.ts} +4 -10
  158. package/dist/types/user-defined-options/general.d.ts +8 -4
  159. package/dist/types/user-defined-options/important.d.ts +2 -2
  160. package/dist/uni-app-x/style-asset.d.ts +1 -0
  161. package/dist/{utils-Dolmt8EO.js → utils-BCa37Wqj.js} +2 -17
  162. package/dist/{utils-DsaS975I.mjs → utils-DodxWHGz.mjs} +2 -17
  163. package/dist/v4-engine-CF9zt4Cw.mjs +2396 -0
  164. package/dist/v4-engine-D4ubP7N5.js +2778 -0
  165. package/dist/{vite-BBGOjh9e.js → vite-CP0ylSxZ.js} +2887 -1683
  166. package/dist/{vite-CS5DE-HD.mjs → vite-CPO83EhA.mjs} +2753 -1548
  167. package/dist/vite.js +1 -1
  168. package/dist/vite.mjs +1 -1
  169. package/dist/weapp-tw-css-import-rewrite-loader.js +5741 -4396
  170. package/dist/weapp-tw-runtime-classset-loader.js +36 -0
  171. package/dist/webpack-Bsek8VhR.js +2094 -0
  172. package/dist/webpack-BzqhJ8yK.mjs +2082 -0
  173. package/dist/webpack.js +1 -1
  174. package/dist/webpack.mjs +1 -1
  175. package/package.json +11 -7
  176. package/dist/auto-CTp6wE5a.js +0 -33
  177. package/dist/auto-Cl8_hsG6.mjs +0 -22
  178. package/dist/bundlers/vite/incremental-runtime-class-set/v3-candidates.d.ts +0 -13
  179. package/dist/bundlers/vite/source-candidates/tailwind-v3-default-extractor.d.ts +0 -1
  180. package/dist/context/tailwindcss/rax.d.ts +0 -2
  181. package/dist/generator-Cb1Zp3Al.js +0 -92
  182. package/dist/generator-mvNFUvns.mjs +0 -67
  183. package/dist/tailwindcss/patcher-options.d.ts +0 -8
  184. package/dist/tailwindcss/patcher.d.ts +0 -12
  185. package/dist/tailwindcss/runtime-patch.d.ts +0 -5
  186. package/dist/tailwindcss/v3-engine/generator/cache-key.d.ts +0 -3
  187. package/dist/tailwindcss/v3-engine/generator/content.d.ts +0 -10
  188. package/dist/tailwindcss/v3-engine/generator/runtime-ready.d.ts +0 -2
  189. package/dist/tailwindcss/v3-engine/generator.d.ts +0 -19
  190. package/dist/tailwindcss/v3-engine/index.d.ts +0 -4
  191. package/dist/tailwindcss/v3-engine/miniprogram.d.ts +0 -4
  192. package/dist/tailwindcss/v3-engine/source.d.ts +0 -5
  193. package/dist/tailwindcss/v3-engine/types.d.ts +0 -61
  194. package/dist/tailwindcss/v4/multi-patcher.d.ts +0 -2
  195. package/dist/tailwindcss/v4/patcher-options.d.ts +0 -2
  196. package/dist/tailwindcss/v4/patcher.d.ts +0 -15
  197. package/dist/tailwindcss/v4-engine/tailwind-v3-compatibility.d.ts +0 -1
  198. package/dist/tailwindcss/v4-engine/tailwind-v3-default-colors.d.ts +0 -1
  199. package/dist/tailwindcss-CK84uGBp.mjs +0 -556
  200. package/dist/tailwindcss-Clpkz1oR.js +0 -613
  201. package/dist/v3-engine-CQE5JJNZ.js +0 -4639
  202. package/dist/v3-engine-DKBaKWGL.mjs +0 -4231
  203. package/dist/webpack-DIWrcpRo.js +0 -1066
  204. package/dist/webpack-SPcri_D8.mjs +0 -1054
  205. /package/dist/tailwindcss/{patcher-resolve.d.ts → runtime-resolve.d.ts} +0 -0
@@ -1,1054 +0,0 @@
1
- import { J as getTailwindV4IncrementalGenerateCacheStats, N as removeTailwindSourceDirectives, a as getTailwindV3IncrementalGenerateCacheStats, at as createDebug, h as resolveViteSourceScanEntries, lt as resolveTailwindcssOptions, u as getRuntimeClassSetSignature } from "./v3-engine-DKBaKWGL.mjs";
2
- import { i as normalizeWeappTailwindcssGeneratorOptions } from "./generator-mvNFUvns.mjs";
3
- import { b as refreshTailwindRuntimeState, d as _defineProperty, i as pluginName, n as getCompilerContext, t as shouldSkipJsTransform, v as createTailwindRuntimeReadyPromise, y as ensureRuntimeClassSet } from "./precheck-CsFr1q2l.mjs";
4
- import { r as getGroupedEntries } from "./utils-DsaS975I.mjs";
5
- import { c as hasConfiguredTailwindV4CssRoots, l as upsertTailwindV4CssSource } from "./tailwindcss-CK84uGBp.mjs";
6
- import { _ as createCssSourceTraceCacheSignature, a as createTailwindV3DefaultExtractor, b as processCachedTask, g as annotateCssSourceTrace, h as pruneMiniProgramGeneratedCss, l as pushConcurrentTaskFactories, m as finalizeMiniProgramCss, n as emitHmrTiming, o as createBundleRuntimeClassSetManager, p as isPureLocalCssImportWrapper, r as createSourceCandidateCollector, s as generateCssByGenerator, v as createCssTokenSourceMap, y as isCssSourceTraceEnabled } from "./hmr-timing-DNjF8bWA.mjs";
7
- import { S as toAbsoluteOutputPath, c as hasBundlerGeneratedCssMarker, d as resolvePackageDir, f as resolvePluginDisabledState, n as createBundleBuildState, r as updateBundleBuildState, t as buildBundleSnapshot, u as stripBundlerGeneratedCssMarkers, v as isSourceStyleRequest, x as resolveOutputSpecifier, y as stripRequestQuery } from "./bundle-state-BxMNKjBV.mjs";
8
- import Module, { createRequire } from "node:module";
9
- import fs from "node:fs";
10
- import path from "node:path";
11
- import process from "node:process";
12
- import { fileURLToPath } from "node:url";
13
- import micromatch from "micromatch";
14
- //#region src/shared/tailwindcss-css-redirect.ts
15
- const moduleWithMutableResolve = Module;
16
- const patched = /* @__PURE__ */ new WeakSet();
17
- function installTailwindcssCssRedirect(pkgDir) {
18
- const target = path.join(pkgDir, "index.css");
19
- const original = moduleWithMutableResolve._resolveFilename;
20
- if (patched.has(original)) return;
21
- const replacements = new Set(["tailwindcss", "tailwindcss$"]);
22
- const resolveTailwindcssCss = (request, parent, isMain, options) => {
23
- if (replacements.has(request)) return target;
24
- if (request.startsWith("tailwindcss/")) return path.join(pkgDir, request.slice(12));
25
- return original(request, parent, isMain, options);
26
- };
27
- moduleWithMutableResolve._resolveFilename = resolveTailwindcssCss;
28
- patched.add(moduleWithMutableResolve._resolveFilename);
29
- }
30
- //#endregion
31
- //#region src/shared/mpx.ts
32
- const localRequire = createRequire(import.meta.url);
33
- const MPX_STYLE_RESOURCE_QUERY_RE$1 = /(?:^|[?&])type=styles(?:&|$)/;
34
- const MPX_WEBPACK_PLUGIN_PACKAGE_RE = /@mpxjs[\\/]webpack-plugin[\\/]package\.json$/;
35
- function isMpxStyleResourceQuery(query) {
36
- if (typeof query !== "string") return false;
37
- return MPX_STYLE_RESOURCE_QUERY_RE$1.test(query);
38
- }
39
- function isMpx(appType) {
40
- return appType === "mpx";
41
- }
42
- function getTailwindcssCssEntry(pkgDir) {
43
- return path.join(pkgDir, "index.css");
44
- }
45
- function resolveMpxWebpackPluginDir(compiler) {
46
- const candidates = [
47
- compiler?.context,
48
- compiler?.options?.context,
49
- process.cwd()
50
- ].filter((item) => typeof item === "string" && item.length > 0);
51
- for (const candidate of candidates) try {
52
- const projectRequire = createRequire(path.join(candidate, "package.json"));
53
- return path.dirname(projectRequire.resolve("@mpxjs/webpack-plugin/package.json"));
54
- } catch {}
55
- const cachedPackageJson = Object.keys(localRequire.cache).find((file) => MPX_WEBPACK_PLUGIN_PACKAGE_RE.test(file));
56
- if (cachedPackageJson) return path.dirname(cachedPackageJson);
57
- try {
58
- return path.dirname(localRequire.resolve("@mpxjs/webpack-plugin/package.json"));
59
- } catch {
60
- return;
61
- }
62
- }
63
- function isMpxWebpackPluginRequest(request) {
64
- return request === "@mpxjs/webpack-plugin" || Boolean(request?.startsWith("@mpxjs/webpack-plugin/"));
65
- }
66
- function resolveMpxWebpackPluginRequest(request, mpxWebpackPluginDir) {
67
- if (request === "@mpxjs/webpack-plugin") return mpxWebpackPluginDir;
68
- return path.join(mpxWebpackPluginDir, request.slice(22));
69
- }
70
- function addMpxWebpackPluginAlias(alias, pkgDir) {
71
- const recordLoader = path.join(pkgDir, "lib/record-loader");
72
- const styleCompiler = path.join(pkgDir, "lib/style-compiler/index");
73
- const stripConditionalLoader = path.join(pkgDir, "lib/style-compiler/strip-conditional-loader");
74
- if (Array.isArray(alias)) alias.push({
75
- name: "@mpxjs/webpack-plugin/lib/record-loader",
76
- alias: recordLoader
77
- }, {
78
- name: "@mpxjs/webpack-plugin/lib/style-compiler/index",
79
- alias: styleCompiler
80
- }, {
81
- name: "@mpxjs/webpack-plugin/lib/style-compiler/strip-conditional-loader",
82
- alias: stripConditionalLoader
83
- }, {
84
- name: /^@mpxjs\/webpack-plugin\//,
85
- alias: pkgDir
86
- });
87
- else {
88
- alias["@mpxjs/webpack-plugin"] = pkgDir;
89
- alias["@mpxjs/webpack-plugin$"] = pkgDir;
90
- alias["@mpxjs/webpack-plugin/lib/record-loader"] = recordLoader;
91
- alias["@mpxjs/webpack-plugin/lib/style-compiler/index"] = styleCompiler;
92
- alias["@mpxjs/webpack-plugin/lib/style-compiler/strip-conditional-loader"] = stripConditionalLoader;
93
- }
94
- }
95
- function ensureResolveLoaderAlias(compiler, mpxWebpackPluginDir) {
96
- compiler.options.resolveLoader = compiler.options.resolveLoader || {};
97
- const alias = compiler.options.resolveLoader.alias ?? {};
98
- compiler.options.resolveLoader.alias = alias;
99
- addMpxWebpackPluginAlias(alias, mpxWebpackPluginDir);
100
- }
101
- function resolveMpxWebpackPluginRequire(compiler) {
102
- const candidates = [
103
- compiler?.context,
104
- compiler?.options?.context,
105
- process.cwd()
106
- ].filter((item) => typeof item === "string" && item.length > 0);
107
- for (const candidate of candidates) try {
108
- const projectRequire = createRequire(path.join(candidate, "package.json"));
109
- projectRequire.resolve("@mpxjs/webpack-plugin/package.json");
110
- return projectRequire;
111
- } catch {}
112
- const cachedPackageJson = Object.keys(localRequire.cache).find((file) => MPX_WEBPACK_PLUGIN_PACKAGE_RE.test(file));
113
- if (cachedPackageJson) return createRequire(cachedPackageJson);
114
- return localRequire;
115
- }
116
- function patchMpxWebpackPluginNormalizeLib(compiler, mpxWebpackPluginDir) {
117
- if (!mpxWebpackPluginDir) return false;
118
- const projectRequire = resolveMpxWebpackPluginRequire(compiler);
119
- let normalize;
120
- try {
121
- normalize = projectRequire("@mpxjs/webpack-plugin/lib/utils/normalize");
122
- } catch {
123
- return false;
124
- }
125
- if (typeof normalize.lib !== "function") return false;
126
- if (normalize.lib.__weappTwPatched) return true;
127
- const wrappedLib = (file) => path.join(mpxWebpackPluginDir, "lib", file);
128
- wrappedLib.__weappTwPatched = true;
129
- wrappedLib.__weappTwOriginal = normalize.lib;
130
- normalize.lib = wrappedLib;
131
- return true;
132
- }
133
- function ensureMpxTailwindcssAliases(compiler, pkgDir) {
134
- const tailwindcssCssEntry = getTailwindcssCssEntry(pkgDir);
135
- compiler.options = compiler.options || {};
136
- compiler.options.resolve = compiler.options.resolve || {};
137
- const mpxWebpackPluginDir = resolveMpxWebpackPluginDir(compiler);
138
- patchMpxWebpackPluginNormalizeLib(compiler, mpxWebpackPluginDir);
139
- if (mpxWebpackPluginDir) ensureResolveLoaderAlias(compiler, mpxWebpackPluginDir);
140
- const alias = compiler.options.resolve.alias ?? {};
141
- compiler.options.resolve.alias = alias;
142
- if (Array.isArray(alias)) alias.push({
143
- name: "tailwindcss",
144
- alias: tailwindcssCssEntry
145
- }, {
146
- name: "tailwindcss$",
147
- alias: tailwindcssCssEntry
148
- });
149
- else {
150
- alias.tailwindcss = tailwindcssCssEntry;
151
- alias.tailwindcss$ = tailwindcssCssEntry;
152
- }
153
- if (mpxWebpackPluginDir) addMpxWebpackPluginAlias(alias, mpxWebpackPluginDir);
154
- return tailwindcssCssEntry;
155
- }
156
- function patchMpxLoaderResolve(loaderContext, pkgDir, enabled) {
157
- if (!enabled || typeof loaderContext.resolve !== "function") return;
158
- const originalResolve = loaderContext.resolve;
159
- if (originalResolve.__weappTwPatched) return;
160
- const tailwindcssCssEntry = getTailwindcssCssEntry(pkgDir);
161
- const mpxWebpackPluginDir = resolveMpxWebpackPluginDir(loaderContext);
162
- const wrappedResolve = function(context, request, callback) {
163
- if (request === "tailwindcss" || request === "tailwindcss$") return callback(null, tailwindcssCssEntry);
164
- if (request?.startsWith("tailwindcss/")) return callback(null, path.join(pkgDir, request.slice(12)));
165
- if (mpxWebpackPluginDir && isMpxWebpackPluginRequest(request)) return callback(null, resolveMpxWebpackPluginRequest(request, mpxWebpackPluginDir));
166
- return originalResolve.call(this, context, request, callback);
167
- };
168
- wrappedResolve.__weappTwPatched = true;
169
- loaderContext.resolve = wrappedResolve;
170
- }
171
- function setupMpxTailwindcssRedirect(pkgDir, enabled) {
172
- if (enabled) installTailwindcssCssRedirect(pkgDir);
173
- }
174
- const CSS_EXT_RE = /\.css$/i;
175
- function injectMpxCssRewritePreRules(compiler, loader, loaderOptions) {
176
- var _compiler$options;
177
- if (!loader) return;
178
- const moduleOptions = (_compiler$options = compiler.options).module ?? (_compiler$options.module = { rules: [] });
179
- moduleOptions.rules = moduleOptions.rules || [];
180
- const createRule = (match) => ({
181
- ...match,
182
- enforce: "pre",
183
- use: [{
184
- loader,
185
- options: loaderOptions
186
- }]
187
- });
188
- moduleOptions.rules.unshift(createRule({ resourceQuery: (query) => isMpxStyleResourceQuery(query) }), createRule({
189
- test: CSS_EXT_RE,
190
- resourceQuery: (query) => !isMpxStyleResourceQuery(query)
191
- }));
192
- }
193
- //#endregion
194
- //#region src/bundlers/webpack/BaseUnifiedPlugin/shared.ts
195
- const MPX_STYLE_RESOURCE_QUERY_RE = /(?:\?|&)type=styles\b/;
196
- function getCacheKey(filename) {
197
- return filename;
198
- }
199
- function stripResourceQuery(resource) {
200
- if (typeof resource !== "string") return resource;
201
- return stripRequestQuery(resource);
202
- }
203
- function isCssLikeModuleResource(resource, cssMatcher, appType) {
204
- if (typeof resource !== "string") return false;
205
- const normalizedResource = stripResourceQuery(resource);
206
- if (normalizedResource && cssMatcher(normalizedResource)) return true;
207
- if (isSourceStyleRequest(resource)) return true;
208
- if (appType === "mpx") return MPX_STYLE_RESOURCE_QUERY_RE.test(resource);
209
- return false;
210
- }
211
- function hasLoaderEntry(entries, target) {
212
- if (!target) return false;
213
- return entries.some((entry) => entry.loader?.includes?.(target));
214
- }
215
- function normalizeWatchPath(file) {
216
- return path.resolve(file);
217
- }
218
- function isFileInContext(file, context) {
219
- const relative = path.relative(normalizeWatchPath(context), normalizeWatchPath(file));
220
- return relative.length > 0 && !relative.startsWith("..") && !path.isAbsolute(relative);
221
- }
222
- function toChunkFiles(files) {
223
- if (!files) return [];
224
- if (Array.isArray(files)) return files;
225
- return [...files];
226
- }
227
- function createAssetHashByChunkMap(chunks) {
228
- const partsByFile = /* @__PURE__ */ new Map();
229
- for (const chunk of chunks) {
230
- const hash = typeof chunk.hash === "string" ? chunk.hash : void 0;
231
- if (!hash) continue;
232
- const chunkId = String(chunk.id ?? chunk.name ?? "");
233
- for (const file of toChunkFiles(chunk.files)) {
234
- if (!file) continue;
235
- let parts = partsByFile.get(file);
236
- if (!parts) {
237
- parts = [];
238
- partsByFile.set(file, parts);
239
- }
240
- parts.push(`${chunkId}:${hash}`);
241
- }
242
- }
243
- const hashByFile = /* @__PURE__ */ new Map();
244
- for (const [file, parts] of partsByFile.entries()) hashByFile.set(file, parts.sort().join("|"));
245
- return hashByFile;
246
- }
247
- function createRuntimeAwareCssHash(assetHash, sourceHash, runtimeSetHash) {
248
- return `${assetHash ?? sourceHash}:${runtimeSetHash}`;
249
- }
250
- function isWatchFileInRuntimeDependencies(file, dependencies) {
251
- const normalizedFile = normalizeWatchPath(file);
252
- for (const dependency of dependencies.files ?? []) if (normalizeWatchPath(dependency) === normalizedFile) return true;
253
- for (const context of dependencies.contexts ?? []) if (isFileInContext(normalizedFile, context)) return true;
254
- return false;
255
- }
256
- //#endregion
257
- //#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets/helpers.ts
258
- function createWebpackSnapshotAssets(assets) {
259
- return Object.fromEntries(Object.entries(assets).map(([file, asset]) => {
260
- const source = asset.source();
261
- return [file, {
262
- fileName: file,
263
- source: typeof source === "string" ? source : source?.toString() ?? "",
264
- type: "asset"
265
- }];
266
- }));
267
- }
268
- function stringifyWebpackSource(source) {
269
- if (typeof source === "string") return source;
270
- return source?.toString() ?? "";
271
- }
272
- function createWebpackAssetUpdater(options) {
273
- const getCurrentAssetSource = (file) => {
274
- const asset = options.compilation.getAsset(file);
275
- if (!asset) return;
276
- return stringifyWebpackSource(asset.source.source());
277
- };
278
- const updateAssetIfChanged = (file, source, { notifyUpdate = true } = {}) => {
279
- const nextSource = typeof source === "string" ? source : stringifyWebpackSource(source.source());
280
- const previousSource = getCurrentAssetSource(file);
281
- if (previousSource === nextSource) {
282
- options.debug("asset unchanged, skip update: %s", file);
283
- return false;
284
- }
285
- options.compilation.updateAsset(file, typeof source === "string" ? new options.ConcatSource(source) : source);
286
- if (notifyUpdate) options.onUpdate(file, previousSource ?? "", nextSource);
287
- return true;
288
- };
289
- return {
290
- getCurrentAssetSource,
291
- updateAssetIfChanged
292
- };
293
- }
294
- //#endregion
295
- //#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets.ts
296
- const WEBPACK_CSS_HANDLER_OPTIONS_CACHE_MAX = 128;
297
- function toMb(bytes) {
298
- return Math.round(bytes / 1024 / 1024);
299
- }
300
- function pruneMapToMaxSize(map, maxSize) {
301
- while (map.size > maxSize) {
302
- const oldestKey = map.keys().next().value;
303
- if (oldestKey === void 0) break;
304
- map.delete(oldestKey);
305
- }
306
- }
307
- function pruneWebpackCssHandlerOptionCaches(cssHandlerOptionsCache, cssUserHandlerOptionsCache, activeCssFiles) {
308
- const activeSuffixes = [...activeCssFiles].map((file) => `:${file}`);
309
- for (const key of cssHandlerOptionsCache.keys()) if (!activeSuffixes.some((suffix) => key.endsWith(suffix))) cssHandlerOptionsCache.delete(key);
310
- for (const key of cssUserHandlerOptionsCache.keys()) if (!activeSuffixes.some((suffix) => key.endsWith(suffix))) cssUserHandlerOptionsCache.delete(key);
311
- pruneMapToMaxSize(cssHandlerOptionsCache, WEBPACK_CSS_HANDLER_OPTIONS_CACHE_MAX);
312
- pruneMapToMaxSize(cssUserHandlerOptionsCache, WEBPACK_CSS_HANDLER_OPTIONS_CACHE_MAX);
313
- }
314
- function resolveWebpackMemoryDebugStats(context) {
315
- if (process.env["WEAPP_TW_HMR_MEMORY_DEBUG"] !== "1") return;
316
- const memory = process.memoryUsage();
317
- return {
318
- phase: context.phase,
319
- process: {
320
- rssMb: toMb(memory.rss),
321
- heapTotalMb: toMb(memory.heapTotal),
322
- heapUsedMb: toMb(memory.heapUsed),
323
- externalMb: toMb(memory.external),
324
- arrayBuffersMb: toMb(memory.arrayBuffers)
325
- },
326
- assets: {
327
- active: context.activeAssetFiles,
328
- activeCss: context.activeCssFiles
329
- },
330
- processCache: {
331
- instance: context.cache.instance.size,
332
- hashMap: context.cache.hashMap.size,
333
- activeCacheKeys: context.activeProcessCacheKeys.size,
334
- activeHashKeys: context.activeProcessHashKeys.size
335
- },
336
- webpackCss: {
337
- handlerOptions: context.cssHandlerOptionsCache.size,
338
- userHandlerOptions: context.cssUserHandlerOptionsCache.size,
339
- maxHandlerOptions: WEBPACK_CSS_HANDLER_OPTIONS_CACHE_MAX
340
- },
341
- tailwind: {
342
- v3: getTailwindV3IncrementalGenerateCacheStats(),
343
- v4: getTailwindV4IncrementalGenerateCacheStats()
344
- }
345
- };
346
- }
347
- function setupWebpackV5ProcessAssetsHook(options) {
348
- const { compiler, options: compilerOptions, appType, runtimeState, getRuntimeRefreshRequirement, refreshRuntimeMetadata, isWebpackProcessedCssAsset, consumeRuntimeRefreshRequirement, isWatchMode, runtimeClassSetManager, debug } = options;
349
- const { Compilation, sources } = compiler.webpack;
350
- const { ConcatSource } = sources;
351
- const isWebGeneratorTarget = compilerOptions.generator?.target === "web";
352
- const cssHandlerOptionsCache = /* @__PURE__ */ new Map();
353
- const cssUserHandlerOptionsCache = /* @__PURE__ */ new Map();
354
- const bundleBuildState = createBundleBuildState();
355
- const bundleRuntimeClassSetManager = runtimeClassSetManager ?? createBundleRuntimeClassSetManager();
356
- let webpackWatchRuntimeScanInitialized = false;
357
- compiler.hooks.compilation.tap(pluginName, (compilation) => {
358
- compilation.hooks.processAssets.tapPromise({
359
- name: pluginName,
360
- stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
361
- }, async (assets) => {
362
- compilerOptions.onStart();
363
- debug("start");
364
- await runtimeState.readyPromise;
365
- const hmrTimingStartedAt = performance.now();
366
- for (const chunk of compilation.chunks) if (chunk.id && chunk.hash) compilerOptions.cache.calcHashValueChanged(chunk.id, chunk.hash);
367
- const assetHashByChunk = createAssetHashByChunkMap(compilation.chunks);
368
- const { updateAssetIfChanged } = createWebpackAssetUpdater({
369
- compilation,
370
- ConcatSource,
371
- onUpdate: compilerOptions.onUpdate,
372
- debug
373
- });
374
- const entries = Object.entries(assets);
375
- const compilerOutputPath = compilation.compiler?.outputPath ?? compiler.outputPath;
376
- const outputDir = compilerOutputPath ? path.resolve(compilerOutputPath) : compilation.outputOptions?.path ?? process.cwd();
377
- const jsAssets = /* @__PURE__ */ new Map();
378
- for (const [file] of entries) if (compilerOptions.jsMatcher(file) || compilerOptions.wxsMatcher(file)) {
379
- const absolute = toAbsoluteOutputPath(file, outputDir);
380
- jsAssets.set(absolute, file);
381
- }
382
- const moduleGraphOptions = {
383
- resolve(specifier, importer) {
384
- return resolveOutputSpecifier(specifier, importer, outputDir, (candidate) => jsAssets.has(candidate));
385
- },
386
- load: (id) => {
387
- const assetName = jsAssets.get(id);
388
- if (!assetName) return;
389
- const asset = compilation.getAsset(assetName);
390
- if (!asset) return;
391
- const source = asset.source.source();
392
- return typeof source === "string" ? source : source.toString();
393
- },
394
- filter(id) {
395
- return jsAssets.has(id);
396
- }
397
- };
398
- const applyLinkedResults = (linked) => {
399
- if (!linked) return;
400
- for (const [id, { code }] of Object.entries(linked)) {
401
- const assetName = jsAssets.get(id);
402
- if (!assetName) continue;
403
- const asset = compilation.getAsset(assetName);
404
- if (!asset) continue;
405
- const previousSource = asset.source.source();
406
- if ((typeof previousSource === "string" ? previousSource : previousSource.toString()) === code) continue;
407
- if (updateAssetIfChanged(assetName, new ConcatSource(code))) debug("js linked handle: %s", assetName);
408
- }
409
- };
410
- const groupedEntries = getGroupedEntries(entries, compilerOptions);
411
- const activeProcessCacheKeys = /* @__PURE__ */ new Set();
412
- const activeProcessHashKeys = /* @__PURE__ */ new Set();
413
- const rememberProcessCacheKey = (cacheKey, hashKey = cacheKey) => {
414
- activeProcessCacheKeys.add(cacheKey);
415
- activeProcessHashKeys.add(hashKey);
416
- };
417
- for (const chunk of compilation.chunks) if (chunk.id) activeProcessHashKeys.add(chunk.id);
418
- const getCssHandlerOptions = (file) => {
419
- const majorVersion = runtimeState.twPatcher.majorVersion;
420
- const isMainChunk = compilerOptions.mainCssChunkMatcher(file, appType);
421
- const cacheKey = `${majorVersion ?? "unknown"}:${isMainChunk ? "1" : "0"}:${file}`;
422
- const cached = cssHandlerOptionsCache.get(cacheKey);
423
- if (cached) return cached;
424
- const created = {
425
- isMainChunk,
426
- postcssOptions: { options: { from: file } },
427
- ...majorVersion === void 0 ? {} : { majorVersion }
428
- };
429
- cssHandlerOptionsCache.set(cacheKey, created);
430
- return created;
431
- };
432
- const getCssUserHandlerOptions = (file) => {
433
- const cacheKey = `${runtimeState.twPatcher.majorVersion ?? "unknown"}:${file}`;
434
- const cached = cssUserHandlerOptionsCache.get(cacheKey);
435
- if (cached) return cached;
436
- const created = {
437
- ...getCssHandlerOptions(file),
438
- isMainChunk: false
439
- };
440
- cssUserHandlerOptionsCache.set(cacheKey, created);
441
- return created;
442
- };
443
- const finalizeCssAssetSource = (source, options = {}) => {
444
- let finalized = removeTailwindSourceDirectives(stripBundlerGeneratedCssMarkers(source), { importFallback: true });
445
- if (isWebGeneratorTarget || options.generatedCss !== true) return finalized;
446
- try {
447
- finalized = pruneMiniProgramGeneratedCss(finalized, { preservePreflight: runtimeState.twPatcher.majorVersion === 3 });
448
- } catch {
449
- finalized = finalizeMiniProgramCss(finalized, {
450
- cssPreflight: runtimeState.twPatcher.majorVersion === 4 ? compilerOptions.cssPreflight : void 0,
451
- isTailwindcssV4: runtimeState.twPatcher.majorVersion === 4,
452
- preservePseudoContentInit: runtimeState.twPatcher.majorVersion === 3
453
- });
454
- }
455
- return finalized;
456
- };
457
- const finalizeMiniProgramUserCssAssetSource = (source) => {
458
- if (isWebGeneratorTarget) return source;
459
- return finalizeMiniProgramCss(source, {
460
- cssPreflight: runtimeState.twPatcher.majorVersion === 4 ? compilerOptions.cssPreflight : void 0,
461
- isTailwindcssV4: runtimeState.twPatcher.majorVersion === 4,
462
- preservePseudoContentInit: runtimeState.twPatcher.majorVersion === 3
463
- });
464
- };
465
- const cssSourceTraceTokenSources = isCssSourceTraceEnabled(compilerOptions) ? await (async () => {
466
- const root = compilerOptions.tailwindcssBasedir ?? process.cwd();
467
- const sourceScan = await resolveViteSourceScanEntries(compilerOptions, runtimeState.twPatcher, { root });
468
- const collector = createSourceCandidateCollector({
469
- bareArbitraryValues: compilerOptions.arbitraryValues?.bareArbitraryValues,
470
- extractor: runtimeState.twPatcher.majorVersion === 3 ? createTailwindV3DefaultExtractor() : void 0
471
- });
472
- await collector.scanRoot({
473
- entries: sourceScan?.entries,
474
- explicit: sourceScan?.explicit,
475
- root
476
- });
477
- collector.syncInline(sourceScan?.inlineCandidates);
478
- return createCssTokenSourceMap(collector.sourcesForEntries(sourceScan?.entries), compilerOptions);
479
- })() : void 0;
480
- const cssSourceTraceSignature = createCssSourceTraceCacheSignature(cssSourceTraceTokenSources, compilerOptions);
481
- const annotateCss = (css) => annotateCssSourceTrace(css, {
482
- opts: compilerOptions,
483
- tokenSources: cssSourceTraceTokenSources
484
- });
485
- const finalizeTracedCss = (css) => {
486
- const traced = annotateCss(css);
487
- if (isWebGeneratorTarget || !isCssSourceTraceEnabled(compilerOptions)) return traced;
488
- return finalizeMiniProgramUserCssAssetSource(traced);
489
- };
490
- const forceRuntimeRefresh = getRuntimeRefreshRequirement();
491
- debug("processAssets ensure runtime set forceRefresh=%s major=%s", forceRuntimeRefresh, runtimeState.twPatcher.majorVersion ?? "unknown");
492
- let runtimeSet;
493
- const watchMode = isWatchMode?.() === true;
494
- if (watchMode && runtimeState.twPatcher.majorVersion === 4 && !forceRuntimeRefresh) {
495
- const snapshot = buildBundleSnapshot(createWebpackSnapshotAssets(assets), compilerOptions, outputDir, bundleBuildState);
496
- if (!webpackWatchRuntimeScanInitialized) {
497
- for (const entry of snapshot.entries) if (entry.type === "html" || entry.type === "js") snapshot.runtimeAffectingChangedByType[entry.type].add(entry.file);
498
- }
499
- try {
500
- runtimeSet = await bundleRuntimeClassSetManager.sync(runtimeState.twPatcher, snapshot);
501
- } catch (error) {
502
- debug("webpack incremental runtime set sync failed, fallback to full collect: %O", error);
503
- await bundleRuntimeClassSetManager.reset();
504
- runtimeSet = await ensureRuntimeClassSet(runtimeState, {
505
- forceRefresh: false,
506
- forceCollect: true,
507
- clearCache: false,
508
- allowEmpty: false
509
- });
510
- }
511
- updateBundleBuildState(bundleBuildState, snapshot, /* @__PURE__ */ new Map(), { incremental: true });
512
- webpackWatchRuntimeScanInitialized = true;
513
- } else {
514
- if (forceRuntimeRefresh) {
515
- await bundleRuntimeClassSetManager.reset();
516
- webpackWatchRuntimeScanInitialized = false;
517
- }
518
- runtimeSet = await ensureRuntimeClassSet(runtimeState, {
519
- forceRefresh: forceRuntimeRefresh,
520
- forceCollect: !watchMode || forceRuntimeRefresh,
521
- clearCache: forceRuntimeRefresh,
522
- allowEmpty: false
523
- });
524
- }
525
- await refreshRuntimeMetadata(forceRuntimeRefresh);
526
- consumeRuntimeRefreshRequirement();
527
- const runtimeSetHash = compilerOptions.cache.computeHash([getRuntimeClassSetSignature(runtimeState.twPatcher), [...runtimeSet].sort().join("\n")].join("\n\n"));
528
- const defaultTemplateHandlerOptions = { runtimeSet };
529
- debug("get runtimeSet, class count: %d", runtimeSet.size);
530
- const tasks = [];
531
- if (!isWebGeneratorTarget && Array.isArray(groupedEntries.html)) for (const element of groupedEntries.html) {
532
- const [file, originalSource] = element;
533
- const rawSource = originalSource.source().toString();
534
- const cacheKey = file;
535
- const hashKey = `${file}:asset`;
536
- rememberProcessCacheKey(cacheKey, hashKey);
537
- const chunkHash = assetHashByChunk.get(file);
538
- tasks.push(processCachedTask({
539
- cache: compilerOptions.cache,
540
- cacheKey,
541
- hashKey,
542
- rawSource,
543
- hash: chunkHash,
544
- applyResult(source, { cacheHit }) {
545
- updateAssetIfChanged(file, source, { notifyUpdate: !cacheHit });
546
- },
547
- onCacheHit() {
548
- debug("html cache hit: %s", file);
549
- },
550
- transform: async () => {
551
- const source = new ConcatSource(await compilerOptions.templateHandler(rawSource, defaultTemplateHandlerOptions));
552
- debug("html handle: %s", file);
553
- return { result: source };
554
- }
555
- }));
556
- }
557
- const jsTaskFactories = [];
558
- if (!isWebGeneratorTarget && Array.isArray(groupedEntries.js)) for (const [file] of groupedEntries.js) {
559
- const cacheKey = getCacheKey(file);
560
- const asset = compilation.getAsset(file);
561
- if (!asset) continue;
562
- const hashKey = `${file}:asset`;
563
- rememberProcessCacheKey(cacheKey, hashKey);
564
- const absoluteFile = toAbsoluteOutputPath(file, outputDir);
565
- const initialSource = asset.source.source();
566
- const initialRawSource = typeof initialSource === "string" ? initialSource : initialSource.toString();
567
- const chunkHash = assetHashByChunk.get(file);
568
- jsTaskFactories.push(async () => {
569
- await processCachedTask({
570
- cache: compilerOptions.cache,
571
- cacheKey,
572
- hashKey,
573
- rawSource: initialRawSource,
574
- hash: chunkHash,
575
- applyResult(source, { cacheHit }) {
576
- updateAssetIfChanged(file, source, { notifyUpdate: !cacheHit });
577
- },
578
- onCacheHit() {
579
- debug("js cache hit: %s", file);
580
- },
581
- transform: async () => {
582
- const currentSourceValue = compilation.getAsset(file)?.source.source();
583
- const currentSource = typeof currentSourceValue === "string" ? currentSourceValue : currentSourceValue?.toString() ?? "";
584
- const handlerOptions = {
585
- tailwindcssMajorVersion: runtimeState.twPatcher.majorVersion,
586
- filename: absoluteFile,
587
- moduleGraph: moduleGraphOptions,
588
- babelParserOptions: { sourceFilename: absoluteFile }
589
- };
590
- if (shouldSkipJsTransform(currentSource, {
591
- ...handlerOptions,
592
- classNameSet: runtimeSet
593
- })) return { result: new ConcatSource(currentSource) };
594
- const { code, linked } = await compilerOptions.jsHandler(currentSource, runtimeSet, handlerOptions);
595
- const source = new ConcatSource(code);
596
- debug("js handle: %s", file);
597
- applyLinkedResults(linked);
598
- return { result: source };
599
- }
600
- });
601
- });
602
- }
603
- if (Array.isArray(groupedEntries.css)) for (const element of groupedEntries.css) {
604
- const [file, originalSource] = element;
605
- const rawSource = originalSource.source().toString();
606
- if (isWebpackProcessedCssAsset?.(file, rawSource)) {
607
- const nextCss = finalizeCssAssetSource(rawSource, { generatedCss: hasBundlerGeneratedCssMarker(rawSource) });
608
- const hashKey = `${file}:asset`;
609
- rememberProcessCacheKey(file, hashKey);
610
- tasks.push(processCachedTask({
611
- cache: compilerOptions.cache,
612
- cacheKey: file,
613
- hashKey,
614
- rawSource,
615
- hash: createRuntimeAwareCssHash(assetHashByChunk.get(file), compilerOptions.cache.computeHash(rawSource), `${runtimeSetHash}:${cssSourceTraceSignature}`),
616
- applyResult(source, { cacheHit }) {
617
- updateAssetIfChanged(file, source, { notifyUpdate: !cacheHit });
618
- },
619
- onCacheHit() {
620
- debug("css webpack-loader-pipeline cache hit: %s", file);
621
- },
622
- transform: async () => {
623
- debug("css skip webpack-loader-pipeline asset: %s", file);
624
- return { result: new ConcatSource(finalizeTracedCss(nextCss)) };
625
- }
626
- }));
627
- continue;
628
- }
629
- const cacheKey = file;
630
- const hashKey = `${file}:asset`;
631
- rememberProcessCacheKey(cacheKey, hashKey);
632
- const runtimeAwareHash = createRuntimeAwareCssHash(assetHashByChunk.get(file), compilerOptions.cache.computeHash(rawSource), `${runtimeSetHash}:${cssSourceTraceSignature}`);
633
- tasks.push(processCachedTask({
634
- cache: compilerOptions.cache,
635
- cacheKey,
636
- hashKey,
637
- rawSource,
638
- hash: runtimeAwareHash,
639
- applyResult(source, { cacheHit }) {
640
- updateAssetIfChanged(file, source, { notifyUpdate: !cacheHit });
641
- },
642
- onCacheHit() {
643
- debug("css cache hit: %s", file);
644
- },
645
- transform: async () => {
646
- await runtimeState.readyPromise;
647
- const cssHandlerOptions = getCssHandlerOptions(file);
648
- if (isPureLocalCssImportWrapper(rawSource)) return { result: new ConcatSource(removeTailwindSourceDirectives(stripBundlerGeneratedCssMarkers(rawSource), { importFallback: true })) };
649
- const generated = await generateCssByGenerator({
650
- opts: compilerOptions,
651
- runtimeState,
652
- runtime: runtimeSet,
653
- rawSource,
654
- file,
655
- cssHandlerOptions,
656
- cssUserHandlerOptions: getCssUserHandlerOptions(file),
657
- styleHandler: compilerOptions.styleHandler,
658
- debug
659
- });
660
- const source = new ConcatSource(finalizeTracedCss(finalizeCssAssetSource(generated?.css ?? (await compilerOptions.styleHandler(rawSource, cssHandlerOptions)).css, { generatedCss: generated != null })));
661
- if (generated) debug("css handle via tailwind v%s engine(%s): %s", runtimeState.twPatcher.majorVersion, generated.target, file);
662
- else debug("css handle: %s", file);
663
- return { result: source };
664
- }
665
- }));
666
- }
667
- pushConcurrentTaskFactories(tasks, jsTaskFactories);
668
- await Promise.all(tasks);
669
- compilerOptions.cache.prune?.({
670
- cacheKeys: activeProcessCacheKeys,
671
- hashKeys: activeProcessHashKeys
672
- });
673
- const activeCssFiles = new Set(groupedEntries.css?.map(([file]) => file) ?? []);
674
- pruneWebpackCssHandlerOptionCaches(cssHandlerOptionsCache, cssUserHandlerOptionsCache, activeCssFiles);
675
- debug("end");
676
- emitHmrTiming("webpack", "processAssets", performance.now() - hmrTimingStartedAt, { memoryDebug: resolveWebpackMemoryDebugStats({
677
- activeAssetFiles: entries.length,
678
- activeCssFiles: activeCssFiles.size,
679
- activeProcessCacheKeys,
680
- activeProcessHashKeys,
681
- cache: compilerOptions.cache,
682
- cssHandlerOptionsCache,
683
- cssUserHandlerOptionsCache,
684
- phase: "processAssets"
685
- }) });
686
- compilerOptions.onEnd();
687
- });
688
- });
689
- }
690
- //#endregion
691
- //#region ../../node_modules/.pnpm/tsdown@0.22.2_oxc-resolver@11.20.0_tsx@4.22.4_typescript@6.0.3_unrun@0.2.37_synckit@0.1_c2142480ddc0e0584f1991298dd762a0/node_modules/tsdown/esm-shims.js
692
- const getFilename = () => fileURLToPath(import.meta.url);
693
- const getDirname = () => path.dirname(getFilename());
694
- const __dirname = /* @__PURE__ */ getDirname();
695
- //#endregion
696
- //#region src/bundlers/webpack/loaders/runtime-registry.ts
697
- const runtimeRegistryHolder = globalThis;
698
- const runtimeRegistry = runtimeRegistryHolder.__WEAPP_TW_WEBPACK_LOADER_RUNTIME_REGISTRY__ ?? (runtimeRegistryHolder.__WEAPP_TW_WEBPACK_LOADER_RUNTIME_REGISTRY__ = /* @__PURE__ */ new Map());
699
- function setWebpackLoaderRuntime(key, entry) {
700
- runtimeRegistry.set(key, entry);
701
- }
702
- //#endregion
703
- //#region src/bundlers/webpack/shared/loader-anchors.ts
704
- const MPX_STRIP_CONDITIONAL_LOADER = "@mpxjs/webpack-plugin/lib/style-compiler/strip-conditional-loader";
705
- const MPX_STYLE_COMPILER_LOADER = "@mpxjs/webpack-plugin/lib/style-compiler/index";
706
- const MPX_REWRITE_PRECEDENCE_LOADERS = [MPX_STYLE_COMPILER_LOADER, MPX_STRIP_CONDITIONAL_LOADER];
707
- function createFinder(targets) {
708
- return (entries) => entries.findIndex((entry) => targets.some((target) => entry?.loader?.includes?.(target)));
709
- }
710
- function createPrioritizedFinder(targets) {
711
- return (entries) => {
712
- for (const target of targets) {
713
- const idx = entries.findIndex((entry) => entry?.loader?.includes?.(target));
714
- if (idx !== -1) return idx;
715
- }
716
- return -1;
717
- };
718
- }
719
- function createLoaderAnchorFinders(appType) {
720
- if (isMpx(appType)) return {
721
- findRewriteAnchor: createPrioritizedFinder(MPX_REWRITE_PRECEDENCE_LOADERS),
722
- findClassSetAnchor: createFinder([MPX_STYLE_COMPILER_LOADER])
723
- };
724
- const fallbackFinder = createFinder(["postcss-loader"]);
725
- return {
726
- findRewriteAnchor: fallbackFinder,
727
- findClassSetAnchor: fallbackFinder
728
- };
729
- }
730
- //#endregion
731
- //#region src/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.ts
732
- function setupWebpackV5Loaders(options) {
733
- const { compiler, options: compilerOptions, appType, weappTailwindcssPackageDir, shouldRewriteCssImports, runtimeLoaderPath, registerAutoCssSource, runtimeState, getClassSetInLoader, getRuntimeSetInLoader, markWebpackProcessedCssSource, getRuntimeWatchDependencies, runtimeRegistryKey = `weapp-tailwindcss-${Date.now()}-${Math.random().toString(36).slice(2)}`, debug } = options;
734
- const isMpxApp = isMpx(appType);
735
- if (shouldRewriteCssImports && isMpxApp) ensureMpxTailwindcssAliases(compiler, weappTailwindcssPackageDir);
736
- const runtimeClassSetLoader = runtimeLoaderPath ?? path.resolve(__dirname, "./weapp-tw-runtime-classset-loader.js");
737
- const runtimeCssImportRewriteLoader = shouldRewriteCssImports ? path.resolve(__dirname, "./weapp-tw-css-import-rewrite-loader.js") : void 0;
738
- const runtimeClassSetLoaderExists = fs.existsSync(runtimeClassSetLoader);
739
- const runtimeCssImportRewriteLoaderExists = runtimeCssImportRewriteLoader ? fs.existsSync(runtimeCssImportRewriteLoader) : false;
740
- const runtimeLoaderRewriteOptions = shouldRewriteCssImports ? {
741
- pkgDir: weappTailwindcssPackageDir,
742
- compilerOptions,
743
- runtimeState,
744
- ...appType === void 0 ? {} : { appType },
745
- ...registerAutoCssSource === void 0 ? {} : { registerCssSource: registerAutoCssSource },
746
- getRuntimeSet: getRuntimeSetInLoader,
747
- ...markWebpackProcessedCssSource === void 0 ? {} : { markGeneratedCssSource: markWebpackProcessedCssSource }
748
- } : void 0;
749
- setWebpackLoaderRuntime(runtimeRegistryKey, {
750
- classSet: {
751
- getClassSet: getClassSetInLoader,
752
- getWatchDependencies: getRuntimeWatchDependencies
753
- },
754
- ...runtimeLoaderRewriteOptions === void 0 ? {} : { cssImportRewrite: runtimeLoaderRewriteOptions }
755
- });
756
- const { findRewriteAnchor, findClassSetAnchor } = createLoaderAnchorFinders(appType);
757
- const cssImportRewriteLoaderOptions = runtimeLoaderRewriteOptions ? { tailwindcssImportRewriteRuntimeKey: runtimeRegistryKey } : void 0;
758
- if (runtimeCssImportRewriteLoader && shouldRewriteCssImports && cssImportRewriteLoaderOptions && isMpxApp) injectMpxCssRewritePreRules(compiler, runtimeCssImportRewriteLoader, cssImportRewriteLoaderOptions);
759
- const createRuntimeClassSetLoaderEntry = () => ({
760
- loader: runtimeClassSetLoader,
761
- options: { weappTailwindcssRuntimeKey: runtimeRegistryKey },
762
- ident: null,
763
- type: null
764
- });
765
- const createCssImportRewriteLoaderEntry = () => {
766
- if (!runtimeCssImportRewriteLoader || !cssImportRewriteLoaderOptions) return null;
767
- return {
768
- loader: runtimeCssImportRewriteLoader,
769
- options: cssImportRewriteLoaderOptions,
770
- ident: null,
771
- type: null
772
- };
773
- };
774
- const { NormalModule } = compiler.webpack;
775
- compiler.hooks.compilation.tap(pluginName, (compilation) => {
776
- NormalModule.getCompilationHooks(compilation).loader.tap(pluginName, (_loaderContext, module) => {
777
- if (!(runtimeClassSetLoaderExists || runtimeCssImportRewriteLoaderExists)) return;
778
- patchMpxLoaderResolve(_loaderContext, weappTailwindcssPackageDir, shouldRewriteCssImports && isMpxApp);
779
- const loaderEntries = module.loaders || [];
780
- let rewriteAnchorIdx = findRewriteAnchor(loaderEntries);
781
- const classSetAnchorIdx = findClassSetAnchor(loaderEntries);
782
- const isCssModule = isCssLikeModuleResource(module.resource, compilerOptions.cssMatcher, appType);
783
- if (process.env["WEAPP_TW_LOADER_DEBUG"] && isCssModule) debug("loader hook css module: %s loaders=%o anchors=%o", module.resource, loaderEntries.map((x) => x.loader), {
784
- rewriteAnchorIdx,
785
- classSetAnchorIdx
786
- });
787
- if (process.env["WEAPP_TW_LOADER_DEBUG"] && typeof module.resource === "string" && module.resource.includes("app.css")) debug("app.css module loaders=%o anchors=%o", loaderEntries.map((x) => x.loader), {
788
- rewriteAnchorIdx,
789
- classSetAnchorIdx
790
- });
791
- else if (process.env["WEAPP_TW_LOADER_DEBUG"] && typeof module.resource === "string" && module.resource.endsWith(".css")) debug("css module seen: %s loaders=%o anchors=%o", module.resource, loaderEntries.map((x) => x.loader), {
792
- rewriteAnchorIdx,
793
- classSetAnchorIdx
794
- });
795
- if (rewriteAnchorIdx === -1 && classSetAnchorIdx === -1 && !isCssModule) return;
796
- const anchorlessInsert = (entry, position) => {
797
- if (position === "after") loaderEntries.push(entry);
798
- else loaderEntries.unshift(entry);
799
- };
800
- if (cssImportRewriteLoaderOptions && runtimeCssImportRewriteLoaderExists && runtimeCssImportRewriteLoader) {
801
- const existingIndex = loaderEntries.findIndex((entry) => entry.loader?.includes?.(runtimeCssImportRewriteLoader));
802
- const rewriteLoaderEntry = existingIndex !== -1 ? loaderEntries.splice(existingIndex, 1)[0] : createCssImportRewriteLoaderEntry();
803
- if (rewriteLoaderEntry) {
804
- const anchorIndex = findRewriteAnchor(loaderEntries);
805
- if (anchorIndex === -1) anchorlessInsert(rewriteLoaderEntry, "after");
806
- else loaderEntries.splice(anchorIndex + 1, 0, rewriteLoaderEntry);
807
- rewriteAnchorIdx = findRewriteAnchor(loaderEntries);
808
- }
809
- }
810
- if (runtimeClassSetLoaderExists && !hasLoaderEntry(loaderEntries, runtimeClassSetLoader)) {
811
- const classSetLoaderEntry = createRuntimeClassSetLoaderEntry();
812
- const anchorIndex = findClassSetAnchor(loaderEntries);
813
- if (anchorIndex === -1) anchorlessInsert(classSetLoaderEntry, "before");
814
- else {
815
- const insertIndex = anchorIndex === -1 ? rewriteAnchorIdx : anchorIndex;
816
- loaderEntries.splice(insertIndex, 0, classSetLoaderEntry);
817
- }
818
- }
819
- });
820
- });
821
- }
822
- //#endregion
823
- //#region src/bundlers/webpack/BaseUnifiedPlugin/v5.ts
824
- const debug = createDebug();
825
- const weappTailwindcssPackageDir = resolvePackageDir("weapp-tailwindcss");
826
- const outputIgnoredPredicatePath = Symbol("weapp-tailwindcss.outputIgnoredPredicatePath");
827
- function normalizeIgnoredList(ignored) {
828
- return (Array.isArray(ignored) ? [...ignored] : [ignored]).filter((item) => typeof item === "string" || item instanceof RegExp || typeof item === "function");
829
- }
830
- function createOutputIgnoredPredicate(ignoredList, ignoredPath) {
831
- const predicate = (file) => {
832
- const resolvedFile = path.resolve(file);
833
- if (resolvedFile === ignoredPath || resolvedFile.startsWith(`${ignoredPath}${path.sep}`)) return true;
834
- const normalizedFile = file.replace(/\\/g, "/");
835
- return ignoredList.some((item) => {
836
- if (typeof item === "string") {
837
- const resolvedItem = path.resolve(item);
838
- if (resolvedFile === resolvedItem || resolvedFile.startsWith(`${resolvedItem}${path.sep}`)) return true;
839
- return micromatch.isMatch(normalizedFile, item);
840
- }
841
- if (item instanceof RegExp) return item.test(normalizedFile);
842
- return item(file);
843
- });
844
- };
845
- predicate[outputIgnoredPredicatePath] = ignoredPath;
846
- return predicate;
847
- }
848
- function appendIgnoredPath(ignored, ignoredPath) {
849
- if (typeof ignored === "function" && ignored[outputIgnoredPredicatePath] === ignoredPath) return ignored;
850
- const ignoredList = normalizeIgnoredList(ignored);
851
- if (ignoredList.some((item) => typeof item !== "string")) return createOutputIgnoredPredicate(ignoredList, ignoredPath);
852
- if (ignoredList.some((item) => typeof item === "string" && path.resolve(item) === ignoredPath)) return ignored;
853
- return [...ignoredList, ignoredPath];
854
- }
855
- function setupWebpackWatchOutputIgnore(compiler) {
856
- const appendOutputIgnoredPath = (watchOptions) => {
857
- const outputPath = compiler.outputPath || compiler.options?.output?.path;
858
- const outputDir = outputPath ? path.resolve(outputPath) : void 0;
859
- if (!outputDir) return watchOptions;
860
- if (watchOptions && typeof watchOptions === "object") {
861
- const nextIgnored = appendIgnoredPath(watchOptions.ignored, outputDir);
862
- if (nextIgnored === void 0) delete watchOptions.ignored;
863
- else watchOptions.ignored = nextIgnored;
864
- return watchOptions;
865
- }
866
- return { ignored: appendIgnoredPath(void 0, outputDir) };
867
- };
868
- const compilerWatchOptions = appendOutputIgnoredPath(compiler.options.watchOptions);
869
- if (compilerWatchOptions) compiler.options.watchOptions = compilerWatchOptions;
870
- const syncOutputIgnoredPath = () => {
871
- const outputPath = compiler.outputPath || compiler.options?.output?.path;
872
- if (!(outputPath ? path.resolve(outputPath) : void 0)) return;
873
- const watchOptions = compiler.watching?.watchOptions;
874
- if (watchOptions) appendOutputIgnoredPath(watchOptions);
875
- };
876
- compiler.hooks.watchRun?.tap(pluginName, syncOutputIgnoredPath);
877
- }
878
- /**
879
- * @name WeappTailwindcss
880
- * @description webpack5 核心转义插件
881
- * @link https://tw.icebreaker.top/docs/intro
882
- */
883
- var WeappTailwindcss = class {
884
- constructor(options = {}) {
885
- _defineProperty(this, "options", void 0);
886
- _defineProperty(this, "appType", void 0);
887
- _defineProperty(this, "hasInitialTailwindCssRoots", void 0);
888
- this.hasInitialTailwindCssRoots = hasConfiguredTailwindV4CssRoots(options);
889
- this.options = getCompilerContext({
890
- ...options,
891
- __internalDeferMissingCssEntriesWarning: true
892
- });
893
- this.appType = this.options.appType;
894
- }
895
- apply(compiler) {
896
- compiler.options = compiler.options || {};
897
- const { disabled, onLoad, runtimeLoaderPath, twPatcher: initialTwPatcher, refreshTailwindcssPatcher } = this.options;
898
- const disabledOptions = resolvePluginDisabledState(disabled);
899
- const isTailwindcssV4 = (initialTwPatcher.majorVersion ?? 0) >= 4;
900
- const generatorOptions = normalizeWeappTailwindcssGeneratorOptions(this.options.generator);
901
- const shouldRewriteCssImports = isTailwindcssV4 || generatorOptions.target === "web";
902
- const isMpxApp = isMpx(this.appType);
903
- if (shouldRewriteCssImports) setupMpxTailwindcssRedirect(weappTailwindcssPackageDir, isMpxApp);
904
- if (disabledOptions.plugin) return;
905
- setupWebpackWatchOutputIgnore(compiler);
906
- const runtimeState = {
907
- twPatcher: initialTwPatcher,
908
- readyPromise: createTailwindRuntimeReadyPromise(initialTwPatcher),
909
- refreshTailwindcssPatcher
910
- };
911
- let runtimeSetPrepared = false;
912
- let runtimeSetSignature;
913
- let runtimeRefreshRequiredForCompilation = false;
914
- let watchRunObserved = false;
915
- const runtimeWatchDependencyFiles = /* @__PURE__ */ new Set();
916
- const runtimeWatchDependencyContexts = /* @__PURE__ */ new Set();
917
- const webpackProcessedCssSourceFiles = /* @__PURE__ */ new Set();
918
- let runtimeMetadataPrepared = false;
919
- const updateRuntimeWatchDependencies = async () => {
920
- runtimeWatchDependencyFiles.clear();
921
- runtimeWatchDependencyContexts.clear();
922
- const tailwindOptions = resolveTailwindcssOptions(runtimeState.twPatcher.options);
923
- if (tailwindOptions?.config) runtimeWatchDependencyFiles.add(tailwindOptions.config);
924
- for (const entry of tailwindOptions?.v4?.cssEntries ?? []) runtimeWatchDependencyFiles.add(entry);
925
- for (const source of tailwindOptions?.v4?.cssSources ?? []) {
926
- if (source.file) runtimeWatchDependencyFiles.add(source.file);
927
- for (const dependency of source.dependencies ?? []) runtimeWatchDependencyFiles.add(dependency);
928
- }
929
- for (const source of tailwindOptions?.v4?.sources ?? []) if (source?.base) runtimeWatchDependencyContexts.add(source.base);
930
- if (typeof runtimeState.twPatcher.collectContentTokens !== "function") return;
931
- try {
932
- const report = await runtimeState.twPatcher.collectContentTokens();
933
- for (const entry of report.entries ?? []) if (entry.file) runtimeWatchDependencyFiles.add(entry.file);
934
- for (const source of report.sources ?? []) if (source?.base) runtimeWatchDependencyContexts.add(source.base);
935
- } catch (error) {
936
- debug("collect runtime watch dependencies failed: %O", error);
937
- }
938
- };
939
- const ensureRuntimeMetadata = async (force = false) => {
940
- if (runtimeMetadataPrepared && !force) return;
941
- await updateRuntimeWatchDependencies();
942
- runtimeMetadataPrepared = true;
943
- };
944
- const collectWatchChangedFiles = () => {
945
- const compilerLike = compiler;
946
- return new Set([...compilerLike.modifiedFiles ?? [], ...compilerLike.removedFiles ?? []]);
947
- };
948
- const hasRuntimeDependencyChanges = (files) => {
949
- for (const file of files) if (isWatchFileInRuntimeDependencies(file, {
950
- contexts: runtimeWatchDependencyContexts,
951
- files: runtimeWatchDependencyFiles
952
- })) return true;
953
- return false;
954
- };
955
- const syncRuntimeRefreshRequirement = (markWatchRun = false) => {
956
- if (markWatchRun) watchRunObserved = true;
957
- const changedFiles = collectWatchChangedFiles();
958
- runtimeRefreshRequiredForCompilation = runtimeRefreshRequiredForCompilation || hasRuntimeDependencyChanges(changedFiles);
959
- };
960
- const resetRuntimePreparation = () => {
961
- runtimeSetPrepared = false;
962
- syncRuntimeRefreshRequirement();
963
- };
964
- const registerAutoCssSource = async (source) => {
965
- if (this.hasInitialTailwindCssRoots || (runtimeState.twPatcher.majorVersion ?? 0) < 4 || !source.file) return;
966
- if (!upsertTailwindV4CssSource(this.options, source)) return;
967
- runtimeSetPrepared = false;
968
- runtimeMetadataPrepared = false;
969
- runtimeRefreshRequiredForCompilation = true;
970
- await refreshTailwindRuntimeState(runtimeState, {
971
- force: true,
972
- clearCache: true
973
- });
974
- debug("detected tailwindcss v4 css source from webpack css module: %s", source.file);
975
- };
976
- const markWebpackProcessedCssSource = (file) => {
977
- webpackProcessedCssSourceFiles.add(path.resolve(file));
978
- };
979
- const isWebpackProcessedTailwindEntryAsset = (file) => {
980
- if ((runtimeState.twPatcher.majorVersion ?? 0) < 4 || !this.options.mainCssChunkMatcher(file, this.appType) || webpackProcessedCssSourceFiles.size === 0) return false;
981
- const tailwindOptions = resolveTailwindcssOptions(runtimeState.twPatcher.options);
982
- for (const entry of tailwindOptions?.v4?.cssEntries ?? []) if (webpackProcessedCssSourceFiles.has(path.resolve(entry))) return true;
983
- for (const source of tailwindOptions?.v4?.cssSources ?? []) if (source.file && webpackProcessedCssSourceFiles.has(path.resolve(source.file))) return true;
984
- return false;
985
- };
986
- compiler.hooks.invalid?.tap?.(pluginName, (fileName) => {
987
- if (!fileName) return;
988
- runtimeRefreshRequiredForCompilation = runtimeRefreshRequiredForCompilation || hasRuntimeDependencyChanges([path.resolve(fileName)]);
989
- });
990
- compiler.hooks.watchRun?.tap?.(pluginName, () => syncRuntimeRefreshRequirement(true));
991
- if (compiler.hooks.thisCompilation?.tap) compiler.hooks.thisCompilation.tap(pluginName, resetRuntimePreparation);
992
- else if (compiler.hooks.compilation?.tap) compiler.hooks.compilation.tap(pluginName, resetRuntimePreparation);
993
- async function getClassSetInLoader() {
994
- if (runtimeSetPrepared) return;
995
- const signature = getRuntimeClassSetSignature(runtimeState.twPatcher);
996
- const forceRefresh = runtimeRefreshRequiredForCompilation || signature !== runtimeSetSignature;
997
- debug("runtime loader ensure class set forceRefresh=%s watchDirty=%s signatureChanged=%s", forceRefresh, runtimeRefreshRequiredForCompilation, signature !== runtimeSetSignature);
998
- runtimeSetPrepared = true;
999
- await ensureRuntimeClassSet(runtimeState, {
1000
- forceRefresh,
1001
- forceCollect: forceRefresh || !watchRunObserved,
1002
- clearCache: forceRefresh,
1003
- allowEmpty: true
1004
- });
1005
- await ensureRuntimeMetadata(forceRefresh);
1006
- runtimeSetSignature = signature;
1007
- runtimeRefreshRequiredForCompilation = false;
1008
- }
1009
- async function getRuntimeSetInLoader() {
1010
- await getClassSetInLoader();
1011
- return ensureRuntimeClassSet(runtimeState, { allowEmpty: true });
1012
- }
1013
- onLoad();
1014
- setupWebpackV5Loaders({
1015
- compiler,
1016
- options: this.options,
1017
- appType: this.appType,
1018
- weappTailwindcssPackageDir,
1019
- shouldRewriteCssImports,
1020
- runtimeLoaderPath,
1021
- registerAutoCssSource,
1022
- runtimeState,
1023
- getClassSetInLoader,
1024
- getRuntimeSetInLoader,
1025
- markWebpackProcessedCssSource,
1026
- getRuntimeWatchDependencies() {
1027
- return {
1028
- files: runtimeWatchDependencyFiles,
1029
- contexts: runtimeWatchDependencyContexts
1030
- };
1031
- },
1032
- debug
1033
- });
1034
- setupWebpackV5ProcessAssetsHook({
1035
- compiler,
1036
- options: this.options,
1037
- appType: this.appType,
1038
- runtimeState,
1039
- getRuntimeRefreshRequirement: () => runtimeRefreshRequiredForCompilation,
1040
- refreshRuntimeMetadata: ensureRuntimeMetadata,
1041
- isWebpackProcessedCssAsset(file, rawSource) {
1042
- return webpackProcessedCssSourceFiles.has(path.resolve(file)) || isWebpackProcessedTailwindEntryAsset(file) || rawSource.includes("weapp-tailwindcss webpack-generated-css");
1043
- },
1044
- consumeRuntimeRefreshRequirement() {
1045
- runtimeRefreshRequiredForCompilation = false;
1046
- },
1047
- isWatchMode: () => watchRunObserved || compiler.options?.watch === true,
1048
- runtimeClassSetManager: this.options.__internalWebpackRuntimeClassSetManager,
1049
- debug
1050
- });
1051
- }
1052
- };
1053
- //#endregion
1054
- export { weappTailwindcssPackageDir as n, WeappTailwindcss as t };