weapp-tailwindcss 5.0.0-next.3 → 5.0.0-next.31

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 (244) hide show
  1. package/README.md +6 -7
  2. package/bin/weapp-tailwindcss.js +1 -21
  3. package/dist/auto-TH1jG2UW.js +115 -0
  4. package/dist/auto-XyKTOP7B.mjs +78 -0
  5. package/dist/bundle-state-Bi-cQua6.mjs +413 -0
  6. package/dist/bundle-state-Ct_8GcSR.js +529 -0
  7. package/dist/bundlers/shared/cache.d.ts +6 -6
  8. package/dist/bundlers/shared/css-cleanup/at-rules.d.ts +1 -0
  9. package/dist/bundlers/shared/css-cleanup.d.ts +1 -4
  10. package/dist/bundlers/shared/css-imports.d.ts +3 -3
  11. package/dist/bundlers/shared/generated-css-marker.d.ts +3 -0
  12. package/dist/bundlers/shared/generator-css/config-directive.d.ts +2 -0
  13. package/dist/bundlers/shared/generator-css/directives.d.ts +21 -0
  14. package/dist/bundlers/shared/generator-css/legacy-compat.d.ts +7 -0
  15. package/dist/bundlers/shared/generator-css/legacy-selectors.d.ts +5 -0
  16. package/dist/bundlers/shared/generator-css/legacy-units.d.ts +1 -0
  17. package/dist/bundlers/shared/generator-css/markers.d.ts +28 -0
  18. package/dist/bundlers/shared/generator-css/source-files.d.ts +14 -0
  19. package/dist/bundlers/shared/generator-css/source-resolver.d.ts +24 -0
  20. package/dist/bundlers/shared/generator-css/user-layer-order.d.ts +10 -0
  21. package/dist/bundlers/shared/generator-css.d.ts +16 -22
  22. package/dist/bundlers/shared/hmr-timing.d.ts +22 -0
  23. package/dist/bundlers/shared/style-requests.d.ts +2 -0
  24. package/dist/bundlers/vite/bundle-state.d.ts +1 -0
  25. package/dist/bundlers/vite/css-finalizer.d.ts +7 -1
  26. package/dist/bundlers/vite/generate-bundle/candidates.d.ts +2 -0
  27. package/dist/bundlers/vite/generate-bundle/css-handler-options.d.ts +24 -0
  28. package/dist/bundlers/vite/generate-bundle/css-share-scope.d.ts +4 -0
  29. package/dist/bundlers/vite/generate-bundle/dirty-state.d.ts +1 -0
  30. package/dist/bundlers/vite/generate-bundle/js-entries.d.ts +2 -0
  31. package/dist/bundlers/vite/generate-bundle/js-handler-options.d.ts +8 -0
  32. package/dist/bundlers/vite/generate-bundle/js-linking.d.ts +13 -0
  33. package/dist/bundlers/vite/generate-bundle/metrics.d.ts +17 -0
  34. package/dist/bundlers/vite/generate-bundle/process-plan.d.ts +9 -0
  35. package/dist/bundlers/vite/generate-bundle/rollup-assets.d.ts +7 -0
  36. package/dist/bundlers/vite/generate-bundle/signatures.d.ts +8 -0
  37. package/dist/bundlers/vite/generate-bundle.d.ts +14 -2
  38. package/dist/bundlers/vite/incremental-runtime-class-set.d.ts +5 -1
  39. package/dist/bundlers/vite/index.d.ts +5 -2
  40. package/dist/bundlers/vite/official-tailwind-plugins.d.ts +5 -0
  41. package/dist/bundlers/vite/postcss-config.d.ts +6 -0
  42. package/dist/bundlers/vite/processed-css-assets.d.ts +32 -0
  43. package/dist/bundlers/vite/rewrite-css-imports.d.ts +8 -3
  44. package/dist/bundlers/vite/runtime-class-set.d.ts +25 -0
  45. package/dist/bundlers/vite/serve-css-generation.d.ts +11 -0
  46. package/dist/bundlers/vite/source-candidates.d.ts +19 -1
  47. package/dist/bundlers/vite/source-scan.d.ts +26 -0
  48. package/dist/bundlers/vite/static-config-content.d.ts +5 -0
  49. package/dist/bundlers/vite/tailwind-basedir.d.ts +1 -0
  50. package/dist/bundlers/webpack/BaseUnifiedPlugin/shared.d.ts +6 -0
  51. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-assets.d.ts +6 -2
  52. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.d.ts +9 -3
  53. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5.d.ts +2 -1
  54. package/dist/bundlers/webpack/loaders/runtime-registry.d.ts +31 -0
  55. package/dist/bundlers/webpack/loaders/weapp-tw-css-import-rewrite-loader.d.ts +2 -6
  56. package/dist/bundlers/webpack/loaders/weapp-tw-runtime-classset-loader.d.ts +3 -7
  57. package/dist/cache/index.d.ts +6 -6
  58. package/dist/{chunk-8l464Juk.js → chunk-C5U5_Hdc.js} +14 -0
  59. package/dist/cli/context.d.ts +1 -14
  60. package/dist/cli/doctor/types.d.ts +11 -11
  61. package/dist/cli/helpers.d.ts +1 -2
  62. package/dist/cli/mount-options.d.ts +2 -0
  63. package/dist/cli/types.d.ts +0 -2
  64. package/dist/cli/vscode-entry.d.ts +3 -3
  65. package/dist/cli.js +758 -604
  66. package/dist/cli.mjs +766 -612
  67. package/dist/constants.d.ts +1 -2
  68. package/dist/context/runtime-package-replacements.d.ts +2 -0
  69. package/dist/context/style-options.d.ts +3 -0
  70. package/dist/core.js +12 -20
  71. package/dist/core.mjs +8 -14
  72. package/dist/css-macro/auto.d.ts +10 -0
  73. package/dist/css-macro/constants.d.ts +5 -2
  74. package/dist/css-macro/postcss.d.ts +1 -0
  75. package/dist/css-macro/postcss.js +7 -46
  76. package/dist/css-macro/postcss.mjs +2 -46
  77. package/dist/css-macro.d.ts +1 -0
  78. package/dist/css-macro.js +16 -7
  79. package/dist/css-macro.mjs +15 -6
  80. package/dist/defaults-8xrgzxFY.mjs +151 -0
  81. package/dist/defaults-zKUH2mDe.js +193 -0
  82. package/dist/defaults.d.ts +15 -1
  83. package/dist/defaults.js +6 -131
  84. package/dist/defaults.mjs +2 -129
  85. package/dist/escape.js +10 -2
  86. package/dist/escape.mjs +10 -2
  87. package/dist/generator/index.d.ts +1 -1
  88. package/dist/generator/options.d.ts +9 -8
  89. package/dist/generator/types.d.ts +3 -3
  90. package/dist/generator-CrU-Ghc1.js +90 -0
  91. package/dist/generator-Qw-tZ0Z2.mjs +65 -0
  92. package/dist/generator.js +12 -12
  93. package/dist/generator.mjs +2 -1
  94. package/dist/gulp.js +187 -48
  95. package/dist/gulp.mjs +180 -41
  96. package/dist/incremental-runtime-class-set-Boqi1QlB.mjs +2224 -0
  97. package/dist/incremental-runtime-class-set-FAOHZmzh.js +2293 -0
  98. package/dist/index.d.ts +3 -2
  99. package/dist/index.js +19 -7
  100. package/dist/index.mjs +6 -5
  101. package/dist/js/babel/cache-options.d.ts +3 -0
  102. package/dist/js/babel/parse.d.ts +7 -4
  103. package/dist/js/index.d.ts +1 -0
  104. package/dist/js/literal-transform.d.ts +2 -0
  105. package/dist/js/precheck.d.ts +2 -2
  106. package/dist/logger-BNzxZbZj.mjs +2 -0
  107. package/dist/logger-TlKT3xmR.js +1 -0
  108. package/dist/postcss/config-directive.d.ts +1 -0
  109. package/dist/postcss/context.d.ts +9 -0
  110. package/dist/postcss/source-files.d.ts +8 -0
  111. package/dist/postcss/tailwind-version.d.ts +3 -0
  112. package/dist/postcss-C6zOQqlL.mjs +228 -0
  113. package/dist/postcss-C7BMYpEF.mjs +169 -0
  114. package/dist/postcss-CiYLsqZn.js +192 -0
  115. package/dist/postcss-DAWf9D3C.js +237 -0
  116. package/dist/postcss-html-transform.js +1 -1
  117. package/dist/postcss.d.ts +2 -2
  118. package/dist/postcss.js +3 -276
  119. package/dist/postcss.mjs +1 -269
  120. package/dist/precheck-D7K12zeX.mjs +4716 -0
  121. package/dist/precheck-D7gJSmJz.js +4842 -0
  122. package/dist/presets/index.d.ts +1 -0
  123. package/dist/presets/uni-app-x.d.ts +1 -0
  124. package/dist/presets.js +29 -13
  125. package/dist/presets.mjs +25 -11
  126. package/dist/reset.d.ts +1 -0
  127. package/dist/reset.js +1 -1
  128. package/dist/runtime-registry-DpcR3IHI.js +5496 -0
  129. package/dist/shared/mpx.d.ts +1 -0
  130. package/dist/source-candidates-CX2ozpKM.mjs +322 -0
  131. package/dist/source-candidates-DNM8iwXW.js +335 -0
  132. package/dist/tailwindcss/miniprogram.d.ts +1 -1
  133. package/dist/tailwindcss/patcher-options.d.ts +3 -51
  134. package/dist/tailwindcss/patcher.d.ts +1 -2
  135. package/dist/tailwindcss/remove-unsupported-css.d.ts +1 -2
  136. package/dist/tailwindcss/runtime/cache.d.ts +4 -3
  137. package/dist/tailwindcss/runtime-patch.d.ts +5 -0
  138. package/dist/tailwindcss/runtime.d.ts +11 -12
  139. package/dist/tailwindcss/source-scan.d.ts +35 -0
  140. package/dist/tailwindcss/targets.d.ts +1 -5
  141. package/dist/tailwindcss/v3-engine/types.d.ts +17 -14
  142. package/dist/tailwindcss/v4/css-entries.d.ts +2 -2
  143. package/dist/tailwindcss/v4/css-sources.d.ts +5 -0
  144. package/dist/tailwindcss/v4/patcher-options.d.ts +1 -23
  145. package/dist/tailwindcss/v4/patcher.d.ts +1 -0
  146. package/dist/tailwindcss/v4-engine/source.d.ts +2 -2
  147. package/dist/tailwindcss/v4-engine/types.d.ts +17 -5
  148. package/dist/tailwindcss/version.d.ts +4 -0
  149. package/dist/tailwindcss-B-e2RiXr.js +642 -0
  150. package/dist/tailwindcss-C7dJHZ0G.mjs +591 -0
  151. package/dist/typedoc.export.d.ts +0 -2
  152. package/dist/types/index.d.ts +52 -49
  153. package/dist/types/shared.d.ts +6 -0
  154. package/dist/types/user-defined-options/general.d.ts +25 -24
  155. package/dist/types/user-defined-options/important.d.ts +33 -28
  156. package/dist/types/user-defined-options/lifecycle.d.ts +4 -4
  157. package/dist/types/user-defined-options/matcher.d.ts +6 -6
  158. package/dist/uni-app-x/vite.d.ts +1 -1
  159. package/dist/unocss/index.d.ts +2 -0
  160. package/dist/utils/disabled.d.ts +2 -3
  161. package/dist/utils/object.d.ts +9 -0
  162. package/dist/utils/options.d.ts +2 -0
  163. package/dist/utils/regex.d.ts +1 -0
  164. package/dist/{utils-DmC9_In3.js → utils-D7Ygohep.js} +2 -2
  165. package/dist/{utils-7DUGTFED.mjs → utils-DsaS975I.mjs} +1 -1
  166. package/dist/v3-engine-CHItlVq5.js +3616 -0
  167. package/dist/v3-engine-DcvCCHfs.mjs +3321 -0
  168. package/dist/vite-BgTPSkQS.js +24446 -0
  169. package/dist/vite-fFRpSvyz.mjs +24432 -0
  170. package/dist/vite.d.ts +1 -2
  171. package/dist/vite.js +3 -4
  172. package/dist/vite.mjs +2 -2
  173. package/dist/weapp-tw-css-import-rewrite-loader.js +5227 -18
  174. package/dist/weapp-tw-runtime-classset-loader.js +32 -9
  175. package/dist/webpack-BXSWVdXh.js +851 -0
  176. package/dist/webpack-Dx2AZpGU.mjs +841 -0
  177. package/dist/webpack.d.ts +1 -3
  178. package/dist/webpack.js +3 -4
  179. package/dist/webpack.mjs +2 -2
  180. package/package.json +38 -48
  181. package/dist/bundlers/shared/generator-candidates.d.ts +0 -5
  182. package/dist/bundlers/webpack/BaseUnifiedPlugin/v4-assets.d.ts +0 -14
  183. package/dist/bundlers/webpack/BaseUnifiedPlugin/v4-loaders.d.ts +0 -15
  184. package/dist/bundlers/webpack/BaseUnifiedPlugin/v4.d.ts +0 -9
  185. package/dist/bundlers/webpack/shared/css-imports.d.ts +0 -6
  186. package/dist/cli/config.d.ts +0 -5
  187. package/dist/cli/helpers/patch-cwd.d.ts +0 -1
  188. package/dist/cli/mount-options/patch-status.d.ts +0 -2
  189. package/dist/cli/patch-options.d.ts +0 -6
  190. package/dist/cli/tokens.d.ts +0 -4
  191. package/dist/cli/workspace/package-dirs.d.ts +0 -3
  192. package/dist/cli/workspace/patch-package.d.ts +0 -3
  193. package/dist/cli/workspace/patch-utils.d.ts +0 -3
  194. package/dist/cli/workspace/types.d.ts +0 -11
  195. package/dist/cli/workspace/workspace-globs.d.ts +0 -2
  196. package/dist/cli/workspace/workspace-io.d.ts +0 -1
  197. package/dist/cli/workspace/workspace-lock.d.ts +0 -1
  198. package/dist/cli/workspace.d.ts +0 -2
  199. package/dist/constants-B-_T5UnW.mjs +0 -44
  200. package/dist/constants-p1dyh1x1.js +0 -73
  201. package/dist/css-imports-BbrbluP9.js +0 -177
  202. package/dist/css-imports-CSdPq_Sc.mjs +0 -128
  203. package/dist/experimental/index.d.ts +0 -2
  204. package/dist/experimental/oxc/ast-utils.d.ts +0 -30
  205. package/dist/experimental/oxc/index.d.ts +0 -2
  206. package/dist/experimental/oxc/module-specifiers.d.ts +0 -2
  207. package/dist/experimental/shared/cache.d.ts +0 -3
  208. package/dist/experimental/shared/transform.d.ts +0 -3
  209. package/dist/experimental/shared.d.ts +0 -8
  210. package/dist/experimental/swc/ast-utils.d.ts +0 -30
  211. package/dist/experimental/swc/index.d.ts +0 -2
  212. package/dist/experimental/swc/module-specifiers.d.ts +0 -2
  213. package/dist/generator-Y-Ikv4Fu.mjs +0 -1177
  214. package/dist/generator-css-Bwy_Uz89.mjs +0 -1097
  215. package/dist/generator-css-CRLrHW4F.js +0 -1124
  216. package/dist/generator-mmhXzZnv.js +0 -1276
  217. package/dist/js/syntax.d.ts +0 -10
  218. package/dist/lightningcss/index.d.ts +0 -8
  219. package/dist/lightningcss/style-handler/options.d.ts +0 -3
  220. package/dist/lightningcss/style-handler/selector-transform.d.ts +0 -10
  221. package/dist/lightningcss/style-handler/selector-utils.d.ts +0 -10
  222. package/dist/lightningcss/style-handler.d.ts +0 -17
  223. package/dist/loader-anchors-1MumTAtA.mjs +0 -205
  224. package/dist/loader-anchors-TrFvT6g1.js +0 -273
  225. package/dist/logger-BZ45DZJT.js +0 -1003
  226. package/dist/logger-BoVx1Dbt.mjs +0 -935
  227. package/dist/patcher-options-6gJN2EXy.js +0 -115
  228. package/dist/patcher-options-DQfR5xxT.mjs +0 -92
  229. package/dist/recorder-GdTJ3QqX.js +0 -2878
  230. package/dist/recorder-XdFvVASS.mjs +0 -2763
  231. package/dist/tailwindcss/recorder.d.ts +0 -13
  232. package/dist/tailwindcss/targets/paths.d.ts +0 -13
  233. package/dist/tailwindcss/targets/record-io.d.ts +0 -5
  234. package/dist/tailwindcss/targets/recorder.d.ts +0 -3
  235. package/dist/tailwindcss/targets/types.d.ts +0 -35
  236. package/dist/types/disabled-options.d.ts +0 -4
  237. package/dist/vite-BDywuCjn.mjs +0 -2186
  238. package/dist/vite-DgRh_GXn.js +0 -2199
  239. package/dist/webpack-CAJR4hhP.js +0 -456
  240. package/dist/webpack-CiHqVZTg.mjs +0 -441
  241. package/dist/webpack4.d.ts +0 -4
  242. package/dist/webpack4.js +0 -387
  243. package/dist/webpack4.mjs +0 -379
  244. package/scripts/postinstall.mjs +0 -59
