weapp-tailwindcss 2.8.4 → 2.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,27 @@
1
+ /// <reference types="node" />
2
+ import { LRUCache } from 'lru-cache';
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;
10
+ export interface ICreateCacheReturnType {
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;
25
+ }
26
+ declare function createCache(): ICreateCacheReturnType;
27
+ export { createCache };
package/dist/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var options = require('./options-904051d2.js');
3
+ var options = require('./options-b96f6338.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');
@@ -23,6 +23,8 @@ require('node:fs');
23
23
  require('semver');
24
24
  require('tailwindcss-patch');
25
25
  require('@tailwindcss-mangle/shared');
26
+ require('lru-cache');
27
+ require('md5');
26
28
 
27
29
  const args = process.argv.slice(2);
28
30
  if (args[0] === 'patch') {
package/dist/cli.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { g as getOptions, c as createPatch } from './options-c9c14817.mjs';
1
+ import { g as getOptions, c as createPatch } from './options-f70d1c6f.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';
@@ -21,6 +21,8 @@ import 'node:fs';
21
21
  import 'semver';
22
22
  import 'tailwindcss-patch';
23
23
  import '@tailwindcss-mangle/shared';
24
+ import 'lru-cache';
25
+ import 'md5';
24
26
 
25
27
  const args = process.argv.slice(2);
26
28
  if (args[0] === 'patch') {
@@ -0,0 +1,2 @@
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-904051d2.js');
6
+ var options = require('./options-b96f6338.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');
@@ -26,6 +26,8 @@ require('node:fs');
26
26
  require('semver');
27
27
  require('tailwindcss-patch');
28
28
  require('@tailwindcss-mangle/shared');
29
+ require('lru-cache');
30
+ require('md5');
29
31
 
30
32
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
31
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-c9c14817.mjs';
2
+ import { g as getOptions, a as createTailwindcssPatcher } from './options-f70d1c6f.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';
@@ -22,6 +22,8 @@ import 'node:fs';
22
22
  import 'semver';
23
23
  import 'tailwindcss-patch';
24
24
  import '@tailwindcss-mangle/shared';
25
+ import 'lru-cache';
26
+ import 'md5';
25
27
 
26
28
  const Transform = stream.Transform;
27
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-904051d2.js');
10
+ require('./options-b96f6338.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');
@@ -28,6 +28,10 @@ require('@csstools/postcss-is-pseudo-class');
28
28
  require('semver');
29
29
  require('tailwindcss-patch');
30
30
  require('@tailwindcss-mangle/shared');
31
+ require('lru-cache');
32
+ require('md5');
33
+ require('./index-aede98ce.js');
34
+ require('debug');
31
35
  require('node:stream');
32
36
 
33
37
 
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-c9c14817.mjs';
6
+ import './options-f70d1c6f.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';
@@ -24,4 +24,8 @@ import '@csstools/postcss-is-pseudo-class';
24
24
  import 'semver';
25
25
  import 'tailwindcss-patch';
26
26
  import '@tailwindcss-mangle/shared';
27
+ import 'lru-cache';
28
+ import 'md5';
29
+ import './index-84c7aa87.mjs';
30
+ import 'debug';
27
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');
@@ -20,6 +20,8 @@ var fs = require('node:fs');
20
20
  var semver = require('semver');
21
21
  var tailwindcssPatch = require('tailwindcss-patch');
22
22
  var shared = require('@tailwindcss-mangle/shared');
23
+ var lruCache = require('lru-cache');
24
+ var md5 = require('md5');
23
25
 
24
26
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
25
27
 
@@ -49,6 +51,7 @@ var postcss__default = /*#__PURE__*/_interopDefaultCompat(postcss);
49
51
  var postcssIsPseudoClass__default = /*#__PURE__*/_interopDefaultCompat(postcssIsPseudoClass);
50
52
  var path__default = /*#__PURE__*/_interopDefaultCompat(path);
51
53
  var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
54
+ var md5__default = /*#__PURE__*/_interopDefaultCompat(md5);
52
55
 
53
56
  const validateFilterRE = /[\w%-?\u00A0-\uFFFF-]/;
54
57
  function isValidSelector(selector = '') {
@@ -697,6 +700,69 @@ function useMangleStore() {
697
700
  };
698
701
  }
699
702
 
703
+ function createCache() {
704
+ const hashMap = new Map();
705
+ const instance = new lruCache.LRUCache({
706
+ max: 1024,
707
+ ttl: 0,
708
+ ttlAutopurge: false
709
+ });
710
+ return {
711
+ hashMap,
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
+ }
763
+ };
764
+ }
765
+
700
766
  function createGlobMatcher(pattern) {
701
767
  return function (file) {
702
768
  return micromatch.isMatch(file, pattern);
@@ -767,6 +833,7 @@ function getOptions(options = {}) {
767
833
  result.templateHandler = templateHandler;
768
834
  result.patch = createPatch(supportCustomLengthUnitsPatch);
769
835
  result.setMangleRuntimeSet = setMangleRuntimeSet;
836
+ result.cache = createCache();
770
837
  return result;
771
838
  }
772
839
 
@@ -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';
@@ -18,6 +18,8 @@ import fs from 'node:fs';
18
18
  import { gte } from 'semver';
19
19
  import { monkeyPatchForExposingContext, requireResolve, TailwindcssPatcher } from 'tailwindcss-patch';
20
20
  import { ClassGenerator, defaultMangleClassFilter } from '@tailwindcss-mangle/shared';
21
+ import { LRUCache } from 'lru-cache';
22
+ import md5 from 'md5';
21
23
 
22
24
  const validateFilterRE = /[\w%-?\u00A0-\uFFFF-]/;
23
25
  function isValidSelector(selector = '') {
@@ -666,6 +668,69 @@ function useMangleStore() {
666
668
  };
667
669
  }
668
670
 
671
+ function createCache() {
672
+ const hashMap = new Map();
673
+ const instance = new LRUCache({
674
+ max: 1024,
675
+ ttl: 0,
676
+ ttlAutopurge: false
677
+ });
678
+ return {
679
+ hashMap,
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
+ }
731
+ };
732
+ }
733
+
669
734
  function createGlobMatcher(pattern) {
670
735
  return function (file) {
671
736
  return isMatch(file, pattern);
@@ -736,6 +801,7 @@ function getOptions(options = {}) {
736
801
  result.templateHandler = templateHandler;
737
802
  result.patch = createPatch(supportCustomLengthUnitsPatch);
738
803
  result.setMangleRuntimeSet = setMangleRuntimeSet;
804
+ result.cache = createCache();
739
805
  return result;
740
806
  }
741
807
 
package/dist/types.d.ts CHANGED
@@ -3,6 +3,7 @@ import type { IClassGeneratorOptions, ClassGenerator } from '@tailwindcss-mangle
3
3
  import type { SourceMap } from 'magic-string';
4
4
  import type { GeneratorResult } from '@babel/generator';
5
5
  import type { InjectPreflight } from './postcss/preflight';
6
+ import type { ICreateCacheReturnType } from "./cache";
6
7
  export type ItemOrItemArray<T> = T | T[];
7
8
  export type AppType = 'uni-app' | 'uni-app-vite' | 'taro' | 'remax' | 'rax' | 'native' | 'kbone' | 'mpx';
8
9
  export interface IPropValue {
@@ -141,6 +142,7 @@ export type InternalUserDefinedOptions = Required<Omit<UserDefinedOptions, GlobO
141
142
  patch: () => void;
142
143
  customReplaceDictionary: Record<string, string>;
143
144
  setMangleRuntimeSet: (runtimeSet: Set<string>) => void;
145
+ cache: ICreateCacheReturnType;
144
146
  }>;
145
147
  export type InternalPostcssOptions = Pick<UserDefinedOptions, 'cssMatcher' | 'mainCssChunkMatcher' | 'cssPreflight' | 'replaceUniversalSelectorWith' | 'cssPreflightRange' | 'customRuleCallback' | 'disabled'>;
146
148
  export interface IBaseWebpackPlugin {
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-904051d2.js');
5
+ var options = require('./options-b96f6338.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');
@@ -24,14 +25,18 @@ require('node:fs');
24
25
  require('semver');
25
26
  require('tailwindcss-patch');
26
27
  require('@tailwindcss-mangle/shared');
28
+ require('lru-cache');
29
+ require('md5');
27
30
  require('postcss-selector-parser');
31
+ require('debug');
28
32
 
33
+ const debug = index.createDebug('generateBundle: ');
29
34
  function UnifiedViteWeappTailwindcssPlugin(options$1 = {}) {
30
35
  if (options$1.customReplaceDictionary === undefined) {
31
36
  options$1.customReplaceDictionary = 'simple';
32
37
  }
33
38
  const opts = options.getOptions(options$1);
34
- 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;
35
40
  if (disabled) {
36
41
  return;
37
42
  }
@@ -42,49 +47,115 @@ function UnifiedViteWeappTailwindcssPlugin(options$1 = {}) {
42
47
  name: postcss.vitePluginName,
43
48
  enforce: 'post',
44
49
  generateBundle(opt, bundle) {
50
+ debug('start');
45
51
  onStart();
46
52
  const entries = Object.entries(bundle);
47
53
  const groupedEntries = defaults.getGroupedEntries(entries, opts);
48
54
  const runtimeSet = twPatcher.getClassSet();
49
55
  setMangleRuntimeSet(runtimeSet);
56
+ debug('get runtimeSet, class count: %d', runtimeSet.size);
50
57
  if (Array.isArray(groupedEntries.html)) {
58
+ let noCachedCount = 0;
51
59
  for (let i = 0; i < groupedEntries.html.length; i++) {
52
60
  const [file, originalSource] = groupedEntries.html[i];
53
61
  const oldVal = originalSource.source.toString();
54
- originalSource.source = templateHandler(oldVal, {
55
- 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
+ };
56
84
  });
57
- onUpdate(file, oldVal, originalSource.source);
58
- }
59
- }
60
- if (Array.isArray(groupedEntries.css)) {
61
- for (let i = 0; i < groupedEntries.css.length; i++) {
62
- const [file, originalSource] = groupedEntries.css[i];
63
- const rawSource = originalSource.source.toString();
64
- const css = styleHandler(rawSource, {
65
- isMainChunk: mainCssChunkMatcher(originalSource.fileName, appType)
66
- });
67
- originalSource.source = css;
68
- onUpdate(file, rawSource, css);
69
85
  }
86
+ debug('html handle finish, total: %d, no-cached: %d', groupedEntries.html.length, noCachedCount);
70
87
  }
71
88
  if (Array.isArray(groupedEntries.js)) {
89
+ let noCachedCount = 0;
72
90
  for (let i = 0; i < groupedEntries.js.length; i++) {
73
91
  const [file, originalSource] = groupedEntries.js[i];
74
92
  const rawSource = originalSource.code;
75
- const mapFilename = file + '.map';
76
- const hasMap = Boolean(bundle[mapFilename]);
77
- const { code, map } = jsHandler(rawSource, runtimeSet, {
78
- 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
+ };
79
153
  });
80
- originalSource.code = code;
81
- onUpdate(file, rawSource, code);
82
- if (hasMap && map) {
83
- bundle[mapFilename].source = map.toString();
84
- }
85
154
  }
155
+ debug('css handle finish, total: %d, no-cached: %d', groupedEntries.css.length, noCachedCount);
86
156
  }
87
157
  onEnd();
158
+ debug('end');
88
159
  }
89
160
  };
90
161
  }
package/dist/vite.mjs CHANGED
@@ -1,6 +1,7 @@
1
- import { g as getOptions, a as createTailwindcssPatcher } from './options-c9c14817.mjs';
1
+ import { g as getOptions, a as createTailwindcssPatcher } from './options-f70d1c6f.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';
@@ -20,14 +21,18 @@ import 'node:fs';
20
21
  import 'semver';
21
22
  import 'tailwindcss-patch';
22
23
  import '@tailwindcss-mangle/shared';
24
+ import 'lru-cache';
25
+ import 'md5';
23
26
  import 'postcss-selector-parser';
27
+ import 'debug';
24
28
 
29
+ const debug = createDebug('generateBundle: ');
25
30
  function UnifiedViteWeappTailwindcssPlugin(options = {}) {
26
31
  if (options.customReplaceDictionary === undefined) {
27
32
  options.customReplaceDictionary = 'simple';
28
33
  }
29
34
  const opts = getOptions(options);
30
- 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;
31
36
  if (disabled) {
32
37
  return;
33
38
  }
@@ -38,49 +43,115 @@ function UnifiedViteWeappTailwindcssPlugin(options = {}) {
38
43
  name: vitePluginName,
39
44
  enforce: 'post',
40
45
  generateBundle(opt, bundle) {
46
+ debug('start');
41
47
  onStart();
42
48
  const entries = Object.entries(bundle);
43
49
  const groupedEntries = getGroupedEntries(entries, opts);
44
50
  const runtimeSet = twPatcher.getClassSet();
45
51
  setMangleRuntimeSet(runtimeSet);
52
+ debug('get runtimeSet, class count: %d', runtimeSet.size);
46
53
  if (Array.isArray(groupedEntries.html)) {
54
+ let noCachedCount = 0;
47
55
  for (let i = 0; i < groupedEntries.html.length; i++) {
48
56
  const [file, originalSource] = groupedEntries.html[i];
49
57
  const oldVal = originalSource.source.toString();
50
- originalSource.source = templateHandler(oldVal, {
51
- 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
+ };
52
80
  });
53
- onUpdate(file, oldVal, originalSource.source);
54
- }
55
- }
56
- if (Array.isArray(groupedEntries.css)) {
57
- for (let i = 0; i < groupedEntries.css.length; i++) {
58
- const [file, originalSource] = groupedEntries.css[i];
59
- const rawSource = originalSource.source.toString();
60
- const css = styleHandler(rawSource, {
61
- isMainChunk: mainCssChunkMatcher(originalSource.fileName, appType)
62
- });
63
- originalSource.source = css;
64
- onUpdate(file, rawSource, css);
65
81
  }
82
+ debug('html handle finish, total: %d, no-cached: %d', groupedEntries.html.length, noCachedCount);
66
83
  }
67
84
  if (Array.isArray(groupedEntries.js)) {
85
+ let noCachedCount = 0;
68
86
  for (let i = 0; i < groupedEntries.js.length; i++) {
69
87
  const [file, originalSource] = groupedEntries.js[i];
70
88
  const rawSource = originalSource.code;
71
- const mapFilename = file + '.map';
72
- const hasMap = Boolean(bundle[mapFilename]);
73
- const { code, map } = jsHandler(rawSource, runtimeSet, {
74
- 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
+ };
75
149
  });
76
- originalSource.code = code;
77
- onUpdate(file, rawSource, code);
78
- if (hasMap && map) {
79
- bundle[mapFilename].source = map.toString();
80
- }
81
150
  }
151
+ debug('css handle finish, total: %d, no-cached: %d', groupedEntries.css.length, noCachedCount);
82
152
  }
83
153
  onEnd();
154
+ debug('end');
84
155
  }
85
156
  };
86
157
  }
package/dist/webpack.js CHANGED
@@ -4,9 +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-904051d2.js');
7
+ var options = require('./options-b96f6338.js');
8
8
  var postcss = require('./postcss-8d7f67b4.js');
9
- var defaults = require('./defaults-263271f9.js');
9
+ var defaults = require('./defaults-b7341550.js');
10
+ var index = require('./index-aede98ce.js');
10
11
  require('micromatch');
11
12
  require('magic-string');
12
13
  require('./replace.js');
@@ -24,13 +25,17 @@ require('@csstools/postcss-is-pseudo-class');
24
25
  require('semver');
25
26
  require('tailwindcss-patch');
26
27
  require('@tailwindcss-mangle/shared');
28
+ require('lru-cache');
29
+ require('md5');
27
30
  require('postcss-selector-parser');
31
+ require('debug');
28
32
 
29
33
  function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
30
34
 
31
35
  var path__default = /*#__PURE__*/_interopDefaultCompat(path);
32
36
  var fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
33
37
 
38
+ const debug = index.createDebug('');
34
39
  class UnifiedWebpackPluginV5 {
35
40
  constructor(options$1 = {}) {
36
41
  if (options$1.customReplaceDictionary === undefined) {
@@ -40,7 +45,7 @@ class UnifiedWebpackPluginV5 {
40
45
  this.appType = this.options.appType;
41
46
  }
42
47
  apply(compiler) {
43
- const { mainCssChunkMatcher, disabled, onLoad, onUpdate, onEnd, onStart, styleHandler, patch, templateHandler, jsHandler, setMangleRuntimeSet, runtimeLoaderPath } = this.options;
48
+ const { mainCssChunkMatcher, disabled, onLoad, onUpdate, onEnd, onStart, styleHandler, patch, templateHandler, jsHandler, setMangleRuntimeSet, runtimeLoaderPath, cache } = this.options;
44
49
  if (disabled) {
45
50
  return;
46
51
  }
@@ -76,52 +81,124 @@ class UnifiedWebpackPluginV5 {
76
81
  stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
77
82
  }, (assets) => {
78
83
  onStart();
84
+ debug('start');
85
+ for (const chunk of compilation.chunks) {
86
+ if (chunk.id && chunk.hash) {
87
+ cache.calcHashValueChanged(chunk.id, chunk.hash);
88
+ }
89
+ }
79
90
  const entries = Object.entries(assets);
80
91
  const groupedEntries = defaults.getGroupedEntries(entries, this.options);
81
92
  const runtimeSet = getClassSet();
82
93
  setMangleRuntimeSet(runtimeSet);
94
+ debug('get runtimeSet, class count: %d', runtimeSet.size);
83
95
  if (Array.isArray(groupedEntries.html)) {
96
+ let noCachedCount = 0;
84
97
  for (let i = 0; i < groupedEntries.html.length; i++) {
85
98
  const [file, originalSource] = groupedEntries.html[i];
86
99
  const rawSource = originalSource.source().toString();
87
- const wxml = templateHandler(rawSource, {
88
- 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
+ };
89
125
  });
90
- const source = new ConcatSource(wxml);
91
- compilation.updateAsset(file, source);
92
- onUpdate(file, rawSource, wxml);
93
126
  }
127
+ debug('html handle finish, total: %d, no-cached: %d', groupedEntries.html.length, noCachedCount);
94
128
  }
95
129
  if (Array.isArray(groupedEntries.js)) {
130
+ let noCachedCount = 0;
96
131
  for (let i = 0; i < groupedEntries.js.length; i++) {
97
132
  const [file, originalSource] = groupedEntries.js[i];
98
- const rawSource = originalSource.source().toString();
99
- const mapFilename = file + '.map';
100
- const hasMap = Boolean(assets[mapFilename]);
101
- const { code, map } = jsHandler(rawSource, runtimeSet, {
102
- generateMap: hasMap
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
+ }, () => {
144
+ const rawSource = originalSource.source().toString();
145
+ const mapFilename = file + '.map';
146
+ const hasMap = Boolean(assets[mapFilename]);
147
+ const { code, map } = jsHandler(rawSource, runtimeSet, {
148
+ generateMap: hasMap
149
+ });
150
+ const source = new ConcatSource(code);
151
+ compilation.updateAsset(file, source);
152
+ onUpdate(file, rawSource, code);
153
+ debug('js handle: %s', file);
154
+ noCachedCount++;
155
+ if (hasMap && map) {
156
+ const source = new RawSource(map.toString());
157
+ compilation.updateAsset(mapFilename, source);
158
+ }
159
+ return {
160
+ key: cacheKey,
161
+ source
162
+ };
103
163
  });
104
- const source = new ConcatSource(code);
105
- compilation.updateAsset(file, source);
106
- onUpdate(file, rawSource, code);
107
- if (hasMap && map) {
108
- const source = new RawSource(map.toString());
109
- compilation.updateAsset(mapFilename, source);
110
- }
111
164
  }
165
+ debug('js handle finish, total: %d, no-cached: %d', groupedEntries.js.length, noCachedCount);
112
166
  }
113
167
  if (Array.isArray(groupedEntries.css)) {
168
+ let noCachedCount = 0;
114
169
  for (let i = 0; i < groupedEntries.css.length; i++) {
115
170
  const [file, originalSource] = groupedEntries.css[i];
116
171
  const rawSource = originalSource.source().toString();
117
- const css = styleHandler(rawSource, {
118
- 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
+ };
119
197
  });
120
- const source = new ConcatSource(css);
121
- compilation.updateAsset(file, source);
122
- onUpdate(file, rawSource, css);
123
198
  }
199
+ debug('css handle finish, total: %d, no-cached: %d', groupedEntries.css.length, noCachedCount);
124
200
  }
201
+ debug('end');
125
202
  onEnd();
126
203
  });
127
204
  });
