weapp-tailwindcss 4.8.7 → 4.8.9

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 (60) hide show
  1. package/dist/{chunk-JYHBNTYH.mjs → chunk-3BMQ6ZWL.mjs} +2 -2
  2. package/dist/{chunk-ZB6MFKXJ.mjs → chunk-3IP5JCFZ.mjs} +1 -1
  3. package/dist/{chunk-ZSTF2AEN.js → chunk-3URI7W6X.js} +11 -1
  4. package/dist/chunk-4KBHUV2C.js +136 -0
  5. package/dist/{chunk-KRRIFURM.mjs → chunk-5ROWVF7O.mjs} +191 -127
  6. package/dist/{chunk-MIC6E7DV.mjs → chunk-6OE4Q2BC.mjs} +100 -29
  7. package/dist/{chunk-5F64FE7K.js → chunk-6UW6DOPI.js} +5 -5
  8. package/dist/chunk-AGWNHP3C.mjs +136 -0
  9. package/dist/chunk-BYXBJQAS.js +1 -0
  10. package/dist/{chunk-BMUQ4OAB.mjs → chunk-FYYIFZ36.mjs} +13 -107
  11. package/dist/{chunk-YQQ3HDQD.mjs → chunk-H6YMPVI6.mjs} +2 -2
  12. package/dist/{chunk-JW7P34IH.mjs → chunk-HXYNNE6Q.mjs} +178 -59
  13. package/dist/{chunk-3XGTIDA6.mjs → chunk-IXK4ZWFR.mjs} +337 -169
  14. package/dist/{chunk-322IEI2K.js → chunk-J25ZFRYM.js} +172 -53
  15. package/dist/{chunk-GORSBZA2.js → chunk-M4NERJO7.js} +1 -1
  16. package/dist/{chunk-VONLQCG7.js → chunk-PBUQRF6F.js} +211 -147
  17. package/dist/{chunk-DKPIYG24.mjs → chunk-QF65JGNW.mjs} +11 -1
  18. package/dist/{chunk-ESYZLHZI.js → chunk-S2YGU6BU.js} +354 -186
  19. package/dist/{chunk-U4WEDSBF.js → chunk-XQKBWIFI.js} +7 -7
  20. package/dist/{chunk-WUJAJ42W.js → chunk-Z366CKKB.js} +118 -47
  21. package/dist/{chunk-7BASRP3P.js → chunk-ZTGB2D5W.js} +24 -118
  22. package/dist/cli.js +39 -32
  23. package/dist/cli.mjs +12 -5
  24. package/dist/core.js +11 -11
  25. package/dist/core.mjs +5 -5
  26. package/dist/css-macro/postcss.js +1 -1
  27. package/dist/css-macro/postcss.mjs +1 -1
  28. package/dist/css-macro.js +1 -1
  29. package/dist/css-macro.mjs +1 -1
  30. package/dist/defaults.js +3 -3
  31. package/dist/defaults.mjs +2 -2
  32. package/dist/gulp.js +7 -7
  33. package/dist/gulp.mjs +6 -6
  34. package/dist/index.js +11 -11
  35. package/dist/index.mjs +10 -10
  36. package/dist/postcss-html-transform.js +1 -1
  37. package/dist/postcss-html-transform.mjs +1 -1
  38. package/dist/presets.js +4 -4
  39. package/dist/presets.mjs +2 -2
  40. package/dist/reset.js +1 -1
  41. package/dist/reset.mjs +1 -1
  42. package/dist/types.d.mts +7 -0
  43. package/dist/types.d.ts +7 -0
  44. package/dist/types.js +1 -1
  45. package/dist/types.mjs +1 -1
  46. package/dist/vite.js +8 -8
  47. package/dist/vite.mjs +7 -7
  48. package/dist/{weapp-tw-runtime-loader.js → weapp-tw-css-import-rewrite-loader.js} +49 -18
  49. package/dist/weapp-tw-runtime-classset-loader.js +23 -0
  50. package/dist/webpack.d.mts +0 -1
  51. package/dist/webpack.d.ts +0 -1
  52. package/dist/webpack.js +9 -9
  53. package/dist/webpack.mjs +8 -8
  54. package/dist/webpack4.d.mts +0 -1
  55. package/dist/webpack4.d.ts +0 -1
  56. package/dist/webpack4.js +123 -48
  57. package/dist/webpack4.mjs +105 -30
  58. package/package.json +4 -4
  59. package/dist/chunk-PFUB74BL.mjs +0 -61
  60. package/dist/chunk-WYXD5IW7.js +0 -61
