weapp-tailwindcss 3.4.0-alpha.0 → 3.4.0-alpha.2

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 (124) hide show
  1. package/dist/babel/index.d.ts +16 -0
  2. package/dist/bundlers/gulp/index.d.ts +8 -0
  3. package/dist/bundlers/vite/index.d.ts +3 -0
  4. package/dist/bundlers/webpack/BaseUnifiedPlugin/v4.d.ts +8 -0
  5. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5.d.ts +8 -0
  6. package/dist/bundlers/webpack/index.d.ts +1 -0
  7. package/dist/{weapp-tw-runtime-loader.d.ts → bundlers/webpack/loaders/weapp-tw-runtime-loader.d.ts} +2 -4
  8. package/dist/cache/index.d.ts +32 -0
  9. package/dist/cli.d.ts +1 -2
  10. package/dist/cli.js +51 -1760
  11. package/dist/cli.mjs +45 -34
  12. package/dist/constants-CFM1J-h1.js +42 -0
  13. package/dist/constants-Dy2Dd3Fz.mjs +36 -0
  14. package/dist/constants.d.ts +7 -0
  15. package/dist/core.d.ts +2 -16
  16. package/dist/core.js +60 -1775
  17. package/dist/core.mjs +60 -46
  18. package/dist/css-macro/constants.d.ts +14 -0
  19. package/dist/css-macro/index.d.ts +4 -7
  20. package/dist/css-macro/index.js +30 -140
  21. package/dist/css-macro/index.mjs +28 -35
  22. package/dist/css-macro/postcss.d.ts +3 -5
  23. package/dist/css-macro/postcss.js +46 -99
  24. package/dist/css-macro/postcss.mjs +45 -54
  25. package/dist/debug/index.d.ts +2 -0
  26. package/dist/defaults-DW-EahCC.js +145 -0
  27. package/dist/defaults-w3rlKQwe.mjs +139 -0
  28. package/dist/defaults.d.ts +2 -16
  29. package/dist/defaults.js +7 -208
  30. package/dist/defaults.mjs +4 -9
  31. package/dist/defu-Cdz2PomB.js +60 -0
  32. package/dist/defu-n46TJT6t.mjs +57 -0
  33. package/dist/env.d.ts +2 -0
  34. package/dist/escape.d.ts +4 -0
  35. package/dist/extractors/split.d.ts +3 -0
  36. package/dist/gulp.d.ts +1 -26
  37. package/dist/gulp.js +38 -1898
  38. package/dist/gulp.mjs +30 -15
  39. package/dist/index-B2TNoaOv.mjs +134 -0
  40. package/dist/index-B5NiRecR.js +130 -0
  41. package/dist/index-BEIjgKpF.mjs +11 -0
  42. package/dist/index-BPzIdybK.mjs +513 -0
  43. package/dist/index-DeW_zXzo.mjs +124 -0
  44. package/dist/index-DmzxhHCX.js +136 -0
  45. package/dist/index-DwZHOkK3.js +526 -0
  46. package/dist/index-HC-Qkn0i.js +17 -0
  47. package/dist/index.d.ts +4 -17
  48. package/dist/index.js +43 -2291
  49. package/dist/index.mjs +33 -23
  50. package/dist/js/handlers.d.ts +13 -0
  51. package/dist/js/index.d.ts +7 -0
  52. package/dist/mangle/index.d.ts +8 -0
  53. package/dist/options-7EjuAISl.mjs +869 -0
  54. package/dist/options-C-rvBixk.js +901 -0
  55. package/dist/options.d.ts +2 -0
  56. package/dist/postcss/cssVars.d.ts +5 -0
  57. package/dist/postcss/index.d.ts +3 -0
  58. package/dist/postcss/mp.d.ts +8 -0
  59. package/dist/postcss/plugins/ctx.d.ts +6 -0
  60. package/dist/postcss/plugins/index.d.ts +7 -0
  61. package/dist/postcss/plugins/post.d.ts +5 -0
  62. package/dist/postcss/plugins/pre.d.ts +5 -0
  63. package/dist/postcss/preflight.d.ts +3 -0
  64. package/dist/postcss/selectorParser.d.ts +6 -0
  65. package/dist/postcss/shared.d.ts +3 -0
  66. package/dist/postcss/symbols.d.ts +1 -0
  67. package/dist/postcss.d.ts +1 -23
  68. package/dist/postcss.js +22 -598
  69. package/dist/postcss.mjs +8 -17
  70. package/dist/reg.d.ts +1 -0
  71. package/dist/replace.d.ts +3 -19
  72. package/dist/replace.js +42 -93
  73. package/dist/replace.mjs +26 -30
  74. package/dist/shared-DbJl6i6a.mjs +25 -0
  75. package/dist/shared-hzYeE1wX.js +28 -0
  76. package/dist/tailwindcss/patcher.d.ts +3 -0
  77. package/dist/types.d.ts +165 -0
  78. package/dist/utils.d.ts +18 -0
  79. package/dist/v5-BD9-sqra.mjs +174 -0
  80. package/dist/v5-Ch6783yy.js +181 -0
  81. package/dist/vite.d.ts +1 -22
  82. package/dist/vite.js +36 -1947
  83. package/dist/vite.mjs +28 -15
  84. package/dist/weapp-tw-runtime-loader.js +14 -41
  85. package/dist/weapp-tw-runtime-loader.mjs +8 -12
  86. package/dist/webpack.d.ts +1 -26
  87. package/dist/webpack.js +37 -1994
  88. package/dist/webpack.mjs +29 -15
  89. package/dist/webpack4.d.ts +1 -27
  90. package/dist/webpack4.js +190 -1979
  91. package/dist/webpack4.mjs +188 -211
  92. package/dist/wxml/Tokenizer.d.ts +31 -0
  93. package/dist/wxml/index.d.ts +2 -0
  94. package/dist/wxml/shared.d.ts +2 -0
  95. package/dist/wxml/utils.d.ts +13 -0
  96. package/package.json +3 -3
  97. package/dist/chunk-257YPDSI.mjs +0 -173
  98. package/dist/chunk-75EWCRQW.mjs +0 -13
  99. package/dist/chunk-AB467PG7.mjs +0 -43
  100. package/dist/chunk-E7XGHGC7.mjs +0 -62
  101. package/dist/chunk-GUE4UCRJ.mjs +0 -126
  102. package/dist/chunk-IOYI6MSW.mjs +0 -533
  103. package/dist/chunk-LDWI65M5.mjs +0 -152
  104. package/dist/chunk-NVFWRLOI.mjs +0 -27
  105. package/dist/chunk-ORMKM6ZA.mjs +0 -30
  106. package/dist/chunk-PC4B5JJB.mjs +0 -953
  107. package/dist/chunk-SRLZU2YE.mjs +0 -95
  108. package/dist/chunk-VECXHWWG.mjs +0 -31
  109. package/dist/chunk-VN37QGSM.mjs +0 -216
  110. package/dist/cli.d.mts +0 -2
  111. package/dist/core.d.mts +0 -22
  112. package/dist/css-macro/index.d.mts +0 -18
  113. package/dist/css-macro/postcss.d.mts +0 -7
  114. package/dist/defaults.d.mts +0 -16
  115. package/dist/gulp.d.mts +0 -26
  116. package/dist/index.d.mts +0 -17
  117. package/dist/postcss.d.mts +0 -23
  118. package/dist/replace.d.mts +0 -19
  119. package/dist/types-DSNuiOhH.d.mts +0 -519
  120. package/dist/types-DSNuiOhH.d.ts +0 -519
  121. package/dist/vite.d.mts +0 -22
  122. package/dist/weapp-tw-runtime-loader.d.mts +0 -7
  123. package/dist/webpack.d.mts +0 -26
  124. package/dist/webpack4.d.mts +0 -27