package/dist/webpack.mjs CHANGED
@@ -1,8 +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-c9c14817.mjs';
3
+ import { g as getOptions, a as createTailwindcssPatcher } from './options-f70d1c6f.mjs';
4
4
  import { a as pluginName } from './postcss-55ed4d42.mjs';
5
- import { g as getGroupedEntries } from './defaults-dc8a0e3d.mjs';
5
+ import { g as getGroupedEntries, r as removeExt } from './defaults-d2c66d23.mjs';
6
+ import { c as createDebug } from './index-84c7aa87.mjs';
6
7
  import 'micromatch';
7
8
  import 'magic-string';
8
9
  import './replace.mjs';
@@ -20,8 +21,12 @@ import '@csstools/postcss-is-pseudo-class';
20
21
  import 'semver';
21
22
  import 'tailwindcss-patch';
22
23
  import '@tailwindcss-mangle/shared';
24
+ import 'lru-cache';
25
+ import 'md5';
23
26
  import 'postcss-selector-parser';
27
+ import 'debug';
24
28
 
29
+ const debug = createDebug('');
25
30
  class UnifiedWebpackPluginV5 {
26
31
  constructor(options = {}) {
27
32
  if (options.customReplaceDictionary === undefined) {
@@ -31,7 +36,7 @@ class UnifiedWebpackPluginV5 {
31
36
  this.appType = this.options.appType;
32
37
  }
33
38
  apply(compiler) {
34
- const { mainCssChunkMatcher, disabled, onLoad, onUpdate, onEnd, onStart, styleHandler, patch, templateHandler, jsHandler, setMangleRuntimeSet, runtimeLoaderPath } = this.options;
39
+ const { mainCssChunkMatcher, disabled, onLoad, onUpdate, onEnd, onStart, styleHandler, patch, templateHandler, jsHandler, setMangleRuntimeSet, runtimeLoaderPath, cache } = this.options;
35
40
  if (disabled) {
36
41
  return;
37
42
  }
@@ -67,52 +72,124 @@ class UnifiedWebpackPluginV5 {
67
72
  stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
68
73
  }, (assets) => {
69
74
  onStart();
75
+ debug('start');
76
+ for (const chunk of compilation.chunks) {
77
+ if (chunk.id && chunk.hash) {
78
+ cache.calcHashValueChanged(chunk.id, chunk.hash);
79
+ }
80
+ }
70
81
  const entries = Object.entries(assets);
71
82
  const groupedEntries = getGroupedEntries(entries, this.options);
72
83
  const runtimeSet = getClassSet();
73
84
  setMangleRuntimeSet(runtimeSet);
85
+ debug('get runtimeSet, class count: %d', runtimeSet.size);
74
86
  if (Array.isArray(groupedEntries.html)) {
87
+ let noCachedCount = 0;
75
88
  for (let i = 0; i < groupedEntries.html.length; i++) {
76
89
  const [file, originalSource] = groupedEntries.html[i];
77
90
  const rawSource = originalSource.source().toString();
78
- const wxml = templateHandler(rawSource, {
79
- 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
+ };
80
116
  });
81
- const source = new ConcatSource(wxml);
82
- compilation.updateAsset(file, source);
83
- onUpdate(file, rawSource, wxml);
84
117
  }
118
+ debug('html handle finish, total: %d, no-cached: %d', groupedEntries.html.length, noCachedCount);
85
119
  }
86
120
  if (Array.isArray(groupedEntries.js)) {
121
+ let noCachedCount = 0;
87
122
  for (let i = 0; i < groupedEntries.js.length; i++) {
88
123
  const [file, originalSource] = groupedEntries.js[i];
89
- const rawSource = originalSource.source().toString();
90
- const mapFilename = file + '.map';
91
- const hasMap = Boolean(assets[mapFilename]);
92
- const { code, map } = jsHandler(rawSource, runtimeSet, {
93
- generateMap: hasMap
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
+ }, () => {
135
+ const rawSource = originalSource.source().toString();
136
+ const mapFilename = file + '.map';
137
+ const hasMap = Boolean(assets[mapFilename]);
138
+ const { code, map } = jsHandler(rawSource, runtimeSet, {
139
+ generateMap: hasMap
140
+ });
141
+ const source = new ConcatSource(code);
142
+ compilation.updateAsset(file, source);
143
+ onUpdate(file, rawSource, code);
144
+ debug('js handle: %s', file);
145
+ noCachedCount++;
146
+ if (hasMap && map) {
147
+ const source = new RawSource(map.toString());
148
+ compilation.updateAsset(mapFilename, source);
149
+ }
150
+ return {
151
+ key: cacheKey,
152
+ source
153
+ };
94
154
  });
95
- const source = new ConcatSource(code);
96
- compilation.updateAsset(file, source);
97
- onUpdate(file, rawSource, code);
98
- if (hasMap && map) {
99
- const source = new RawSource(map.toString());
100
- compilation.updateAsset(mapFilename, source);
101
- }
102
155
  }
156
+ debug('js handle finish, total: %d, no-cached: %d', groupedEntries.js.length, noCachedCount);
103
157
  }
104
158
  if (Array.isArray(groupedEntries.css)) {
159
+ let noCachedCount = 0;
105
160
  for (let i = 0; i < groupedEntries.css.length; i++) {
106
161
  const [file, originalSource] = groupedEntries.css[i];
107
162
  const rawSource = originalSource.source().toString();
108
- const css = styleHandler(rawSource, {
109
- 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
+ };
110
188
  });
111
- const source = new ConcatSource(css);
112
- compilation.updateAsset(file, source);
113
- onUpdate(file, rawSource, css);
114
189
  }
190
+ debug('css handle finish, total: %d, no-cached: %d', groupedEntries.css.length, noCachedCount);
115
191
  }
192
+ debug('end');
116
193
  onEnd();
117
194
  });
118
195
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "weapp-tailwindcss",
3
- "version": "2.8.4",
3
+ "version": "2.9.1",
4
4
  "description": "把tailwindcss jit引擎,带给小程序开发者们! bring tailwindcss jit engine to miniprogram developers!",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -102,7 +102,7 @@
102
102
  },