@@ -1,10 +1,10 @@
1
1
  import {
2
2
  createPatchTargetRecorder,
3
3
  createTailwindPatchPromise
4
- } from "./chunk-BMUQ4OAB.mjs";
4
+ } from "./chunk-FYYIFZ36.mjs";
5
5
  import {
6
6
  logger
7
- } from "./chunk-3XGTIDA6.mjs";
7
+ } from "./chunk-IXK4ZWFR.mjs";
8
8
 
9
9
  // src/tailwindcss/recorder.ts
10
10
  function setupPatchRecorder(patcher, baseDir, options) {
@@ -1,4 +1,4 @@
1
- // ../../node_modules/.pnpm/tsup@8.5.1_@microsoft+api-extractor@7.53.1_@types+node@24.10.1__@swc+core@1.15.3_@swc+h_c0fd57d7feba03b3e4bcfd5e91aeb7d6/node_modules/tsup/assets/esm_shims.js
1
+ // ../../node_modules/.pnpm/tsup@8.5.1_@microsoft+api-extractor@7.53.1_@types+node@24.10.1__@swc+core@1.15.3_@swc+h_608bab04d60812eb190cd7b30c36eaf7/node_modules/tsup/assets/esm_shims.js
2
2
  import path from "path";
3
3
  import { fileURLToPath } from "url";
4
4
  var getFilename = () => fileURLToPath(import.meta.url);
@@ -7,10 +7,20 @@ var _escape = require('@weapp-core/escape');
7
7
  var CSS_FILE_PATTERN = /.+\.(?:wx|ac|jx|tt|q|c|ty)ss$/;
8
8
  var HTML_FILE_PATTERN = /.+\.(?:(?:wx|ax|jx|ks|tt|q|ty|xhs)ml|swan)$/;
9
9
  var JS_FILE_PATTERN = /.+\.[cm]?js?$/;
10
+ function normalizePath(p) {
11
+ return p.replace(/\\/g, "/");
12
+ }
13
+ var MPX_STYLES_DIR_PATTERN = /(?:^|\/)styles\/.*\.(?:wx|ac|jx|tt|q|c|ty)ss$/i;
10
14
  var MAIN_CSS_CHUNK_MATCHERS = {
11
15
  "uni-app": (file) => file.startsWith("common/main") || file.startsWith("app"),
12
16
  "uni-app-vite": (file) => file.startsWith("app") || file.startsWith("common/main"),
13
- "mpx": (file) => file.startsWith("app"),
17
+ "mpx": (file) => {
18
+ const normalized = normalizePath(file);
19
+ if (normalized.startsWith("app")) {
20
+ return true;
21
+ }
22
+ return MPX_STYLES_DIR_PATTERN.test(normalized);
23
+ },
14
24
  "taro": (file) => file.startsWith("app"),
15
25
  "remax": (file) => file.startsWith("app"),
16
26
  "rax": (file) => file.startsWith("bundle"),
@@ -0,0 +1,136 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+
4
+ var _chunkJ25ZFRYMjs = require('./chunk-J25ZFRYM.js');
5
+
6
+
7
+ var _chunkZTGB2D5Wjs = require('./chunk-ZTGB2D5W.js');
8
+
9
+ // src/bundlers/webpack/shared/css-imports.ts
10
+ var CSS_EXT_RE = /\.(?:css|scss|sass|less|styl|pcss)$/i;
11
+ function stripResourceQuery(file) {
12
+ let idx = file.indexOf("?");
13
+ if (idx === -1) {
14
+ idx = file.indexOf("&");
15
+ }
16
+ return idx === -1 ? file : file.slice(0, idx);
17
+ }
18
+ function rewriteTailwindcssRequestForCss(data, pkgDir, appType) {
19
+ if (!data) {
20
+ return;
21
+ }
22
+ const request = data.request;
23
+ if (!request) {
24
+ return;
25
+ }
26
+ if (request !== "tailwindcss" && request !== "tailwindcss$" && !request.startsWith("tailwindcss/")) {
27
+ return;
28
+ }
29
+ const issuer = _optionalChain([data, 'access', _ => _.contextInfo, 'optionalAccess', _2 => _2.issuer]);
30
+ if (!issuer) {
31
+ return;
32
+ }
33
+ const normalizedIssuer = stripResourceQuery(issuer);
34
+ if (!CSS_EXT_RE.test(normalizedIssuer)) {
35
+ return;
36
+ }
37
+ const resolved = _chunkJ25ZFRYMjs.resolveTailwindcssImport.call(void 0, request, pkgDir, { appType });
38
+ if (!resolved) {
39
+ return;
40
+ }
41
+ data.request = resolved;
42
+ }
43
+ function applyTailwindcssCssImportRewrite(compiler, options) {
44
+ if (!options.enabled) {
45
+ return;
46
+ }
47
+ compiler.hooks.normalModuleFactory.tap(_chunkZTGB2D5Wjs.pluginName, (factory) => {
48
+ factory.hooks.beforeResolve.tap(_chunkZTGB2D5Wjs.pluginName, (data) => {
49
+ rewriteTailwindcssRequestForCss(data, options.pkgDir, options.appType);
50
+ });
51
+ });
52
+ }
53
+
54
+ // src/bundlers/webpack/shared/loader-anchors.ts
55
+ var MPX_STRIP_CONDITIONAL_LOADER = "@mpxjs/webpack-plugin/lib/style-compiler/strip-conditional-loader";
56
+ var MPX_STYLE_COMPILER_LOADER = "@mpxjs/webpack-plugin/lib/style-compiler/index";
57
+ var MPX_REWRITE_PRECEDENCE_LOADERS = [
58
+ MPX_STYLE_COMPILER_LOADER,
59
+ MPX_STRIP_CONDITIONAL_LOADER
60
+ ];
61
+ function createFinder(targets) {
62
+ return (entries) => entries.findIndex(
63
+ (entry) => targets.some((target) => _optionalChain([entry, 'optionalAccess', _3 => _3.loader, 'optionalAccess', _4 => _4.includes, 'optionalCall', _5 => _5(target)]))
64
+ );
65
+ }
66
+ function createPrioritizedFinder(targets) {
67
+ return (entries) => {
68
+ for (const target of targets) {
69
+ const idx = entries.findIndex((entry) => _optionalChain([entry, 'optionalAccess', _6 => _6.loader, 'optionalAccess', _7 => _7.includes, 'optionalCall', _8 => _8(target)]));
70
+ if (idx !== -1) {
71
+ return idx;
72
+ }
73
+ }
74
+ return -1;
75
+ };
76
+ }
77
+ function createLoaderAnchorFinders(appType) {
78
+ if (_chunkJ25ZFRYMjs.isMpx.call(void 0, appType)) {
79
+ return {
80
+ findRewriteAnchor: createPrioritizedFinder(MPX_REWRITE_PRECEDENCE_LOADERS),
81
+ findClassSetAnchor: createFinder([MPX_STYLE_COMPILER_LOADER])
82
+ };
83
+ }
84
+ const fallbackFinder = createFinder(["postcss-loader"]);
85
+ return {
86
+ findRewriteAnchor: fallbackFinder,
87
+ findClassSetAnchor: fallbackFinder
88
+ };
89
+ }
90
+
91
+ // src/bundlers/webpack/BaseUnifiedPlugin/shared.ts
92
+ var MPX_STYLE_RESOURCE_QUERY_RE = /(?:\?|&)type=styles\b/;
93
+ function getCacheKey(filename) {
94
+ return filename;
95
+ }
96
+ function stripResourceQuery2(resource) {
97
+ if (typeof resource !== "string") {
98
+ return resource;
99
+ }
100
+ const queryIndex = resource.indexOf("?");
101
+ if (queryIndex !== -1) {
102
+ return resource.slice(0, queryIndex);
103
+ }
104
+ const hashIndex = resource.indexOf("#");
105
+ if (hashIndex !== -1) {
106
+ return resource.slice(0, hashIndex);
107
+ }
108
+ return resource;
109
+ }
110
+ function isCssLikeModuleResource(resource, cssMatcher, appType) {
111
+ if (typeof resource !== "string") {
112
+ return false;
113
+ }
114
+ const normalizedResource = stripResourceQuery2(resource);
115
+ if (normalizedResource && cssMatcher(normalizedResource)) {
116
+ return true;
117
+ }
118
+ if (appType === "mpx") {
119
+ return MPX_STYLE_RESOURCE_QUERY_RE.test(resource);
120
+ }
121
+ return false;
122
+ }
123
+ function hasLoaderEntry(entries, target) {
124
+ if (!target) {
125
+ return false;
126
+ }
127
+ return entries.some((entry) => _optionalChain([entry, 'access', _9 => _9.loader, 'optionalAccess', _10 => _10.includes, 'optionalCall', _11 => _11(target)]));
128
+ }
129
+
130
+
131
+
132
+
133
+
134
+
135
+
136
+ exports.applyTailwindcssCssImportRewrite = applyTailwindcssCssImportRewrite; exports.createLoaderAnchorFinders = createLoaderAnchorFinders; exports.getCacheKey = getCacheKey; exports.isCssLikeModuleResource = isCssLikeModuleResource; exports.hasLoaderEntry = hasLoaderEntry;
@@ -5,13 +5,13 @@ import {
5
5
  resolveTailwindcssImport,
6
6
  rewriteTailwindcssImportsInCode,
7
7
  toAbsoluteOutputPath
8
- } from "./chunk-JW7P34IH.mjs";
8
+ } from "./chunk-HXYNNE6Q.mjs";
9
9
  import {
10
10
  processCachedTask
11
11
  } from "./chunk-RRHPTTCP.mjs";
12
12
  import {
13
13
  setupPatchRecorder
14
- } from "./chunk-JYHBNTYH.mjs";
14
+ } from "./chunk-3BMQ6ZWL.mjs";
15
15
  import {
16
16
  collectRuntimeClassSet,
17
17
  createAttributeMatcher,
@@ -22,7 +22,7 @@ import {
22
22
  replaceWxml,
23
23
  toCustomAttributesEntities,
24
24
  vitePluginName
25
- } from "./chunk-BMUQ4OAB.mjs";
25
+ } from "./chunk-FYYIFZ36.mjs";
26
26
  import {
27
27
  getGroupedEntries
28
28
  } from "./chunk-ZNKIYZRQ.mjs";
