weapp-tailwindcss 2.9.0 → 2.9.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.
@@ -1,11 +1,27 @@
1
+ /// <reference types="node" />
1
2
  import { LRUCache } from 'lru-cache';
2
3
  import type { sources } from 'webpack';
4
+ export interface HashMapValue {
5
+ hash: string;
6
+ changed: boolean;
7
+ }
8
+ export type HashMapKey = string | number;
9
+ export type CacheValue = sources.Source | string;
3
10
  export interface ICreateCacheReturnType {
4
- hashMap: Map<string | number, {
5
- hash: string;
6
- changed: boolean;
7
- }>;
8
- instance: LRUCache<string, sources.Source>;
11
+ hashMap: Map<HashMapKey, HashMapValue>;
12
+ instance: LRUCache<string, CacheValue>;
13
+ hasHashKey: (key: HashMapKey) => boolean;
14
+ getHashValue: (key: HashMapKey) => HashMapValue | undefined;
15
+ setHashValue: (key: HashMapKey, value: HashMapValue) => this['hashMap'];
16
+ computeHash: (message: string | Buffer) => string;
17
+ get: <V extends CacheValue = sources.Source>(key: string) => V | undefined;
18
+ set: <V extends CacheValue = sources.Source>(key: string, value: V) => this['instance'];
19
+ has: (key: string) => boolean;
20
+ calcHashValueChanged: (key: HashMapKey, hash: string) => this;
21
+ process: (key: string, callback: () => void | false, fallback: () => void | {
22
+ key: string;
23
+ source: CacheValue;
24
+ }) => void;
9
25
  }
10
26
  declare function createCache(): ICreateCacheReturnType;
11
27
  export { createCache };
package/dist/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var options = require('./options-84d4eeb7.js');
3
+ var options = require('./options-9dd8de2e.js');
4
4
  require('micromatch');
5
5
  require('magic-string');
6
6
  require('./replace.js');
@@ -11,7 +11,7 @@ require('@weapp-core/regex');
11
11
  require('@babel/generator');
12
12
  require('@babel/parser');
13
13
  require('@babel/traverse');
14
- require('./defaults-263271f9.js');
14
+ require('./defaults-b7341550.js');
15
15
  require('@babel/types');
16
16
  require('htmlparser2');
17
17
  require('postcss');
@@ -24,6 +24,7 @@ require('semver');
24
24
  require('tailwindcss-patch');
25
25
  require('@tailwindcss-mangle/shared');
26
26
  require('lru-cache');
27
+ require('md5');
27
28
 
28
29
  const args = process.argv.slice(2);
29
30
  if (args[0] === 'patch') {
package/dist/cli.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { g as getOptions, c as createPatch } from './options-d2268f8f.mjs';
1
+ import { g as getOptions, c as createPatch } from './options-e1a9fdd3.mjs';
2
2
  import 'micromatch';
3
3
  import 'magic-string';
4
4
  import './replace.mjs';
@@ -9,7 +9,7 @@ import '@weapp-core/regex';
9
9
  import '@babel/generator';
10
10
  import '@babel/parser';
11
11
  import '@babel/traverse';
12
- import './defaults-dc8a0e3d.mjs';
12
+ import './defaults-d2c66d23.mjs';
13
13
  import '@babel/types';
14
14
  import 'htmlparser2';
15
15
  import 'postcss';
@@ -22,6 +22,7 @@ import 'semver';
22
22
  import 'tailwindcss-patch';
23
23
  import '@tailwindcss-mangle/shared';
24
24
  import 'lru-cache';
25
+ import 'md5';
25
26
 
26
27
  const args = process.argv.slice(2);
27
28
  if (args[0] === 'patch') {
@@ -1,2 +1,2 @@
1
- import createDebug from 'debug';
2
- export declare const debug: createDebug.Debugger;
1
+ declare function createDebug(prefix?: string): (formatter: any, ...args: any[]) => void;
2
+ export { createDebug };
@@ -45,6 +45,9 @@ function getGroupedEntries(entries, options) {
45
45
  });
46
46
  return groupedEntries;
47
47
  }
48
+ function removeExt(file) {
49
+ return file.replace(/\.[^./]+$/, '');
50
+ }
48
51
 
49
52
  const defaultOptions = {
50
53
  cssMatcher: (file) => /.+\.(?:wx|ac|jx|tt|q|c)ss$/.test(file),
@@ -140,3 +143,4 @@ exports.defaultOptions = defaultOptions;
140
143
  exports.getGroupedEntries = getGroupedEntries;
141
144
  exports.isMap = isMap;
142
145
  exports.noop = noop;
146
+ exports.removeExt = removeExt;
@@ -43,6 +43,9 @@ function getGroupedEntries(entries, options) {
43
43
  });
44
44
  return groupedEntries;
45
45
  }
46
+ function removeExt(file) {
47
+ return file.replace(/\.[^./]+$/, '');
48
+ }
46
49
 
47
50
  const defaultOptions = {
48
51
  cssMatcher: (file) => /.+\.(?:wx|ac|jx|tt|q|c)ss$/.test(file),
@@ -134,4 +137,4 @@ const defaultOptions = {
134
137
  }
135
138
  };
136
139
 
137
- export { defaultOptions as d, getGroupedEntries as g, isMap as i, noop as n };
140
+ export { defaultOptions as d, getGroupedEntries as g, isMap as i, noop as n, removeExt as r };
package/dist/defaults.js CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var defaults = require('./defaults-263271f9.js');
5
+ var defaults = require('./defaults-b7341550.js');
6
6
  require('@weapp-core/escape');
7
7
  require('@ast-core/escape');
8
8
 
package/dist/defaults.mjs CHANGED
@@ -1,3 +1,3 @@
1
- export { d as defaultOptions } from './defaults-dc8a0e3d.mjs';
1
+ export { d as defaultOptions } from './defaults-d2c66d23.mjs';
2
2
  import '@weapp-core/escape';
3
3
  import '@ast-core/escape';
package/dist/gulp.js CHANGED
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var stream = require('node:stream');
6
- var options = require('./options-84d4eeb7.js');
6
+ var options = require('./options-9dd8de2e.js');
7
7
  require('micromatch');
8
8
  require('magic-string');
9
9
  require('./replace.js');
@@ -14,7 +14,7 @@ require('@weapp-core/regex');
14
14
  require('@babel/generator');
15
15
  require('@babel/parser');
16
16
  require('@babel/traverse');
17
- require('./defaults-263271f9.js');
17
+ require('./defaults-b7341550.js');
18
18
  require('@babel/types');
19
19
  require('htmlparser2');
20
20
  require('postcss');
@@ -27,6 +27,7 @@ require('semver');
27
27
  require('tailwindcss-patch');
28
28
  require('@tailwindcss-mangle/shared');
29
29
  require('lru-cache');
30
+ require('md5');
30
31
 
31
32
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
32
33
 