@@ -1,441 +0,0 @@
1
- import { r as resolveTailwindcssOptions } from "./patcher-options-DQfR5xxT.mjs";
2
- import { g as ensureRuntimeClassSet, n as shouldSkipJsTransform, p as pluginName, r as getCompilerContext, t as setupPatchRecorder, v as createDebug } from "./recorder-XdFvVASS.mjs";
3
- import { r as getGroupedEntries } from "./utils-7DUGTFED.mjs";
4
- import { d as getRuntimeClassSetSignature } from "./logger-BoVx1Dbt.mjs";
5
- import { i as processCachedTask, t as generateCssByGenerator } from "./generator-css-Bwy_Uz89.mjs";
6
- import { a as resolveDisabledOptions, c as toAbsoluteOutputPath, i as resolvePackageDir, r as pushConcurrentTaskFactories, s as resolveOutputSpecifier } from "./css-imports-CSdPq_Sc.mjs";
7
- import { a as hasLoaderEntry, c as applyTailwindcssCssImportRewrite, d as isMpx, f as patchMpxLoaderResolve, i as getCacheKey, l as ensureMpxTailwindcssAliases, n as __dirname, o as hasWatchChanges, p as setupMpxTailwindcssRedirect, r as createAssetHashByChunkMap, s as isCssLikeModuleResource, t as createLoaderAnchorFinders, u as injectMpxCssRewritePreRules } from "./loader-anchors-1MumTAtA.mjs";
8
- import path from "node:path";
9
- import process from "node:process";
10
- import fs from "node:fs";
11
- //#region src/bundlers/webpack/BaseUnifiedPlugin/v5-assets.ts
12
- function resolveWebpackStaleClassNameFallback(option, _compiler) {
13
- if (typeof option === "boolean") return option;
14
- return false;
15
- }
16
- function setupWebpackV5ProcessAssetsHook(options) {
17
- const { compiler, options: compilerOptions, appType, runtimeState, getRuntimeRefreshRequirement, refreshRuntimeMetadata, consumeRuntimeRefreshRequirement, debug } = options;
18
- const { Compilation, sources } = compiler.webpack;
19
- const { ConcatSource } = sources;
20
- const cssHandlerOptionsCache = /* @__PURE__ */ new Map();
21
- const cssUserHandlerOptionsCache = /* @__PURE__ */ new Map();
22
- compiler.hooks.compilation.tap(pluginName, (compilation) => {
23
- compilation.hooks.processAssets.tapPromise({
24
- name: pluginName,
25
- stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
26
- }, async (assets) => {
27
- compilerOptions.onStart();
28
- debug("start");
29
- await runtimeState.patchPromise;
30
- for (const chunk of compilation.chunks) if (chunk.id && chunk.hash) compilerOptions.cache.calcHashValueChanged(chunk.id, chunk.hash);
31
- const assetHashByChunk = createAssetHashByChunkMap(compilation.chunks);
32
- const entries = Object.entries(assets);
33
- const compilerOutputPath = compilation.compiler?.outputPath ?? compiler.outputPath;
34
- const outputDir = compilerOutputPath ? path.resolve(compilerOutputPath) : compilation.outputOptions?.path ?? process.cwd();
35
- const jsAssets = /* @__PURE__ */ new Map();
36
- for (const [file] of entries) if (compilerOptions.jsMatcher(file) || compilerOptions.wxsMatcher(file)) {
37
- const absolute = toAbsoluteOutputPath(file, outputDir);
38
- jsAssets.set(absolute, file);
39
- }
40
- const moduleGraphOptions = {
41
- resolve(specifier, importer) {
42
- return resolveOutputSpecifier(specifier, importer, outputDir, (candidate) => jsAssets.has(candidate));
43
- },
44
- load: (id) => {
45
- const assetName = jsAssets.get(id);
46
- if (!assetName) return;
47
- const asset = compilation.getAsset(assetName);
48
- if (!asset) return;
49
- const source = asset.source.source();
50
- return typeof source === "string" ? source : source.toString();
51
- },
52
- filter(id) {
53
- return jsAssets.has(id);
54
- }
55
- };
56
- const applyLinkedResults = (linked) => {
57
- if (!linked) return;
58
- for (const [id, { code }] of Object.entries(linked)) {
59
- const assetName = jsAssets.get(id);
60
- if (!assetName) continue;
61
- const asset = compilation.getAsset(assetName);
62
- if (!asset) continue;
63
- const previousSource = asset.source.source();
64
- const previous = typeof previousSource === "string" ? previousSource : previousSource.toString();
65
- if (previous === code) continue;
66
- const source = new ConcatSource(code);
67
- compilation.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 forceRuntimeRefresh = getRuntimeRefreshRequirement();
100
- debug("processAssets ensure runtime set forceRefresh=%s major=%s", forceRuntimeRefresh, runtimeState.twPatcher.majorVersion ?? "unknown");
101
- const runtimeSet = await ensureRuntimeClassSet(runtimeState, {
102
- forceRefresh: forceRuntimeRefresh,
103
- forceCollect: true,
104
- clearCache: forceRuntimeRefresh,
105
- allowEmpty: false
106
- });
107
- await refreshRuntimeMetadata(forceRuntimeRefresh);
108
- consumeRuntimeRefreshRequirement();
109
- const defaultTemplateHandlerOptions = { runtimeSet };
110
- debug("get runtimeSet, class count: %d", runtimeSet.size);
111
- const tasks = [];
112
- if (Array.isArray(groupedEntries.html)) for (const element of groupedEntries.html) {
113
- const [file, originalSource] = element;
114
- const rawSource = originalSource.source().toString();
115
- const cacheKey = file;
116
- const chunkHash = assetHashByChunk.get(file);
117
- tasks.push(processCachedTask({
118
- cache: compilerOptions.cache,
119
- cacheKey,
120
- hashKey: `${file}:asset`,
121
- rawSource,
122
- hash: chunkHash,
123
- applyResult(source) {
124
- compilation.updateAsset(file, source);
125
- },
126
- onCacheHit() {
127
- debug("html cache hit: %s", file);
128
- },
129
- transform: async () => {
130
- const wxml = await compilerOptions.templateHandler(rawSource, defaultTemplateHandlerOptions);
131
- const source = new ConcatSource(wxml);
132
- compilerOptions.onUpdate(file, rawSource, wxml);
133
- debug("html handle: %s", file);
134
- return { result: source };
135
- }
136
- }));
137
- }
138
- const jsTaskFactories = [];
139
- if (Array.isArray(groupedEntries.js)) for (const [file] of groupedEntries.js) {
140
- const cacheKey = getCacheKey(file);
141
- const asset = compilation.getAsset(file);
142
- if (!asset) continue;
143
- const absoluteFile = toAbsoluteOutputPath(file, outputDir);
144
- const initialSource = asset.source.source();
145
- const initialRawSource = typeof initialSource === "string" ? initialSource : initialSource.toString();
146
- const chunkHash = assetHashByChunk.get(file);
147
- jsTaskFactories.push(async () => {
148
- await processCachedTask({
149
- cache: compilerOptions.cache,
150
- cacheKey,
151
- hashKey: `${file}:asset`,
152
- rawSource: initialRawSource,
153
- hash: chunkHash,
154
- applyResult(source) {
155
- compilation.updateAsset(file, source);
156
- },
157
- onCacheHit() {
158
- debug("js cache hit: %s", file);
159
- },
160
- transform: async () => {
161
- const currentSourceValue = compilation.getAsset(file)?.source.source();
162
- const currentSource = typeof currentSourceValue === "string" ? currentSourceValue : currentSourceValue?.toString() ?? "";
163
- const handlerOptions = {
164
- staleClassNameFallback,
165
- tailwindcssMajorVersion: runtimeState.twPatcher.majorVersion,
166
- filename: absoluteFile,
167
- moduleGraph: moduleGraphOptions,
168
- babelParserOptions: { sourceFilename: absoluteFile }
169
- };
170
- if (shouldSkipJsTransform(currentSource, handlerOptions)) return { result: new ConcatSource(currentSource) };
171
- const { code, linked } = await compilerOptions.jsHandler(currentSource, runtimeSet, handlerOptions);
172
- const source = new ConcatSource(code);
173
- compilerOptions.onUpdate(file, currentSource, code);
174
- debug("js handle: %s", file);
175
- applyLinkedResults(linked);
176
- return { result: source };
177
- }
178
- });
179
- });
180
- }
181
- if (Array.isArray(groupedEntries.css)) for (const element of groupedEntries.css) {
182
- const [file, originalSource] = element;
183
- const rawSource = originalSource.source().toString();
184
- const cacheKey = file;
185
- const chunkHash = assetHashByChunk.get(file);
186
- tasks.push(processCachedTask({
187
- cache: compilerOptions.cache,
188
- cacheKey,
189
- hashKey: `${file}:asset`,
190
- rawSource,
191
- hash: chunkHash,
192
- applyResult(source) {
193
- compilation.updateAsset(file, source);
194
- },
195
- onCacheHit() {
196
- debug("css cache hit: %s", file);
197
- },
198
- transform: async () => {
199
- await runtimeState.patchPromise;
200
- const cssHandlerOptions = getCssHandlerOptions(file);
201
- const generated = await generateCssByGenerator({
202
- opts: compilerOptions,
203
- runtimeState,
204
- runtime: runtimeSet,
205
- rawSource,
206
- file,
207
- cssHandlerOptions,
208
- cssUserHandlerOptions: getCssUserHandlerOptions(file),
209
- styleHandler: compilerOptions.styleHandler,
210
- debug
211
- });
212
- const css = generated?.css ?? (await compilerOptions.styleHandler(rawSource, cssHandlerOptions)).css;
213
- const source = new ConcatSource(css);
214
- compilerOptions.onUpdate(file, rawSource, css);
215
- if (generated) debug("css handle via tailwind v%s engine(%s): %s", runtimeState.twPatcher.majorVersion, generated.target, file);
216
- else debug("css handle: %s", file);
217
- return { result: source };
218
- }
219
- }));
220
- }
221
- pushConcurrentTaskFactories(tasks, jsTaskFactories);
222
- await Promise.all(tasks);
223
- debug("end");
224
- compilerOptions.onEnd();
225
- });
226
- });
227
- }
228
- //#endregion
229
- //#region src/bundlers/webpack/BaseUnifiedPlugin/v5-loaders.ts
230
- function setupWebpackV5Loaders(options) {
231
- const { compiler, options: compilerOptions, appType, weappTailwindcssPackageDir, shouldRewriteCssImports, runtimeLoaderPath, runtimeCssImportRewriteLoaderPath, getClassSetInLoader, getRuntimeWatchDependencies, debug } = options;
232
- const isMpxApp = isMpx(appType);
233
- if (shouldRewriteCssImports && isMpxApp) ensureMpxTailwindcssAliases(compiler, weappTailwindcssPackageDir);
234
- const runtimeClassSetLoader = runtimeLoaderPath ?? path.resolve(__dirname, "./weapp-tw-runtime-classset-loader.js");
235
- const runtimeCssImportRewriteLoader = shouldRewriteCssImports ? runtimeCssImportRewriteLoaderPath ?? path.resolve(__dirname, "./weapp-tw-css-import-rewrite-loader.js") : void 0;
236
- const runtimeClassSetLoaderExists = fs.existsSync(runtimeClassSetLoader);
237
- const runtimeCssImportRewriteLoaderExists = runtimeCssImportRewriteLoader ? fs.existsSync(runtimeCssImportRewriteLoader) : false;
238
- const runtimeLoaderRewriteOptions = shouldRewriteCssImports ? {
239
- pkgDir: weappTailwindcssPackageDir,
240
- appType
241
- } : void 0;
242
- const classSetLoaderOptions = {
243
- getClassSet: getClassSetInLoader,
244
- getWatchDependencies: getRuntimeWatchDependencies
245
- };
246
- const { findRewriteAnchor, findClassSetAnchor } = createLoaderAnchorFinders(appType);
247
- const cssImportRewriteLoaderOptions = runtimeLoaderRewriteOptions ? { rewriteCssImports: runtimeLoaderRewriteOptions } : void 0;
248
- if (runtimeCssImportRewriteLoader && shouldRewriteCssImports && cssImportRewriteLoaderOptions && isMpxApp) injectMpxCssRewritePreRules(compiler, runtimeCssImportRewriteLoader, cssImportRewriteLoaderOptions);
249
- const createRuntimeClassSetLoaderEntry = () => ({
250
- loader: runtimeClassSetLoader,
251
- options: classSetLoaderOptions,
252
- ident: null,
253
- type: null
254
- });
255
- const createCssImportRewriteLoaderEntry = () => {
256
- if (!runtimeCssImportRewriteLoader) return null;
257
- return {
258
- loader: runtimeCssImportRewriteLoader,
259
- options: cssImportRewriteLoaderOptions,
260
- ident: null,
261
- type: null
262
- };
263
- };
264
- const { NormalModule } = compiler.webpack;
265
- compiler.hooks.compilation.tap(pluginName, (compilation) => {
266
- NormalModule.getCompilationHooks(compilation).loader.tap(pluginName, (_loaderContext, module) => {
267
- if (!(runtimeClassSetLoaderExists || runtimeCssImportRewriteLoaderExists)) return;
268
- patchMpxLoaderResolve(_loaderContext, weappTailwindcssPackageDir, shouldRewriteCssImports && isMpxApp);
269
- const loaderEntries = module.loaders || [];
270
- let rewriteAnchorIdx = findRewriteAnchor(loaderEntries);
271
- const classSetAnchorIdx = findClassSetAnchor(loaderEntries);
272
- const isCssModule = isCssLikeModuleResource(module.resource, compilerOptions.cssMatcher, appType);
273
- 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), {
274
- rewriteAnchorIdx,
275
- classSetAnchorIdx
276
- });
277
- 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), {
278
- rewriteAnchorIdx,
279
- classSetAnchorIdx
280
- });
281
- 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), {
282
- rewriteAnchorIdx,
283
- classSetAnchorIdx
284
- });
285
- if (rewriteAnchorIdx === -1 && classSetAnchorIdx === -1 && !isCssModule) return;
286
- const anchorlessInsert = (entry, position) => {
287
- if (position === "after") loaderEntries.push(entry);
288
- else loaderEntries.unshift(entry);
289
- };
290
- if (cssImportRewriteLoaderOptions && runtimeCssImportRewriteLoaderExists && runtimeCssImportRewriteLoader) {
291
- const existingIndex = loaderEntries.findIndex((entry) => entry.loader?.includes?.(runtimeCssImportRewriteLoader));
292
- const rewriteLoaderEntry = existingIndex !== -1 ? loaderEntries.splice(existingIndex, 1)[0] : createCssImportRewriteLoaderEntry();
293
- if (rewriteLoaderEntry) {
294
- const anchorIndex = findRewriteAnchor(loaderEntries);
295
- if (anchorIndex === -1) anchorlessInsert(rewriteLoaderEntry, "after");
296
- else loaderEntries.splice(anchorIndex + 1, 0, rewriteLoaderEntry);
297
- rewriteAnchorIdx = findRewriteAnchor(loaderEntries);
298
- }
299
- }
300
- if (runtimeClassSetLoaderExists && !hasLoaderEntry(loaderEntries, runtimeClassSetLoader)) {
301
- const classSetLoaderEntry = createRuntimeClassSetLoaderEntry();
302
- const anchorIndex = findClassSetAnchor(loaderEntries);
303
- if (anchorIndex === -1) anchorlessInsert(classSetLoaderEntry, "before");
304
- else {
305
- const insertIndex = anchorIndex === -1 ? rewriteAnchorIdx : anchorIndex;
306
- loaderEntries.splice(insertIndex, 0, classSetLoaderEntry);
307
- }
308
- }
309
- });
310
- });
311
- }
312
- //#endregion
313
- //#region src/bundlers/webpack/BaseUnifiedPlugin/v5.ts
314
- const debug = createDebug();
315
- const weappTailwindcssPackageDir = resolvePackageDir("weapp-tailwindcss");
316
- /**
317
- * @name UnifiedWebpackPluginV5
318
- * @description webpack5 核心转义插件
319
- * @link https://tw.icebreaker.top/docs/intro
320
- */
321
- var UnifiedWebpackPluginV5 = class {
322
- constructor(options = {}) {
323
- this.options = getCompilerContext(options);
324
- this.appType = this.options.appType;
325
- }
326
- apply(compiler) {
327
- compiler.options = compiler.options || {};
328
- const { disabled, onLoad, runtimeLoaderPath, runtimeCssImportRewriteLoaderPath, twPatcher: initialTwPatcher, refreshTailwindcssPatcher } = this.options;
329
- const disabledOptions = resolveDisabledOptions(disabled);
330
- const shouldRewriteCssImports = (initialTwPatcher.majorVersion ?? 0) >= 4 && this.options.rewriteCssImports !== false && !disabledOptions.rewriteCssImports;
331
- const isMpxApp = isMpx(this.appType);
332
- if (shouldRewriteCssImports) {
333
- applyTailwindcssCssImportRewrite(compiler, {
334
- pkgDir: weappTailwindcssPackageDir,
335
- enabled: true,
336
- appType: this.appType
337
- });
338
- setupMpxTailwindcssRedirect(weappTailwindcssPackageDir, isMpxApp);
339
- }
340
- if (disabledOptions.plugin) return;
341
- const patchRecorderState = setupPatchRecorder(initialTwPatcher, this.options.tailwindcssBasedir, {
342
- source: "runtime",
343
- cwd: this.options.tailwindcssBasedir ?? process.cwd()
344
- });
345
- const runtimeState = {
346
- twPatcher: initialTwPatcher,
347
- patchPromise: patchRecorderState.patchPromise,
348
- refreshTailwindcssPatcher,
349
- onPatchCompleted: patchRecorderState.onPatchCompleted
350
- };
351
- let runtimeSetPrepared = false;
352
- let runtimeSetSignature;
353
- let runtimeRefreshRequiredForCompilation = false;
354
- const runtimeWatchDependencyFiles = /* @__PURE__ */ new Set();
355
- const runtimeWatchDependencyContexts = /* @__PURE__ */ new Set();
356
- let runtimeMetadataPrepared = false;
357
- const updateRuntimeWatchDependencies = async () => {
358
- runtimeWatchDependencyFiles.clear();
359
- runtimeWatchDependencyContexts.clear();
360
- const tailwindOptions = resolveTailwindcssOptions(runtimeState.twPatcher.options);
361
- if (tailwindOptions?.config) runtimeWatchDependencyFiles.add(tailwindOptions.config);
362
- for (const entry of tailwindOptions?.v4?.cssEntries ?? []) runtimeWatchDependencyFiles.add(entry);
363
- for (const source of tailwindOptions?.v4?.sources ?? []) if (source?.base) runtimeWatchDependencyContexts.add(source.base);
364
- if (typeof runtimeState.twPatcher.collectContentTokens !== "function") return;
365
- try {
366
- const report = await runtimeState.twPatcher.collectContentTokens();
367
- for (const entry of report.entries ?? []) if (entry.file) runtimeWatchDependencyFiles.add(entry.file);
368
- for (const source of report.sources ?? []) if (source?.base) runtimeWatchDependencyContexts.add(source.base);
369
- } catch (error) {
370
- debug("collect runtime watch dependencies failed: %O", error);
371
- }
372
- };
373
- const ensureRuntimeMetadata = async (force = false) => {
374
- if (runtimeMetadataPrepared && !force) return;
375
- await updateRuntimeWatchDependencies();
376
- runtimeMetadataPrepared = true;
377
- };
378
- const syncRuntimeRefreshRequirement = () => {
379
- runtimeRefreshRequiredForCompilation = runtimeRefreshRequiredForCompilation || hasWatchChanges(compiler);
380
- };
381
- const resetRuntimePreparation = () => {
382
- runtimeSetPrepared = false;
383
- runtimeMetadataPrepared = false;
384
- syncRuntimeRefreshRequirement();
385
- };
386
- compiler.hooks.invalid?.tap?.(pluginName, () => {
387
- runtimeRefreshRequiredForCompilation = true;
388
- });
389
- compiler.hooks.watchRun?.tap?.(pluginName, syncRuntimeRefreshRequirement);
390
- if (compiler.hooks.thisCompilation?.tap) compiler.hooks.thisCompilation.tap(pluginName, resetRuntimePreparation);
391
- else if (compiler.hooks.compilation?.tap) compiler.hooks.compilation.tap(pluginName, resetRuntimePreparation);
392
- async function getClassSetInLoader() {
393
- if (runtimeSetPrepared) return;
394
- const signature = getRuntimeClassSetSignature(runtimeState.twPatcher);
395
- const forceRefresh = runtimeRefreshRequiredForCompilation || signature !== runtimeSetSignature;
396
- debug("runtime loader ensure class set forceRefresh=%s watchDirty=%s signatureChanged=%s", forceRefresh, runtimeRefreshRequiredForCompilation, signature !== runtimeSetSignature);
397
- runtimeSetPrepared = true;
398
- await ensureRuntimeClassSet(runtimeState, {
399
- forceRefresh,
400
- forceCollect: true,
401
- clearCache: forceRefresh,
402
- allowEmpty: true
403
- });
404
- await ensureRuntimeMetadata(forceRefresh);
405
- runtimeSetSignature = signature;
406
- runtimeRefreshRequiredForCompilation = false;
407
- }
408
- onLoad();
409
- setupWebpackV5Loaders({
410
- compiler,
411
- options: this.options,
412
- appType: this.appType,
413
- weappTailwindcssPackageDir,
414
- shouldRewriteCssImports,
415
- runtimeLoaderPath,
416
- runtimeCssImportRewriteLoaderPath,
417
- getClassSetInLoader,
418
- getRuntimeWatchDependencies() {
419
- return {
420
- files: runtimeWatchDependencyFiles,
421
- contexts: runtimeWatchDependencyContexts
422
- };
423
- },
424
- debug
425
- });
426
- setupWebpackV5ProcessAssetsHook({
427
- compiler,
428
- options: this.options,
429
- appType: this.appType,
430
- runtimeState,
431
- getRuntimeRefreshRequirement: () => runtimeRefreshRequiredForCompilation,
432
- refreshRuntimeMetadata: ensureRuntimeMetadata,
433
- consumeRuntimeRefreshRequirement() {
434
- runtimeRefreshRequiredForCompilation = false;
435
- },
436
- debug
437
- });
438
- }
439
- };
440
- //#endregion
441
- export { weappTailwindcssPackageDir as n, UnifiedWebpackPluginV5 as t };
@@ -1,4 +0,0 @@
1
- export * from './bundlers/webpack/BaseUnifiedPlugin/v4';
2
- export { UnifiedWebpackPluginV4 as WeappTailwindcss } from './bundlers/webpack/BaseUnifiedPlugin/v4';
3
- export { UnifiedWebpackPluginV4 as weappTailwindcss } from './bundlers/webpack/BaseUnifiedPlugin/v4';
4
- export type { UserDefinedOptions } from './types';