@@ -33,7 +33,7 @@ import path2 from "path";
33
33
  import process2 from "process";
34
34
  import postcssHtmlTransform from "@weapp-tailwindcss/postcss/html-transform";
35
35
 
36
- // src/uni-app-x/index.ts
36
+ // src/uni-app-x/transform.ts
37
37
  import { NodeTypes } from "@vue/compiler-dom";
38
38
  import { parse } from "@vue/compiler-sfc";
39
39
  import MagicString from "magic-string";
@@ -217,6 +217,149 @@ async function formatPostcssSourceMap(rawMap, file) {
217
217
  };
218
218
  }
219
219
 
220
+ // src/uni-app-x/vite.ts
221
+ function createUniAppXPlugins(options) {
222
+ const {
223
+ appType,
224
+ customAttributesEntities,
225
+ disabledDefaultTemplateHandler,
226
+ mainCssChunkMatcher,
227
+ runtimeState,
228
+ styleHandler,
229
+ jsHandler,
230
+ ensureRuntimeClassSet,
231
+ getResolvedConfig
232
+ } = options;
233
+ const cssPlugins = [void 0, "pre"].map((enforce) => ({
234
+ name: `weapp-tailwindcss:uni-app-x:css${enforce ? `:${enforce}` : ""}`,
235
+ enforce,
236
+ async transform(code, id) {
237
+ await runtimeState.patchPromise;
238
+ const { query } = parseVueRequest(id);
239
+ if (isCSSRequest(id) || query.vue && query.type === "style") {
240
+ const postcssResult = await styleHandler(code, {
241
+ isMainChunk: mainCssChunkMatcher(id, appType),
242
+ postcssOptions: {
243
+ options: {
244
+ from: id,
245
+ map: {
246
+ inline: false,
247
+ annotation: false,
248
+ // PostCSS 可能返回虚拟文件,因此需要启用这一项以获取源内容
249
+ sourcesContent: true
250
+ // 若上游预处理器已经生成 source map,sources 中可能出现重复条目
251
+ }
252
+ }
253
+ }
254
+ });
255
+ const rawPostcssMap = postcssResult.map.toJSON();
256
+ const postcssMap = await formatPostcssSourceMap(
257
+ rawPostcssMap,
258
+ cleanUrl(id)
259
+ );
260
+ return {
261
+ code: postcssResult.css,
262
+ map: postcssMap
263
+ };
264
+ }
265
+ }
266
+ }));
267
+ const nvuePlugin = {
268
+ name: "weapp-tailwindcss:uni-app-x:nvue",
269
+ enforce: "pre",
270
+ async buildStart() {
271
+ await ensureRuntimeClassSet(true);
272
+ },
273
+ async transform(code, id) {
274
+ if (!/\.(?:uvue|nvue)(?:\?.*)?$/.test(id)) {
275
+ return;
276
+ }
277
+ const resolvedConfig = getResolvedConfig();
278
+ const isServeCommand = resolvedConfig?.command === "serve";
279
+ const isWatchBuild = resolvedConfig?.command === "build" && !!resolvedConfig.build?.watch;
280
+ const isNonWatchBuild = resolvedConfig?.command === "build" && !resolvedConfig.build?.watch;
281
+ const shouldForceRefresh = isServeCommand || isWatchBuild || isNonWatchBuild;
282
+ const currentRuntimeSet = shouldForceRefresh ? await ensureRuntimeClassSet(true) : await ensureRuntimeClassSet();
283
+ const extraOptions = customAttributesEntities.length > 0 || disabledDefaultTemplateHandler ? {
284
+ customAttributesEntities,
285
+ disabledDefaultTemplateHandler
286
+ } : void 0;
287
+ if (extraOptions) {
288
+ return transformUVue(code, id, jsHandler, currentRuntimeSet, extraOptions);
289
+ }
290
+ return transformUVue(code, id, jsHandler, currentRuntimeSet);
291
+ },
292
+ async handleHotUpdate(ctx) {
293
+ const resolvedConfig = getResolvedConfig();
294
+ if (resolvedConfig?.command !== "serve") {
295
+ return;
296
+ }
297
+ if (!/\.(?:uvue|nvue)$/.test(ctx.file)) {
298
+ return;
299
+ }
300
+ await ensureRuntimeClassSet(true);
301
+ },
302
+ async watchChange(id) {
303
+ const resolvedConfig = getResolvedConfig();
304
+ if (resolvedConfig?.command !== "build" || !resolvedConfig.build?.watch) {
305
+ return;
306
+ }
307
+ if (!/\.(?:uvue|nvue)(?:\?.*)?$/.test(id)) {
308
+ return;
309
+ }
310
+ await ensureRuntimeClassSet(true);
311
+ }
312
+ };
313
+ return [
314
+ ...cssPlugins,
315
+ nvuePlugin
316
+ ];
317
+ }
318
+ function createUniAppXAssetTask(file, originalSource, outDir, options) {
319
+ return async () => {
320
+ const {
321
+ cache,
322
+ createHandlerOptions,
323
+ debug: debug2,
324
+ jsHandler,
325
+ onUpdate,
326
+ runtimeSet,
327
+ applyLinkedResults: applyLinkedResults2
328
+ } = options;
329
+ const absoluteFile = toAbsoluteOutputPath(file, outDir);
330
+ const rawSource = originalSource.source.toString();
331
+ await processCachedTask({
332
+ cache,
333
+ cacheKey: file,
334
+ rawSource,
335
+ applyResult(source) {
336
+ originalSource.source = source;
337
+ },
338
+ onCacheHit() {
339
+ debug2("js cache hit: %s", file);
340
+ },
341
+ async transform() {
342
+ const currentSource = originalSource.source.toString();
343
+ const { code, linked } = await jsHandler(currentSource, runtimeSet, createHandlerOptions(absoluteFile, {
344
+ uniAppX: options.uniAppX ?? true,
345
+ babelParserOptions: {
346
+ plugins: [
347
+ "typescript"
348
+ ],
349
+ sourceType: "unambiguous"
350
+ }
351
+ }));
352
+ onUpdate(file, currentSource, code);
353
+ debug2("js handle: %s", file);
354
+ applyLinkedResults2(linked);
355
+ return {
356
+ result: code
357
+ };
358
+ }
359
+ });
360
+ };
361
+ }
362
+
220
363
  // src/bundlers/vite/index.ts
