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