weapp-tailwindcss 4.12.0 → 5.0.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (308) hide show
  1. package/dist/babel/index.d.ts +3 -0
  2. package/dist/bundlers/gulp/index.d.ts +7 -0
  3. package/dist/bundlers/shared/cache.d.ts +16 -0
  4. package/dist/bundlers/shared/css-cleanup.d.ts +4 -0
  5. package/dist/bundlers/shared/css-imports.d.ts +8 -0
  6. package/dist/bundlers/shared/generator-candidates.d.ts +5 -0
  7. package/dist/bundlers/shared/generator-css.d.ts +41 -0
  8. package/dist/bundlers/shared/module-graph.d.ts +5 -0
  9. package/dist/bundlers/shared/run-tasks.d.ts +2 -0
  10. package/dist/bundlers/vite/bundle-entries.d.ts +14 -0
  11. package/dist/bundlers/vite/bundle-state.d.ts +43 -0
  12. package/dist/bundlers/vite/css-finalizer.d.ts +19 -0
  13. package/dist/bundlers/vite/generate-bundle.d.ts +20 -0
  14. package/dist/bundlers/vite/incremental-runtime-class-set.d.ts +21 -0
  15. package/dist/bundlers/vite/index.d.ts +3 -0
  16. package/dist/bundlers/vite/js-precheck.d.ts +1 -0
  17. package/dist/bundlers/vite/query.d.ts +15 -0
  18. package/dist/bundlers/vite/resolve-app-type.d.ts +2 -0
  19. package/dist/bundlers/vite/rewrite-css-imports.d.ts +11 -0
  20. package/dist/bundlers/vite/runtime-affecting-signature.d.ts +2 -0
  21. package/dist/bundlers/vite/utils.d.ts +9 -0
  22. package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +20 -0
  23. package/dist/bundlers/webpack/BaseUnifiedPlugin/v4-assets.d.ts +14 -0
  24. package/dist/bundlers/webpack/BaseUnifiedPlugin/v4-loaders.d.ts +15 -0
  25. package/dist/bundlers/webpack/BaseUnifiedPlugin/v4.d.ts +9 -0
  26. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets.d.ts +17 -0
  27. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +19 -0
  28. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5.d.ts +9 -0
  29. package/dist/bundlers/webpack/index.d.ts +1 -0
  30. package/dist/bundlers/webpack/loaders/weapp-tw-css-import-rewrite-loader.d.ts +12 -0
  31. package/dist/bundlers/webpack/loaders/weapp-tw-runtime-classset-loader.d.ts +11 -0
  32. package/dist/bundlers/webpack/shared/css-imports.d.ts +6 -0
  33. package/dist/bundlers/webpack/shared/loader-anchors.d.ts +8 -0
  34. package/dist/cache/index.d.ts +38 -0
  35. package/dist/cache/md5.d.ts +1 -0
  36. package/dist/chunk-8l464Juk.js +28 -0
  37. package/dist/cli/config.d.ts +5 -0
  38. package/dist/cli/context.d.ts +16 -0
  39. package/dist/cli/doctor/constants.d.ts +7 -0
  40. package/dist/cli/doctor/types.d.ts +31 -0
  41. package/dist/cli/doctor.d.ts +4 -0
  42. package/dist/cli/helpers/options/format.d.ts +2 -0
  43. package/dist/cli/helpers/options/parse.d.ts +3 -0
  44. package/dist/cli/helpers/options/resolve.d.ts +1 -0
  45. package/dist/cli/helpers/options.d.ts +3 -0
  46. package/dist/cli/helpers/patch-cwd.d.ts +1 -0
  47. package/dist/cli/helpers.d.ts +5 -0
  48. package/dist/cli/mount-options/patch-status.d.ts +2 -0
  49. package/dist/cli/mount-options.d.ts +2 -0
  50. package/dist/cli/patch-options.d.ts +6 -0
  51. package/dist/cli/tokens.d.ts +4 -0
  52. package/dist/cli/types.d.ts +17 -0
  53. package/dist/cli/vscode-entry.d.ts +14 -0
  54. package/dist/cli/workspace/package-dirs.d.ts +3 -0
  55. package/dist/cli/workspace/patch-package.d.ts +3 -0
  56. package/dist/cli/workspace/patch-utils.d.ts +3 -0
  57. package/dist/cli/workspace/types.d.ts +11 -0
  58. package/dist/cli/workspace/workspace-globs.d.ts +2 -0
  59. package/dist/cli/workspace/workspace-io.d.ts +1 -0
  60. package/dist/cli/workspace/workspace-lock.d.ts +1 -0
  61. package/dist/cli/workspace.d.ts +2 -0
  62. package/dist/cli.d.ts +1 -2
  63. package/dist/cli.js +2425 -3524
  64. package/dist/cli.mjs +2402 -3505
  65. package/dist/constants-B-_T5UnW.mjs +44 -0
  66. package/dist/constants-p1dyh1x1.js +73 -0
  67. package/dist/constants.d.ts +13 -0
  68. package/dist/context/compiler-context-cache.d.ts +3 -0
  69. package/dist/context/custom-attributes.d.ts +2 -0
  70. package/dist/context/handlers.d.ts +6 -0
  71. package/dist/context/index.d.ts +7 -0
  72. package/dist/context/logger.d.ts +4 -0
  73. package/dist/context/tailwindcss/basedir.d.ts +1 -0
  74. package/dist/context/tailwindcss/rax.d.ts +2 -0
  75. package/dist/context/tailwindcss.d.ts +4 -0
  76. package/dist/context/workspace.d.ts +3 -0
  77. package/dist/core.d.ts +5 -21
  78. package/dist/core.js +138 -180
  79. package/dist/core.mjs +135 -180
  80. package/dist/css-imports-BbrbluP9.js +177 -0
  81. package/dist/css-imports-CSdPq_Sc.mjs +128 -0
  82. package/dist/css-macro/constants.d.ts +14 -0
  83. package/dist/css-macro/index.d.ts +15 -0
  84. package/dist/css-macro/postcss.d.ts +3 -7
  85. package/dist/css-macro/postcss.js +44 -58
  86. package/dist/css-macro/postcss.mjs +44 -56
  87. package/dist/css-macro.d.ts +1 -20
  88. package/dist/css-macro.js +37 -50
  89. package/dist/css-macro.mjs +33 -47
  90. package/dist/debug/index.d.ts +5 -0
  91. package/dist/defaults.d.ts +2 -11
  92. package/dist/defaults.js +132 -8
  93. package/dist/defaults.mjs +128 -7
  94. package/dist/escape.js +31 -54
  95. package/dist/escape.mjs +18 -25
  96. package/dist/experimental/index.d.ts +2 -0
  97. package/dist/experimental/oxc/ast-utils.d.ts +30 -0
  98. package/dist/experimental/oxc/index.d.ts +2 -0
  99. package/dist/experimental/oxc/module-specifiers.d.ts +2 -0
  100. package/dist/experimental/shared/cache.d.ts +3 -0
  101. package/dist/experimental/shared/transform.d.ts +3 -0
  102. package/dist/experimental/shared.d.ts +8 -0
  103. package/dist/experimental/swc/ast-utils.d.ts +30 -0
  104. package/dist/experimental/swc/index.d.ts +2 -0
  105. package/dist/experimental/swc/module-specifiers.d.ts +2 -0
  106. package/dist/generator/index.d.ts +11 -0
  107. package/dist/generator/options.d.ts +15 -0
  108. package/dist/generator/types.d.ts +19 -0
  109. package/dist/generator-CZ-JXw6T.js +492 -0
  110. package/dist/generator-Dwxgra97.mjs +399 -0
  111. package/dist/generator-css-CnYjiMrD.js +1084 -0
  112. package/dist/generator-css-DhPFjSzK.mjs +1057 -0
  113. package/dist/generator.d.ts +1 -0
  114. package/dist/generator.js +19 -0
  115. package/dist/generator.mjs +2 -0
  116. package/dist/gulp.d.ts +4 -24
  117. package/dist/gulp.js +271 -13
  118. package/dist/gulp.mjs +263 -13
  119. package/dist/index.d.ts +8 -15
  120. package/dist/index.js +12 -24
  121. package/dist/index.mjs +6 -24
  122. package/dist/js/JsTokenUpdater.d.ts +14 -0
  123. package/dist/js/ModuleGraph.d.ts +18 -0
  124. package/dist/js/NodePathWalker.d.ts +33 -0
  125. package/dist/js/babel/parse.d.ts +9 -0
  126. package/dist/js/babel/process.d.ts +4 -0
  127. package/dist/js/babel.d.ts +13 -0
  128. package/dist/js/class-context.d.ts +3 -0
  129. package/dist/js/evalTransforms.d.ts +7 -0
  130. package/dist/js/handlers.d.ts +5 -0
  131. package/dist/js/index.d.ts +4 -0
  132. package/dist/js/module-graph/ignored-exports.d.ts +18 -0
  133. package/dist/js/module-graph/types.d.ts +17 -0
  134. package/dist/js/node-path-walker/export-handlers.d.ts +12 -0
  135. package/dist/js/node-path-walker/import-tokens.d.ts +24 -0
  136. package/dist/js/precheck.d.ts +2 -0
  137. package/dist/js/sourceAnalysis.d.ts +17 -0
  138. package/dist/js/syntax.d.ts +10 -0
  139. package/dist/js/taggedTemplateIgnore.d.ts +13 -0
  140. package/dist/js/types.d.ts +11 -0
  141. package/dist/lightningcss/index.d.ts +8 -0
  142. package/dist/lightningcss/style-handler/options.d.ts +3 -0
  143. package/dist/lightningcss/style-handler/selector-transform.d.ts +10 -0
  144. package/dist/lightningcss/style-handler/selector-utils.d.ts +10 -0
  145. package/dist/lightningcss/style-handler.d.ts +17 -0
  146. package/dist/loader-anchors-DvwgIYdA.mjs +205 -0
  147. package/dist/loader-anchors-cprm4Klq.js +273 -0
  148. package/dist/logger/index.d.ts +2 -0
  149. package/dist/logger-BZ45DZJT.js +1003 -0
  150. package/dist/logger-BoVx1Dbt.mjs +935 -0
  151. package/dist/patcher-options-6gJN2EXy.js +115 -0
  152. package/dist/patcher-options-DQfR5xxT.mjs +92 -0
  153. package/dist/postcss-html-transform.d.ts +3 -3
  154. package/dist/postcss-html-transform.js +7 -10
  155. package/dist/postcss-html-transform.mjs +3 -6
  156. package/dist/postcss.d.ts +15 -0
  157. package/dist/postcss.js +278 -0
  158. package/dist/postcss.mjs +268 -0
  159. package/dist/presets/hbuilderx.d.ts +4 -0
  160. package/dist/presets/index.d.ts +3 -0
  161. package/dist/presets/shared.d.ts +10 -0
  162. package/dist/presets/taro.d.ts +4 -0
  163. package/dist/presets/uni-app-x.d.ts +16 -0
  164. package/dist/presets/uni-app.d.ts +4 -0
  165. package/dist/presets.d.ts +1 -76
  166. package/dist/presets.js +115 -163
  167. package/dist/presets.mjs +107 -163
  168. package/dist/recorder-B_XyZ576.mjs +2763 -0
  169. package/dist/recorder-rn_2v_nd.js +2878 -0
  170. package/dist/reset/index.d.ts +2 -0
  171. package/dist/reset.d.ts +1 -4
  172. package/dist/reset.js +19 -8
  173. package/dist/reset.mjs +2 -8
  174. package/dist/shared/classname-transform.d.ts +14 -0
  175. package/dist/shared/mpx.d.ts +7 -0
  176. package/dist/shared/tailwindcss-css-redirect.d.ts +1 -0
  177. package/dist/tailwindcss/index.d.ts +11 -0
  178. package/dist/tailwindcss/miniprogram.d.ts +1 -0
  179. package/dist/tailwindcss/patcher-options.d.ts +56 -0
  180. package/dist/tailwindcss/patcher-resolve.d.ts +4 -0
  181. package/dist/tailwindcss/patcher.d.ts +13 -0
  182. package/dist/tailwindcss/recorder.d.ts +13 -0
  183. package/dist/tailwindcss/remove-unsupported-css.d.ts +2 -0
  184. package/dist/tailwindcss/runtime/cache.d.ts +11 -0
  185. package/dist/tailwindcss/runtime-logs.d.ts +3 -0
  186. package/dist/tailwindcss/runtime.d.ts +29 -0
  187. package/dist/tailwindcss/targets/paths.d.ts +13 -0
  188. package/dist/tailwindcss/targets/record-io.d.ts +5 -0
  189. package/dist/tailwindcss/targets/recorder.d.ts +3 -0
  190. package/dist/tailwindcss/targets/types.d.ts +35 -0
  191. package/dist/tailwindcss/targets.d.ts +6 -0
  192. package/dist/tailwindcss/v3-engine/generator.d.ts +2 -0
  193. package/dist/tailwindcss/v3-engine/index.d.ts +4 -0
  194. package/dist/tailwindcss/v3-engine/miniprogram.d.ts +4 -0
  195. package/dist/tailwindcss/v3-engine/source.d.ts +5 -0
  196. package/dist/tailwindcss/v3-engine/types.d.ts +55 -0
  197. package/dist/tailwindcss/v4/config.d.ts +5 -0
  198. package/dist/tailwindcss/v4/css-entries.d.ts +7 -0
  199. package/dist/tailwindcss/v4/index.d.ts +2 -0
  200. package/dist/tailwindcss/v4/multi-patcher.d.ts +2 -0
  201. package/dist/tailwindcss/v4/patcher-options.d.ts +24 -0
  202. package/dist/tailwindcss/v4/patcher.d.ts +14 -0
  203. package/dist/tailwindcss/v4-engine/design-system.d.ts +1 -0
  204. package/dist/tailwindcss/v4-engine/generator.d.ts +2 -0
  205. package/dist/tailwindcss/v4-engine/index.d.ts +5 -0
  206. package/dist/tailwindcss/v4-engine/miniprogram.d.ts +4 -0
  207. package/dist/tailwindcss/v4-engine/source.d.ts +7 -0
  208. package/dist/tailwindcss/v4-engine/types.d.ts +17 -0
  209. package/dist/typedoc.export.d.ts +5 -0
  210. package/dist/types/base.d.ts +1 -0
  211. package/dist/types/disabled-options.d.ts +4 -0
  212. package/dist/types/index.d.ts +104 -0
  213. package/dist/types/shared.d.ts +7 -0
  214. package/dist/types/user-defined-options/general.d.ts +31 -0
  215. package/dist/types/user-defined-options/important.d.ts +37 -0
  216. package/dist/types/user-defined-options/index.d.ts +11 -0
  217. package/dist/types/user-defined-options/lifecycle.d.ts +6 -0
  218. package/dist/types/user-defined-options/matcher.d.ts +9 -0
  219. package/dist/types.d.ts +1 -150
  220. package/dist/types.js +0 -1
  221. package/dist/types.mjs +1 -1
  222. package/dist/uni-app-x/component-local-style.d.ts +19 -0
  223. package/dist/uni-app-x/index.d.ts +2 -0
  224. package/dist/uni-app-x/options.d.ts +12 -0
  225. package/dist/uni-app-x/style-isolation.d.ts +2 -0
  226. package/dist/uni-app-x/transform.d.ts +9 -0
  227. package/dist/uni-app-x/vite.d.ts +36 -0
  228. package/dist/utils/decode.d.ts +2 -0
  229. package/dist/utils/disabled.d.ts +6 -0
  230. package/dist/utils/hbuilderx.d.ts +5 -0
  231. package/dist/utils/index.d.ts +7 -0
  232. package/dist/utils/nameMatcher.d.ts +4 -0
  233. package/dist/utils/resolve-package.d.ts +1 -0
  234. package/dist/utils/uni-platform.d.ts +11 -0
  235. package/dist/utils-7DUGTFED.mjs +48 -0
  236. package/dist/utils-DmC9_In3.js +61 -0
  237. package/dist/vite-BHpAqldo.js +1952 -0
  238. package/dist/vite-C8JlHiyR.mjs +1940 -0
  239. package/dist/vite.d.ts +4 -17
  240. package/dist/vite.js +5 -14
  241. package/dist/vite.mjs +2 -14
  242. package/dist/weapp-tw-css-import-rewrite-loader.js +59 -92
  243. package/dist/weapp-tw-runtime-classset-loader.js +31 -50
  244. package/dist/webpack-CABjKGGQ.mjs +441 -0
  245. package/dist/webpack-DNIJ0ysE.js +456 -0
  246. package/dist/webpack.d.ts +4 -25
  247. package/dist/webpack.js +6 -17
  248. package/dist/webpack.mjs +2 -17
  249. package/dist/webpack4.d.ts +4 -26
  250. package/dist/webpack4.js +375 -481
  251. package/dist/webpack4.mjs +366 -482
  252. package/dist/wxml/Tokenizer.d.ts +15 -0
  253. package/dist/wxml/custom-attributes.d.ts +4 -0
  254. package/dist/wxml/index.d.ts +2 -0
  255. package/dist/wxml/shared.d.ts +2 -0
  256. package/dist/wxml/tokenizer/types.d.ts +18 -0
  257. package/dist/wxml/utils/codegen/legacy-rewriter.d.ts +2 -0
  258. package/dist/wxml/utils/codegen/legacy-visitor.d.ts +8 -0
  259. package/dist/wxml/utils/codegen.d.ts +2 -0
  260. package/dist/wxml/utils/custom-template.d.ts +3 -0
  261. package/dist/wxml/utils/fragment-helpers.d.ts +6 -0
  262. package/dist/wxml/utils/fragment-updater.d.ts +4 -0
  263. package/dist/wxml/utils/template-fragments.d.ts +3 -0
  264. package/dist/wxml/utils.d.ts +8 -0
  265. package/dist/wxml/whitespace.d.ts +2 -0
  266. package/generator-placeholder.css +1 -0
  267. package/package.json +19 -5
  268. package/dist/chunk-24AGZQVR.js +0 -183
  269. package/dist/chunk-3VQKDHGP.mjs +0 -179
  270. package/dist/chunk-4AFQP74Z.js +0 -24
  271. package/dist/chunk-57SOQCAU.mjs +0 -582
  272. package/dist/chunk-5ZYHNDEK.mjs +0 -2439
  273. package/dist/chunk-76S2EME4.mjs +0 -34
  274. package/dist/chunk-A5PB4KZT.js +0 -138
  275. package/dist/chunk-DUHYLR2R.js +0 -276
  276. package/dist/chunk-DYLQ6UOI.js +0 -71
  277. package/dist/chunk-E7I5TW5K.js +0 -52
  278. package/dist/chunk-FS2NOOEB.js +0 -292
  279. package/dist/chunk-HVNGIKLS.js +0 -3930
  280. package/dist/chunk-JZQBZHN5.js +0 -579
  281. package/dist/chunk-KGTVD4EP.mjs +0 -3930
  282. package/dist/chunk-NNOQDMUP.mjs +0 -10
  283. package/dist/chunk-OF6MFURR.js +0 -34
  284. package/dist/chunk-OFB2KBRP.js +0 -2442
  285. package/dist/chunk-OOHJLO5M.mjs +0 -71
  286. package/dist/chunk-PCDYXXSK.mjs +0 -1515
  287. package/dist/chunk-RKISS72P.js +0 -7
  288. package/dist/chunk-RRQZL7FQ.mjs +0 -292
  289. package/dist/chunk-XAKAD2CR.mjs +0 -138
  290. package/dist/chunk-XZP3MREK.mjs +0 -276
  291. package/dist/chunk-ZAA5ZG3D.js +0 -1518
  292. package/dist/chunk-ZCH4YINE.mjs +0 -52
  293. package/dist/cli.d.mts +0 -2
  294. package/dist/core.d.mts +0 -26
  295. package/dist/css-macro/postcss.d.mts +0 -7
  296. package/dist/css-macro.d.mts +0 -18
  297. package/dist/defaults.d.mts +0 -11
  298. package/dist/gulp.d.mts +0 -24
  299. package/dist/index-BXrmQelt.d.mts +0 -672
  300. package/dist/index-BXrmQelt.d.ts +0 -672
  301. package/dist/index.d.mts +0 -15
  302. package/dist/postcss-html-transform.d.mts +0 -2
  303. package/dist/presets.d.mts +0 -76
  304. package/dist/reset.d.mts +0 -1
  305. package/dist/types.d.mts +0 -150
  306. package/dist/vite.d.mts +0 -17
  307. package/dist/webpack.d.mts +0 -25
  308. package/dist/webpack4.d.mts +0 -26