221
364
  var debug = createDebug();
222
365
  var weappTailwindcssPackageDir = resolvePackageDir("weapp-tailwindcss");
@@ -376,7 +519,10 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
376
519
  resolveId: {
377
520
  order: "pre",
378
521
  handler(id, importer) {
379
- const replacement = resolveTailwindcssImport(id, weappTailwindcssDirPosix, { join: joinPosixPath });
522
+ const replacement = resolveTailwindcssImport(id, weappTailwindcssDirPosix, {
523
+ join: joinPosixPath,
524
+ appType
525
+ });
380
526
  if (!replacement) {
381
527
  return null;
382
528
  }
@@ -392,7 +538,10 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
392
538
  if (!isCSSRequest(id)) {
393
539
  return null;
394
540
  }
395
- const rewritten = rewriteTailwindcssImportsInCode(code, weappTailwindcssDirPosix, { join: joinPosixPath });
541
+ const rewritten = rewriteTailwindcssImportsInCode(code, weappTailwindcssDirPosix, {
542
+ join: joinPosixPath,
543
+ appType
544
+ });
396
545
  if (!rewritten) {
397
546
  return null;
398
547
  }
@@ -404,6 +553,18 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
404
553
  }
405
554
  }
406
555
  ];
556
+ const getResolvedConfig = () => resolvedConfig;
557
+ const uniAppXPlugins = uniAppX ? createUniAppXPlugins({
558
+ appType,
559
+ customAttributesEntities,
560
+ disabledDefaultTemplateHandler,
561
+ mainCssChunkMatcher,
562
+ runtimeState,
563
+ styleHandler,
564
+ jsHandler,
565
+ ensureRuntimeClassSet,
566
+ getResolvedConfig
567
+ }) : void 0;
407
568
  const plugins = [
408
569
  ...rewritePlugins,
409
570
  {
@@ -455,6 +616,9 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
455
616
  }
456
617
  });