package/dist/webpack4.js CHANGED
@@ -1,1991 +1,202 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __defProps = Object.defineProperties;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
7
- var __getOwnPropNames = Object.getOwnPropertyNames;
8
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
9
- var __getProtoOf = Object.getPrototypeOf;
10
- var __hasOwnProp = Object.prototype.hasOwnProperty;
11
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
12
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
13
- var __spreadValues = (a, b) => {
14
- for (var prop in b || (b = {}))
15
- if (__hasOwnProp.call(b, prop))
16
- __defNormalProp(a, prop, b[prop]);
17
- if (__getOwnPropSymbols)
18
- for (var prop of __getOwnPropSymbols(b)) {
19
- if (__propIsEnum.call(b, prop))
20
- __defNormalProp(a, prop, b[prop]);
21
- }
22
- return a;
23
- };
24
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
25
- var __export = (target, all) => {
26
- for (var name in all)
27
- __defProp(target, name, { get: all[name], enumerable: true });
28
- };
29
- var __copyProps = (to, from, except, desc) => {
30
- if (from && typeof from === "object" || typeof from === "function") {
31
- for (let key of __getOwnPropNames(from))
32
- if (!__hasOwnProp.call(to, key) && key !== except)
33
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
34
- }
35
- return to;
36
- };
37
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
38
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
39
- // If the importer is in node compatibility mode or this is not an ESM
40
- // file that has been converted to a CommonJS file using a Babel-
41
- // compatible transform (i.e. "__esModule" has not been set), then set
42
- // "default" to the CommonJS "module.exports" for node compatibility.
43
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
44
- mod
45
- ));
46
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
47
- var __async = (__this, __arguments, generator) => {
48
- return new Promise((resolve, reject) => {
49
- var fulfilled = (value) => {
50
- try {
51
- step(generator.next(value));
52
- } catch (e) {
53
- reject(e);
54
- }
55
- };
56
- var rejected = (value) => {
57
- try {
58
- step(generator.throw(value));
59
- } catch (e) {
60
- reject(e);
61
- }
62
- };
63
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
64
- step((generator = generator.apply(__this, __arguments)).next());
65
- });
66
- };
67
-
68
- // src/webpack4.ts
69
- var webpack4_exports = {};
70
- __export(webpack4_exports, {
71
- UnifiedWebpackPluginV4: () => UnifiedWebpackPluginV4
72
- });
73
- module.exports = __toCommonJS(webpack4_exports);
74
-
75
- // src/bundlers/webpack/BaseUnifiedPlugin/v4.ts
76
- var import_node_path2 = __toESM(require("path"));
77
- var import_node_fs = __toESM(require("fs"));
78
- var import_webpack_sources = require("webpack-sources");
79
-
80
- // src/js/index.ts
81
- var import_magic_string = __toESM(require("magic-string"));
82
-
83
- // src/escape.ts
84
- var escape_exports = {};
85
- __export(escape_exports, {
86
- decodeUnicode: () => decodeUnicode,
87
- decodeUnicode2: () => decodeUnicode2,
88
- jsStringEscape: () => import_escape.jsStringEscape
89
- });
90
- __reExport(escape_exports, require("@weapp-core/escape"));
91
- var import_escape = require("@ast-core/escape");
92
- function decodeUnicode(s) {
93
- return unescape(s.replaceAll(/\\(u[\dA-Fa-f]{4})/g, "%$1"));
94
- }
95
- function decodeUnicode2(input) {
96
- try {
97
- return JSON.parse(`"${input}"`);
98
- } catch (_error) {
99
- return input;
100
- }
101
- }
102
-
103
- // src/wxml/shared.ts
104
- function replaceWxml(original, options = {
105
- keepEOL: false,
106
- escapeMap: escape_exports.SimpleMappingChars2String
107
- }) {
108
- const { keepEOL, escapeMap, mangleContext, ignoreHead } = options;
109
- let res = original;
110
- if (!keepEOL) {
111
- res = res.replaceAll(/[\n\r]+/g, "");
112
- }
113
- if (mangleContext) {
114
- res = mangleContext.wxmlHandler(res);
115
- }
116
- res = (0, escape_exports.escape)(res, {
117
- map: escapeMap,
118
- ignoreHead
119
- });
120
- return res;
121
- }
122
-
123
- // src/reg.ts
124
- var reg_exports = {};
125
- __reExport(reg_exports, require("@weapp-core/regex"));
126
-
127
- // src/extractors/split.ts
128
- var validateFilterRE = /[\w\u00A0-\uFFFF%-?]/;
129
- function isValidSelector(selector = "") {
130
- return validateFilterRE.test(selector);
131
- }
132
- function splitCode(code, allowDoubleQuotes = false) {
133
- const splitter = allowDoubleQuotes ? /\s+/ : /\s+|"/;
134
- return code.split(splitter).filter((element) => isValidSelector(element));
135
- }
136
-
137
- // src/js/handlers.ts
138
- function replaceHandleValue(str, node, options, ms, offset = 0) {
139
- const {
140
- classNameSet: set,
141
- escapeMap,
142
- mangleContext: ctx,
143
- needEscaped = false,
144
- jsPreserveClass,
145
- arbitraryValues,
146
- always,
147
- unescapeUnicode
148
- } = options;
149
- const allowDoubleQuotes = arbitraryValues == null ? void 0 : arbitraryValues.allowDoubleQuotes;
150
- let rawStr = str;
151
- let needUpdate = false;
152
- if (unescapeUnicode && rawStr.includes("\\u")) {
153
- rawStr = decodeUnicode2(rawStr);
154
- }
155
- const arr = splitCode(rawStr, allowDoubleQuotes);
156
- for (const v of arr) {
157
- if (always || set && set.has(v) && !(jsPreserveClass == null ? void 0 : jsPreserveClass(v))) {
158
- let ignoreFlag = false;
159
- if (Array.isArray(node.leadingComments)) {
160
- ignoreFlag = node.leadingComments.findIndex((x) => x.value.includes("weapp-tw") && x.value.includes("ignore")) > -1;
161
- }
162
- if (!ignoreFlag) {
163
- if (ctx) {
164
- rawStr = ctx.jsHandler(rawStr);
165
- }
166
- rawStr = rawStr.replace(
167
- new RegExp((0, reg_exports.escapeStringRegexp)(v)),
168
- replaceWxml(v, {
169
- escapeMap
170
- })
171
- );
172
- needUpdate = true;
173
- }
174
- }
175
- }
176
- if (needUpdate && typeof node.start === "number" && typeof node.end === "number") {
177
- const start = node.start + offset;
178
- const end = node.end - offset;
179
- if (start < end && str !== rawStr) {
180
- const content = needEscaped ? (0, import_escape.jsStringEscape)(rawStr) : rawStr;
181
- ms.update(start, end, content);
182
- }
183
- }
184
- return rawStr;
185
- }
186
-
187
- // src/babel/index.ts
188
- var import_generator = __toESM(require("@babel/generator"));
189
- var import_traverse = __toESM(require("@babel/traverse"));
190
- var import_parser = require("@babel/parser");
191
- function _interopDefaultCompat(e) {
192
- return e && typeof e === "object" && "default" in e ? e.default : e;
193
- }
194
- var generate = _interopDefaultCompat(import_generator.default);
195
- var traverse = _interopDefaultCompat(import_traverse.default);
196
-
197
- // ../../node_modules/.pnpm/defu@6.1.4/node_modules/defu/dist/defu.mjs
198
- function isPlainObject(value) {
199
- if (value === null || typeof value !== "object") {
200
- return false;
201
- }
202
- const prototype = Object.getPrototypeOf(value);
203
- if (prototype !== null && prototype !== Object.prototype && Object.getPrototypeOf(prototype) !== null) {
204
- return false;
205
- }
206
- if (Symbol.iterator in value) {
207
- return false;
208
- }
209
- if (Symbol.toStringTag in value) {
210
- return Object.prototype.toString.call(value) === "[object Module]";
211
- }
212
- return true;
213
- }
214
- function _defu(baseObject, defaults, namespace = ".", merger) {
215
- if (!isPlainObject(defaults)) {
216
- return _defu(baseObject, {}, namespace, merger);
217
- }
218
- const object = Object.assign({}, defaults);
219
- for (const key in baseObject) {
220
- if (key === "__proto__" || key === "constructor") {
221
- continue;
222
- }
223
- const value = baseObject[key];
224
- if (value === null || value === void 0) {
225
- continue;
226
- }
227
- if (merger && merger(object, key, value, namespace)) {
228
- continue;
229
- }
230
- if (Array.isArray(value) && Array.isArray(object[key])) {
231
- object[key] = [...value, ...object[key]];
232
- } else if (isPlainObject(value) && isPlainObject(object[key])) {
233
- object[key] = _defu(
234
- value,
235
- object[key],
236
- (namespace ? `${namespace}.` : "") + key.toString(),
237
- merger
238
- );
239
- } else {
240
- object[key] = value;
241
- }
242
- }
243
- return object;
244
- }
245
- function createDefu(merger) {
246
- return (...arguments_) => (
247
- // eslint-disable-next-line unicorn/no-array-reduce
248
- arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
249
- );
250
- }
251
- var defu = createDefu();
252
- var defuFn = createDefu((object, key, currentValue) => {
253
- if (object[key] !== void 0 && typeof currentValue === "function") {
254
- object[key] = currentValue(object[key]);
255
- return true;
256
- }
257
- });
258
- var defuArrayFn = createDefu((object, key, currentValue) => {
259
- if (Array.isArray(object[key]) && typeof currentValue === "function") {
260
- object[key] = currentValue(object[key]);
261
- return true;
262
- }
263
- });
264
-
265
- // src/utils.ts
266
- function isMap(value) {
267
- return Object.prototype.toString.call(value) === "[object Map]";
268
- }
269
- function noop() {
270
- }
271
- function groupBy(arr, cb) {
272
- if (!Array.isArray(arr)) {
273
- throw new TypeError("expected an array for first argument");
274
- }
275
- if (typeof cb !== "function") {
276
- throw new TypeError("expected a function for second argument");
277
- }
278
- const result = {};
279
- for (const item of arr) {
280
- const bucketCategory = cb(item);
281
- const bucket = result[bucketCategory];
282
- if (Array.isArray(bucket)) {
283
- result[bucketCategory].push(item);
284
- } else {
285
- result[bucketCategory] = [item];
286
- }
287
- }
288
- return result;
289
- }
290
- function getGroupedEntries(entries, options) {
291
- const { cssMatcher, htmlMatcher, jsMatcher, wxsMatcher } = options;
292
- const groupedEntries = groupBy(entries, ([file]) => {
293
- if (cssMatcher(file)) {
294
- return "css";
295
- } else if (htmlMatcher(file)) {
296
- return "html";
297
- } else if (jsMatcher(file) || wxsMatcher(file)) {
298
- return "js";
299
- } else {
300
- return "other";
301
- }
302
- });
303
- return groupedEntries;
304
- }
305
- function removeExt(file) {
306
- return file.replace(/\.[^./]+$/, "");
307
- }
308
- var defuOverrideArray = createDefu((obj, key, value) => {
309
- if (Array.isArray(obj[key]) && Array.isArray(value)) {
310
- obj[key] = value;
311
- return true;
312
- }
313
- });
314
-
315
- // src/js/index.ts
316
- function isEvalPath(p) {
317
- if (p.isCallExpression()) {
318
- const calleePath = p.get("callee");
319
- return calleePath.isIdentifier() && calleePath.node.name === "eval";
320
- }
321
- return false;
322
- }
323
- function getAstGrep() {
324
- return __async(this, null, function* () {
325
- try {
326
- const { js } = yield import("@ast-grep/napi");
327
- return js;
328
- } catch (error) {
329
- console.warn("\u8BF7\u5148\u5B89\u88C5 `@ast-grep/napi` , \u5B89\u88C5\u5B8C\u6210\u540E\u518D\u5C1D\u8BD5\u8FD0\u884C\uFF01");
330
- throw error;
331
- }
332
- });
333
- }
334
- function astGrepUpdateString(ast, options, ms) {
335
- return __async(this, null, function* () {
336
- const js = yield getAstGrep();
337
- const nodes = ast.findAll(js.kind("string"));
338
- for (const node of nodes) {
339
- const range = node.range();
340
- const text = node.text();
341
- replaceHandleValue(
342
- text.slice(1, -1),
343
- {
344
- end: range.end.index - 1,
345
- start: range.start.index + 1
346
- },
347
- __spreadProps(__spreadValues({}, options), {
348
- unescapeUnicode: true
349
- }),
350
- ms,
351
- 0
352
- );
353
- }
354
- const templateNodes = ast.findAll(js.kind("template_string"));
355
- for (const node of templateNodes) {
356
- const fragments = node.findAll(js.kind("string_fragment"));
357
- for (const fragment of fragments) {
358
- const range = fragment.range();
359
- const text = fragment.text();
360
- replaceHandleValue(
361
- text,
362
- {
363
- end: range.end.index,
364
- start: range.start.index
365
- },
366
- __spreadProps(__spreadValues({}, options), {
367
- unescapeUnicode: true
368
- }),
369
- ms,
370
- 0
371
- );
372
- }
373
- }
374
- });
375
- }
376
- function jsHandler(rawSource, options) {
377
- const ms = new import_magic_string.default(rawSource);
378
- let ast;
379
- try {
380
- ast = (0, import_parser.parse)(rawSource, options.babelParserOptions);
381
- } catch (error) {
382
- return {
383
- code: rawSource,
384
- error
385
- };
386
- }
387
- const traverseOptions = {
388
- StringLiteral: {
389
- enter(p) {
390
- var _a;
391
- if (isEvalPath(p.parentPath)) {
392
- return;
393
- }
394
- const n = p.node;
395
- replaceHandleValue(
396
- n.value,
397
- n,
398
- __spreadProps(__spreadValues({}, options), {
399
- needEscaped: (_a = options.needEscaped) != null ? _a : true
400
- }),
401
- ms,
402
- 1
403
- );
404
- }
405
- // exit(p) {}
406
- },
407
- TemplateElement: {
408
- enter(p) {
409
- if (p.parentPath.isTemplateLiteral() && isEvalPath(p.parentPath.parentPath)) {
410
- return;
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var options = require('./options-C-rvBixk.js');
6
+ var path = require('node:path');
7
+ var fs = require('node:fs');
8
+ var webpackSources = require('webpack-sources');
9
+ var index = require('./index-DwZHOkK3.js');
10
+ var defaults = require('./defaults-DW-EahCC.js');
11
+ var index$1 = require('./index-HC-Qkn0i.js');
12
+ require('magic-string');
13
+ require('./replace.js');
14
+ require('@weapp-core/escape');
15
+ require('@ast-core/escape');
16
+ require('./shared-hzYeE1wX.js');
17
+ require('@weapp-core/regex');
18
+ require('@babel/generator');
19
+ require('@babel/traverse');
20
+ require('@babel/parser');
21
+ require('@babel/types');
22
+ require('htmlparser2');
23
+ require('postcss');
24
+ require('node:process');
25
+ require('tailwindcss-patch');
26
+ require('@tailwindcss-mangle/shared');
27
+ require('lru-cache');
28
+ require('md5');
29
+ require('@csstools/postcss-is-pseudo-class');
30
+ require('postcss-rem-to-responsive-pixel');
31
+ require('postcss-selector-parser');
32
+ require('./defu-Cdz2PomB.js');
33
+ require('debug');
34
+
35
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
36
+
37
+ var path__default = /*#__PURE__*/_interopDefaultCompat(path);
38
+ var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
39
+
40
+ const debug = index$1.createDebug();
41
+ class UnifiedWebpackPluginV4 {
42
+ constructor(options$1 = {}) {
43
+ this.options = options.getOptions(options$1);
44
+ this.appType = this.options.appType;
45
+ }
46
+ apply(compiler) {
47
+ const { mainCssChunkMatcher, disabled, onLoad, onUpdate, onEnd, onStart, styleHandler, patch, templateHandler, jsHandler, setMangleRuntimeSet, runtimeLoaderPath, cache, twPatcher, } = this.options;
48
+ if (disabled) {
49
+ return;
411
50
  }
412
- const n = p.node;
413
- replaceHandleValue(
414
- n.value.raw,
415
- n,
416
- __spreadProps(__spreadValues({}, options), {
417
- needEscaped: false
418
- }),
419
- ms,
420
- 0
421
- );
422
- }
423
- },
424
- CallExpression: {
425
- enter(p) {
426
- if (isEvalPath(p)) {
427
- p.traverse({
428
- StringLiteral: {
429
- enter(s) {
430
- const res = jsHandler(s.node.value, __spreadProps(__spreadValues({}, options), {
431
- needEscaped: false,
432
- generateMap: false
433
- }));
434
- if (res.code) {
435
- const node = s.node;
436
- if (typeof node.start === "number" && typeof node.end === "number") {
437
- const start = node.start + 1;
438
- const end = node.end - 1;
439
- if (start < end && s.node.value !== res.code) {
440
- ms.update(start, end, (0, import_escape.jsStringEscape)(res.code));
441
- node.value = res.code;
442
- }
443
- }
444
- }
445
- }
51
+ patch === null || patch === void 0 ? void 0 : patch();
52
+ function getClassSet() {
53
+ return twPatcher.getClassSet();
54
+ }
55
+ onLoad();
56
+ const loader = runtimeLoaderPath !== null && runtimeLoaderPath !== void 0 ? runtimeLoaderPath : path__default["default"].resolve(__dirname, './weapp-tw-runtime-loader.js');
57
+ const isExisted = fs__default["default"].existsSync(loader);
58
+ const WeappTwRuntimeAopLoader = {
59
+ loader,
60
+ options: {
61
+ getClassSet,
446
62
  },
447
- TemplateElement: {
448
- enter(s) {
449
- const res = jsHandler(s.node.value.raw, __spreadProps(__spreadValues({}, options), {
450
- generateMap: false
451
- }));
452
- if (res.code) {
453
- const node = s.node;
454
- if (typeof node.start === "number" && typeof node.end === "number") {
455
- const start = node.start;
456
- const end = node.end;
457
- if (start < end && s.node.value.raw !== res.code) {
458
- ms.update(start, end, res.code);
459
- s.node.value.raw = res.code;
63
+ ident: null,
64
+ type: null,
65
+ };
66
+ compiler.hooks.compilation.tap(index.pluginName, (compilation) => {
67
+ compilation.hooks.normalModuleLoader.tap(index.pluginName, (_loaderContext, module) => {
68
+ if (isExisted) {
69
+ const idx = module.loaders.findIndex(x => x.loader.includes('postcss-loader'));
70
+ if (idx > -1) {
71
+ module.loaders.unshift(WeappTwRuntimeAopLoader);
460
72
  }
461
- }
462
73
  }
463
- }
464
- }
465
- });
466
- }
467
- }
468
- }
469
- };
470
- traverse(ast, traverseOptions);
471
- return {
472
- code: ms.toString()
473
- };
474
- }
475
- function jsHandlerAsync(rawSource, options) {
476
- return __async(this, null, function* () {
477
- const ms = new import_magic_string.default(rawSource);
478
- const js = yield getAstGrep();
479
- let ast;
480
- try {
481
- const root = yield js.parseAsync(rawSource);
482
- ast = root.root();
483
- } catch (e) {
484
- return {
485
- code: rawSource
486
- };
487
- }
488
- yield astGrepUpdateString(ast, options, ms);
489
- return {
490
- code: ms.toString()
491
- };
492
- });
493
- }
494
- function createJsHandler(options) {
495
- const { mangleContext, arbitraryValues, escapeMap, jsPreserveClass, generateMap, jsAstTool, babelParserOptions } = options;
496
- function _jsHandler(rawSource, set, options2) {
497
- const opts = defuOverrideArray(options2, {
498
- classNameSet: set,
499
- escapeMap,
500
- arbitraryValues,
501
- mangleContext,
502
- jsPreserveClass,
503
- generateMap,
504
- jsAstTool,
505
- babelParserOptions
506
- });
507
- if (opts.jsAstTool === "ast-grep") {
508
- return jsHandlerAsync(rawSource, opts);
509
- }
510
- return jsHandler(rawSource, opts);
511
- }
512
- function sync(rawSource, set, options2) {
513
- const opts = defuOverrideArray(options2, {
514
- classNameSet: set,
515
- escapeMap,
516
- arbitraryValues,
517
- mangleContext,
518
- jsPreserveClass,
519
- generateMap,
520
- jsAstTool,
521
- babelParserOptions
522
- });
523
- return jsHandler(rawSource, opts);
524
- }
525
- _jsHandler.sync = sync;
526
- return _jsHandler;
527
- }
528
-
529
- // src/defaults.ts
530
- var defaultOptions = {
531
- cssMatcher: (file) => /.+\.(?:wx|ac|jx|tt|q|c|ty)ss$/.test(file),
532
- htmlMatcher: (file) => /.+\.(?:(?:wx|ax|jx|ks|tt|q|ty)ml|swan)$/.test(file),
533
- jsMatcher: (file) => {
534
- if (file.includes("node_modules")) {
535
- return false;
536
- }
537
- return /.+\.[cm]?js?$/.test(file);
538
- },
539
- mainCssChunkMatcher: (file, appType) => {
540
- switch (appType) {
541
- case "uni-app": {
542
- return /^common\/main/.test(file);
543
- }
544
- case "uni-app-vite": {
545
- return file.startsWith("app") || /^common\/main/.test(file);
546
- }
547
- case "mpx": {
548
- return file.startsWith("app");
549
- }
550
- case "taro": {
551
- return file.startsWith("app");
552
- }
553
- case "remax": {
554
- return file.startsWith("app");
555
- }
556
- case "rax": {
557
- return file.startsWith("bundle");
558
- }
559
- case "native": {
560
- return file.startsWith("app");
561
- }
562
- case "kbone": {
563
- return /^(?:common\/)?miniprogram-app/.test(file);
564
- }
565
- default: {
566
- return true;
567
- }
568
- }
569
- },
570
- wxsMatcher: () => {
571
- return false;
572
- },
573
- // https://tailwindcss.com/docs/preflight#border-styles-are-reset-globally
574
- cssPreflight: {
575
- "box-sizing": "border-box",
576
- "border-width": "0",
577
- "border-style": "solid",
578
- "border-color": "currentColor"
579
- },
580
- disabled: false,
581
- customRuleCallback: noop,
582
- onLoad: noop,
583
- onStart: noop,
584
- onEnd: noop,
585
- onUpdate: noop,
586
- customAttributes: {},
587
- customReplaceDictionary: escape_exports.SimpleMappingChars2String,
588
- appType: void 0,
589
- arbitraryValues: {
590
- allowDoubleQuotes: false
591
- },
592
- cssChildCombinatorReplaceValue: ["view"],
593
- inlineWxs: false,
594
- injectAdditionalCssVarScope: false,
595
- jsPreserveClass: (keyword) => {
596
- if (keyword === "*") {
597
- return true;
598
- }
599
- return false;
600
- },
601
- disabledDefaultTemplateHandler: false,
602
- cssSelectorReplacement: {
603
- root: "page",
604
- universal: ["view", "text"]
605
- },
606
- babelParserOptions: {
607
- sourceType: "unambiguous"
608
- },
609
- postcssOptions: {},
610
- cssRemoveHoverPseudoClass: true
611
- // jsAstTool: 'ast-grep'
612
- };
613
-
614
- // src/wxml/utils.ts
615
- var t = __toESM(require("@babel/types"));
616
- var import_htmlparser2 = require("htmlparser2");
617
- var import_magic_string2 = __toESM(require("magic-string"));
618
-
619
- // src/wxml/Tokenizer.ts
620
- var Tokenizer = class {
621
- constructor() {
622
- this.reset();
623
- }
624
- processChar(char, index) {
625
- switch (this.state) {
626
- case 0 /* START */:
627
- if (char === " ") {
628
- } else if (char === "{") {
629
- this.state = 2 /* OPEN_BRACE */;
630
- this.bufferStartIndex = index;
631
- this.buffer += char;
632
- this.expressionBuffer = char;
633
- this.expressionStartIndex = index;
634
- } else {
635
- this.state = 1 /* TEXT */;
636
- this.bufferStartIndex = index;
637
- this.buffer += char;
638
- }
639
- break;
640
- case 1 /* TEXT */:
641
- if (char === " ") {
642
- this.tokens.push({ start: this.bufferStartIndex, end: index, value: this.buffer, expressions: this.expressions });
643
- this.buffer = "";
644
- this.expressions = [];
645
- this.state = 0 /* START */;
646
- } else if (char === "{") {
647
- this.buffer += char;
648
- this.expressionBuffer = char;
649
- this.expressionStartIndex = index;
650
- this.state = 2 /* OPEN_BRACE */;
651
- } else {
652
- this.buffer += char;
653
- }
654
- break;
655
- case 2 /* OPEN_BRACE */:
656
- if (char === "}") {
657
- this.buffer += char;
658
- this.expressionBuffer += char;
659
- this.state = 3 /* POTENTIAL_CLOSE */;
660
- } else {
661
- this.buffer += char;
662
- this.expressionBuffer += char;
663
- }
664
- break;
665
- case 3 /* POTENTIAL_CLOSE */:
666
- if (char === "}") {
667
- this.buffer += char;
668
- this.expressionBuffer += char;
669
- this.expressions.push({
670
- start: this.expressionStartIndex,
671
- end: index + 1,
672
- value: this.expressionBuffer
673
- });
674
- this.expressionBuffer = "";
675
- this.state = 4 /* BRACES_COMPLETE */;
676
- } else {
677
- this.buffer += char;
678
- this.expressionBuffer += char;
679
- this.state = 2 /* OPEN_BRACE */;
680
- }
681
- break;
682
- case 4 /* BRACES_COMPLETE */:
683
- if (char === " ") {
684
- this.tokens.push({
685
- start: this.bufferStartIndex,
686
- end: index,
687
- value: this.buffer,
688
- expressions: this.expressions
689
- });
690
- this.buffer = "";
691
- this.expressions = [];
692
- this.state = 0 /* START */;
693
- } else if (char === "{") {
694
- this.expressionStartIndex = index;
695
- this.expressionBuffer = char;
696
- this.buffer += char;
697
- this.state = 2 /* OPEN_BRACE */;
698
- } else {
699
- this.buffer += char;
700
- this.state = 1 /* TEXT */;
701
- }
702
- break;
703
- default:
704
- throw new Error("Unexpected state");
705
- }
706
- }
707
- run(input) {
708
- for (let i = 0; i < input.length; i++) {
709
- const char = input[i];
710
- this.processChar(char, i);
711
- }
712
- if (this.buffer.length > 0) {
713
- this.tokens.push({
714
- start: this.bufferStartIndex,
715
- end: input.length,
716
- value: this.buffer,
717
- expressions: this.expressions
718
- });
719
- }
720
- return this.tokens;
721
- }
722
- reset() {
723
- this.state = 0 /* START */;
724
- this.buffer = "";
725
- this.tokens = [];
726
- this.bufferStartIndex = 0;
727
- this.expressionBuffer = "";
728
- this.expressionStartIndex = 0;
729
- this.expressions = [];
730
- }
731
- };
732
-
733
- // src/wxml/utils.ts
734
- function generateCode(match, options = {}) {
735
- try {
736
- const { jsHandler: jsHandler2, runtimeSet } = options;
737
- if (jsHandler2 && jsHandler2.sync && runtimeSet) {
738
- const { code } = jsHandler2.sync(match, runtimeSet);
739
- return code;
740
- } else {
741
- const ms = new import_magic_string2.default(match);
742
- const ast = (0, import_parser.parseExpression)(match);
743
- traverse(ast, {
744
- StringLiteral(path3) {
745
- var _a, _b;
746
- if (t.isMemberExpression(path3.parent)) {
747
- return;
748
- }
749
- if (t.isBinaryExpression(path3.parent) && (t.isConditionalExpression((_a = path3.parentPath) == null ? void 0 : _a.parent) || t.isLogicalExpression((_b = path3.parentPath) == null ? void 0 : _b.parent))) {
750
- return;
751
- }
752
- const n = path3.node;
753
- replaceHandleValue(
754
- n.value,
755
- n,
756
- {
757
- mangleContext: options.mangleContext,
758
- escapeMap: options.escapeMap,
759
- classNameSet: options.runtimeSet,
760
- needEscaped: true,
761
- always: true
762
- },
763
- ms,
764
- 1
765
- );
766
- },
767
- noScope: true
768
- });
769
- return ms.toString();
770
- }
771
- } catch (e) {
772
- return match;
773
- }
774
- }
775
- function extract(original, reg) {
776
- let match = reg.exec(original);
777
- const sources = [];
778
- while (match !== null) {
779
- const start = match.index;
780
- const end = reg.lastIndex;
781
- sources.push({
782
- start,
783
- end,
784
- raw: match[1]
785
- });
786
- match = reg.exec(original);
787
- }
788
- return sources;
789
- }
790
- function extractSource(original) {
791
- return extract(original, reg_exports.variableRegExp);
792
- }
793
- function handleEachClassFragment(original, options = {}) {
794
- const sources = extractSource(original);
795
- if (sources.length > 0) {
796
- const resultArray = [];
797
- let p = 0;
798
- for (let i = 0; i < sources.length; i++) {
799
- const m = sources[i];
800
- const before = original.slice(p, m.start);
801
- resultArray.push(
802
- replaceWxml(before, {
803
- keepEOL: true,
804
- escapeMap: options.escapeMap,
805
- mangleContext: options.mangleContext,
806
- // 首的str才会被转译
807
- // example: 2xl:xx 2x{{y}}
808
- ignoreHead: p > 0
809
- })
810
- );
811
- p = m.start;
812
- if (m.raw.trim().length > 0) {
813
- const code = generateCode(m.raw, options);
814
- const source = `{{${code}}}`;
815
- m.source = source;
816
- } else {
817
- m.source = "";
818
- }
819
- resultArray.push(m.source);
820
- p = m.end;
821
- if (i === sources.length - 1) {
822
- const after = original.slice(m.end);
823
- resultArray.push(
824
- replaceWxml(after, {
825
- keepEOL: true,
826
- escapeMap: options.escapeMap,
827
- mangleContext: options.mangleContext,
828
- ignoreHead: true
829
- })
830
- );
831
- }
832
- }
833
- return resultArray.filter(Boolean).join("").trim();
834
- } else {
835
- return replaceWxml(original, {
836
- keepEOL: false,
837
- escapeMap: options.escapeMap,
838
- mangleContext: options.mangleContext,
839
- ignoreHead: false
840
- });
841
- }
842
- }
843
- function templateReplacer(original, options = {}) {
844
- const ms = new import_magic_string2.default(original);
845
- const tokenizer = new Tokenizer();
846
- const tokens = tokenizer.run(ms.original);
847
- for (const token of tokens) {
848
- const target = handleEachClassFragment(token.value, options);
849
- ms.update(token.start, token.end, target);
850
- }
851
- return ms.toString();
852
- }
853
- function regTest(reg, str) {
854
- reg.lastIndex = 0;
855
- return reg.test(str);
856
- }
857
- function isPropsMatch(props, attr) {
858
- if (Array.isArray(props)) {
859
- for (const prop of props) {
860
- const res = typeof prop === "string" ? prop.toLowerCase() === attr.toLowerCase() : regTest(prop, attr);
861
- if (res) {
862
- return res;
863
- }
864
- }
865
- return false;
866
- } else if (typeof props === "string") {
867
- return props === attr;
868
- } else {
869
- return regTest(props, attr);
870
- }
871
- }
872
- function customTemplateHandler(rawSource, options) {
873
- return __async(this, null, function* () {
874
- const {
875
- customAttributesEntities = [],
876
- disabledDefaultTemplateHandler,
877
- inlineWxs,
878
- runtimeSet,
879
- jsHandler: jsHandler2
880
- } = options != null ? options : {};
881
- const s = new import_magic_string2.default(rawSource);
882
- let tag = "";
883
- const wxsArray = [];
884
- const parser = new import_htmlparser2.Parser(
885
- {
886
- onopentagname(name) {
887
- tag = name;
888
- },
889
- onattribute(name, value, quote) {
890
- if (value) {
891
- let update2 = function() {
892
- s.update(
893
- parser.startIndex + name.length + 2,
894
- // !important
895
- // htmlparser2 9.0.0: parser.endIndex
896
- // htmlparser2 9.1.0: parser.endIndex - 1
897
- // https://github.com/sonofmagic/weapp-tailwindcss/issues/269
898
- parser.endIndex - 1,
899
- templateReplacer(value, __spreadProps(__spreadValues({}, options), {
900
- quote
901
- }))
902
- );
903
- };
904
- var update = update2;
905
- if (!disabledDefaultTemplateHandler && (name === "class" || name === "hover-class" || name === "virtualHostClass" || name === "virtualhostclass")) {
906
- update2();
74
+ });
75
+ });
76
+ compiler.hooks.emit.tapPromise(index.pluginName, (compilation) => options.__awaiter(this, void 0, void 0, function* () {
77
+ onStart();
78
+ debug('start');
79
+ for (const chunk of compilation.chunks) {
80
+ if (chunk.id && chunk.hash) {
81
+ cache.calcHashValueChanged(chunk.id, chunk.hash);
82
+ }
907
83
  }
908
- for (const [t2, props] of customAttributesEntities) {
909
- if (t2 === "*") {
910
- if (isPropsMatch(props, name)) {
911
- update2();
84
+ const assets = compilation.assets;
85
+ const entries = Object.entries(assets);
86
+ const groupedEntries = defaults.getGroupedEntries(entries, this.options);
87
+ const runtimeSet = getClassSet();
88
+ setMangleRuntimeSet(runtimeSet);
89
+ debug('get runtimeSet, class count: %d', runtimeSet.size);
90
+ if (Array.isArray(groupedEntries.html)) {
91
+ let noCachedCount = 0;
92
+ for (let i = 0; i < groupedEntries.html.length; i++) {
93
+ const [file, originalSource] = groupedEntries.html[i];
94
+ const rawSource = originalSource.source().toString();
95
+ const hash = cache.computeHash(rawSource);
96
+ const cacheKey = file;
97
+ cache.calcHashValueChanged(cacheKey, hash);
98
+ yield cache.process(cacheKey, () => {
99
+ const source = cache.get(cacheKey);
100
+ if (source) {
101
+ compilation.updateAsset(file, source);
102
+ debug('html cache hit: %s', file);
103
+ }
104
+ else {
105
+ return false;
106
+ }
107
+ }, () => options.__awaiter(this, void 0, void 0, function* () {
108
+ const wxml = yield templateHandler(rawSource, {
109
+ runtimeSet,
110
+ });
111
+ const source = new webpackSources.ConcatSource(wxml);
112
+ compilation.updateAsset(file, source);
113
+ onUpdate(file, rawSource, wxml);
114
+ debug('html handle: %s', file);
115
+ noCachedCount++;
116
+ return {
117
+ key: cacheKey,
118
+ source,
119
+ };
120
+ }));
912
121
  }
913
- } else if (typeof t2 === "string") {
914
- if (t2 === tag && isPropsMatch(props, name)) {
915
- update2();
122
+ debug('html handle finish, total: %d, no-cached: %d', groupedEntries.html.length, noCachedCount);
123
+ }
124
+ if (Array.isArray(groupedEntries.js)) {
125
+ let noCachedCount = 0;
126
+ for (let i = 0; i < groupedEntries.js.length; i++) {
127
+ const [file, originalSource] = groupedEntries.js[i];
128
+ const cacheKey = defaults.removeExt(file);
129
+ yield cache.process(cacheKey, () => {
130
+ const source = cache.get(cacheKey);
131
+ if (source) {
132
+ compilation.updateAsset(file, source);
133
+ debug('js cache hit: %s', file);
134
+ }
135
+ else {
136
+ return false;
137
+ }
138
+ }, () => options.__awaiter(this, void 0, void 0, function* () {
139
+ const rawSource = originalSource.source().toString();
140
+ const mapFilename = `${file}.map`;
141
+ const hasMap = Boolean(assets[mapFilename]);
142
+ const { code, map } = yield jsHandler(rawSource, runtimeSet, {
143
+ generateMap: hasMap,
144
+ });
145
+ const source = new webpackSources.ConcatSource(code);
146
+ compilation.updateAsset(file, source);
147
+ onUpdate(file, rawSource, code);
148
+ debug('js handle: %s', file);
149
+ noCachedCount++;
150
+ if (hasMap && map) {
151
+ const source = new webpackSources.RawSource(map.toString());
152
+ compilation.updateAsset(mapFilename, source);
153
+ }
154
+ return {
155
+ key: cacheKey,
156
+ source,
157
+ };
158
+ }));
916
159
  }
917
- } else if (regTest(t2, tag) && isPropsMatch(props, name)) {
918
- update2();
919
- }
160
+ debug('js handle finish, total: %d, no-cached: %d', groupedEntries.js.length, noCachedCount);
920
161
  }
921
- }
922
- },
923
- ontext(data) {
924
- if (inlineWxs && tag === "wxs") {
925
- wxsArray.push({
926
- data,
927
- endIndex: parser.endIndex + 1,
928
- startIndex: parser.startIndex
929
- });
930
- }
931
- },
932
- onclosetag() {
933
- tag = "";
934
- }
935
- },
936
- {
937
- xmlMode: true
938
- }
939
- );
940
- parser.write(s.original);
941
- parser.end();
942
- for (const { data, endIndex, startIndex } of wxsArray) {
943
- const { code } = yield jsHandler2(data, runtimeSet);
944
- s.update(startIndex, endIndex, code);
945
- }
946
- return s.toString();
947
- });
948
- }
949
- function createTemplateHandler(options = {}) {
950
- return (rawSource, opt = {}) => {
951
- return customTemplateHandler(rawSource, defuOverrideArray(opt, options));
952
- };
953
- }
954
-
955
- // src/postcss/index.ts
956
- var import_postcss2 = __toESM(require("postcss"));
957
-
958
- // src/postcss/plugins/index.ts
959
- var import_postcss_is_pseudo_class = __toESM(require("@csstools/postcss-is-pseudo-class"));
960
- var import_postcss_rem_to_responsive_pixel = __toESM(require("postcss-rem-to-responsive-pixel"));
961
-
962
- // src/postcss/selectorParser.ts
963
- var import_postcss_selector_parser = __toESM(require("postcss-selector-parser"));
964
-
965
- // src/postcss/shared.ts
966
- function internalCssSelectorReplacer(selectors, options = {
967
- escapeMap: escape_exports.SimpleMappingChars2String
968
- }) {
969
- const { mangleContext, escapeMap } = options;
970
- if (mangleContext) {
971
- selectors = mangleContext.cssHandler(selectors);
972
- }
973
- return (0, escape_exports.escape)(selectors, {
974
- map: escapeMap
975
- });
976
- }
977
- function composeIsPseudo(strs) {
978
- if (typeof strs === "string") {
979
- return strs;
980
- }
981
- if (strs.length > 1) {
982
- return `:is(${strs.join(",")})`;
983
- }
984
- return strs.join("");
985
- }
986
-
987
- // src/postcss/selectorParser.ts
988
- function createRuleTransform(rule, options) {
989
- const { escapeMap, mangleContext, cssSelectorReplacement, cssRemoveHoverPseudoClass } = options;
990
- const transform = (selectors) => {
991
- selectors.walk((selector) => {
992
- if (selector.type === "universal" && cssSelectorReplacement && cssSelectorReplacement.universal) {
993
- selector.value = composeIsPseudo(cssSelectorReplacement.universal);
994
- }
995
- if (cssRemoveHoverPseudoClass && selector.type === "selector") {
996
- const node = selector.nodes.find((x) => x.type === "pseudo" && x.value === ":hover");
997
- node && selector.remove();
998
- }
999
- if (selector.type === "pseudo" && selector.value === ":root" && cssSelectorReplacement && cssSelectorReplacement.root) {
1000
- selector.value = composeIsPseudo(cssSelectorReplacement.root);
1001
- }
1002
- if (selector.type === "class") {
1003
- selector.value = internalCssSelectorReplacer(selector.value, {
1004
- escapeMap,
1005
- mangleContext
1006
- });
1007
- }
1008
- });
1009
- if (selectors.length === 0) {
1010
- rule.remove();
1011
- }
1012
- };
1013
- return transform;
1014
- }
1015
- function getRuleTransformer(rule, options) {
1016
- return (0, import_postcss_selector_parser.default)(createRuleTransform(rule, options));
1017
- }
1018
- function ruleTransformSync(rule, options) {
1019
- const transformer = getRuleTransformer(rule, options);
1020
- return transformer.transformSync(rule, {
1021
- lossless: false,
1022
- updateSelector: true
1023
- });
1024
- }
1025
- function isOnlyBeforeAndAfterPseudoElement(node) {
1026
- let b = false;
1027
- let a = false;
1028
- (0, import_postcss_selector_parser.default)((selectors) => {
1029
- selectors.walkPseudos((s) => {
1030
- var _a;
1031
- if (((_a = s.parent) == null ? void 0 : _a.length) === 1) {
1032
- if (/^:?:before$/.test(s.value)) {
1033
- b = true;
1034
- }
1035
- if (/^:?:after$/.test(s.value)) {
1036
- a = true;
1037
- }
1038
- }
1039
- });
1040
- }).astSync(node);
1041
- return b && a;
1042
- }
1043
- var fallbackRemove = (0, import_postcss_selector_parser.default)((selectors) => {
1044
- selectors.walk((selector) => {
1045
- var _a, _b;
1046
- if (selector.type === "universal") {
1047
- (_a = selector.parent) == null ? void 0 : _a.remove();
1048
- }
1049
- if (selector.type === "pseudo" && selector.value === ":is") {
1050
- (_b = selector.parent) == null ? void 0 : _b.remove();
1051
- }
1052
- });
1053
- });
1054
-
1055
- // src/postcss/mp.ts
1056
- var import_postcss = require("postcss");
1057
-
1058
- // src/postcss/cssVars.ts
1059
- var cssVars_default = [
1060
- {
1061
- prop: "--tw-border-spacing-x",
1062
- value: "0"
1063
- },
1064
- {
1065
- prop: "--tw-border-spacing-y",
1066
- value: "0"
1067
- },
1068
- {
1069
- prop: "--tw-translate-x",
1070
- value: "0"
1071
- },
1072
- {
1073
- prop: "--tw-translate-y",
1074
- value: "0"
1075
- },
1076
- {
1077
- prop: "--tw-rotate",
1078
- value: "0"
1079
- },
1080
- {
1081
- prop: "--tw-skew-x",
1082
- value: "0"
1083
- },
1084
- {
1085
- prop: "--tw-skew-y",
1086
- value: "0"
1087
- },
1088
- {
1089
- prop: "--tw-scale-x",
1090
- value: "1"
1091
- },
1092
- {
1093
- prop: "--tw-scale-y",
1094
- value: "1"
1095
- },
1096
- {
1097
- prop: "--tw-pan-x",
1098
- value: " "
1099
- },
1100
- {
1101
- prop: "--tw-pan-y",
1102
- value: " "
1103
- },
1104
- {
1105
- prop: "--tw-pinch-zoom",
1106
- value: " "
1107
- },
1108
- {
1109
- prop: "--tw-scroll-snap-strictness",
1110
- value: "proximity"
1111
- },
1112
- {
1113
- prop: "--tw-gradient-from-position",
1114
- value: " "
1115
- },
1116
- {
1117
- prop: "--tw-gradient-via-position",
1118
- value: " "
1119
- },
1120
- {
1121
- prop: "--tw-gradient-to-position",
1122
- value: " "
1123
- },
1124
- {
1125
- prop: "--tw-ordinal",
1126
- value: " "
1127
- },
1128
- {
1129
- prop: "--tw-slashed-zero",
1130
- value: " "
1131
- },
1132
- {
1133
- prop: "--tw-numeric-figure",
1134
- value: " "
1135
- },
1136
- {
1137
- prop: "--tw-numeric-spacing",
1138
- value: " "
1139
- },
1140
- {
1141
- prop: "--tw-numeric-fraction",
1142
- value: " "
1143
- },
1144
- {
1145
- prop: "--tw-ring-inset",
1146
- value: " "
1147
- },
1148
- {
1149
- prop: "--tw-ring-offset-width",
1150
- value: "0px"
1151
- },
1152
- {
1153
- prop: "--tw-ring-offset-color",
1154
- value: "#fff"
1155
- },
1156
- {
1157
- prop: "--tw-ring-color",
1158
- value: "rgb(59 130 246 / 0.5)"
1159
- },
1160
- {
1161
- prop: "--tw-ring-offset-shadow",
1162
- value: "0 0 #0000"
1163
- },
1164
- {
1165
- prop: "--tw-ring-shadow",
1166
- value: "0 0 #0000"
1167
- },
1168
- {
1169
- prop: "--tw-shadow",
1170
- value: "0 0 #0000"
1171
- },
1172
- {
1173
- prop: "--tw-shadow-colored",
1174
- value: "0 0 #0000"
1175
- },
1176
- {
1177
- prop: "--tw-blur",
1178
- value: " "
1179
- },
1180
- {
1181
- prop: "--tw-brightness",
1182
- value: " "
1183
- },
1184
- {
1185
- prop: "--tw-contrast",
1186
- value: " "
1187
- },
1188
- {
1189
- prop: "--tw-grayscale",
1190
- value: " "
1191
- },
1192
- {
1193
- prop: "--tw-hue-rotate",
1194
- value: " "
1195
- },
1196
- {
1197
- prop: "--tw-invert",
1198
- value: " "
1199
- },
1200
- {
1201
- prop: "--tw-saturate",
1202
- value: " "
1203
- },
1204
- {
1205
- prop: "--tw-sepia",
1206
- value: " "
1207
- },
1208
- {
1209
- prop: "--tw-drop-shadow",
1210
- value: " "
1211
- },
1212
- {
1213
- prop: "--tw-backdrop-blur",
1214
- value: " "
1215
- },
1216
- {
1217
- prop: "--tw-backdrop-brightness",
1218
- value: " "
1219
- },
1220
- {
1221
- prop: "--tw-backdrop-contrast",
1222
- value: " "
1223
- },
1224
- {
1225
- prop: "--tw-backdrop-grayscale",
1226
- value: " "
1227
- },
1228
- {
1229
- prop: "--tw-backdrop-hue-rotate",
1230
- value: " "
1231
- },
1232
- {
1233
- prop: "--tw-backdrop-invert",
1234
- value: " "
1235
- },
1236
- {
1237
- prop: "--tw-backdrop-opacity",
1238
- value: " "
1239
- },
1240
- {
1241
- prop: "--tw-backdrop-saturate",
1242
- value: " "
1243
- },
1244
- {
1245
- prop: "--tw-backdrop-sepia",
1246
- value: " "
1247
- },
1248
- {
1249
- prop: "--tw-contain-size",
1250
- value: " "
1251
- },
1252
- {
1253
- prop: "--tw-contain-layout",
1254
- value: " "
1255
- },
1256
- {
1257
- prop: "--tw-contain-paint",
1258
- value: " "
1259
- },
1260
- {
1261
- prop: "--tw-contain-style",
1262
- value: " "
1263
- }
1264
- ];
1265
-
1266
- // src/postcss/mp.ts
1267
- var initialNodes = cssVars_default.map((x) => {
1268
- return new import_postcss.Declaration({
1269
- prop: x.prop,
1270
- value: x.value
1271
- });
1272
- });
1273
- var PATTERNS = [
1274
- /:not\(template\)\s*[~+]\s*:not\(template\)/.source,
1275
- /:not\(\[hidden\]\)\s*[~+]\s*:not\(\[hidden\]\)/.source
1276
- ].join("|");
1277
- var BROAD_MATCH_GLOBAL_REGEXP = new RegExp(PATTERNS, "g");
1278
- function testIfVariablesScope(node, count = 2) {
1279
- if (isOnlyBeforeAndAfterPseudoElement(node)) {
1280
- const nodes = node.nodes;
1281
- let c = 0;
1282
- for (const tryTestDecl of nodes) {
1283
- if (tryTestDecl && tryTestDecl.type === "decl" && tryTestDecl.prop.startsWith("--tw-")) {
1284
- c++;
1285
- }
1286
- if (c >= count) {
1287
- return true;
1288
- }
1289
- }
1290
- return false;
1291
- }
1292
- return false;
1293
- }
1294
- function testIfTwBackdrop(node, count = 2) {
1295
- if (node.type === "rule" && node.selector === "::backdrop") {
1296
- const nodes = node.nodes;
1297
- let c = 0;
1298
- for (const tryTestDecl of nodes) {
1299
- if (tryTestDecl && tryTestDecl.type === "decl" && tryTestDecl.prop.startsWith("--tw-")) {
1300
- c++;
1301
- }
1302
- if (c >= count) {
1303
- return true;
1304
- }
1305
- }
1306
- return false;
1307
- }
1308
- return false;
1309
- }
1310
- function makePseudoVarRule() {
1311
- const pseudoVarRule = new import_postcss.Rule({
1312
- // selectors: ['::before', '::after'],
1313
- selector: "::before,::after"
1314
- });
1315
- pseudoVarRule.append(
1316
- new import_postcss.Declaration({
1317
- prop: "--tw-content",
1318
- value: '""'
1319
- })
1320
- );
1321
- return pseudoVarRule;
1322
- }
1323
- function remakeCssVarSelector(selectors, options) {
1324
- const { cssPreflightRange, cssSelectorReplacement } = options;
1325
- if (cssPreflightRange === "all" && !selectors.includes(":not(not)")) {
1326
- selectors.push(":not(not)");
1327
- }
1328
- if (cssSelectorReplacement) {
1329
- if (Array.isArray(cssSelectorReplacement.universal)) {
1330
- if (!cssSelectorReplacement.universal.every((x) => {
1331
- return selectors.includes(x);
1332
- }) && !selectors.includes("*")) {
1333
- selectors.unshift("*");
1334
- }
1335
- } else if (typeof cssSelectorReplacement.universal === "string" && !selectors.includes(cssSelectorReplacement.universal) && !selectors.includes("*")) {
1336
- selectors.unshift("*");
1337
- }
1338
- }
1339
- return selectors;
1340
- }
1341
- function remakeCombinatorSelector(selector, cssChildCombinatorReplaceValue) {
1342
- let childCombinatorReplaceValue = "view + view";
1343
- if (Array.isArray(cssChildCombinatorReplaceValue) && cssChildCombinatorReplaceValue.length > 0) {
1344
- const x = composeIsPseudo(cssChildCombinatorReplaceValue);
1345
- childCombinatorReplaceValue = `${x} + ${x}`;
1346
- } else if (typeof cssChildCombinatorReplaceValue === "string") {
1347
- childCombinatorReplaceValue = cssChildCombinatorReplaceValue;
1348
- }
1349
- return selector.replaceAll(BROAD_MATCH_GLOBAL_REGEXP, childCombinatorReplaceValue);
1350
- }
1351
- function commonChunkPreflight(node, options) {
1352
- const { ctx, cssChildCombinatorReplaceValue, cssInjectPreflight, injectAdditionalCssVarScope } = options;
1353
- node.selector = remakeCombinatorSelector(node.selector, cssChildCombinatorReplaceValue);
1354
- if (testIfVariablesScope(node)) {
1355
- ctx == null ? void 0 : ctx.markVariablesScope(node);
1356
- node.selectors = remakeCssVarSelector(node.selectors, options);
1357
- node.before(makePseudoVarRule());
1358
- if (typeof cssInjectPreflight === "function") {
1359
- node.append(...cssInjectPreflight());
1360
- }
1361
- }
1362
- if (injectAdditionalCssVarScope && testIfTwBackdrop(node)) {
1363
- const syntheticRule = new import_postcss.Rule({
1364
- selectors: ["*", "::after", "::before"],
1365
- nodes: initialNodes
1366
- });
1367
- syntheticRule.selectors = remakeCssVarSelector(syntheticRule.selectors, options);
1368
- node.before(syntheticRule);
1369
- node.before(makePseudoVarRule());
1370
- if (typeof cssInjectPreflight === "function") {
1371
- syntheticRule.append(...cssInjectPreflight());
1372
- }
1373
- }
1374
- }
1375
-
1376
- // src/constants.ts
1377
- var postcssPlugin = "postcss-weapp-tailwindcss-rename-plugin";
1378
- var pluginName = "weapp-tailwindcss-webpack-plugin";
1379
-
1380
- // src/postcss/plugins/pre.ts
1381
- function isAtMediaHover(atRule) {
1382
- return /media\(\s*hover\s*:\s*hover\s*\)/.test(atRule.name) || atRule.name === "media" && /\(\s*hover\s*:\s*hover\s*\)/.test(atRule.params);
1383
- }
1384
- var postcssWeappTailwindcssPrePlugin = (options = {
1385
- isMainChunk: true
1386
- }) => {
1387
- const { isMainChunk } = options;
1388
- const p = {
1389
- postcssPlugin,
1390
- Rule(rule) {
1391
- ruleTransformSync(rule, options);
1392
- },
1393
- AtRule(atRule) {
1394
- if (isAtMediaHover(atRule)) {
1395
- if (atRule.nodes) {
1396
- atRule.replaceWith(atRule.nodes);
1397
- } else {
1398
- atRule.remove();
1399
- }
1400
- }
1401
- }
1402
- };
1403
- if (isMainChunk) {
1404
- p.Once = (root) => {
1405
- root.walkRules((rule) => {
1406
- commonChunkPreflight(rule, options);
1407
- });
1408
- };
1409
- }
1410
- return p;
1411
- };
1412
- postcssWeappTailwindcssPrePlugin.postcss = true;
1413
-
1414
- // src/postcss/plugins/post.ts
1415
- var postcssWeappTailwindcssPostPlugin = (options = {
1416
- isMainChunk: true
1417
- }) => {
1418
- const { customRuleCallback, isMainChunk, ctx } = options;
1419
- const p = {
1420
- postcssPlugin
1421
- };
1422
- if (isMainChunk) {
1423
- p.OnceExit = (root) => {
1424
- root.walkRules((rule) => {
1425
- if (ctx) {
1426
- if (ctx.isVariablesScope(rule)) {
1427
- fallbackRemove.transformSync(rule, {
1428
- updateSelector: true,
1429
- lossless: false
1430
- });
1431
- }
1432
- } else if (testIfVariablesScope(rule)) {
1433
- fallbackRemove.transformSync(rule, {
1434
- updateSelector: true,
1435
- lossless: false
1436
- });
1437
- }
1438
- });
1439
- };
1440
- }
1441
- if (typeof customRuleCallback === "function") {
1442
- p.Rule = (rule) => {
1443
- customRuleCallback(rule, options);
1444
- };
1445
- }
1446
- return p;
1447
- };
1448
- postcssWeappTailwindcssPostPlugin.postcss = true;
1449
-
1450
- // src/postcss/symbols.ts
1451
- var VariablesScopeSymbol = Symbol("VariablesScope");
1452
-
1453
- // src/postcss/plugins/ctx.ts
1454
- function createContext() {
1455
- const variablesScopeWeakMap = /* @__PURE__ */ new WeakMap();
1456
- function isVariablesScope(rule) {
1457
- return variablesScopeWeakMap.get(rule) === VariablesScopeSymbol;
1458
- }
1459
- function markVariablesScope(rule) {
1460
- variablesScopeWeakMap.set(rule, VariablesScopeSymbol);
1461
- }
1462
- return {
1463
- variablesScopeWeakMap,
1464
- isVariablesScope,
1465
- markVariablesScope
1466
- };
1467
- }
1468
-
1469
- // src/postcss/plugins/index.ts
1470
- var import_postcss_is_pseudo_class2 = __toESM(require("@csstools/postcss-is-pseudo-class"));
1471
- var import_postcss_rem_to_responsive_pixel2 = __toESM(require("postcss-rem-to-responsive-pixel"));
1472
- function getPlugins(options) {
1473
- var _a, _b;
1474
- const ctx = createContext();
1475
- options.ctx = ctx;
1476
- const plugins = [
1477
- ...(_b = (_a = options.postcssOptions) == null ? void 0 : _a.plugins) != null ? _b : [],
1478
- postcssWeappTailwindcssPrePlugin(options),
1479
- (0, import_postcss_is_pseudo_class.default)({
1480
- specificityMatchingName: "weapp-tw-ig"
1481
- })
1482
- ];
1483
- if (options.rem2rpx) {
1484
- plugins.push(
1485
- (0, import_postcss_rem_to_responsive_pixel.default)(
1486
- typeof options.rem2rpx === "object" ? options.rem2rpx : {
1487
- rootValue: 32,
1488
- propList: ["*"],
1489
- transformUnit: "rpx"
1490
- }
1491
- )
1492
- );
1493
- }
1494
- plugins.push(postcssWeappTailwindcssPostPlugin(options));
1495
- return plugins;
1496
- }
1497
-
1498
- // src/postcss/index.ts
1499
- function styleHandler(rawSource, options) {
1500
- return __async(this, null, function* () {
1501
- var _a, _b;
1502
- return (yield (0, import_postcss2.default)(getPlugins(options)).process(
1503
- rawSource,
1504
- (_b = (_a = options.postcssOptions) == null ? void 0 : _a.options) != null ? _b : {
1505
- from: void 0
1506
- }
1507
- ).async()).css;
1508
- });
1509
- }
1510
- function createStyleHandler(options) {
1511
- return (rawSource, opt) => {
1512
- return styleHandler(
1513
- rawSource,
1514
- defuOverrideArray(opt, options)
1515
- );
1516
- };
1517
- }
1518
-
1519
- // src/postcss/preflight.ts
1520
- function createInjectPreflight(options) {
1521
- const result = [];
1522
- if (options && typeof options === "object") {
1523
- const entries = Object.entries(options);
1524
- for (const [prop, value] of entries) {
1525
- if (value !== false) {
1526
- result.push({
1527
- prop,
1528
- value: value.toString()
1529
- });
1530
- }
1531
- }
1532
- }
1533
- return () => {
1534
- return result;
1535
- };
1536
- }
1537
-
1538
- // src/tailwindcss/patcher.ts
1539
- var import_node_path = __toESM(require("path"));
1540
- var import_node_process = __toESM(require("process"));
1541
- var import_tailwindcss_patch = require("tailwindcss-patch");
1542
- function createTailwindcssPatcher(basedir, cacheDir, supportCustomLengthUnitsPatch) {
1543
- const cache = {};
1544
- if (cacheDir) {
1545
- if (import_node_path.default.isAbsolute(cacheDir)) {
1546
- cache.dir = cacheDir;
1547
- } else if (basedir) {
1548
- cache.dir = import_node_path.default.resolve(basedir, cacheDir);
1549
- } else {
1550
- cache.dir = import_node_path.default.resolve(import_node_process.default.cwd(), cacheDir);
1551
- }
1552
- }
1553
- return new import_tailwindcss_patch.TailwindcssPatcher({
1554
- cache,
1555
- patch: {
1556
- basedir,
1557
- applyPatches: {
1558
- exportContext: true,
1559
- extendLengthUnits: supportCustomLengthUnitsPatch
1560
- }
1561
- }
1562
- });
1563
- }
1564
-
1565
- // src/mangle/index.ts
1566
- var import_shared5 = require("@tailwindcss-mangle/shared");
1567
- function getSelf(x) {
1568
- return x;
1569
- }
1570
- var defaultMangleContext = {
1571
- rawOptions: false,
1572
- runtimeSet: /* @__PURE__ */ new Set(),
1573
- classGenerator: new import_shared5.ClassGenerator(),
1574
- filter: import_shared5.defaultMangleClassFilter,
1575
- cssHandler: getSelf,
1576
- jsHandler: getSelf,
1577
- wxmlHandler: getSelf
1578
- };
1579
- function useMangleStore() {
1580
- const ctx = Object.assign({}, defaultMangleContext);
1581
- function resetMangle() {
1582
- return Object.assign(ctx, defaultMangleContext);
1583
- }
1584
- function handleValue(rawSource) {
1585
- const arr = splitCode(rawSource);
1586
- for (const x of arr) {
1587
- if (ctx.runtimeSet.has(x)) {
1588
- rawSource = rawSource.replace(new RegExp((0, reg_exports.escapeStringRegexp)(x)), ctx.classGenerator.generateClassName(x).name);
1589
- }
1590
- }
1591
- return rawSource;
1592
- }
1593
- function initMangle(options) {
1594
- var _a;
1595
- ctx.rawOptions = options;
1596
- if (options) {
1597
- if (options === true) {
1598
- options = {
1599
- classGenerator: {},
1600
- mangleClassFilter: import_shared5.defaultMangleClassFilter
1601
- };
1602
- }
1603
- ctx.classGenerator = new import_shared5.ClassGenerator(options.classGenerator);
1604
- ctx.filter = (_a = options.mangleClassFilter) != null ? _a : import_shared5.defaultMangleClassFilter;
1605
- ctx.jsHandler = (rawSource) => {
1606
- return handleValue(rawSource);
1607
- };
1608
- ctx.cssHandler = (rawSource) => {
1609
- return handleValue(rawSource);
1610
- };
1611
- ctx.wxmlHandler = (rawSource) => {
1612
- return handleValue(rawSource);
1613
- };
1614
- }
1615
- }
1616
- function setMangleRuntimeSet(runtimeSet) {
1617
- const newSet = /* @__PURE__ */ new Set();
1618
- for (const c of runtimeSet) {
1619
- if (ctx.filter(c)) {
1620
- newSet.add(c);
1621
- }
1622
- }
1623
- ctx.runtimeSet = newSet;
1624
- }
1625
- return {
1626
- mangleContext: ctx,
1627
- resetMangle,
1628
- initMangle,
1629
- setMangleRuntimeSet
1630
- };
1631
- }
1632
-
1633
- // src/cache/index.ts
1634
- var import_lru_cache = require("lru-cache");
1635
- var import_md5 = __toESM(require("md5"));
1636
- function createCache(options) {
1637
- const disabled = options === false;
1638
- const hashMap = /* @__PURE__ */ new Map();
1639
- const instance = new import_lru_cache.LRUCache({
1640
- // 可能会添加和删除一些页面和组件, 先设定 1024 吧
1641
- max: 1024,
1642
- ttl: 0,
1643
- ttlAutopurge: false
1644
- });
1645
- return {
1646
- hashMap,
1647
- instance,
1648
- hasHashKey(key) {
1649
- return hashMap.has(key);
1650
- },
1651
- getHashValue(key) {
1652
- return hashMap.get(key);
1653
- },
1654
- setHashValue(key, value) {
1655
- return hashMap.set(key, value);
1656
- },
1657
- get(key) {
1658
- return instance.get(key);
1659
- },
1660
- set(key, value) {
1661
- return instance.set(key, value);
1662
- },
1663
- computeHash(message) {
1664
- return (0, import_md5.default)(message);
1665
- },
1666
- calcHashValueChanged(key, hash) {
1667
- const hit = this.getHashValue(key);
1668
- if (hit) {
1669
- this.setHashValue(key, {
1670
- // new file should be changed
1671
- changed: hash !== hit.hash,
1672
- // new hash
1673
- hash
1674
- });
1675
- } else {
1676
- this.setHashValue(key, {
1677
- // new file should be changed
1678
- changed: true,
1679
- hash
1680
- });
1681
- }
1682
- return this;
1683
- },
1684
- has(key) {
1685
- return instance.has(key);
1686
- },
1687
- process(key, callback, fallback) {
1688
- return __async(this, null, function* () {
1689
- if (disabled) {
1690
- const res = yield fallback();
1691
- if (res) {
1692
- this.set(res.key, res.source);
1693
- }
1694
- } else {
1695
- const hit = this.getHashValue(key);
1696
- if (hit && !hit.changed) {
1697
- const returnFlag = yield callback();
1698
- if (returnFlag !== false) {
1699
- return;
162
+ if (Array.isArray(groupedEntries.css)) {
163
+ let noCachedCount = 0;
164
+ for (let i = 0; i < groupedEntries.css.length; i++) {
165
+ const [file, originalSource] = groupedEntries.css[i];
166
+ const rawSource = originalSource.source().toString();
167
+ const hash = cache.computeHash(rawSource);
168
+ const cacheKey = file;
169
+ cache.calcHashValueChanged(cacheKey, hash);
170
+ yield cache.process(cacheKey, () => {
171
+ const source = cache.get(cacheKey);
172
+ if (source) {
173
+ compilation.updateAsset(file, source);
174
+ debug('css cache hit: %s', file);
175
+ }
176
+ else {
177
+ return false;
178
+ }
179
+ }, () => options.__awaiter(this, void 0, void 0, function* () {
180
+ const css = yield styleHandler(rawSource, {
181
+ isMainChunk: mainCssChunkMatcher(file, this.appType),
182
+ });
183
+ const source = new webpackSources.ConcatSource(css);
184
+ compilation.updateAsset(file, source);
185
+ onUpdate(file, rawSource, css);
186
+ debug('css handle: %s', file);
187
+ noCachedCount++;
188
+ return {
189
+ key: cacheKey,
190
+ source,
191
+ };
192
+ }));
193
+ }
194
+ debug('css handle finish, total: %d, no-cached: %d', groupedEntries.css.length, noCachedCount);
1700
195
  }
1701
- }
1702
- const res = yield fallback();
1703
- if (res) {
1704
- this.set(res.key, res.source);
1705
- }
1706
- }
1707
- });
196
+ debug('end');
197
+ onEnd();
198
+ }));
1708
199
  }
1709
- };
1710
- }
1711
-
1712
- // src/options.ts
1713
- function getOptions(opts) {
1714
- const result = defuOverrideArray(
1715
- opts,
1716
- defaultOptions,
1717
- {}
1718
- );
1719
- result.escapeMap = result.customReplaceDictionary;
1720
- const {
1721
- cssPreflight,
1722
- customRuleCallback,
1723
- cssPreflightRange,
1724
- customAttributes,
1725
- supportCustomLengthUnitsPatch,
1726
- arbitraryValues,
1727
- cssChildCombinatorReplaceValue,
1728
- inlineWxs,
1729
- injectAdditionalCssVarScope,
1730
- jsPreserveClass,
1731
- disabledDefaultTemplateHandler,
1732
- cssSelectorReplacement,
1733
- rem2rpx,
1734
- cache,
1735
- jsAstTool,
1736
- babelParserOptions,
1737
- postcssOptions,
1738
- cssRemoveHoverPseudoClass,
1739
- escapeMap,
1740
- mangle,
1741
- tailwindcssBasedir,
1742
- appType
1743
- } = result;
1744
- const cssInjectPreflight = createInjectPreflight(cssPreflight);
1745
- const customAttributesEntities = isMap(customAttributes) ? [...customAttributes.entries()] : Object.entries(customAttributes);
1746
- const { initMangle, mangleContext, setMangleRuntimeSet } = useMangleStore();
1747
- initMangle(mangle);
1748
- const styleHandler2 = createStyleHandler({
1749
- cssInjectPreflight,
1750
- customRuleCallback,
1751
- cssPreflightRange,
1752
- escapeMap,
1753
- mangleContext,
1754
- cssChildCombinatorReplaceValue,
1755
- injectAdditionalCssVarScope,
1756
- cssSelectorReplacement,
1757
- rem2rpx,
1758
- postcssOptions,
1759
- cssRemoveHoverPseudoClass
1760
- });
1761
- const jsHandler2 = createJsHandler({
1762
- escapeMap,
1763
- mangleContext,
1764
- arbitraryValues,
1765
- jsPreserveClass,
1766
- generateMap: true,
1767
- jsAstTool,
1768
- babelParserOptions
1769
- });
1770
- const templateHandler = createTemplateHandler({
1771
- customAttributesEntities,
1772
- escapeMap,
1773
- mangleContext,
1774
- inlineWxs,
1775
- jsHandler: jsHandler2,
1776
- disabledDefaultTemplateHandler
1777
- });
1778
- result.styleHandler = styleHandler2;
1779
- result.jsHandler = jsHandler2;
1780
- result.templateHandler = templateHandler;
1781
- const twPatcher = createTailwindcssPatcher(tailwindcssBasedir, appType === "mpx" ? "node_modules/tailwindcss-patch/.cache" : void 0, supportCustomLengthUnitsPatch);
1782
- result.patch = twPatcher.patch;
1783
- result.setMangleRuntimeSet = setMangleRuntimeSet;
1784
- result.cache = cache === void 0 || typeof cache === "boolean" ? createCache(cache) : cache;
1785
- result.twPatcher = twPatcher;
1786
- return result;
1787
- }
1788
-
1789
- // src/debug/index.ts
1790
- var import_debug = __toESM(require("debug"));
1791
- var _debug = (0, import_debug.default)("weapp-tw");
1792
- function createDebug(prefix) {
1793
- function debug2(formatter, ...args) {
1794
- return _debug((prefix != null ? prefix : "") + formatter, ...args);
1795
- }
1796
- return debug2;
1797
200
  }
1798
201
 
1799
- // src/bundlers/webpack/BaseUnifiedPlugin/v4.ts
1800
- var debug = createDebug();
1801
- var UnifiedWebpackPluginV4 = class {
1802
- constructor(options = {}) {
1803
- this.options = getOptions(options);
1804
- this.appType = this.options.appType;
1805
- }
1806
- apply(compiler) {
1807
- const {
1808
- mainCssChunkMatcher,
1809
- disabled,
1810
- onLoad,
1811
- onUpdate,
1812
- onEnd,
1813
- onStart,
1814
- styleHandler: styleHandler2,
1815
- patch,
1816
- templateHandler,
1817
- jsHandler: jsHandler2,
1818
- setMangleRuntimeSet,
1819
- runtimeLoaderPath,
1820
- cache,
1821
- twPatcher
1822
- } = this.options;
1823
- if (disabled) {
1824
- return;
1825
- }
1826
- patch == null ? void 0 : patch();
1827
- function getClassSet() {
1828
- return twPatcher.getClassSet();
1829
- }
1830
- onLoad();
1831
- const loader = runtimeLoaderPath != null ? runtimeLoaderPath : import_node_path2.default.resolve(__dirname, "./weapp-tw-runtime-loader.js");
1832
- const isExisted = import_node_fs.default.existsSync(loader);
1833
- const WeappTwRuntimeAopLoader = {
1834
- loader,
1835
- options: {
1836
- getClassSet
1837
- },
1838
- ident: null,
1839
- type: null
1840
- };
1841
- compiler.hooks.compilation.tap(pluginName, (compilation) => {
1842
- compilation.hooks.normalModuleLoader.tap(pluginName, (_loaderContext, module2) => {
1843
- if (isExisted) {
1844
- const idx = module2.loaders.findIndex((x) => x.loader.includes("postcss-loader"));
1845
- if (idx > -1) {
1846
- module2.loaders.unshift(WeappTwRuntimeAopLoader);
1847
- }
1848
- }
1849
- });
1850
- });
1851
- compiler.hooks.emit.tapPromise(pluginName, (compilation) => __async(this, null, function* () {
1852
- onStart();
1853
- debug("start");
1854
- for (const chunk of compilation.chunks) {
1855
- if (chunk.id && chunk.hash) {
1856
- cache.calcHashValueChanged(chunk.id, chunk.hash);
1857
- }
1858
- }
1859
- const assets = compilation.assets;
1860
- const entries = Object.entries(assets);
1861
- const groupedEntries = getGroupedEntries(entries, this.options);
1862
- const runtimeSet = getClassSet();
1863
- setMangleRuntimeSet(runtimeSet);
1864
- debug("get runtimeSet, class count: %d", runtimeSet.size);
1865
- if (Array.isArray(groupedEntries.html)) {
1866
- let noCachedCount = 0;
1867
- for (let i = 0; i < groupedEntries.html.length; i++) {
1868
- const [file, originalSource] = groupedEntries.html[i];
1869
- const rawSource = originalSource.source().toString();
1870
- const hash = cache.computeHash(rawSource);
1871
- const cacheKey = file;
1872
- cache.calcHashValueChanged(cacheKey, hash);
1873
- yield cache.process(
1874
- cacheKey,
1875
- () => {
1876
- const source = cache.get(cacheKey);
1877
- if (source) {
1878
- compilation.updateAsset(file, source);
1879
- debug("html cache hit: %s", file);
1880
- } else {
1881
- return false;
1882
- }
1883
- },
1884
- // @ts-ignore
1885
- () => __async(this, null, function* () {
1886
- const wxml = yield templateHandler(rawSource, {
1887
- runtimeSet
1888
- });
1889
- const source = new import_webpack_sources.ConcatSource(wxml);
1890
- compilation.updateAsset(file, source);
1891
- onUpdate(file, rawSource, wxml);
1892
- debug("html handle: %s", file);
1893
- noCachedCount++;
1894
- return {
1895
- key: cacheKey,
1896
- source
1897
- };
1898
- })
1899
- );
1900
- }
1901
- debug("html handle finish, total: %d, no-cached: %d", groupedEntries.html.length, noCachedCount);
1902
- }
1903
- if (Array.isArray(groupedEntries.js)) {
1904
- let noCachedCount = 0;
1905
- for (let i = 0; i < groupedEntries.js.length; i++) {
1906
- const [file, originalSource] = groupedEntries.js[i];
1907
- const cacheKey = removeExt(file);
1908
- yield cache.process(
1909
- cacheKey,
1910
- () => {
1911
- const source = cache.get(cacheKey);
1912
- if (source) {
1913
- compilation.updateAsset(file, source);
1914
- debug("js cache hit: %s", file);
1915
- } else {
1916
- return false;
1917
- }
1918
- },
1919
- // @ts-ignore
1920
- () => __async(this, null, function* () {
1921
- const rawSource = originalSource.source().toString();
1922
- const mapFilename = `${file}.map`;
1923
- const hasMap = Boolean(assets[mapFilename]);
1924
- const { code, map } = yield jsHandler2(rawSource, runtimeSet, {
1925
- generateMap: hasMap
1926
- });
1927
- const source = new import_webpack_sources.ConcatSource(code);
1928
- compilation.updateAsset(file, source);
1929
- onUpdate(file, rawSource, code);
1930
- debug("js handle: %s", file);
1931
- noCachedCount++;
1932
- if (hasMap && map) {
1933
- const source2 = new import_webpack_sources.RawSource(map.toString());
1934
- compilation.updateAsset(mapFilename, source2);
1935
- }
1936
- return {
1937
- key: cacheKey,
1938
- source
1939
- };
1940
- })
1941
- );
1942
- }
1943
- debug("js handle finish, total: %d, no-cached: %d", groupedEntries.js.length, noCachedCount);
1944
- }
1945
- if (Array.isArray(groupedEntries.css)) {
1946
- let noCachedCount = 0;
1947
- for (let i = 0; i < groupedEntries.css.length; i++) {
1948
- const [file, originalSource] = groupedEntries.css[i];
1949
- const rawSource = originalSource.source().toString();
1950
- const hash = cache.computeHash(rawSource);
1951
- const cacheKey = file;
1952
- cache.calcHashValueChanged(cacheKey, hash);
1953
- yield cache.process(
1954
- cacheKey,
1955
- () => {
1956
- const source = cache.get(cacheKey);
1957
- if (source) {
1958
- compilation.updateAsset(file, source);
1959
- debug("css cache hit: %s", file);
1960
- } else {
1961
- return false;
1962
- }
1963
- },
1964
- // @ts-ignore
1965
- () => __async(this, null, function* () {
1966
- const css = yield styleHandler2(rawSource, {
1967
- isMainChunk: mainCssChunkMatcher(file, this.appType)
1968
- });
1969
- const source = new import_webpack_sources.ConcatSource(css);
1970
- compilation.updateAsset(file, source);
1971
- onUpdate(file, rawSource, css);
1972
- debug("css handle: %s", file);
1973
- noCachedCount++;
1974
- return {
1975
- key: cacheKey,
1976
- source
1977
- };
1978
- })
1979
- );
1980
- }
1981
- debug("css handle finish, total: %d, no-cached: %d", groupedEntries.css.length, noCachedCount);
1982
- }
1983
- debug("end");
1984
- onEnd();
1985
- }));
1986
- }
1987
- };
1988
- // Annotate the CommonJS export names for ESM import in node:
1989
- 0 && (module.exports = {
1990
- UnifiedWebpackPluginV4
1991
- });
202
+ exports.UnifiedWebpackPluginV4 = UnifiedWebpackPluginV4;