103
103
  "homepage": "https://weapp-tw.icebreaker.top",
104
104
  "devDependencies": {
105
- "@babel/core": "^7.22.17",
105
+ "@babel/core": "^7.22.20",
106
106
  "@icebreakers/cli": "0.1.1",
107
107
  "@icebreakers/readme": "0.1.0",
108
108
  "@rollup/plugin-alias": "^5.0.0",
@@ -111,21 +111,23 @@
111
111
  "@rollup/plugin-node-resolve": "^15.2.1",
112
112
  "@rollup/plugin-terser": "^0.4.3",
113
113
  "@rollup/plugin-typescript": "^11.1.3",
114
- "@tsconfig/recommended": "^1.0.2",
115
- "@types/babel__generator": "^7.6.4",
116
- "@types/babel__traverse": "^7.20.1",
117
- "@types/diff": "^5.0.3",
118
- "@types/fs-extra": "^11.0.1",
114
+ "@tsconfig/recommended": "^1.0.3",
115
+ "@types/babel__generator": "^7.6.5",
116
+ "@types/babel__traverse": "^7.20.2",
117
+ "@types/debug": "^4.1.8",
118
+ "@types/diff": "^5.0.4",
119
+ "@types/fs-extra": "^11.0.2",
119
120
  "@types/gulp": "^4.0.13",
120
121
  "@types/gulp-postcss": "^8.0.3",
121
- "@types/jest": "^29.5.4",
122
- "@types/js-beautify": "^1.14.0",
123
- "@types/klaw": "^3.0.3",
122
+ "@types/jest": "^29.5.5",
123
+ "@types/js-beautify": "^1.14.1",
124
+ "@types/klaw": "^3.0.4",
124
125
  "@types/loader-utils": "^2.0.4",
125
126
  "@types/lodash": "^4.14.198",
127
+ "@types/md5": "^2.3.2",
126
128
  "@types/micromatch": "^4.0.2",
127
- "@types/node": "^20.6.0",
128
- "@types/semver": "^7.5.1",
129
+ "@types/node": "^20.6.2",
130
+ "@types/semver": "^7.5.2",
129
131
  "@types/vinyl": "^2.0.7",
130
132
  "@types/webpack": "^5.28.2",
131
133
  "@types/webpack-sources": "^3.2.0",
@@ -163,7 +165,7 @@
163
165
  "postcss-rem-to-responsive-pixel": "^5.1.3",
164
166
  "prettier": "^3.0.3",
165
167
  "promisify-loader-runner": "^1.0.0",
166
- "rollup": "^3.29.1",
168
+ "rollup": "^3.29.2",
167
169
  "rollup-plugin-visualizer": "^5.9.2",
168
170
  "style-loader": "^3.3.3",
169
171
  "tailwind-children": "^0.5.0",
@@ -186,22 +188,25 @@
186
188
  "@ast-core/escape": "^1.0.1",
187
189
  "@babel/generator": "^7.22.15",
188
190
  "@babel/parser": "^7.22.16",
189
- "@babel/traverse": "^7.22.17",
190
- "@babel/types": "^7.22.17",
191
+ "@babel/traverse": "^7.22.20",
192
+ "@babel/types": "^7.22.19",
191
193
  "@csstools/postcss-is-pseudo-class": "^4.0.1",
192
- "@tailwindcss-mangle/shared": "^2.1.0",
194
+ "@tailwindcss-mangle/shared": "^2.2.1",
193
195
  "@weapp-core/escape": "^2.0.0",
194
196
  "@weapp-core/regex": "^1.0.1",
197
+ "debug": "^4.3.4",
195
198
  "htmlparser2": "^9.0.0",
196
199
  "loader-utils": "^2.0.3",
200
+ "lru-cache": "^10.0.1",
197
201
  "magic-string": "^0.30.3",
202
+ "md5": "^2.3.0",
198
203
  "micromatch": "^4.0.5",
199
204
  "postcss": "8.4.29",
200
205
  "postcss-selector-parser": "^6.0.13",
201
206
  "semver": "^7.5.4",
202
- "tailwindcss-patch": "^2.1.1"
207
+ "tailwindcss-patch": "^2.2.1"
203
208
  },
204
- "packageManager": "pnpm@8.6.12",
209
+ "packageManager": "pnpm@8.7.4",
205
210
  "engines": {
206
211
  "node": ">=16.6.0"
207
212
  },
@@ -211,7 +216,7 @@
211
216
  "build:demo": "yarn demo:del-dist && cross-env NODE_ENV=demo rollup -c rollup.config.ts --configPlugin typescript && yarn demo:sync-dist",
212
217
  "build:tsc": "cross-env NODE_ENV=development tsc --build tsconfig.json",
213
218
  "dts": "tsc --emitDeclarationOnly -p tsconfig.dts.json",
214
- "test": "jest && vitest run",
219
+ "test": "cross-env DEBUG=weapp-tw jest && vitest run",
215
220
  "jest-u": "jest -u",
216
221
  "jest:u": "jest -u",
217
222
  "test:dev": "vitest",