457
618
  };
619
+ const applyLinkedUpdates = (linked) => {
620
+ applyLinkedResults(linked, jsEntries, handleLinkedUpdate, scheduleLinkedApply);
621
+ };
458
622
  const createHandlerOptions = (absoluteFilename, extra) => ({
459
623
  ...extra,
460
624
  filename: absoluteFilename,
@@ -481,7 +645,7 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
481
645
  },
482
646
  async transform() {
483
647
  const transformed = await templateHandler(rawSource, {
484
- runtimeSet
648
+ runtimeSet: runtime
485
649
  });
486
650
  onUpdate(file, rawSource, transformed);
487
651
  debug("html handle: %s", file);
@@ -512,10 +676,10 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
512
676
  },
513
677
  async transform() {
514
678
  const rawSource = originalSource.code;
515
- const { code, linked } = await jsHandler(rawSource, runtimeSet, createHandlerOptions(absoluteFile));
679
+ const { code, linked } = await jsHandler(rawSource, runtime, createHandlerOptions(absoluteFile));
516
680
  onUpdate(file, rawSource, code);
517
681
  debug("js handle: %s", file);
518
- applyLinkedResults(linked, jsEntries, handleLinkedUpdate, scheduleLinkedApply);
682
+ applyLinkedUpdates(linked);
519
683
  return {
520
684
  result: code
521
685
  };
@@ -523,39 +687,23 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
523
687
  });