package/dist/webpack4.mjs CHANGED
@@ -1,495 +1,379 @@
1
- import {
2
- applyTailwindcssCssImportRewrite,
3
- createAssetHashByChunkMap,
4
- createLoaderAnchorFinders,
5
- ensureMpxTailwindcssAliases,
6
- getCacheKey,
7
- hasLoaderEntry,
8
- injectMpxCssRewritePreRules,
9
- isCssLikeModuleResource,
10
- isMpx,
11
- patchMpxLoaderResolve,
12
- setupMpxTailwindcssRedirect
13
- } from "./chunk-RRQZL7FQ.mjs";
14
- import {
15
- pushConcurrentTaskFactories,
16
- resolveDisabledOptions,
17
- resolveOutputSpecifier,
18
- resolvePackageDir,
19
- toAbsoluteOutputPath
20
- } from "./chunk-3VQKDHGP.mjs";
21
- import {
22
- processCachedTask
23
- } from "./chunk-76S2EME4.mjs";
24
- import {
25
- createDebug,
26
- ensureRuntimeClassSet,
27
- getCompilerContext,
28
- pluginName,
29
- setupPatchRecorder,
30
- shouldSkipJsTransform
31
- } from "./chunk-KGTVD4EP.mjs";
32
- import {
33
- getRuntimeClassSetSignature
34
- } from "./chunk-PCDYXXSK.mjs";
35
- import "./chunk-XAKAD2CR.mjs";
36
- import {
37
- getGroupedEntries
38
- } from "./chunk-OOHJLO5M.mjs";
39
- import {
40
- __dirname
41
- } from "./chunk-NNOQDMUP.mjs";
42
-
43
- // src/bundlers/webpack/BaseUnifiedPlugin/v4.ts
44
- import process3 from "process";
45
-
46
- // src/bundlers/webpack/BaseUnifiedPlugin/v4-assets.ts
47
- import path from "path";
48
- import process from "process";
1
+ import { g as ensureRuntimeClassSet, n as shouldSkipJsTransform, p as pluginName, r as getCompilerContext, t as setupPatchRecorder, v as createDebug } from "./recorder-B_XyZ576.mjs";
2
+ import { r as getGroupedEntries } from "./utils-7DUGTFED.mjs";
3
+ import { d as getRuntimeClassSetSignature } from "./logger-BoVx1Dbt.mjs";
4
+ import { i as processCachedTask, t as generateCssByGenerator } from "./generator-css-DhPFjSzK.mjs";
5
+ import { a as resolveDisabledOptions, c as toAbsoluteOutputPath, i as resolvePackageDir, r as pushConcurrentTaskFactories, s as resolveOutputSpecifier } from "./css-imports-CSdPq_Sc.mjs";
6
+ import { a as hasLoaderEntry, c as applyTailwindcssCssImportRewrite, d as isMpx, f as patchMpxLoaderResolve, i as getCacheKey, l as ensureMpxTailwindcssAliases, n as __dirname, p as setupMpxTailwindcssRedirect, r as createAssetHashByChunkMap, s as isCssLikeModuleResource, t as createLoaderAnchorFinders, u as injectMpxCssRewritePreRules } from "./loader-anchors-DvwgIYdA.mjs";
7
+ import path from "node:path";
8
+ import process from "node:process";
9
+ import fs from "node:fs";
49
10
  import { ConcatSource } from "webpack-sources";
