weapp-tailwindcss 4.11.1 → 4.12.0-alpha.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 (67) hide show
  1. package/README.md +38 -0
  2. package/dist/{chunk-VOCOKTZW.js → chunk-4LBAL3RE.js} +117 -119
  3. package/dist/{chunk-ZUV5AZRB.mjs → chunk-5CF3HTTN.mjs} +1 -1
  4. package/dist/{chunk-OMARW5NC.mjs → chunk-AYJ4HLWZ.mjs} +4 -2
  5. package/dist/{chunk-SV55AOBL.mjs → chunk-C2E5ZLNI.mjs} +12 -7
  6. package/dist/{chunk-6YV5WADN.js → chunk-CAZQZPMY.js} +45 -40
  7. package/dist/{chunk-Q2HTQFI4.js → chunk-CTGWJGKJ.js} +5 -5
  8. package/dist/{chunk-7LKMJZD2.js → chunk-GMKSBLNY.js} +2 -2
  9. package/dist/{chunk-EFBQ4SQR.mjs → chunk-HL3US2OT.mjs} +1 -1
  10. package/dist/{chunk-Y6JUVWRU.js → chunk-IUYO6NQO.js} +10 -6
  11. package/dist/{chunk-WSMWD4MC.mjs → chunk-JRLWGMVZ.mjs} +6 -2
  12. package/dist/{chunk-QK6VNNNL.js → chunk-NIS74SI6.js} +8 -6
  13. package/dist/{chunk-CRDOWYG4.js → chunk-ONLKZIRQ.js} +1 -1
  14. package/dist/{chunk-SSASUP5F.js → chunk-RQWWSU4U.js} +187 -82
  15. package/dist/{chunk-KX2JVTVM.mjs → chunk-V34LWQTS.mjs} +49 -51
  16. package/dist/{chunk-4O2J5ZM6.mjs → chunk-ZABCOAAS.mjs} +195 -90
  17. package/dist/cli.js +121 -81
  18. package/dist/cli.mjs +121 -81
  19. package/dist/core.d.mts +1 -1
  20. package/dist/core.d.ts +1 -1
  21. package/dist/core.js +14 -9
  22. package/dist/core.mjs +10 -5
  23. package/dist/css-macro/postcss.js +1 -1
  24. package/dist/css-macro/postcss.mjs +1 -1
  25. package/dist/css-macro.js +1 -1
  26. package/dist/css-macro.mjs +1 -1
  27. package/dist/defaults.d.mts +1 -1
  28. package/dist/defaults.d.ts +1 -1
  29. package/dist/defaults.js +1 -1
  30. package/dist/defaults.mjs +1 -1
  31. package/dist/gulp.d.mts +1 -1
  32. package/dist/gulp.d.ts +1 -1
  33. package/dist/gulp.js +5 -5
  34. package/dist/gulp.mjs +4 -4
  35. package/dist/{index-CoXntW_P.d.mts → index-BXrmQelt.d.mts} +29 -1
  36. package/dist/{index-CoXntW_P.d.ts → index-BXrmQelt.d.ts} +29 -1
  37. package/dist/index.d.mts +1 -1
  38. package/dist/index.d.ts +1 -1
  39. package/dist/index.js +9 -9
  40. package/dist/index.mjs +7 -7
  41. package/dist/postcss-html-transform.js +1 -1
  42. package/dist/postcss-html-transform.mjs +1 -1
  43. package/dist/presets.d.mts +8 -1
  44. package/dist/presets.d.ts +8 -1
  45. package/dist/presets.js +7 -6
  46. package/dist/presets.mjs +3 -2
  47. package/dist/reset.d.mts +1 -31
  48. package/dist/reset.d.ts +3 -32
  49. package/dist/reset.js +3 -160
  50. package/dist/reset.mjs +3 -160
  51. package/dist/types.d.mts +2 -2
  52. package/dist/types.d.ts +2 -2
  53. package/dist/types.js +1 -1
  54. package/dist/types.mjs +1 -1
  55. package/dist/vite.d.mts +1 -1
  56. package/dist/vite.d.ts +1 -1
  57. package/dist/vite.js +6 -6
  58. package/dist/vite.mjs +4 -4
  59. package/dist/webpack.d.mts +1 -1
  60. package/dist/webpack.d.ts +1 -1
  61. package/dist/webpack.js +7 -7
  62. package/dist/webpack.mjs +5 -5
  63. package/dist/webpack4.d.mts +1 -1
  64. package/dist/webpack4.d.ts +1 -1
  65. package/dist/webpack4.js +41 -36
  66. package/dist/webpack4.mjs +12 -7
  67. package/package.json +8 -4