524
688
  });
525
689
  } else if (uniAppX && originalSource.type === "asset") {
526
- const absoluteFile = toAbsoluteOutputPath(file, outDir);
527
- const rawSource = originalSource.source.toString();
528
- jsTaskFactories.push(async () => {
529
- await processCachedTask({
530
- cache,
531
- cacheKey: file,
532
- rawSource,
533
- applyResult(source) {
534
- originalSource.source = source;
535
- },
536
- onCacheHit() {
537
- debug("js cache hit: %s", file);
538
- },
539
- async transform() {
540
- const currentSource = originalSource.source.toString();
541
- const { code, linked } = await jsHandler(currentSource, runtimeSet, createHandlerOptions(absoluteFile, {
542
- uniAppX,
543
- babelParserOptions: {
544
- plugins: [
545
- "typescript"
546
- ],
547
- sourceType: "unambiguous"
548
- }
549
- }));
550
- onUpdate(file, currentSource, code);
551
- debug("js handle: %s", file);
552
- applyLinkedResults(linked, jsEntries, handleLinkedUpdate, scheduleLinkedApply);
553
- return {
554
- result: code
555
- };
690
+ jsTaskFactories.push(
691
+ createUniAppXAssetTask(
692
+ file,
693
+ originalSource,
694
+ outDir,
695
+ {
696
+ cache,
697
+ createHandlerOptions,
698
+ debug,
699
+ jsHandler,
700
+ onUpdate,
701
+ runtimeSet: runtime,
702
+ applyLinkedResults: applyLinkedUpdates,
703
+ uniAppX
556
704
  }
557
- });
558
- });
705
+ )
706
+ );
559
707
  }
560
708
  }