11
+ //#region src/bundlers/webpack/BaseUnifiedPlugin/v4-assets.ts
50
12
  function resolveWebpackStaleClassNameFallback(option, _compiler) {
51
- if (typeof option === "boolean") {
52
- return option;
53
- }
54
- return false;
13
+ if (typeof option === "boolean") return option;
14
+ return false;
55
15
  }
56
16
  function toWebpackV4AssetCompilation(compilation) {
57
- return compilation;
17
+ return compilation;
58
18
  }
59
19
  function readWebpackV4AssetSource(asset) {
60
- const source = asset.source();
61
- return typeof source === "string" ? source : source.toString();
20
+ const source = asset.source();
21
+ return typeof source === "string" ? source : source.toString();
62
22
  }
63
23
  function setupWebpackV4EmitHook(options) {
64
- const {
65
- compiler,
66
- options: compilerOptions,
67
- appType,
68
- runtimeState,
69
- debug: debug2
70
- } = options;
71
- const cssHandlerOptionsCache = /* @__PURE__ */ new Map();
72
- compiler.hooks.emit.tapPromise(pluginName, async (compilation) => {
73
- await runtimeState.patchPromise;
74
- compilerOptions.onStart();
75
- debug2("start");
76
- for (const chunk of compilation.chunks) {
77
- if (chunk.id && chunk.hash) {
78
- compilerOptions.cache.calcHashValueChanged(chunk.id, chunk.hash);
79
- }
80
- }
81
- const assetCompilation = toWebpackV4AssetCompilation(compilation);
82
- const assetHashByChunk = createAssetHashByChunkMap(compilation.chunks);
83
- const assets = assetCompilation.assets;
84
- const entries = Object.entries(assets);
85
- const outputDir = compiler.options?.output?.path ? path.resolve(compiler.options.output.path) : process.cwd();
86
- const jsAssets = /* @__PURE__ */ new Map();
87
- for (const [file] of entries) {
88
- if (compilerOptions.jsMatcher(file) || compilerOptions.wxsMatcher(file)) {
89
- const absolute = toAbsoluteOutputPath(file, outputDir);
90
- jsAssets.set(absolute, file);
91
- }
92
- }
93
- const moduleGraphOptions = {
94
- resolve(specifier, importer) {
95
- return resolveOutputSpecifier(specifier, importer, outputDir, (candidate) => jsAssets.has(candidate));
96
- },
97
- load: (id) => {
98
- const assetName = jsAssets.get(id);
99
- if (!assetName) {
100
- return void 0;
101
- }
102
- const assetSource = assetCompilation.assets[assetName];
103
- if (!assetSource) {
104
- return void 0;
105
- }
106
- return readWebpackV4AssetSource(assetSource);
107
- },
108
- filter(id) {
109
- return jsAssets.has(id);
110
- }
111
- };
112
- const applyLinkedResults = (linked) => {
113
- if (!linked) {
114
- return;
115
- }
116
- for (const [id, { code }] of Object.entries(linked)) {
117
- const assetName = jsAssets.get(id);
118
- if (!assetName) {
119
- continue;
120
- }
121
- const assetSource = assetCompilation.assets[assetName];
122
- if (!assetSource) {
123
- continue;
124
- }
125
- const previous = readWebpackV4AssetSource(assetSource);
126
- if (previous === code) {
127
- continue;
128
- }
129
- const source = new ConcatSource(code);
130
- assetCompilation.updateAsset(assetName, source);
131
- compilerOptions.onUpdate(assetName, previous, code);
132
- debug2("js linked handle: %s", assetName);
133
- }
134
- };
135
- const groupedEntries = getGroupedEntries(entries, compilerOptions);
136
- const getCssHandlerOptions = (file) => {
137
- const majorVersion = runtimeState.twPatcher.majorVersion;
138
- const isMainChunk = compilerOptions.mainCssChunkMatcher(file, appType);
139
- const cacheKey = `${majorVersion ?? "unknown"}:${isMainChunk ? "1" : "0"}:${file}`;
140
- const cached = cssHandlerOptionsCache.get(cacheKey);
141
- if (cached) {
142
- return cached;
143
- }
144
- const created = {
145
- isMainChunk,
146
- postcssOptions: {
147
- options: {
148
- from: file
149
- }
150
- },
151
- majorVersion
152
- };
153
- cssHandlerOptionsCache.set(cacheKey, created);
154
- return created;
155
- };
156
- const staleClassNameFallback = resolveWebpackStaleClassNameFallback(compilerOptions.staleClassNameFallback, compiler);
157
- const runtimeSet = await ensureRuntimeClassSet(runtimeState, {
158
- // webpack 的 script-only 热更新可能不会触发 runtime classset loader,
159
- // 这里强制收集可避免沿用上轮 class set,保证 JS 仅按最新集合精确命中。
160
- forceCollect: true,
161
- allowEmpty: false
162
- });
163
- const defaultTemplateHandlerOptions = {
164
- runtimeSet
165
- };
166
- debug2("get runtimeSet, class count: %d", runtimeSet.size);
167
- const tasks = [];
168
- if (Array.isArray(groupedEntries.html)) {
169
- for (const element of groupedEntries.html) {
170
- const [file, originalSource] = element;
171
- const rawSource = readWebpackV4AssetSource(originalSource);
172
- const cacheKey = file;
173
- const chunkHash = assetHashByChunk.get(file);
174
- tasks.push(
175
- processCachedTask({
176
- cache: compilerOptions.cache,
177
- cacheKey,
178
- hashKey: `${file}:asset`,
179
- rawSource,
180
- hash: chunkHash,
181
- applyResult(source) {
182
- assetCompilation.updateAsset(file, source);
183
- },
184
- onCacheHit() {
185
- debug2("html cache hit: %s", file);
186
- },
187
- transform: async () => {
188
- const wxml = await compilerOptions.templateHandler(rawSource, defaultTemplateHandlerOptions);
189
- const source = new ConcatSource(wxml);
190
- compilerOptions.onUpdate(file, rawSource, wxml);
191
- debug2("html handle: %s", file);
192
- return {
193
- result: source
194
- };
195
- }
196
- })
197
- );
198
- }
199
- }
200
- const jsTaskFactories = [];
201
- if (Array.isArray(groupedEntries.js)) {
202
- for (const [file] of groupedEntries.js) {
203
- const cacheKey = getCacheKey(file);
204
- const assetSource = assetCompilation.assets[file];
205
- if (!assetSource) {
206
- continue;
207
- }
208
- const initialRawSource = readWebpackV4AssetSource(assetSource);
209
- const absoluteFile = toAbsoluteOutputPath(file, outputDir);
210
- const chunkHash = assetHashByChunk.get(file);
211
- const sourceAwareHash = chunkHash ? `${chunkHash}:${compilerOptions.cache.computeHash(initialRawSource)}` : void 0;
212
- jsTaskFactories.push(async () => {
213
- await processCachedTask({
214
- cache: compilerOptions.cache,
215
- cacheKey,
216
- hashKey: `${file}:asset`,
217
- rawSource: initialRawSource,
218
- hash: sourceAwareHash,
219
- applyResult(source) {
220
- assetCompilation.updateAsset(file, source);
221
- },
222
- onCacheHit() {
223
- debug2("js cache hit: %s", file);
224
- },
225
- transform: async () => {
226
- const currentAsset = assetCompilation.assets[file];
227
- const currentSource = currentAsset ? readWebpackV4AssetSource(currentAsset) : "";
228
- const handlerOptions = {
229
- staleClassNameFallback,
230
- tailwindcssMajorVersion: runtimeState.twPatcher.majorVersion,
231
- filename: absoluteFile,
232
- moduleGraph: moduleGraphOptions,
233
- babelParserOptions: {
234
- sourceFilename: absoluteFile
235
- }
236
- };
237
- if (shouldSkipJsTransform(currentSource, handlerOptions)) {
238
- return { result: new ConcatSource(currentSource) };
239
- }
240
- const { code, linked } = await compilerOptions.jsHandler(currentSource, runtimeSet, handlerOptions);
241
- const source = new ConcatSource(code);
242
- compilerOptions.onUpdate(file, currentSource, code);
243
- debug2("js handle: %s", file);
244
- applyLinkedResults(linked);
245
- return {
246
- result: source
247
- };
248
- }
249
- });
250
- });
251
- }
252
- }
253
- if (Array.isArray(groupedEntries.css)) {
254
- for (const element of groupedEntries.css) {
255
- const [file, originalSource] = element;
256
- const rawSource = readWebpackV4AssetSource(originalSource);
257
- const cacheKey = file;
258
- const chunkHash = assetHashByChunk.get(file);
259
- tasks.push(
260
- processCachedTask({
261
- cache: compilerOptions.cache,
262
- cacheKey,
263
- hashKey: `${file}:asset`,
264
- rawSource,
265
- hash: chunkHash,
266
- applyResult(source) {
267
- assetCompilation.updateAsset(file, source);
268
- },
269
- onCacheHit() {
270
- debug2("css cache hit: %s", file);
271
- },
272
- transform: async () => {
273
- await runtimeState.patchPromise;
274
- const { css } = await compilerOptions.styleHandler(rawSource, getCssHandlerOptions(file));
275
- const source = new ConcatSource(css);
276
- compilerOptions.onUpdate(file, rawSource, css);
277
- debug2("css handle: %s", file);
278
- return {
279
- result: source
280
- };
281
- }
282
- })
283
- );
284
- }
285
- }
286
- pushConcurrentTaskFactories(tasks, jsTaskFactories);
287
- await Promise.all(tasks);
288
- debug2("end");
289
- compilerOptions.onEnd();
290
- });
24
+ const { compiler, options: compilerOptions, appType, runtimeState, debug } = options;
25
+ const cssHandlerOptionsCache = /* @__PURE__ */ new Map();
26
+ const cssUserHandlerOptionsCache = /* @__PURE__ */ new Map();
27
+ compiler.hooks.emit.tapPromise(pluginName, async (compilation) => {
28
+ await runtimeState.patchPromise;
29
+ compilerOptions.onStart();
30
+ debug("start");
31
+ for (const chunk of compilation.chunks) if (chunk.id && chunk.hash) compilerOptions.cache.calcHashValueChanged(chunk.id, chunk.hash);
32
+ const assetCompilation = toWebpackV4AssetCompilation(compilation);
33
+ const assetHashByChunk = createAssetHashByChunkMap(compilation.chunks);
34
+ const assets = assetCompilation.assets;
35
+ const entries = Object.entries(assets);
36
+ const outputDir = compiler.options?.output?.path ? path.resolve(compiler.options.output.path) : process.cwd();
37
+ const jsAssets = /* @__PURE__ */ new Map();
38
+ for (const [file] of entries) if (compilerOptions.jsMatcher(file) || compilerOptions.wxsMatcher(file)) {
39
+ const absolute = toAbsoluteOutputPath(file, outputDir);
40
+ jsAssets.set(absolute, file);
41
+ }
42
+ const moduleGraphOptions = {
43
+ resolve(specifier, importer) {
44
+ return resolveOutputSpecifier(specifier, importer, outputDir, (candidate) => jsAssets.has(candidate));
45
+ },
46
+ load: (id) => {
47
+ const assetName = jsAssets.get(id);
48
+ if (!assetName) return;
49
+ const assetSource = assetCompilation.assets[assetName];
50
+ if (!assetSource) return;
51
+ return readWebpackV4AssetSource(assetSource);
52
+ },
53
+ filter(id) {
54
+ return jsAssets.has(id);
55
+ }
56
+ };
57
+ const applyLinkedResults = (linked) => {
58
+ if (!linked) return;
59
+ for (const [id, { code }] of Object.entries(linked)) {
60
+ const assetName = jsAssets.get(id);
61
+ if (!assetName) continue;
62
+ const assetSource = assetCompilation.assets[assetName];
63
+ if (!assetSource) continue;
64
+ const previous = readWebpackV4AssetSource(assetSource);
65
+ if (previous === code) continue;
66
+ const source = new ConcatSource(code);
67
+ assetCompilation.updateAsset(assetName, source);
68
+ compilerOptions.onUpdate(assetName, previous, code);
69
+ debug("js linked handle: %s", assetName);
70
+ }
71
+ };
72
+ const groupedEntries = getGroupedEntries(entries, compilerOptions);
73
+ const getCssHandlerOptions = (file) => {
74
+ const majorVersion = runtimeState.twPatcher.majorVersion;
75
+ const isMainChunk = compilerOptions.mainCssChunkMatcher(file, appType);
76
+ const cacheKey = `${majorVersion ?? "unknown"}:${isMainChunk ? "1" : "0"}:${file}`;
77
+ const cached = cssHandlerOptionsCache.get(cacheKey);
78
+ if (cached) return cached;
79
+ const created = {
80
+ isMainChunk,
81
+ postcssOptions: { options: { from: file } },
82
+ majorVersion
83
+ };
84
+ cssHandlerOptionsCache.set(cacheKey, created);
85
+ return created;
86
+ };
87
+ const getCssUserHandlerOptions = (file) => {
88
+ const cacheKey = `${runtimeState.twPatcher.majorVersion ?? "unknown"}:${file}`;
89
+ const cached = cssUserHandlerOptionsCache.get(cacheKey);
90
+ if (cached) return cached;
91
+ const created = {
92
+ ...getCssHandlerOptions(file),
93
+ isMainChunk: false
94
+ };
95
+ cssUserHandlerOptionsCache.set(cacheKey, created);
96
+ return created;
97
+ };
98
+ const staleClassNameFallback = resolveWebpackStaleClassNameFallback(compilerOptions.staleClassNameFallback, compiler);
99
+ const runtimeSet = await ensureRuntimeClassSet(runtimeState, {
100
+ forceCollect: true,
101
+ allowEmpty: false
102
+ });
103
+ const defaultTemplateHandlerOptions = { runtimeSet };
104
+ debug("get runtimeSet, class count: %d", runtimeSet.size);
105
+ const tasks = [];
106
+ if (Array.isArray(groupedEntries.html)) for (const element of groupedEntries.html) {
107
+ const [file, originalSource] = element;
108
+ const rawSource = readWebpackV4AssetSource(originalSource);
109
+ const cacheKey = file;
110
+ const chunkHash = assetHashByChunk.get(file);
111
+ tasks.push(processCachedTask({
112
+ cache: compilerOptions.cache,
113
+ cacheKey,
114
+ hashKey: `${file}:asset`,
115
+ rawSource,
116
+ hash: chunkHash,
117
+ applyResult(source) {
118
+ assetCompilation.updateAsset(file, source);
119
+ },
120
+ onCacheHit() {
121
+ debug("html cache hit: %s", file);
122
+ },
123
+ transform: async () => {
124
+ const wxml = await compilerOptions.templateHandler(rawSource, defaultTemplateHandlerOptions);
125
+ const source = new ConcatSource(wxml);
126
+ compilerOptions.onUpdate(file, rawSource, wxml);
127
+ debug("html handle: %s", file);
128
+ return { result: source };
129
+ }
130
+ }));
131
+ }
132
+ const jsTaskFactories = [];
133
+ if (Array.isArray(groupedEntries.js)) for (const [file] of groupedEntries.js) {
134
+ const cacheKey = getCacheKey(file);
135
+ const assetSource = assetCompilation.assets[file];
136
+ if (!assetSource) continue;
137
+ const initialRawSource = readWebpackV4AssetSource(assetSource);
138
+ const absoluteFile = toAbsoluteOutputPath(file, outputDir);
139
+ const chunkHash = assetHashByChunk.get(file);
140
+ const sourceAwareHash = chunkHash ? `${chunkHash}:${compilerOptions.cache.computeHash(initialRawSource)}` : void 0;
141
+ jsTaskFactories.push(async () => {
142
+ await processCachedTask({
143
+ cache: compilerOptions.cache,
144
+ cacheKey,
145
+ hashKey: `${file}:asset`,
146
+ rawSource: initialRawSource,
147
+ hash: sourceAwareHash,
148
+ applyResult(source) {
149
+ assetCompilation.updateAsset(file, source);
150
+ },
151
+ onCacheHit() {
152
+ debug("js cache hit: %s", file);
153
+ },
154
+ transform: async () => {
155
+ const currentAsset = assetCompilation.assets[file];
156
+ const currentSource = currentAsset ? readWebpackV4AssetSource(currentAsset) : "";
157
+ const handlerOptions = {
158
+ staleClassNameFallback,
159
+ tailwindcssMajorVersion: runtimeState.twPatcher.majorVersion,
160
+ filename: absoluteFile,
161
+ moduleGraph: moduleGraphOptions,
162
+ babelParserOptions: { sourceFilename: absoluteFile }
163
+ };
164
+ if (shouldSkipJsTransform(currentSource, handlerOptions)) return { result: new ConcatSource(currentSource) };
165
+ const { code, linked } = await compilerOptions.jsHandler(currentSource, runtimeSet, handlerOptions);
166
+ const source = new ConcatSource(code);
167
+ compilerOptions.onUpdate(file, currentSource, code);
168
+ debug("js handle: %s", file);
169
+ applyLinkedResults(linked);
170
+ return { result: source };
171
+ }
172
+ });
173
+ });
174
+ }
175
+ if (Array.isArray(groupedEntries.css)) for (const element of groupedEntries.css) {
176
+ const [file, originalSource] = element;
177
+ const rawSource = readWebpackV4AssetSource(originalSource);
178
+ const cacheKey = file;
179
+ const chunkHash = assetHashByChunk.get(file);
180
+ tasks.push(processCachedTask({
181
+ cache: compilerOptions.cache,
182
+ cacheKey,
183
+ hashKey: `${file}:asset`,
184
+ rawSource,
185
+ hash: chunkHash,
186
+ applyResult(source) {
187
+ assetCompilation.updateAsset(file, source);
188
+ },
189
+ onCacheHit() {
190
+ debug("css cache hit: %s", file);
191
+ },
192
+ transform: async () => {
193
+ await runtimeState.patchPromise;
194
+ const cssHandlerOptions = getCssHandlerOptions(file);
195
+ const generated = await generateCssByGenerator({
196
+ opts: compilerOptions,
197
+ runtimeState,
198
+ runtime: runtimeSet,
199
+ rawSource,
200
+ file,
201
+ cssHandlerOptions,
202
+ cssUserHandlerOptions: getCssUserHandlerOptions(file),
203
+ styleHandler: compilerOptions.styleHandler,
204
+ debug
205
+ });
206
+ const css = generated?.css ?? (await compilerOptions.styleHandler(rawSource, cssHandlerOptions)).css;
207
+ const source = new ConcatSource(css);
208
+ compilerOptions.onUpdate(file, rawSource, css);
209
+ if (generated) debug("css handle via tailwind v%s engine(%s): %s", runtimeState.twPatcher.majorVersion, generated.target, file);
210
+ else debug("css handle: %s", file);
211
+ return { result: source };
212
+ }
213
+ }));
214
+ }
215
+ pushConcurrentTaskFactories(tasks, jsTaskFactories);
216
+ await Promise.all(tasks);
217
+ debug("end");
218
+ compilerOptions.onEnd();
219
+ });
291
220
  }