@@ -23,18 +23,20 @@ import {
23
23
  refreshTailwindRuntimeState,
24
24
  replaceWxml,
25
25
  setupPatchRecorder,
26
+ shouldSkipJsTransform,
26
27
  toCustomAttributesEntities,
27
28
  traverse,
28
29
  vitePluginName
29
- } from "./chunk-4O2J5ZM6.mjs";
30
+ } from "./chunk-ZABCOAAS.mjs";
30
31
  import {
31
32
  findNearestPackageRoot,
32
33
  findTailwindConfig,
33
34
  getRuntimeClassSetSignature,
34
35
  isUniAppXEnabled,
36
+ logger,
35
37
  resolveTailwindcssOptions,
36
38
  resolveUniAppXOptions
37
- } from "./chunk-OMARW5NC.mjs";
39
+ } from "./chunk-AYJ4HLWZ.mjs";
38
40
  import {
39
41
  resolveUniUtsPlatform
40
42
  } from "./chunk-OOHJLO5M.mjs";
@@ -43,7 +45,7 @@ import {
43
45
  import { existsSync as existsSync2 } from "fs";
44
46
  import path6 from "path";
45
47
  import process4 from "process";
46
- import { logger as logger2 } from "@weapp-tailwindcss/logger";
48
+ import { logger as logger3 } from "@weapp-tailwindcss/logger";
47
49
  import postcssHtmlTransform from "@weapp-tailwindcss/postcss/html-transform";
48
50
 
49
51
  // src/uni-app-x/transform.ts
@@ -239,28 +241,28 @@ function traverse2(node, visitor) {
239
241
  }
240
242
  }
241
243
  }