561
709
  }
@@ -604,92 +752,8 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
604
752
  }
605
753
  }
606
754
  ];
607
- if (uniAppX) {
608
- ;
609
- [void 0, "pre"].forEach((enforce) => {
610
- plugins.push(
611
- {
612
- name: `weapp-tailwindcss:uni-app-x:css${enforce ? `:${enforce}` : ""}`,
613
- enforce,
614
- async transform(code, id) {
615
- await runtimeState.patchPromise;
616
- const { query } = parseVueRequest(id);
617
- if (isCSSRequest(id) || query.vue && query.type === "style") {
618
- const postcssResult = await styleHandler(code, {
619
- isMainChunk: mainCssChunkMatcher(id, appType),
620
- postcssOptions: {
621
- options: {
622
- from: id,
623
- map: {
624
- inline: false,
625
- annotation: false,
626
- // PostCSS 可能返回虚拟文件,因此需要启用这一项以获取源内容
627
- sourcesContent: true
628
- // 若上游预处理器已经生成 source map,sources 中可能出现重复条目
629
- }
630
- }
631
- }
632
- });
633
- const rawPostcssMap = postcssResult.map.toJSON();
634
- const postcssMap = await formatPostcssSourceMap(
635
- // rawPostcssMap.version 类型声明为字符串,实际需要数值
636
- rawPostcssMap,
637
- cleanUrl(id)
638
- );
639
- return {
640
- code: postcssResult.css,
641
- map: postcssMap
642
- };
643
- }
644
- }
645
- }
646
- );
647
- });
648
- plugins.push(
649
- {
650
- name: "weapp-tailwindcss:uni-app-x:nvue",
651
- enforce: "pre",
652
- async buildStart() {
653
- await ensureRuntimeClassSet(true);
654
- },
655
- async transform(code, id) {
656
- if (!/\.(?:uvue|nvue)(?:\?.*)?$/.test(id)) {
657
- return;
658
- }
659
- const isServeCommand = resolvedConfig?.command === "serve";
660
- const isWatchBuild = resolvedConfig?.command === "build" && !!resolvedConfig.build?.watch;
661
- const isNonWatchBuild = resolvedConfig?.command === "build" && !resolvedConfig.build?.watch;
662
- const shouldForceRefresh = isServeCommand || isWatchBuild || isNonWatchBuild;
663
- const currentRuntimeSet = shouldForceRefresh ? await ensureRuntimeClassSet(true) : await ensureRuntimeClassSet();
664
- const extraOptions = customAttributesEntities.length > 0 || disabledDefaultTemplateHandler ? {
665
- customAttributesEntities,
666
- disabledDefaultTemplateHandler
667
- } : void 0;
668
- if (extraOptions) {
669
- return transformUVue(code, id, jsHandler, currentRuntimeSet, extraOptions);
670
- }
671
- return transformUVue(code, id, jsHandler, currentRuntimeSet);
672
- },
673
- async handleHotUpdate(ctx) {
674
- if (resolvedConfig?.command !== "serve") {
675
- return;
676
- }
677
- if (!/\.(?:uvue|nvue)$/.test(ctx.file)) {
678
- return;
679
- }
680
- await ensureRuntimeClassSet(true);
681
- },
682
- async watchChange(id) {
683
- if (resolvedConfig?.command !== "build" || !resolvedConfig.build?.watch) {
684
- return;
685
- }
686
- if (!/\.(?:uvue|nvue)(?:\?.*)?$/.test(id)) {
687
- return;
688
- }
689
- await ensureRuntimeClassSet(true);
690
- }
691
- }
692
- );
755
+ if (uniAppXPlugins) {
756
+ plugins.push(...uniAppXPlugins);
693
757
  }
694
758
  return plugins;
695
759
  }