package/dist/gulp.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  import stream from 'node:stream';
2
- import { g as getOptions, a as createTailwindcssPatcher } from './options-d2268f8f.mjs';
2
+ import { g as getOptions, a as createTailwindcssPatcher } from './options-e1a9fdd3.mjs';
3
3
  import 'micromatch';
4
4
  import 'magic-string';
5
5
  import './replace.mjs';
@@ -10,7 +10,7 @@ import '@weapp-core/regex';
10
10
  import '@babel/generator';
11
11
  import '@babel/parser';
12
12
  import '@babel/traverse';
13
- import './defaults-dc8a0e3d.mjs';
13
+ import './defaults-d2c66d23.mjs';
14
14
  import '@babel/types';
15
15
  import 'htmlparser2';
16
16
  import 'postcss';
@@ -23,6 +23,7 @@ import 'semver';
23
23
  import 'tailwindcss-patch';
24
24
  import '@tailwindcss-mangle/shared';
25
25
  import 'lru-cache';
26
+ import 'md5';
26
27
 
27
28
  const Transform = stream.Transform;
28
29
  function createPlugins(options = {}) {
@@ -0,0 +1,10 @@
1
+ import _createDebug from 'debug';
2
+
3
+ const _debug = _createDebug('weapp-tw');
4
+ function createDebug(prefix) {
5
+ return function debug(formatter, ...args) {
6
+ return _debug((prefix !== null && prefix !== void 0 ? prefix : '') + formatter, ...args);
7
+ };
8
+ }
9
+
10
+ export { createDebug as c };
@@ -0,0 +1,16 @@
1
+ 'use strict';
2
+
3
+ var _createDebug = require('debug');
4
+
5
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
6
+
7
+ var _createDebug__default = /*#__PURE__*/_interopDefaultCompat(_createDebug);
8
+
9
+ const _debug = _createDebug__default["default"]('weapp-tw');
10
+ function createDebug(prefix) {
11
+ return function debug(formatter, ...args) {
12
+ return _debug((prefix !== null && prefix !== void 0 ? prefix : '') + formatter, ...args);
13
+ };
14
+ }
15
+
16
+ exports.createDebug = createDebug;
package/dist/index.js CHANGED
@@ -7,7 +7,7 @@ var vite = require('./vite.js');
7
7
  var gulp = require('./gulp.js');
8
8
  require('node:path');
9
9
  require('node:fs');
10
- require('./options-84d4eeb7.js');
10
+ require('./options-9dd8de2e.js');
11
11
  require('micromatch');
12
12
  require('magic-string');
13
13
  require('./replace.js');
@@ -18,7 +18,7 @@ require('@weapp-core/regex');
18
18
  require('@babel/generator');
19
19
  require('@babel/parser');
20
20
  require('@babel/traverse');
21
- require('./defaults-263271f9.js');
21
+ require('./defaults-b7341550.js');
22
22
  require('@babel/types');
23
23
  require('htmlparser2');
24
24
  require('postcss');
@@ -29,6 +29,8 @@ require('semver');
29
29
  require('tailwindcss-patch');
30
30
  require('@tailwindcss-mangle/shared');
31
31
  require('lru-cache');
32
+ require('md5');
33
+ require('./index-aede98ce.js');
32
34
  require('debug');
33
35
  require('node:stream');
34
36
 
package/dist/index.mjs CHANGED
@@ -3,7 +3,7 @@ export { UnifiedViteWeappTailwindcssPlugin } from './vite.mjs';
3
3
  export { createPlugins } from './gulp.mjs';
4
4
  import 'node:path';
5
5
  import 'node:fs';
6
- import './options-d2268f8f.mjs';
6
+ import './options-e1a9fdd3.mjs';
7
7
  import 'micromatch';
8
8
  import 'magic-string';
9
9
  import './replace.mjs';
@@ -14,7 +14,7 @@ import '@weapp-core/regex';
14
14
  import '@babel/generator';
15
15
  import '@babel/parser';
16
16
  import '@babel/traverse';
17
- import './defaults-dc8a0e3d.mjs';
17
+ import './defaults-d2c66d23.mjs';
18
18
  import '@babel/types';
19
19
  import 'htmlparser2';
20
20
  import 'postcss';
@@ -25,5 +25,7 @@ import 'semver';
25
25
  import 'tailwindcss-patch';
26
26
  import '@tailwindcss-mangle/shared';
27
27
  import 'lru-cache';
28
+ import 'md5';
29
+ import './index-84c7aa87.mjs';
28
30
  import 'debug';
29
31
  import 'node:stream';
@@ -9,7 +9,7 @@ var escape = require('@ast-core/escape');
9
9
  var generate = require('@babel/generator');
10
10
  var parser = require('@babel/parser');
11
11
  var traverse = require('@babel/traverse');
12
- var defaults = require('./defaults-263271f9.js');
12
+ var defaults = require('./defaults-b7341550.js');
13
13
  var t = require('@babel/types');
14
14
  var htmlparser2 = require('htmlparser2');
15
15
  var postcss = require('postcss');
@@ -21,6 +21,7 @@ var semver = require('semver');
21
21
  var tailwindcssPatch = require('tailwindcss-patch');
22
22
  var shared = require('@tailwindcss-mangle/shared');
23
23
  var lruCache = require('lru-cache');
24
+ var md5 = require('md5');
24
25
 
25
26
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
26
27
 
@@ -50,6 +51,7 @@ var postcss__default = /*#__PURE__*/_interopDefaultCompat(postcss);
50
51
  var postcssIsPseudoClass__default = /*#__PURE__*/_interopDefaultCompat(postcssIsPseudoClass);
51
52
  var path__default = /*#__PURE__*/_interopDefaultCompat(path);
52
53
  var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
54
+ var md5__default = /*#__PURE__*/_interopDefaultCompat(md5);
53
55
 
54
56
  const validateFilterRE = /[\w%-?\u00A0-\uFFFF-]/;
55
57
  function isValidSelector(selector = '') {
@@ -324,6 +326,10 @@ function createJsHandler(options) {
324
326
  };
325
327
  }
326
328
 
329
+ function getQuotes(quote) {
330
+ const quotes = quote === "'" ? 'double' : 'single';
331
+ return quotes;
332
+ }
327
333
  function generateCode(match, options = {}) {
328
334
  const ast = parser.parseExpression(match);
329
335
  traverse__default["default"](ast, {
@@ -343,7 +349,7 @@ function generateCode(match, options = {}) {
343
349
  compact: true,
344
350
  minified: true,
345
351
  jsescOption: {
346
- quotes: 'single',
352
+ quotes: getQuotes(options.quote),
347
353
  minimal: true
348
354
  }
349
355
  });
@@ -441,12 +447,8 @@ function customTemplateHandler(rawSource, options) {
441
447
  },
442
448
  onattribute(name, value, quote) {
443
449
  if (value) {
444
- if (quote === "'") {
445
- s.update(parser.startIndex + name.length + 1, parser.startIndex + name.length + 2, '"');
446
- s.update(parser.startIndex + name.length + value.length + 2, parser.startIndex + name.length + value.length + 3, '"');
447
- }
448
450
  function update() {
449
- s.update(parser.startIndex + name.length + 2, parser.endIndex, templateReplacer(value, options));
451
+ s.update(parser.startIndex + name.length + 2, parser.endIndex, templateReplacer(value, Object.assign(Object.assign({}, options), { quote })));
450
452
  }
451
453
  if (!disabledDefaultTemplateHandler && (name === 'class' || name === 'hover-class' || name === 'virtualhostclass')) {
452
454
  update();
@@ -707,7 +709,57 @@ function createCache() {
707
709
  });
708
710
  return {
709
711
  hashMap,
710
- instance
712
+ instance,
713
+ hasHashKey(key) {
714
+ return hashMap.has(key);
715
+ },
716
+ getHashValue(key) {
717
+ return hashMap.get(key);
718
+ },
719
+ setHashValue(key, value) {
720
+ return hashMap.set(key, value);
721
+ },
722
+ get(key) {
723
+ return instance.get(key);
724
+ },
725
+ set(key, value) {
726
+ return instance.set(key, value);
727
+ },
728
+ computeHash(message) {
729
+ return md5__default["default"](message);
730
+ },
731
+ calcHashValueChanged(key, hash) {
732
+ const hit = this.getHashValue(key);
733
+ if (hit) {
734
+ this.setHashValue(key, {
735
+ changed: hash !== hit.hash,
736
+ hash
737
+ });
738
+ }
739
+ else {
740
+ this.setHashValue(key, {
741
+ changed: true,
742
+ hash
743
+ });
744
+ }
745
+ return this;
746
+ },
747
+ has(key) {
748
+ return instance.has(key);
749
+ },
750
+ process(key, callback, fallback) {
751
+ const hit = this.getHashValue(key);
752
+ if (hit && !hit.changed) {
753
+ const returnFlag = callback();
754
+ if (returnFlag !== false) {
755
+ return;
756
+ }
757
+ }
758
+ const res = fallback();
759
+ if (res) {
760
+ this.set(res.key, res.source);
761
+ }
762
+ }
711
763
  };
712
764
  }
713
765
 
@@ -7,7 +7,7 @@ import { jsStringEscape } from '@ast-core/escape';
7
7
  import generate from '@babel/generator';
8
8
  import { parse, parseExpression } from '@babel/parser';
9
9
  import traverse from '@babel/traverse';
10
- import { n as noop, d as defaultOptions, i as isMap } from './defaults-dc8a0e3d.mjs';
10
+ import { n as noop, d as defaultOptions, i as isMap } from './defaults-d2c66d23.mjs';
11
11
  import * as t from '@babel/types';
12
12
  import { Parser } from 'htmlparser2';
13
13
  import postcss from 'postcss';
@@ -19,6 +19,7 @@ import { gte } from 'semver';
19
19
  import { monkeyPatchForExposingContext, requireResolve, TailwindcssPatcher } from 'tailwindcss-patch';
20
20
  import { ClassGenerator, defaultMangleClassFilter } from '@tailwindcss-mangle/shared';
21
21
  import { LRUCache } from 'lru-cache';
22
+ import md5 from 'md5';
22
23
 
23
24
  const validateFilterRE = /[\w%-?\u00A0-\uFFFF-]/;
24
25
  function isValidSelector(selector = '') {
@@ -293,6 +294,10 @@ function createJsHandler(options) {
293
294
  };
294
295
  }
295
296
 
297
+ function getQuotes(quote) {
298
+ const quotes = quote === "'" ? 'double' : 'single';
299
+ return quotes;
300
+ }
296
301
  function generateCode(match, options = {}) {
297
302
  const ast = parseExpression(match);
298
303
  traverse(ast, {
@@ -312,7 +317,7 @@ function generateCode(match, options = {}) {
312
317
  compact: true,
313
318
  minified: true,
314
319
  jsescOption: {
315
- quotes: 'single',
320
+ quotes: getQuotes(options.quote),
316
321
  minimal: true
317
322
  }
318
323
  });
@@ -410,12 +415,8 @@ function customTemplateHandler(rawSource, options) {
410
415
  },
411
416
  onattribute(name, value, quote) {
412
417
  if (value) {
413
- if (quote === "'") {
414
- s.update(parser.startIndex + name.length + 1, parser.startIndex + name.length + 2, '"');
415
- s.update(parser.startIndex + name.length + value.length + 2, parser.startIndex + name.length + value.length + 3, '"');
416
- }
417
418
  function update() {
418
- s.update(parser.startIndex + name.length + 2, parser.endIndex, templateReplacer(value, options));
419
+ s.update(parser.startIndex + name.length + 2, parser.endIndex, templateReplacer(value, Object.assign(Object.assign({}, options), { quote })));
419
420
  }
420
421
  if (!disabledDefaultTemplateHandler && (name === 'class' || name === 'hover-class' || name === 'virtualhostclass')) {
421
422
  update();
@@ -676,7 +677,57 @@ function createCache() {
676
677
  });
677
678
  return {
678
679
  hashMap,
679
- instance
680
+ instance,
681
+ hasHashKey(key) {
682
+ return hashMap.has(key);
683
+ },
684
+ getHashValue(key) {
685
+ return hashMap.get(key);
686
+ },
687
+ setHashValue(key, value) {
688
+ return hashMap.set(key, value);
689
+ },
690
+ get(key) {
691
+ return instance.get(key);
692
+ },
693
+ set(key, value) {
694
+ return instance.set(key, value);
695
+ },
696
+ computeHash(message) {
697
+ return md5(message);
698
+ },
699
+ calcHashValueChanged(key, hash) {
700
+ const hit = this.getHashValue(key);
701
+ if (hit) {
702
+ this.setHashValue(key, {
703
+ changed: hash !== hit.hash,
704
+ hash
705
+ });
706
+ }
707
+ else {
708
+ this.setHashValue(key, {
709
+ changed: true,
710
+ hash
711
+ });
712
+ }
713
+ return this;
714
+ },
715
+ has(key) {
716
+ return instance.has(key);
717
+ },
718
+ process(key, callback, fallback) {
719
+ const hit = this.getHashValue(key);
720
+ if (hit && !hit.changed) {
721
+ const returnFlag = callback();
722
+ if (returnFlag !== false) {
723
+ return;
724
+ }
725
+ }
726
+ const res = fallback();
727
+ if (res) {
728
+ this.set(res.key, res.source);
729
+ }
730
+ }
680
731
  };
681
732
  }
682
733
 
package/dist/types.d.ts CHANGED
@@ -129,6 +129,7 @@ export interface ITemplateHandlerOptions extends ICommonReplaceOptions {
129
129
  jsHandler?: JsHandler;
130
130
  runtimeSet?: Set<string>;
131
131
  disabledDefaultTemplateHandler?: boolean;
132
+ quote?: string | null;
132
133
  }
133
134
  export type GlobOrFunctionMatchers = 'htmlMatcher' | 'cssMatcher' | 'jsMatcher' | 'mainCssChunkMatcher' | 'wxsMatcher';
134
135
  export type InternalUserDefinedOptions = Required<Omit<UserDefinedOptions, GlobOrFunctionMatchers | 'supportCustomLengthUnitsPatch' | 'customReplaceDictionary'> & {
package/dist/utils.d.ts CHANGED
@@ -5,4 +5,5 @@ export declare function regExpTest(arr: (string | RegExp)[] | undefined, str: st
5
5
  export declare const noop: () => void;
6
6
  export declare function groupBy<T>(arr: T[], cb: (arg: T) => string): Record<string, T[]>;
7
7
  export declare function getGroupedEntries<T>(entries: [string, T][], options: InternalUserDefinedOptions): Record<"css" | "html" | "js" | "other", [string, T][]>;
8
+ export declare function removeExt(file: string): string;
8
9
  export { default as defu } from 'defu';
package/dist/vite.js CHANGED
@@ -2,9 +2,10 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var options = require('./options-84d4eeb7.js');
5
+ var options = require('./options-9dd8de2e.js');
6
6
  var postcss = require('./postcss-8d7f67b4.js');
7
- var defaults = require('./defaults-263271f9.js');
7
+ var defaults = require('./defaults-b7341550.js');
8
+ var index = require('./index-aede98ce.js');
8
9
  require('micromatch');
9
10
  require('magic-string');
10
11
  require('./replace.js');
@@ -25,14 +26,17 @@ require('semver');
25
26
  require('tailwindcss-patch');
26
27
  require('@tailwindcss-mangle/shared');
27
28
  require('lru-cache');
29
+ require('md5');
28
30
  require('postcss-selector-parser');
31
+ require('debug');
29
32
 
33
+ const debug = index.createDebug('generateBundle: ');
30
34
  function UnifiedViteWeappTailwindcssPlugin(options$1 = {}) {
31
35
  if (options$1.customReplaceDictionary === undefined) {
32
36
  options$1.customReplaceDictionary = 'simple';
33
37
  }
34
38
  const opts = options.getOptions(options$1);
35
- const { disabled, onEnd, onLoad, onStart, onUpdate, templateHandler, styleHandler, patch, jsHandler, mainCssChunkMatcher, appType, setMangleRuntimeSet } = opts;
39
+ const { disabled, onEnd, onLoad, onStart, onUpdate, templateHandler, styleHandler, patch, jsHandler, mainCssChunkMatcher, appType, setMangleRuntimeSet, cache } = opts;
36
40
  if (disabled) {
37
41
  return;
38
42
  }
@@ -43,49 +47,115 @@ function UnifiedViteWeappTailwindcssPlugin(options$1 = {}) {
43
47
  name: postcss.vitePluginName,
44
48
  enforce: 'post',
45
49
  generateBundle(opt, bundle) {
50
+ debug('start');
46
51
  onStart();
47
52
  const entries = Object.entries(bundle);
48
53
  const groupedEntries = defaults.getGroupedEntries(entries, opts);
49
54
  const runtimeSet = twPatcher.getClassSet();
50
55
  setMangleRuntimeSet(runtimeSet);
56
+ debug('get runtimeSet, class count: %d', runtimeSet.size);
51
57
  if (Array.isArray(groupedEntries.html)) {
58
+ let noCachedCount = 0;
52
59
  for (let i = 0; i < groupedEntries.html.length; i++) {
53
60
  const [file, originalSource] = groupedEntries.html[i];
54
61
  const oldVal = originalSource.source.toString();
55
- originalSource.source = templateHandler(oldVal, {
56
- runtimeSet
62
+ const hash = cache.computeHash(oldVal);
63
+ cache.calcHashValueChanged(file, hash);
64
+ cache.process(file, () => {
65
+ const source = cache.get(file);
66
+ if (source) {
67
+ originalSource.source = source;
68
+ debug('html cache hit: %s', file);
69
+ }
70
+ else {
71
+ return false;
72
+ }
73
+ }, () => {
74
+ originalSource.source = templateHandler(oldVal, {
75
+ runtimeSet
76
+ });
77
+ onUpdate(file, oldVal, originalSource.source);
78
+ debug('html handle: %s', file);
79
+ noCachedCount++;
80
+ return {
81
+ key: file,
82
+ source: originalSource.source
83
+ };
57
84
  });
58
- onUpdate(file, oldVal, originalSource.source);
59
- }
60
- }
61
- if (Array.isArray(groupedEntries.css)) {
62
- for (let i = 0; i < groupedEntries.css.length; i++) {
63
- const [file, originalSource] = groupedEntries.css[i];
64
- const rawSource = originalSource.source.toString();
65
- const css = styleHandler(rawSource, {
66
- isMainChunk: mainCssChunkMatcher(originalSource.fileName, appType)
67
- });
68
- originalSource.source = css;
69
- onUpdate(file, rawSource, css);
70
85
  }
86
+ debug('html handle finish, total: %d, no-cached: %d', groupedEntries.html.length, noCachedCount);
71
87
  }
72
88
  if (Array.isArray(groupedEntries.js)) {
89
+ let noCachedCount = 0;
73
90
  for (let i = 0; i < groupedEntries.js.length; i++) {
74
91
  const [file, originalSource] = groupedEntries.js[i];
75
92
  const rawSource = originalSource.code;
76
- const mapFilename = file + '.map';
77
- const hasMap = Boolean(bundle[mapFilename]);
78
- const { code, map } = jsHandler(rawSource, runtimeSet, {
79
- generateMap: hasMap
93
+ const hash = cache.computeHash(rawSource);
94
+ cache.calcHashValueChanged(file, hash);
95
+ cache.process(file, () => {
96
+ const source = cache.get(file);
97
+ if (source) {
98
+ originalSource.code = source;
99
+ debug('js cache hit: %s', file);
100
+ }
101
+ else {
102
+ return false;
103
+ }
104
+ }, () => {
105
+ const mapFilename = file + '.map';
106
+ const hasMap = Boolean(bundle[mapFilename]);
107
+ const { code, map } = jsHandler(rawSource, runtimeSet, {
108
+ generateMap: hasMap
109
+ });
110
+ originalSource.code = code;
111
+ onUpdate(file, rawSource, code);
112
+ debug('js handle: %s', file);
113
+ noCachedCount++;
114
+ if (hasMap && map) {
115
+ bundle[mapFilename].source = map.toString();
116
+ }
117
+ return {
118
+ key: file,
119
+ source: code
120
+ };
121
+ });
122
+ }
123
+ debug('js handle finish, total: %d, no-cached: %d', groupedEntries.js.length, noCachedCount);
124
+ }
125
+ if (Array.isArray(groupedEntries.css)) {
126
+ let noCachedCount = 0;
127
+ for (let i = 0; i < groupedEntries.css.length; i++) {
128
+ const [file, originalSource] = groupedEntries.css[i];
129
+ const rawSource = originalSource.source.toString();
130
+ const hash = cache.computeHash(rawSource);
131
+ cache.calcHashValueChanged(file, hash);
132
+ cache.process(file, () => {
133
+ const source = cache.get(file);
134
+ if (source) {
135
+ originalSource.source = source;
136
+ debug('css cache hit: %s', file);
137
+ }
138
+ else {
139
+ return false;
140
+ }
141
+ }, () => {
142
+ const css = styleHandler(rawSource, {
143
+ isMainChunk: mainCssChunkMatcher(originalSource.fileName, appType)
144
+ });
145
+ originalSource.source = css;
146
+ onUpdate(file, rawSource, css);
147
+ debug('css handle: %s', file);
148
+ noCachedCount++;
149
+ return {
150
+ key: file,
151
+ source: css
152
+ };
80
153
  });
81
- originalSource.code = code;
82
- onUpdate(file, rawSource, code);
83
- if (hasMap && map) {
84
- bundle[mapFilename].source = map.toString();
85
- }
86
154
  }
155
+ debug('css handle finish, total: %d, no-cached: %d', groupedEntries.css.length, noCachedCount);
87
156
  }
88
157
  onEnd();
158
+ debug('end');
89
159
  }
90
160
  };
91
161
  }
package/dist/vite.mjs CHANGED
@@ -1,6 +1,7 @@
1
- import { g as getOptions, a as createTailwindcssPatcher } from './options-d2268f8f.mjs';
1
+ import { g as getOptions, a as createTailwindcssPatcher } from './options-e1a9fdd3.mjs';
2
2
  import { v as vitePluginName } from './postcss-55ed4d42.mjs';
3
- import { g as getGroupedEntries } from './defaults-dc8a0e3d.mjs';
3
+ import { g as getGroupedEntries } from './defaults-d2c66d23.mjs';
4
+ import { c as createDebug } from './index-84c7aa87.mjs';
4
5
  import 'micromatch';
5
6
  import 'magic-string';
6
7
  import './replace.mjs';
@@ -21,14 +22,17 @@ import 'semver';
21
22
  import 'tailwindcss-patch';
22
23
  import '@tailwindcss-mangle/shared';
23
24
  import 'lru-cache';
25
+ import 'md5';
24
26
  import 'postcss-selector-parser';
27
+ import 'debug';
25
28
 
29
+ const debug = createDebug('generateBundle: ');
26
30
  function UnifiedViteWeappTailwindcssPlugin(options = {}) {
27
31
  if (options.customReplaceDictionary === undefined) {
28
32
  options.customReplaceDictionary = 'simple';
29
33
  }
30
34
  const opts = getOptions(options);
31
- const { disabled, onEnd, onLoad, onStart, onUpdate, templateHandler, styleHandler, patch, jsHandler, mainCssChunkMatcher, appType, setMangleRuntimeSet } = opts;
35
+ const { disabled, onEnd, onLoad, onStart, onUpdate, templateHandler, styleHandler, patch, jsHandler, mainCssChunkMatcher, appType, setMangleRuntimeSet, cache } = opts;
32
36
  if (disabled) {
33
37
  return;
34
38
  }
@@ -39,49 +43,115 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
39
43
  name: vitePluginName,
40
44
  enforce: 'post',
41
45
  generateBundle(opt, bundle) {
46
+ debug('start');
42
47
  onStart();
43
48
  const entries = Object.entries(bundle);
44
49
  const groupedEntries = getGroupedEntries(entries, opts);
45
50
  const runtimeSet = twPatcher.getClassSet();
46
51
  setMangleRuntimeSet(runtimeSet);
52
+ debug('get runtimeSet, class count: %d', runtimeSet.size);
47
53
  if (Array.isArray(groupedEntries.html)) {
54
+ let noCachedCount = 0;
48
55
  for (let i = 0; i < groupedEntries.html.length; i++) {
49
56
  const [file, originalSource] = groupedEntries.html[i];
50
57
  const oldVal = originalSource.source.toString();
51
- originalSource.source = templateHandler(oldVal, {
52
- runtimeSet
58
+ const hash = cache.computeHash(oldVal);
59
+ cache.calcHashValueChanged(file, hash);
60
+ cache.process(file, () => {
61
+ const source = cache.get(file);
62
+ if (source) {
63
+ originalSource.source = source;
64
+ debug('html cache hit: %s', file);
65
+ }
66
+ else {
67
+ return false;
68
+ }
69
+ }, () => {
70
+ originalSource.source = templateHandler(oldVal, {
71
+ runtimeSet
72
+ });
73
+ onUpdate(file, oldVal, originalSource.source);
74
+ debug('html handle: %s', file);
75
+ noCachedCount++;
76
+ return {
77
+ key: file,
78
+ source: originalSource.source
79
+ };
53
80
  });
54
- onUpdate(file, oldVal, originalSource.source);
55
- }
56
- }
57
- if (Array.isArray(groupedEntries.css)) {
58
- for (let i = 0; i < groupedEntries.css.length; i++) {
59
- const [file, originalSource] = groupedEntries.css[i];
60
- const rawSource = originalSource.source.toString();
61
- const css = styleHandler(rawSource, {
62
- isMainChunk: mainCssChunkMatcher(originalSource.fileName, appType)
63
- });
64
- originalSource.source = css;
65
- onUpdate(file, rawSource, css);
66
81
  }
82
+ debug('html handle finish, total: %d, no-cached: %d', groupedEntries.html.length, noCachedCount);
67
83
  }
68
84
  if (Array.isArray(groupedEntries.js)) {
85
+ let noCachedCount = 0;
69
86
  for (let i = 0; i < groupedEntries.js.length; i++) {
70
87
  const [file, originalSource] = groupedEntries.js[i];
71
88
  const rawSource = originalSource.code;
72
- const mapFilename = file + '.map';
73
- const hasMap = Boolean(bundle[mapFilename]);
74
- const { code, map } = jsHandler(rawSource, runtimeSet, {
75
- generateMap: hasMap
89
+ const hash = cache.computeHash(rawSource);
90
+ cache.calcHashValueChanged(file, hash);
91
+ cache.process(file, () => {
92
+ const source = cache.get(file);
93
+ if (source) {
94
+ originalSource.code = source;
95
+ debug('js cache hit: %s', file);
96
+ }
97
+ else {
98
+ return false;
99
+ }
100
+ }, () => {
101
+ const mapFilename = file + '.map';
102
+ const hasMap = Boolean(bundle[mapFilename]);
103
+ const { code, map } = jsHandler(rawSource, runtimeSet, {
104
+ generateMap: hasMap
105
+ });
106
+ originalSource.code = code;
107
+ onUpdate(file, rawSource, code);
108
+ debug('js handle: %s', file);
109
+ noCachedCount++;
110
+ if (hasMap && map) {
111
+ bundle[mapFilename].source = map.toString();
112
+ }
113
+ return {
114
+ key: file,
115
+ source: code
116
+ };
117
+ });
118
+ }
119
+ debug('js handle finish, total: %d, no-cached: %d', groupedEntries.js.length, noCachedCount);
120
+ }
121
+ if (Array.isArray(groupedEntries.css)) {
122
+ let noCachedCount = 0;
123
+ for (let i = 0; i < groupedEntries.css.length; i++) {
124
+ const [file, originalSource] = groupedEntries.css[i];
125
+ const rawSource = originalSource.source.toString();
126
+ const hash = cache.computeHash(rawSource);
127
+ cache.calcHashValueChanged(file, hash);
128
+ cache.process(file, () => {
129
+ const source = cache.get(file);
130
+ if (source) {
131
+ originalSource.source = source;
132
+ debug('css cache hit: %s', file);
133
+ }
134
+ else {
135
+ return false;
136
+ }
137
+ }, () => {
138
+ const css = styleHandler(rawSource, {
139
+ isMainChunk: mainCssChunkMatcher(originalSource.fileName, appType)
140
+ });
141
+ originalSource.source = css;
142
+ onUpdate(file, rawSource, css);
143
+ debug('css handle: %s', file);
144
+ noCachedCount++;
145
+ return {
146
+ key: file,
147
+ source: css
148
+ };
76
149
  });
77
- originalSource.code = code;
78
- onUpdate(file, rawSource, code);
79
- if (hasMap && map) {
80
- bundle[mapFilename].source = map.toString();
81
- }
82
150
  }
151
+ debug('css handle finish, total: %d, no-cached: %d', groupedEntries.css.length, noCachedCount);
83
152
  }
84
153
  onEnd();
154
+ debug('end');
85
155
  }
86
156
  };
87
157
  }
package/dist/webpack.js CHANGED
@@ -4,10 +4,10 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var path = require('node:path');
6
6
  var fs = require('node:fs');
7
- var options = require('./options-84d4eeb7.js');
7
+ var options = require('./options-9dd8de2e.js');
8
8
  var postcss = require('./postcss-8d7f67b4.js');
9
- var defaults = require('./defaults-263271f9.js');
10
- var createDebug = require('debug');
9
+ var defaults = require('./defaults-b7341550.js');
10
+ var index = require('./index-aede98ce.js');
11
11
  require('micromatch');
12
12
  require('magic-string');
13
13
  require('./replace.js');
@@ -26,16 +26,16 @@ require('semver');
26
26
  require('tailwindcss-patch');
27
27
  require('@tailwindcss-mangle/shared');
28
28
  require('lru-cache');
29
+ require('md5');
29
30
  require('postcss-selector-parser');
31
+ require('debug');
30
32
 
31
33
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
32
34
 
33
35
  var path__default = /*#__PURE__*/_interopDefaultCompat(path);
34
36
  var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
35
- var createDebug__default = /*#__PURE__*/_interopDefaultCompat(createDebug);
36
-
37
- const debug = createDebug__default["default"]('weapp-tw');
38
37
 
38
+ const debug = index.createDebug('');
39
39
  class UnifiedWebpackPluginV5 {
40
40
  constructor(options$1 = {}) {
41
41
  if (options$1.customReplaceDictionary === undefined) {
@@ -81,63 +81,66 @@ class UnifiedWebpackPluginV5 {
81
81
  stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
82
82
  }, (assets) => {
83
83
  onStart();
84
- debug('processAssets: start');
84
+ debug('start');
85
85
  for (const chunk of compilation.chunks) {
86
86
  if (chunk.id && chunk.hash) {
87
- if (cache.hashMap.has(chunk.id)) {
88
- const value = cache.hashMap.get(chunk.id);
89
- if (value) {
90
- if (chunk.hash === value.hash) {
91
- cache.hashMap.set(chunk.id, {
92
- changed: false,
93
- hash: chunk.hash
94
- });
95
- }
96
- else {
97
- cache.hashMap.set(chunk.id, {
98
- changed: true,
99
- hash: chunk.hash
100
- });
101
- }
102
- }
103
- }
104
- else {
105
- cache.hashMap.set(chunk.id, {
106
- changed: true,
107
- hash: chunk.hash
108
- });
109
- }
87
+ cache.calcHashValueChanged(chunk.id, chunk.hash);
110
88
  }
111
89
  }
112
90
  const entries = Object.entries(assets);
113
91
  const groupedEntries = defaults.getGroupedEntries(entries, this.options);
114
92
  const runtimeSet = getClassSet();
115
93
  setMangleRuntimeSet(runtimeSet);
116
- debug('processAssets: runtimeSet inited, class count: %d', runtimeSet.size);
94
+ debug('get runtimeSet, class count: %d', runtimeSet.size);
117
95
  if (Array.isArray(groupedEntries.html)) {
96
+ let noCachedCount = 0;
118
97
  for (let i = 0; i < groupedEntries.html.length; i++) {
119
98
  const [file, originalSource] = groupedEntries.html[i];
120
99
  const rawSource = originalSource.source().toString();
121
- const wxml = templateHandler(rawSource, {
122
- runtimeSet
100
+ const hash = cache.computeHash(rawSource);
101
+ const cacheKey = file;
102
+ cache.calcHashValueChanged(cacheKey, hash);
103
+ cache.process(cacheKey, () => {
104
+ const source = cache.get(cacheKey);
105
+ if (source) {
106
+ compilation.updateAsset(file, source);
107
+ debug('html cache hit: %s', file);
108
+ }
109
+ else {
110
+ return false;
111
+ }
112
+ }, () => {
113
+ const wxml = templateHandler(rawSource, {
114
+ runtimeSet
115
+ });
116
+ const source = new ConcatSource(wxml);
117
+ compilation.updateAsset(file, source);
118
+ onUpdate(file, rawSource, wxml);
119
+ debug('html handle: %s', file);
120
+ noCachedCount++;
121
+ return {
122
+ key: cacheKey,
123
+ source
124
+ };
123
125
  });
124
- const source = new ConcatSource(wxml);
125
- compilation.updateAsset(file, source);
126
- onUpdate(file, rawSource, wxml);
127
126
  }
128
- debug('processAssets: html handle finish, count: %s', groupedEntries.html.length);
127
+ debug('html handle finish, total: %d, no-cached: %d', groupedEntries.html.length, noCachedCount);
129
128
  }
130
129
  if (Array.isArray(groupedEntries.js)) {
130
+ let noCachedCount = 0;
131
131
  for (let i = 0; i < groupedEntries.js.length; i++) {
132
132
  const [file, originalSource] = groupedEntries.js[i];
133
- const key = file.replace(/\.[^./]+$/, '');
134
- const hit = cache.hashMap.get(key);
135
- if (hit && !hit.changed) {
136
- const source = cache.instance.get(key);
137
- source && compilation.updateAsset(file, source);
138
- debug('processAssets: js cache hited: %s', file);
139
- }
140
- else {
133
+ const cacheKey = defaults.removeExt(file);
134
+ cache.process(cacheKey, () => {
135
+ const source = cache.get(cacheKey);
136
+ if (source) {
137
+ compilation.updateAsset(file, source);
138
+ debug('js cache hit: %s', file);
139
+ }
140
+ else {
141
+ return false;
142
+ }
143
+ }, () => {
141
144
  const rawSource = originalSource.source().toString();
142
145
  const mapFilename = file + '.map';
143
146
  const hasMap = Boolean(assets[mapFilename]);
@@ -147,30 +150,55 @@ class UnifiedWebpackPluginV5 {
147
150
  const source = new ConcatSource(code);
148
151
  compilation.updateAsset(file, source);
149
152
  onUpdate(file, rawSource, code);
150
- debug('processAssets: js handle: %s', file);
151
- cache.instance.set(key, source);
153
+ debug('js handle: %s', file);
154
+ noCachedCount++;
152
155
  if (hasMap && map) {
153
156
  const source = new RawSource(map.toString());
154
157
  compilation.updateAsset(mapFilename, source);
155
158
  }
156
- }
159
+ return {
160
+ key: cacheKey,
161
+ source
162
+ };
163
+ });
157
164
  }
158
- debug('processAssets: js handler finish, count: %s', groupedEntries.js.length);
165
+ debug('js handle finish, total: %d, no-cached: %d', groupedEntries.js.length, noCachedCount);
159
166
  }
160
167
  if (Array.isArray(groupedEntries.css)) {
168
+ let noCachedCount = 0;
161
169
  for (let i = 0; i < groupedEntries.css.length; i++) {
162
170
  const [file, originalSource] = groupedEntries.css[i];
163
171
  const rawSource = originalSource.source().toString();
164
- const css = styleHandler(rawSource, {
165
- isMainChunk: mainCssChunkMatcher(file, this.appType)
172
+ const hash = cache.computeHash(rawSource);
173
+ const cacheKey = file;
174
+ cache.calcHashValueChanged(cacheKey, hash);
175
+ cache.process(cacheKey, () => {
176
+ const source = cache.get(cacheKey);
177
+ if (source) {
178
+ compilation.updateAsset(file, source);
179
+ debug('css cache hit: %s', file);
180
+ }
181
+ else {
182
+ return false;
183
+ }
184
+ }, () => {
185
+ const css = styleHandler(rawSource, {
186
+ isMainChunk: mainCssChunkMatcher(file, this.appType)
187
+ });
188
+ const source = new ConcatSource(css);
189
+ compilation.updateAsset(file, source);
190
+ onUpdate(file, rawSource, css);
191
+ debug('css handle: %s', file);
192
+ noCachedCount++;
193
+ return {
194
+ key: cacheKey,
195
+ source
196
+ };
166
197
  });
167
- const source = new ConcatSource(css);
168
- compilation.updateAsset(file, source);
169
- onUpdate(file, rawSource, css);
170
198
  }
171
- debug('processAssets: css handler finish, count: %s', groupedEntries.css.length);
199
+ debug('css handle finish, total: %d, no-cached: %d', groupedEntries.css.length, noCachedCount);
172
200
  }
173
- debug('processAssets: end');
201
+ debug('end');
174
202
  onEnd();
175
203
  });
176
204
  });
package/dist/webpack.mjs CHANGED
@@ -1,9 +1,9 @@
1
1
  import path from 'node:path';
2
2
  import fs from 'node:fs';
3
- import { g as getOptions, a as createTailwindcssPatcher } from './options-d2268f8f.mjs';
3
+ import { g as getOptions, a as createTailwindcssPatcher } from './options-e1a9fdd3.mjs';
4
4
  import { a as pluginName } from './postcss-55ed4d42.mjs';
5
- import { g as getGroupedEntries } from './defaults-dc8a0e3d.mjs';
6
- import createDebug from 'debug';
5
+ import { g as getGroupedEntries, r as removeExt } from './defaults-d2c66d23.mjs';
6
+ import { c as createDebug } from './index-84c7aa87.mjs';
7
7
  import 'micromatch';
8
8
  import 'magic-string';
9
9
  import './replace.mjs';
@@ -22,10 +22,11 @@ import 'semver';
22
22
  import 'tailwindcss-patch';
23
23
  import '@tailwindcss-mangle/shared';
24
24
  import 'lru-cache';
25
+ import 'md5';
25
26
  import 'postcss-selector-parser';
27
+ import 'debug';
26
28
 
27
- const debug = createDebug('weapp-tw');
28
-
29
+ const debug = createDebug('');
29
30
  class UnifiedWebpackPluginV5 {
30
31
  constructor(options = {}) {
31
32
  if (options.customReplaceDictionary === undefined) {
@@ -71,63 +72,66 @@ class UnifiedWebpackPluginV5 {
71
72
  stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
72
73
  }, (assets) => {
73
74
  onStart();
74
- debug('processAssets: start');
75
+ debug('start');
75
76
  for (const chunk of compilation.chunks) {
76
77
  if (chunk.id && chunk.hash) {
77
- if (cache.hashMap.has(chunk.id)) {
78
- const value = cache.hashMap.get(chunk.id);
79
- if (value) {
80
- if (chunk.hash === value.hash) {
81
- cache.hashMap.set(chunk.id, {
82
- changed: false,
83
- hash: chunk.hash
84
- });
85
- }
86
- else {
87
- cache.hashMap.set(chunk.id, {
88
- changed: true,
89
- hash: chunk.hash
90
- });
91
- }
92
- }
93
- }
94
- else {
95
- cache.hashMap.set(chunk.id, {
96
- changed: true,
97
- hash: chunk.hash
98
- });
99
- }
78
+ cache.calcHashValueChanged(chunk.id, chunk.hash);
100
79
  }
101
80
  }
102
81
  const entries = Object.entries(assets);
103
82
  const groupedEntries = getGroupedEntries(entries, this.options);
104
83
  const runtimeSet = getClassSet();
105
84
  setMangleRuntimeSet(runtimeSet);
106
- debug('processAssets: runtimeSet inited, class count: %d', runtimeSet.size);
85
+ debug('get runtimeSet, class count: %d', runtimeSet.size);
107
86
  if (Array.isArray(groupedEntries.html)) {
87
+ let noCachedCount = 0;
108
88
  for (let i = 0; i < groupedEntries.html.length; i++) {
109
89
  const [file, originalSource] = groupedEntries.html[i];
110
90
  const rawSource = originalSource.source().toString();
111
- const wxml = templateHandler(rawSource, {
112
- runtimeSet
91
+ const hash = cache.computeHash(rawSource);
92
+ const cacheKey = file;
93
+ cache.calcHashValueChanged(cacheKey, hash);
94
+ cache.process(cacheKey, () => {
95
+ const source = cache.get(cacheKey);
96
+ if (source) {
97
+ compilation.updateAsset(file, source);
98
+ debug('html cache hit: %s', file);
99
+ }
100
+ else {
101
+ return false;
102
+ }
103
+ }, () => {
104
+ const wxml = templateHandler(rawSource, {
105
+ runtimeSet
106
+ });
107
+ const source = new ConcatSource(wxml);
108
+ compilation.updateAsset(file, source);
109
+ onUpdate(file, rawSource, wxml);
110
+ debug('html handle: %s', file);
111
+ noCachedCount++;
112
+ return {
113
+ key: cacheKey,
114
+ source
115
+ };
113
116
  });
114
- const source = new ConcatSource(wxml);
115
- compilation.updateAsset(file, source);
116
- onUpdate(file, rawSource, wxml);
117
117
  }
118
- debug('processAssets: html handle finish, count: %s', groupedEntries.html.length);
118
+ debug('html handle finish, total: %d, no-cached: %d', groupedEntries.html.length, noCachedCount);
119
119
  }
120
120
  if (Array.isArray(groupedEntries.js)) {
121
+ let noCachedCount = 0;
121
122
  for (let i = 0; i < groupedEntries.js.length; i++) {
122
123
  const [file, originalSource] = groupedEntries.js[i];
123
- const key = file.replace(/\.[^./]+$/, '');
124
- const hit = cache.hashMap.get(key);
125
- if (hit && !hit.changed) {
126
- const source = cache.instance.get(key);
127
- source && compilation.updateAsset(file, source);
128
- debug('processAssets: js cache hited: %s', file);
129
- }
130
- else {
124
+ const cacheKey = removeExt(file);
125
+ cache.process(cacheKey, () => {
126
+ const source = cache.get(cacheKey);
127
+ if (source) {
128
+ compilation.updateAsset(file, source);
129
+ debug('js cache hit: %s', file);
130
+ }
131
+ else {
132
+ return false;
133
+ }
134
+ }, () => {
131
135
  const rawSource = originalSource.source().toString();
132
136
  const mapFilename = file + '.map';
133
137
  const hasMap = Boolean(assets[mapFilename]);
@@ -137,30 +141,55 @@ class UnifiedWebpackPluginV5 {
137
141
  const source = new ConcatSource(code);
138
142
  compilation.updateAsset(file, source);
139
143
  onUpdate(file, rawSource, code);
140
- debug('processAssets: js handle: %s', file);
141
- cache.instance.set(key, source);
144
+ debug('js handle: %s', file);
145
+ noCachedCount++;
142
146
  if (hasMap && map) {
143
147
  const source = new RawSource(map.toString());
144
148
  compilation.updateAsset(mapFilename, source);
145
149
  }
146
- }
150
+ return {
151
+ key: cacheKey,
152
+ source
153
+ };
154
+ });
147
155
  }
148
- debug('processAssets: js handler finish, count: %s', groupedEntries.js.length);
156
+ debug('js handle finish, total: %d, no-cached: %d', groupedEntries.js.length, noCachedCount);
149
157
  }
150
158
  if (Array.isArray(groupedEntries.css)) {
159
+ let noCachedCount = 0;
151
160
  for (let i = 0; i < groupedEntries.css.length; i++) {
152
161
  const [file, originalSource] = groupedEntries.css[i];
153
162
  const rawSource = originalSource.source().toString();
154
- const css = styleHandler(rawSource, {
155
- isMainChunk: mainCssChunkMatcher(file, this.appType)
163
+ const hash = cache.computeHash(rawSource);
164
+ const cacheKey = file;
165
+ cache.calcHashValueChanged(cacheKey, hash);
166
+ cache.process(cacheKey, () => {
167
+ const source = cache.get(cacheKey);
168
+ if (source) {
169
+ compilation.updateAsset(file, source);
170
+ debug('css cache hit: %s', file);
171
+ }
172
+ else {
173
+ return false;
174
+ }
175
+ }, () => {
176
+ const css = styleHandler(rawSource, {
177
+ isMainChunk: mainCssChunkMatcher(file, this.appType)
178
+ });
179
+ const source = new ConcatSource(css);
180
+ compilation.updateAsset(file, source);
181
+ onUpdate(file, rawSource, css);
182
+ debug('css handle: %s', file);
183
+ noCachedCount++;
184
+ return {
185
+ key: cacheKey,
186
+ source
187
+ };
156
188
  });
157
- const source = new ConcatSource(css);
158
- compilation.updateAsset(file, source);
159
- onUpdate(file, rawSource, css);
160
189
  }
161
- debug('processAssets: css handler finish, count: %s', groupedEntries.css.length);
190
+ debug('css handle finish, total: %d, no-cached: %d', groupedEntries.css.length, noCachedCount);
162
191
  }
163
- debug('processAssets: end');
192
+ debug('end');
164
193
  onEnd();
165
194
  });
166
195
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "weapp-tailwindcss",
3
- "version": "2.9.0",
3
+ "version": "2.9.2",
4
4
  "description": "把tailwindcss jit引擎,带给小程序开发者们! bring tailwindcss jit engine to miniprogram developers!",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -124,6 +124,7 @@
124
124
  "@types/klaw": "^3.0.4",
125
125
  "@types/loader-utils": "^2.0.4",
126
126
  "@types/lodash": "^4.14.198",
127
+ "@types/md5": "^2.3.2",
127
128
  "@types/micromatch": "^4.0.2",
128
129
  "@types/node": "^20.6.2",
129
130
  "@types/semver": "^7.5.2",
@@ -189,7 +190,7 @@
189
190
  "@babel/parser": "^7.22.16",
190
191
  "@babel/traverse": "^7.22.20",
191
192
  "@babel/types": "^7.22.19",
192
- "@csstools/postcss-is-pseudo-class": "^4.0.1",
193
+ "@csstools/postcss-is-pseudo-class": "^4.0.2",
193
194
  "@tailwindcss-mangle/shared": "^2.2.1",
194
195
  "@weapp-core/escape": "^2.0.0",
195
196
  "@weapp-core/regex": "^1.0.1",
@@ -198,8 +199,9 @@
198
199
  "loader-utils": "^2.0.3",
199
200
  "lru-cache": "^10.0.1",
200
201
  "magic-string": "^0.30.3",
202
+ "md5": "^2.3.0",
201
203
  "micromatch": "^4.0.5",
202
- "postcss": "8.4.29",
204
+ "postcss": "8.4.30",
203
205
  "postcss-selector-parser": "^6.0.13",
204
206
  "semver": "^7.5.4",
205
207
  "tailwindcss-patch": "^2.2.1"