292
-
293
- // src/bundlers/webpack/BaseUnifiedPlugin/v4-loaders.ts
294
- import fs from "fs";
295
- import path2 from "path";
296
- import process2 from "process";
221
+ //#endregion
222
+ //#region src/bundlers/webpack/BaseUnifiedPlugin/v4-loaders.ts
297
223
  function setupWebpackV4Loaders(options) {
298
- const {
299
- compiler,
300
- options: compilerOptions,
301
- appType,
302
- weappTailwindcssPackageDir: weappTailwindcssPackageDir2,
303
- shouldRewriteCssImports,
304
- runtimeLoaderPath,
305
- runtimeCssImportRewriteLoaderPath,
306
- getClassSetInLoader,
307
- debug: debug2
308
- } = options;
309
- const isMpxApp = isMpx(appType);
310
- if (shouldRewriteCssImports && isMpxApp) {
311
- ensureMpxTailwindcssAliases(compiler, weappTailwindcssPackageDir2);
312
- }
313
- const runtimeClassSetLoader = runtimeLoaderPath ?? path2.resolve(__dirname, "./weapp-tw-runtime-classset-loader.js");
314
- const runtimeCssImportRewriteLoader = shouldRewriteCssImports ? runtimeCssImportRewriteLoaderPath ?? path2.resolve(__dirname, "./weapp-tw-css-import-rewrite-loader.js") : void 0;
315
- const runtimeClassSetLoaderExists = fs.existsSync(runtimeClassSetLoader);
316
- const runtimeCssImportRewriteLoaderExists = runtimeCssImportRewriteLoader ? fs.existsSync(runtimeCssImportRewriteLoader) : false;
317
- const runtimeLoaderRewriteOptions = shouldRewriteCssImports ? {
318
- pkgDir: weappTailwindcssPackageDir2,
319
- appType
320
- } : void 0;
321
- const classSetLoaderOptions = {
322
- getClassSet: getClassSetInLoader
323
- };
324
- const { findRewriteAnchor, findClassSetAnchor } = createLoaderAnchorFinders(appType);
325
- const cssImportRewriteLoaderOptions = runtimeLoaderRewriteOptions ? {
326
- rewriteCssImports: runtimeLoaderRewriteOptions
327
- } : void 0;
328
- if (runtimeCssImportRewriteLoader && shouldRewriteCssImports && cssImportRewriteLoaderOptions && isMpxApp) {
329
- injectMpxCssRewritePreRules(compiler, runtimeCssImportRewriteLoader, cssImportRewriteLoaderOptions);
330
- }
331
- const createRuntimeClassSetLoaderEntry = () => ({
332
- loader: runtimeClassSetLoader,
333
- options: classSetLoaderOptions,
334
- ident: null,
335
- type: null
336
- });
337
- const createCssImportRewriteLoaderEntry = () => {
338
- if (!runtimeCssImportRewriteLoader) {
339
- return null;
340
- }
341
- return {
342
- loader: runtimeCssImportRewriteLoader,
343
- options: cssImportRewriteLoaderOptions,
344
- ident: null,
345
- type: null
346
- };
347
- };
348
- compiler.hooks.compilation.tap(pluginName, (compilation) => {
349
- compilation.hooks.normalModuleLoader.tap(pluginName, (_loaderContext, module) => {
350
- const hasRuntimeLoader = runtimeClassSetLoaderExists || runtimeCssImportRewriteLoaderExists;
351
- if (!hasRuntimeLoader) {
352
- return;
353
- }
354
- if (shouldRewriteCssImports && isMpx(appType) && typeof _loaderContext.resolve === "function") {
355
- patchMpxLoaderResolve(_loaderContext, weappTailwindcssPackageDir2, true);
356
- }
357
- const loaderEntries = module.loaders || [];
358
- let rewriteAnchorIdx = findRewriteAnchor(loaderEntries);
359
- const classSetAnchorIdx = findClassSetAnchor(loaderEntries);
360
- const isCssModule = isCssLikeModuleResource(module.resource, compilerOptions.cssMatcher, appType);
361
- if (process2.env.WEAPP_TW_LOADER_DEBUG && isCssModule) {
362
- debug2("loader hook css module: %s loaders=%o anchors=%o", module.resource, loaderEntries.map((x) => x.loader), { rewriteAnchorIdx, classSetAnchorIdx });
363
- }
364
- if (process2.env.WEAPP_TW_LOADER_DEBUG && typeof module.resource === "string" && module.resource.includes("app.css")) {
365
- debug2("app.css module loaders=%o anchors=%o", loaderEntries.map((x) => x.loader), { rewriteAnchorIdx, classSetAnchorIdx });
366
- } else if (process2.env.WEAPP_TW_LOADER_DEBUG && typeof module.resource === "string" && module.resource.endsWith(".css")) {
367
- debug2("css module seen: %s loaders=%o anchors=%o", module.resource, loaderEntries.map((x) => x.loader), { rewriteAnchorIdx, classSetAnchorIdx });
368
- }
369
- if (rewriteAnchorIdx === -1 && classSetAnchorIdx === -1 && !isCssModule) {
370
- return;
371
- }
372
- const anchorlessInsert = (entry, position) => {
373
- if (position === "after") {
374
- loaderEntries.push(entry);
375
- } else {
376
- loaderEntries.unshift(entry);
377
- }
378
- };
379
- if (runtimeLoaderRewriteOptions && runtimeCssImportRewriteLoaderExists && cssImportRewriteLoaderOptions && runtimeCssImportRewriteLoader) {
380
- const existingIndex = loaderEntries.findIndex(
381
- (entry) => entry.loader?.includes?.(runtimeCssImportRewriteLoader)
382
- );
383
- const rewriteEntry = existingIndex !== -1 ? loaderEntries.splice(existingIndex, 1)[0] : createCssImportRewriteLoaderEntry();
384
- if (rewriteEntry) {
385
- const anchorIndex = findRewriteAnchor(loaderEntries);
386
- if (anchorIndex === -1) {
387
- anchorlessInsert(rewriteEntry, "after");
388
- } else {
389
- loaderEntries.splice(anchorIndex + 1, 0, rewriteEntry);
390
- }
391
- rewriteAnchorIdx = findRewriteAnchor(loaderEntries);
392
- }
393
- }
394
- if (runtimeClassSetLoaderExists && !hasLoaderEntry(loaderEntries, runtimeClassSetLoader)) {
395
- const anchorIndex = findClassSetAnchor(loaderEntries);
396
- if (anchorIndex === -1) {
397
- anchorlessInsert(createRuntimeClassSetLoaderEntry(), "before");
398
- } else {
399
- const insertIndex = anchorIndex === -1 ? rewriteAnchorIdx : anchorIndex;
400
- loaderEntries.splice(insertIndex, 0, createRuntimeClassSetLoaderEntry());
401
- }
402
- }
403
- });
404
- });
224
+ const { compiler, options: compilerOptions, appType, weappTailwindcssPackageDir, shouldRewriteCssImports, runtimeLoaderPath, runtimeCssImportRewriteLoaderPath, getClassSetInLoader, debug } = options;
225
+ const isMpxApp = isMpx(appType);
226
+ if (shouldRewriteCssImports && isMpxApp) ensureMpxTailwindcssAliases(compiler, weappTailwindcssPackageDir);
227
+ const runtimeClassSetLoader = runtimeLoaderPath ?? path.resolve(__dirname, "./weapp-tw-runtime-classset-loader.js");
228
+ const runtimeCssImportRewriteLoader = shouldRewriteCssImports ? runtimeCssImportRewriteLoaderPath ?? path.resolve(__dirname, "./weapp-tw-css-import-rewrite-loader.js") : void 0;
229
+ const runtimeClassSetLoaderExists = fs.existsSync(runtimeClassSetLoader);
230
+ const runtimeCssImportRewriteLoaderExists = runtimeCssImportRewriteLoader ? fs.existsSync(runtimeCssImportRewriteLoader) : false;
231
+ const runtimeLoaderRewriteOptions = shouldRewriteCssImports ? {
232
+ pkgDir: weappTailwindcssPackageDir,
233
+ appType
234
+ } : void 0;
235
+ const classSetLoaderOptions = { getClassSet: getClassSetInLoader };
236
+ const { findRewriteAnchor, findClassSetAnchor } = createLoaderAnchorFinders(appType);
237
+ const cssImportRewriteLoaderOptions = runtimeLoaderRewriteOptions ? { rewriteCssImports: runtimeLoaderRewriteOptions } : void 0;
238
+ if (runtimeCssImportRewriteLoader && shouldRewriteCssImports && cssImportRewriteLoaderOptions && isMpxApp) injectMpxCssRewritePreRules(compiler, runtimeCssImportRewriteLoader, cssImportRewriteLoaderOptions);
239
+ const createRuntimeClassSetLoaderEntry = () => ({
240
+ loader: runtimeClassSetLoader,
241
+ options: classSetLoaderOptions,
242
+ ident: null,
243
+ type: null
244
+ });
245
+ const createCssImportRewriteLoaderEntry = () => {
246
+ if (!runtimeCssImportRewriteLoader) return null;
247
+ return {
248
+ loader: runtimeCssImportRewriteLoader,
249
+ options: cssImportRewriteLoaderOptions,
250
+ ident: null,
251
+ type: null
252
+ };
253
+ };
254
+ compiler.hooks.compilation.tap(pluginName, (compilation) => {
255
+ compilation.hooks.normalModuleLoader.tap(pluginName, (_loaderContext, module) => {
256
+ if (!(runtimeClassSetLoaderExists || runtimeCssImportRewriteLoaderExists)) return;
257
+ if (shouldRewriteCssImports && isMpx(appType) && typeof _loaderContext.resolve === "function") patchMpxLoaderResolve(_loaderContext, weappTailwindcssPackageDir, true);
258
+ const loaderEntries = module.loaders || [];
259
+ let rewriteAnchorIdx = findRewriteAnchor(loaderEntries);
260
+ const classSetAnchorIdx = findClassSetAnchor(loaderEntries);
261
+ const isCssModule = isCssLikeModuleResource(module.resource, compilerOptions.cssMatcher, appType);
262
+ 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), {
263
+ rewriteAnchorIdx,
264
+ classSetAnchorIdx
265
+ });
266
+ 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), {
267
+ rewriteAnchorIdx,
268
+ classSetAnchorIdx
269
+ });
270
+ 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), {
271
+ rewriteAnchorIdx,
272
+ classSetAnchorIdx
273
+ });
274
+ if (rewriteAnchorIdx === -1 && classSetAnchorIdx === -1 && !isCssModule) return;
275
+ const anchorlessInsert = (entry, position) => {
276
+ if (position === "after") loaderEntries.push(entry);
277
+ else loaderEntries.unshift(entry);
278
+ };
279
+ if (runtimeLoaderRewriteOptions && runtimeCssImportRewriteLoaderExists && cssImportRewriteLoaderOptions && runtimeCssImportRewriteLoader) {
280
+ const existingIndex = loaderEntries.findIndex((entry) => entry.loader?.includes?.(runtimeCssImportRewriteLoader));
281
+ const rewriteEntry = existingIndex !== -1 ? loaderEntries.splice(existingIndex, 1)[0] : createCssImportRewriteLoaderEntry();
282
+ if (rewriteEntry) {
283
+ const anchorIndex = findRewriteAnchor(loaderEntries);
284
+ if (anchorIndex === -1) anchorlessInsert(rewriteEntry, "after");
285
+ else loaderEntries.splice(anchorIndex + 1, 0, rewriteEntry);
286
+ rewriteAnchorIdx = findRewriteAnchor(loaderEntries);
287
+ }
288
+ }
289
+ if (runtimeClassSetLoaderExists && !hasLoaderEntry(loaderEntries, runtimeClassSetLoader)) {
290
+ const anchorIndex = findClassSetAnchor(loaderEntries);
291
+ if (anchorIndex === -1) anchorlessInsert(createRuntimeClassSetLoaderEntry(), "before");
292
+ else {
293
+ const insertIndex = anchorIndex === -1 ? rewriteAnchorIdx : anchorIndex;
294
+ loaderEntries.splice(insertIndex, 0, createRuntimeClassSetLoaderEntry());
295
+ }
296
+ }
297
+ });
298
+ });
405
299
  }