242
- function updateStaticAttribute(ms, prop) {
244
+ function updateStaticAttribute(ms, prop, content = prop.value?.content) {
243
245
  if (!prop.value) {
244
246
  return;
245
247
  }
246
248
  const start = prop.value.loc.start.offset + 1;
247
249
  const end = prop.value.loc.end.offset - 1;
248
250
  if (start < end) {
249
- ms.update(start, end, replaceWxml(prop.value.content));
251
+ ms.update(start, end, replaceWxml(content ?? ""));
250
252
  }
251
253
  }
252
- function updateStaticAttributeWithLocalStyle(ms, prop, collector) {
254
+ function updateStaticAttributeWithLocalStyle(ms, prop, collector, content = prop.value?.content) {
253
255
  if (!prop.value) {
254
256
  return;
255
257
  }
256
258
  const start = prop.value.loc.start.offset + 1;
257
259
  const end = prop.value.loc.end.offset - 1;
258
260
  if (start < end) {
259
- ms.update(start, end, collector.collectAndRewriteStaticClass(prop.value.content));
261
+ ms.update(start, end, collector.collectAndRewriteStaticClass(content ?? ""));
260
262
  }
261
263
  }
262
- function updateDirectiveExpression(ms, prop, jsHandler, runtimeSet) {
263
- if (prop.exp?.type !== NodeTypes.SIMPLE_EXPRESSION) {
264
+ function updateDirectiveExpression(ms, prop, jsHandler, runtimeSet, expression = prop.exp?.content) {
265
+ if (prop.exp?.type !== NodeTypes.SIMPLE_EXPRESSION || expression === void 0) {
264
266
  return;
265
267
  }
266
268
  const start = prop.exp.loc.start.offset;
@@ -268,15 +270,15 @@ function updateDirectiveExpression(ms, prop, jsHandler, runtimeSet) {
268
270
  if (start >= end) {
269
271
  return;
270
272
  }
271
- const generated = generateCode(prop.exp.content, {
273
+ const generated = generateCode(expression, {
272
274
  jsHandler,
273
275
  runtimeSet,
274
276
  wrapExpression: true
275
277
  });
276
278
  ms.update(start, end, generated);
277
279
  }
278
- function updateDirectiveExpressionWithLocalStyle(ms, prop, jsHandler, collector, runtimeSet) {
279
- if (prop.exp?.type !== NodeTypes.SIMPLE_EXPRESSION) {
280
+ function updateDirectiveExpressionWithLocalStyle(ms, prop, jsHandler, collector, runtimeSet, expression = prop.exp?.content) {
281
+ if (prop.exp?.type !== NodeTypes.SIMPLE_EXPRESSION || expression === void 0) {
280
282
  return;
281
283
  }
282
284
  const start = prop.exp.loc.start.offset;
@@ -284,10 +286,10 @@ function updateDirectiveExpressionWithLocalStyle(ms, prop, jsHandler, collector,
284
286
  if (start >= end) {
285
287
  return;
286
288
  }
287
- collector.collectRuntimeClasses(prop.exp.content, {
289
+ collector.collectRuntimeClasses(expression, {
288
290
  wrapExpression: true
289
291
  });
290
- const generated = generateCode(prop.exp.content, {
292
+ const generated = generateCode(expression, {
291
293
  jsHandler,
292
294
  runtimeSet,
293
295
  wrapExpression: true
@@ -359,7 +361,13 @@ function transformUVue(code, id, jsHandler, runtimeSet, options = {}) {
359
361
  continue;
360
362
  }
361
363
  if (attrName.toLowerCase() === "class" && localStyleCollector) {
362
- updateDirectiveExpressionWithLocalStyle(ms, prop, jsHandler, localStyleCollector, runtimeSet);
364
+ updateDirectiveExpressionWithLocalStyle(
365
+ ms,
366
+ prop,
367
+ jsHandler,
368
+ localStyleCollector,
369
+ runtimeSet
370
+ );
363
371
  } else {
364
372
  updateDirectiveExpression(ms, prop, jsHandler, runtimeSet);
365
373
  }
@@ -509,6 +517,9 @@ function isPreprocessorRequest(id, lang) {
509
517
  }
510
518
  return PREPROCESSOR_EXT_RE.test(id);
511
519
  }
520
+ function resolveUniAppXCssTarget(id) {
521
+ return UVUE_NVUE_RE2.test(cleanUrl(id)) ? "uvue" : void 0;
522
+ }
512
523
  function createUniAppXPlugins(options) {
513
524
  const {
514
525
  appType,
@@ -551,6 +562,8 @@ function createUniAppXPlugins(options) {
551
562
  if (!styleHandlerOptions) {
552
563
  styleHandlerOptions = {
553
564
  isMainChunk: mainCssChunkMatcher(id, appType),
565
+ uniAppXCssTarget: resolveUniAppXCssTarget(id),
566
+ uniAppXUnsupported: resolvedUniAppXOptions.uvueUnsupported,
554
567
  postcssOptions: {
555
568
  options: {
556
569
  from: id,
@@ -567,6 +580,10 @@ function createUniAppXPlugins(options) {
567
580
  cssHandlerOptionsCache.set(cacheKey, styleHandlerOptions);
568
581
  }
569
582
  const postcssResult = await styleHandler(code, styleHandlerOptions);
583
+ const warnings = typeof postcssResult.warnings === "function" ? postcssResult.warnings() : [];
584
+ for (const warning of warnings) {
585
+ logger.warn(warning.toString());
586
+ }
570
587
  const rawPostcssMap = postcssResult.map.toJSON();
571
588
  const postcssMap = await formatPostcssSourceMap(
572
589
  rawPostcssMap,
@@ -708,7 +725,7 @@ function createUniAppXAssetTask(file, originalSource, outDir, options) {
708
725
  // src/bundlers/vite/generate-bundle.ts
709
726
  import path3 from "path";
710
727
  import process2 from "process";
711
- import { logger } from "@weapp-tailwindcss/logger";
728
+ import { logger as logger2 } from "@weapp-tailwindcss/logger";
712
729
  import { splitCode as splitCode2 } from "@weapp-tailwindcss/shared/extractors";
713
730
 
714
731
  // src/bundlers/vite/bundle-entries.ts
@@ -1029,28 +1046,6 @@ function updateBundleBuildState(state, snapshot, linkedByEntry, options = {}) {
1029
1046
  state.dependentsByLinkedFile = invertLinkedByEntry(state.linkedByEntry);
1030
1047
  }
1031
1048
 
1032
- // src/bundlers/vite/js-precheck.ts
1033
- var FAST_JS_TRANSFORM_HINT_RE = /className\b|class\s*=|classList\.|\b(?:twMerge|clsx|classnames|cn|cva)\b|\[["'`]class["'`]\]|text-\[|bg-\[|\b(?:[whpm]|px|py|mx|my|rounded|flex|grid|gap)-/;
1034
- var DEPENDENCY_HINT_RE = /\bimport\s*[("'`{*]|\brequire\s*\(|\bexport\s+\*\s+from\s+["'`]|\bexport\s*\{[^}]*\}\s*from\s+["'`]/;
1035
- function shouldSkipViteJsTransform(rawSource, options) {
1036
- if (!rawSource) {
1037
- return true;
1038
- }
1039
- if (options?.alwaysEscape) {
1040
- return false;
1041
- }
1042
- if (options?.moduleSpecifierReplacements && Object.keys(options.moduleSpecifierReplacements).length > 0) {
1043
- return false;
1044
- }
1045
- if (options?.wrapExpression) {
1046
- return false;
1047
- }
1048
- if (DEPENDENCY_HINT_RE.test(rawSource)) {
1049
- return false;
1050
- }
1051
- return !FAST_JS_TRANSFORM_HINT_RE.test(rawSource);
1052
- }
1053
-
1054
1049
  // src/bundlers/vite/generate-bundle.ts
1055
1050
  function formatDebugFileList(files, limit = 8) {
1056
1051
  if (files.size === 0) {
@@ -1336,7 +1331,7 @@ function createGenerateBundleHook(context) {
1336
1331
  let transformed = await templateHandler(rawSource, defaultTemplateHandlerOptions);
1337
1332
  let unresolvedDynamicCandidates = collectUnescapedDynamicCandidates(transformed);
1338
1333
  if (unresolvedDynamicCandidates.length > 0) {
1339
- logger.warn(
1334
+ logger2.warn(
1340
1335
  "\u68C0\u6D4B\u5230 WXML \u52A8\u6001\u7C7B\u540D\u672A\u5B8C\u6210\u8F6C\u8BD1\uFF0C\u5DF2\u56DE\u9000\u5230\u5B8C\u6574 runtimeSet \u91CD\u8BD5: %s -> %O",
1341
1336
  file,
1342
1337
  unresolvedDynamicCandidates
@@ -1347,7 +1342,7 @@ function createGenerateBundleHook(context) {
1347
1342
  });
1348
1343
  unresolvedDynamicCandidates = collectUnescapedDynamicCandidates(transformed);
1349
1344
  if (unresolvedDynamicCandidates.length > 0) {
1350
- logger.warn(
1345
+ logger2.warn(
1351
1346
  "WXML \u52A8\u6001\u7C7B\u540D\u5728\u5B8C\u6574 runtimeSet \u91CD\u8BD5\u540E\u4ECD\u672A\u5B8C\u6210\u8F6C\u8BD1: %s -> %O",
1352
1347
  file,
1353
1348
  unresolvedDynamicCandidates
@@ -1466,7 +1461,7 @@ function createGenerateBundleHook(context) {
1466
1461
  debug3("js cache replay miss, fallback transform: %s", file);
1467
1462
  }
1468
1463
  const handlerOptions = createHandlerOptions(absoluteFile);
1469
- if (!disableJsPrecheck && shouldSkipViteJsTransform(rawSource, handlerOptions)) {
1464
+ if (!disableJsPrecheck && shouldSkipJsTransform(rawSource, handlerOptions)) {
1470
1465
  metrics.js.elapsed += measureElapsed(start);
1471
1466
  metrics.js.transformed++;
1472
1467
  return {
@@ -1552,7 +1547,7 @@ function createGenerateBundleHook(context) {
1552
1547
  sourceType: "unambiguous"
1553
1548
  }
1554
1549
  });
1555
- if (!disableJsPrecheck && shouldSkipViteJsTransform(currentSource, precheckOptions)) {
1550
+ if (!disableJsPrecheck && shouldSkipJsTransform(currentSource, precheckOptions)) {
1556
1551
  metrics.js.elapsed += measureElapsed(start);
1557
1552
  metrics.js.transformed++;
1558
1553
  return;
@@ -2335,7 +2330,7 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
2335
2330
  if (nextAppType && opts.appType !== nextAppType) {
2336
2331
  const previousAppType = opts.appType;
2337
2332
  opts.appType = nextAppType;
2338
- logger2.info("\u6839\u636E Vite \u9879\u76EE\u6839\u76EE\u5F55\u81EA\u52A8\u63A8\u65AD appType -> %s", nextAppType);
2333
+ logger3.info("\u6839\u636E Vite \u9879\u76EE\u6839\u76EE\u5F55\u81EA\u52A8\u63A8\u65AD appType -> %s", nextAppType);
2339
2334
  debug2(
2340
2335
  "align appType with vite root: %s -> %s",
2341
2336
  previousAppType ?? "undefined",
@@ -2359,14 +2354,17 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
2359
2354
  }
2360
2355
  }
2361
2356
  },
2362
- generateBundle: createGenerateBundleHook({
2363
- opts,
2364
- runtimeState,
2365
- ensureRuntimeClassSet,
2366
- ensureBundleRuntimeClassSet,
2367
- debug: debug2,
2368
- getResolvedConfig
2369
- })
2357
+ generateBundle: {
2358
+ order: "post",
2359
+ handler: createGenerateBundleHook({
2360
+ opts,
2361
+ runtimeState,
2362
+ ensureRuntimeClassSet,
2363
+ ensureBundleRuntimeClassSet,
2364
+ debug: debug2,
2365
+ getResolvedConfig
2366
+ })
2367
+ }
2370
2368
  }
2371
2369
  ];
2372
2370
  if (uniAppXPlugins) {