406
-
407
- // src/bundlers/webpack/BaseUnifiedPlugin/v4.ts
408
- var debug = createDebug();
409
- var weappTailwindcssPackageDir = resolvePackageDir("weapp-tailwindcss");
300
+ //#endregion
301
+ //#region src/bundlers/webpack/BaseUnifiedPlugin/v4.ts
302
+ const debug = createDebug();
303
+ const weappTailwindcssPackageDir = resolvePackageDir("weapp-tailwindcss");
304
+ /**
305
+ * @name UnifiedWebpackPluginV4
306
+ * @description webpack4 核心转义插件
307
+ * @link https://tw.icebreaker.top/docs/intro
308
+ */
410
309
  var UnifiedWebpackPluginV4 = class {
411
- constructor(options = {}) {
412
- this.options = getCompilerContext(options);
413
- this.appType = this.options.appType;
414
- }
415
- apply(compiler) {
416
- compiler.options = compiler.options || {};
417
- const {
418
- disabled,
419
- onLoad,
420
- runtimeLoaderPath,
421
- runtimeCssImportRewriteLoaderPath,
422
- twPatcher: initialTwPatcher,
423
- refreshTailwindcssPatcher
424
- } = this.options;
425
- const disabledOptions = resolveDisabledOptions(disabled);
426
- const isTailwindcssV4 = (initialTwPatcher.majorVersion ?? 0) >= 4;
427
- const shouldRewriteCssImports = isTailwindcssV4 && this.options.rewriteCssImports !== false && !disabledOptions.rewriteCssImports;
428
- const isMpxApp = isMpx(this.appType);
429
- if (shouldRewriteCssImports) {
430
- applyTailwindcssCssImportRewrite(compiler, {
431
- pkgDir: weappTailwindcssPackageDir,
432
- enabled: true,
433
- appType: this.appType
434
- });
435
- setupMpxTailwindcssRedirect(weappTailwindcssPackageDir, isMpxApp);
436
- }
437
- if (disabledOptions.plugin) {
438
- return;
439
- }
440
- const patchRecorderState = setupPatchRecorder(initialTwPatcher, this.options.tailwindcssBasedir, {
441
- source: "runtime",
442
- cwd: this.options.tailwindcssBasedir ?? process3.cwd()
443
- });
444
- const runtimeState = {
445
- twPatcher: initialTwPatcher,
446
- patchPromise: patchRecorderState.patchPromise,
447
- refreshTailwindcssPatcher,
448
- onPatchCompleted: patchRecorderState.onPatchCompleted
449
- };
450
- let runtimeSetPrepared = false;
451
- let runtimeSetSignature;
452
- compiler.hooks.compilation.tap(pluginName, () => {
453
- runtimeSetPrepared = false;
454
- });
455
- async function getClassSetInLoader() {
456
- if (runtimeSetPrepared) {
457
- return;
458
- }
459
- const signature = getRuntimeClassSetSignature(runtimeState.twPatcher);
460
- const forceRefresh = signature !== runtimeSetSignature;
461
- runtimeSetPrepared = true;
462
- await ensureRuntimeClassSet(runtimeState, {
463
- forceRefresh,
464
- forceCollect: true,
465
- clearCache: forceRefresh,
466
- allowEmpty: true
467
- });
468
- runtimeSetSignature = signature;
469
- }
470
- onLoad();
471
- setupWebpackV4Loaders({
472
- compiler,
473
- options: this.options,
474
- appType: this.appType,
475
- weappTailwindcssPackageDir,
476
- shouldRewriteCssImports,
477
- runtimeLoaderPath,
478
- runtimeCssImportRewriteLoaderPath,
479
- getClassSetInLoader,
480
- debug
481
- });
482
- setupWebpackV4EmitHook({
483
- compiler,
484
- options: this.options,
485
- appType: this.appType,
486
- runtimeState,
487
- debug
488
- });
489
- }
490
- };
491
- export {
492
- UnifiedWebpackPluginV4,
493
- UnifiedWebpackPluginV4 as weappTailwindcss,
494
- weappTailwindcssPackageDir
310
+ constructor(options = {}) {
311
+ this.options = getCompilerContext(options);
312
+ this.appType = this.options.appType;
313
+ }
314
+ apply(compiler) {
315
+ compiler.options = compiler.options || {};
316
+ const { disabled, onLoad, runtimeLoaderPath, runtimeCssImportRewriteLoaderPath, twPatcher: initialTwPatcher, refreshTailwindcssPatcher } = this.options;
317
+ const disabledOptions = resolveDisabledOptions(disabled);
318
+ const shouldRewriteCssImports = (initialTwPatcher.majorVersion ?? 0) >= 4 && this.options.rewriteCssImports !== false && !disabledOptions.rewriteCssImports;
319
+ const isMpxApp = isMpx(this.appType);
320
+ if (shouldRewriteCssImports) {
321
+ applyTailwindcssCssImportRewrite(compiler, {
322
+ pkgDir: weappTailwindcssPackageDir,
323
+ enabled: true,
324
+ appType: this.appType
325
+ });
326
+ setupMpxTailwindcssRedirect(weappTailwindcssPackageDir, isMpxApp);
327
+ }
328
+ if (disabledOptions.plugin) return;
329
+ const patchRecorderState = setupPatchRecorder(initialTwPatcher, this.options.tailwindcssBasedir, {
330
+ source: "runtime",
331
+ cwd: this.options.tailwindcssBasedir ?? process.cwd()
332
+ });
333
+ const runtimeState = {
334
+ twPatcher: initialTwPatcher,
335
+ patchPromise: patchRecorderState.patchPromise,
336
+ refreshTailwindcssPatcher,
337
+ onPatchCompleted: patchRecorderState.onPatchCompleted
338
+ };
339
+ let runtimeSetPrepared = false;
340
+ let runtimeSetSignature;
341
+ compiler.hooks.compilation.tap(pluginName, () => {
342
+ runtimeSetPrepared = false;
343
+ });
344
+ async function getClassSetInLoader() {
345
+ if (runtimeSetPrepared) return;
346
+ const signature = getRuntimeClassSetSignature(runtimeState.twPatcher);
347
+ const forceRefresh = signature !== runtimeSetSignature;
348
+ runtimeSetPrepared = true;
349
+ await ensureRuntimeClassSet(runtimeState, {
350
+ forceRefresh,
351
+ forceCollect: true,
352
+ clearCache: forceRefresh,
353
+ allowEmpty: true
354
+ });
355
+ runtimeSetSignature = signature;
356
+ }
357
+ onLoad();
358
+ setupWebpackV4Loaders({
359
+ compiler,
360
+ options: this.options,
361
+ appType: this.appType,
362
+ weappTailwindcssPackageDir,
363
+ shouldRewriteCssImports,
364
+ runtimeLoaderPath,
365
+ runtimeCssImportRewriteLoaderPath,
366
+ getClassSetInLoader,
367
+ debug
368
+ });
369
+ setupWebpackV4EmitHook({
370
+ compiler,
371
+ options: this.options,
372
+ appType: this.appType,
373
+ runtimeState,
374
+ debug
375
+ });
376
+ }
495
377
  };
378
+ //#endregion
379
+ export { UnifiedWebpackPluginV4, UnifiedWebpackPluginV4 as WeappTailwindcss, UnifiedWebpackPluginV4 as weappTailwindcss, weappTailwindcssPackageDir };