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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (124) hide show
  1. package/dist/babel/index.d.ts +16 -0
  2. package/dist/bundlers/gulp/index.d.ts +8 -0
  3. package/dist/bundlers/vite/index.d.ts +3 -0
  4. package/dist/bundlers/webpack/BaseUnifiedPlugin/v4.d.ts +8 -0
  5. package/dist/bundlers/webpack/BaseUnifiedPlugin/v5.d.ts +8 -0
  6. package/dist/bundlers/webpack/index.d.ts +1 -0
  7. package/dist/{weapp-tw-runtime-loader.d.ts → bundlers/webpack/loaders/weapp-tw-runtime-loader.d.ts} +2 -4
  8. package/dist/cache/index.d.ts +32 -0
  9. package/dist/cli.d.ts +1 -2
  10. package/dist/cli.js +51 -1760
  11. package/dist/cli.mjs +45 -34
  12. package/dist/constants-CFM1J-h1.js +42 -0
  13. package/dist/constants-Dy2Dd3Fz.mjs +36 -0
  14. package/dist/constants.d.ts +7 -0
  15. package/dist/core.d.ts +2 -16
  16. package/dist/core.js +60 -1775
  17. package/dist/core.mjs +60 -46
  18. package/dist/css-macro/constants.d.ts +14 -0
  19. package/dist/css-macro/index.d.ts +4 -7
  20. package/dist/css-macro/index.js +30 -140
  21. package/dist/css-macro/index.mjs +28 -35
  22. package/dist/css-macro/postcss.d.ts +3 -5
  23. package/dist/css-macro/postcss.js +46 -99
  24. package/dist/css-macro/postcss.mjs +45 -54
  25. package/dist/debug/index.d.ts +2 -0
  26. package/dist/defaults-DW-EahCC.js +145 -0
  27. package/dist/defaults-w3rlKQwe.mjs +139 -0
  28. package/dist/defaults.d.ts +2 -16
  29. package/dist/defaults.js +7 -208
  30. package/dist/defaults.mjs +4 -9
  31. package/dist/defu-Cdz2PomB.js +60 -0
  32. package/dist/defu-n46TJT6t.mjs +57 -0
  33. package/dist/env.d.ts +2 -0
  34. package/dist/escape.d.ts +4 -0
  35. package/dist/extractors/split.d.ts +3 -0
  36. package/dist/gulp.d.ts +1 -26
  37. package/dist/gulp.js +38 -1898
  38. package/dist/gulp.mjs +30 -15
  39. package/dist/index-B2TNoaOv.mjs +134 -0
  40. package/dist/index-B5NiRecR.js +130 -0
  41. package/dist/index-BEIjgKpF.mjs +11 -0
  42. package/dist/index-BPzIdybK.mjs +513 -0
  43. package/dist/index-DeW_zXzo.mjs +124 -0
  44. package/dist/index-DmzxhHCX.js +136 -0
  45. package/dist/index-DwZHOkK3.js +526 -0
  46. package/dist/index-HC-Qkn0i.js +17 -0
  47. package/dist/index.d.ts +4 -17
  48. package/dist/index.js +43 -2291
  49. package/dist/index.mjs +33 -23
  50. package/dist/js/handlers.d.ts +13 -0
  51. package/dist/js/index.d.ts +7 -0
  52. package/dist/mangle/index.d.ts +8 -0
  53. package/dist/options-7EjuAISl.mjs +869 -0
  54. package/dist/options-C-rvBixk.js +901 -0
  55. package/dist/options.d.ts +2 -0
  56. package/dist/postcss/cssVars.d.ts +5 -0
  57. package/dist/postcss/index.d.ts +3 -0
  58. package/dist/postcss/mp.d.ts +8 -0
  59. package/dist/postcss/plugins/ctx.d.ts +6 -0
  60. package/dist/postcss/plugins/index.d.ts +7 -0
  61. package/dist/postcss/plugins/post.d.ts +5 -0
  62. package/dist/postcss/plugins/pre.d.ts +5 -0
  63. package/dist/postcss/preflight.d.ts +3 -0
  64. package/dist/postcss/selectorParser.d.ts +6 -0
  65. package/dist/postcss/shared.d.ts +3 -0
  66. package/dist/postcss/symbols.d.ts +1 -0
  67. package/dist/postcss.d.ts +1 -23
  68. package/dist/postcss.js +22 -598
  69. package/dist/postcss.mjs +8 -17
  70. package/dist/reg.d.ts +1 -0
  71. package/dist/replace.d.ts +3 -19
  72. package/dist/replace.js +42 -93
  73. package/dist/replace.mjs +26 -30
  74. package/dist/shared-DbJl6i6a.mjs +25 -0
  75. package/dist/shared-hzYeE1wX.js +28 -0
  76. package/dist/tailwindcss/patcher.d.ts +3 -0
  77. package/dist/types.d.ts +165 -0
  78. package/dist/utils.d.ts +18 -0
  79. package/dist/v5-BD9-sqra.mjs +174 -0
  80. package/dist/v5-Ch6783yy.js +181 -0
  81. package/dist/vite.d.ts +1 -22
  82. package/dist/vite.js +36 -1947
  83. package/dist/vite.mjs +28 -15
  84. package/dist/weapp-tw-runtime-loader.js +14 -41
  85. package/dist/weapp-tw-runtime-loader.mjs +8 -12
  86. package/dist/webpack.d.ts +1 -26
  87. package/dist/webpack.js +37 -1994
  88. package/dist/webpack.mjs +29 -15
  89. package/dist/webpack4.d.ts +1 -27
  90. package/dist/webpack4.js +190 -1979
  91. package/dist/webpack4.mjs +188 -211
  92. package/dist/wxml/Tokenizer.d.ts +31 -0
  93. package/dist/wxml/index.d.ts +2 -0
  94. package/dist/wxml/shared.d.ts +2 -0
  95. package/dist/wxml/utils.d.ts +13 -0
  96. package/package.json +3 -3
  97. package/dist/chunk-257YPDSI.mjs +0 -173
  98. package/dist/chunk-75EWCRQW.mjs +0 -13
  99. package/dist/chunk-AB467PG7.mjs +0 -43
  100. package/dist/chunk-E7XGHGC7.mjs +0 -62
  101. package/dist/chunk-GUE4UCRJ.mjs +0 -126
  102. package/dist/chunk-IOYI6MSW.mjs +0 -533
  103. package/dist/chunk-LDWI65M5.mjs +0 -152
  104. package/dist/chunk-NVFWRLOI.mjs +0 -27
  105. package/dist/chunk-ORMKM6ZA.mjs +0 -30
  106. package/dist/chunk-PC4B5JJB.mjs +0 -953
  107. package/dist/chunk-SRLZU2YE.mjs +0 -95
  108. package/dist/chunk-VECXHWWG.mjs +0 -31
  109. package/dist/chunk-VN37QGSM.mjs +0 -216
  110. package/dist/cli.d.mts +0 -2
  111. package/dist/core.d.mts +0 -22
  112. package/dist/css-macro/index.d.mts +0 -18
  113. package/dist/css-macro/postcss.d.mts +0 -7
  114. package/dist/defaults.d.mts +0 -16
  115. package/dist/gulp.d.mts +0 -26
  116. package/dist/index.d.mts +0 -17
  117. package/dist/postcss.d.mts +0 -23
  118. package/dist/replace.d.mts +0 -19
  119. package/dist/types-DSNuiOhH.d.mts +0 -519
  120. package/dist/types-DSNuiOhH.d.ts +0 -519
  121. package/dist/vite.d.mts +0 -22
  122. package/dist/weapp-tw-runtime-loader.d.mts +0 -7
  123. package/dist/webpack.d.mts +0 -26
  124. package/dist/webpack4.d.mts +0 -27
package/dist/webpack4.mjs CHANGED
@@ -1,216 +1,193 @@
1
- import {
2
- createDebug
3
- } from "./chunk-75EWCRQW.mjs";
4
- import {
5
- getOptions
6
- } from "./chunk-PC4B5JJB.mjs";
7
- import "./chunk-SRLZU2YE.mjs";
8
- import {
9
- getGroupedEntries,
10
- removeExt
11
- } from "./chunk-GUE4UCRJ.mjs";
12
- import {
13
- pluginName
14
- } from "./chunk-IOYI6MSW.mjs";
15
- import "./chunk-NVFWRLOI.mjs";
16
- import "./chunk-ORMKM6ZA.mjs";
17
- import "./chunk-VECXHWWG.mjs";
18
- import {
19
- __async
20
- } from "./chunk-E7XGHGC7.mjs";
1
+ import { g as getOptions, _ as __awaiter } from './options-7EjuAISl.mjs';
2
+ import path from 'node:path';
3
+ import fs from 'node:fs';
4
+ import { ConcatSource, RawSource } from 'webpack-sources';
5
+ import { b as pluginName } from './index-BPzIdybK.mjs';
6
+ import { g as getGroupedEntries, r as removeExt } from './defaults-w3rlKQwe.mjs';
7
+ import { c as createDebug } from './index-BEIjgKpF.mjs';
8
+ import 'magic-string';
9
+ import './replace.mjs';
10
+ import '@weapp-core/escape';
11
+ import '@ast-core/escape';
12
+ import './shared-DbJl6i6a.mjs';
13
+ import '@weapp-core/regex';
14
+ import '@babel/generator';
15
+ import '@babel/traverse';
16
+ import '@babel/parser';
17
+ import '@babel/types';
18
+ import 'htmlparser2';
19
+ import 'postcss';
20
+ import 'node:process';
21
+ import 'tailwindcss-patch';
22
+ import '@tailwindcss-mangle/shared';
23
+ import 'lru-cache';
24
+ import 'md5';
25
+ import '@csstools/postcss-is-pseudo-class';
26
+ import 'postcss-rem-to-responsive-pixel';
27
+ import 'postcss-selector-parser';
28
+ import './defu-n46TJT6t.mjs';
29
+ import 'debug';
21
30
 
22
- // src/bundlers/webpack/BaseUnifiedPlugin/v4.ts
23
- import path from "path";
24
- import fs from "fs";
25
- import { ConcatSource, RawSource } from "webpack-sources";
26
- var debug = createDebug();
27
- var UnifiedWebpackPluginV4 = class {
28
- constructor(options = {}) {
29
- this.options = getOptions(options);
30
- this.appType = this.options.appType;
31
- }
32
- apply(compiler) {
33
- const {
34
- mainCssChunkMatcher,
35
- disabled,
36
- onLoad,
37
- onUpdate,
38
- onEnd,
39
- onStart,
40
- styleHandler,
41
- patch,
42
- templateHandler,
43
- jsHandler,
44
- setMangleRuntimeSet,
45
- runtimeLoaderPath,
46
- cache,
47
- twPatcher
48
- } = this.options;
49
- if (disabled) {
50
- return;
31
+ const debug = createDebug();
32
+ class UnifiedWebpackPluginV4 {
33
+ constructor(options = {}) {
34
+ this.options = getOptions(options);
35
+ this.appType = this.options.appType;
51
36
  }
52
- patch == null ? void 0 : patch();
53
- function getClassSet() {
54
- return twPatcher.getClassSet();
55
- }
56
- onLoad();
57
- const loader = runtimeLoaderPath != null ? runtimeLoaderPath : path.resolve(__dirname, "./weapp-tw-runtime-loader.js");
58
- const isExisted = fs.existsSync(loader);
59
- const WeappTwRuntimeAopLoader = {
60
- loader,
61
- options: {
62
- getClassSet
63
- },
64
- ident: null,
65
- type: null
66
- };
67
- compiler.hooks.compilation.tap(pluginName, (compilation) => {
68
- compilation.hooks.normalModuleLoader.tap(pluginName, (_loaderContext, module) => {
69
- if (isExisted) {
70
- const idx = module.loaders.findIndex((x) => x.loader.includes("postcss-loader"));
71
- if (idx > -1) {
72
- module.loaders.unshift(WeappTwRuntimeAopLoader);
73
- }
74
- }
75
- });
76
- });
77
- compiler.hooks.emit.tapPromise(pluginName, (compilation) => __async(this, null, function* () {
78
- onStart();
79
- debug("start");
80
- for (const chunk of compilation.chunks) {
81
- if (chunk.id && chunk.hash) {
82
- cache.calcHashValueChanged(chunk.id, chunk.hash);
83
- }
84
- }
85
- const assets = compilation.assets;
86
- const entries = Object.entries(assets);
87
- const groupedEntries = getGroupedEntries(entries, this.options);
88
- const runtimeSet = getClassSet();
89
- setMangleRuntimeSet(runtimeSet);
90
- debug("get runtimeSet, class count: %d", runtimeSet.size);
91
- if (Array.isArray(groupedEntries.html)) {
92
- let noCachedCount = 0;
93
- for (let i = 0; i < groupedEntries.html.length; i++) {
94
- const [file, originalSource] = groupedEntries.html[i];
95
- const rawSource = originalSource.source().toString();
96
- const hash = cache.computeHash(rawSource);
97
- const cacheKey = file;
98
- cache.calcHashValueChanged(cacheKey, hash);
99
- yield cache.process(
100
- cacheKey,
101
- () => {
102
- const source = cache.get(cacheKey);
103
- if (source) {
104
- compilation.updateAsset(file, source);
105
- debug("html cache hit: %s", file);
106
- } else {
107
- return false;
108
- }
109
- },
110
- // @ts-ignore
111
- () => __async(this, null, function* () {
112
- const wxml = yield templateHandler(rawSource, {
113
- runtimeSet
114
- });
115
- const source = new ConcatSource(wxml);
116
- compilation.updateAsset(file, source);
117
- onUpdate(file, rawSource, wxml);
118
- debug("html handle: %s", file);
119
- noCachedCount++;
120
- return {
121
- key: cacheKey,
122
- source
123
- };
124
- })
125
- );
37
+ apply(compiler) {
38
+ const { mainCssChunkMatcher, disabled, onLoad, onUpdate, onEnd, onStart, styleHandler, patch, templateHandler, jsHandler, setMangleRuntimeSet, runtimeLoaderPath, cache, twPatcher, } = this.options;
39
+ if (disabled) {
40
+ return;
126
41
  }
127
- debug("html handle finish, total: %d, no-cached: %d", groupedEntries.html.length, noCachedCount);
128
- }
129
- if (Array.isArray(groupedEntries.js)) {
130
- let noCachedCount = 0;
131
- for (let i = 0; i < groupedEntries.js.length; i++) {
132
- const [file, originalSource] = groupedEntries.js[i];
133
- const cacheKey = removeExt(file);
134
- yield cache.process(
135
- cacheKey,
136
- () => {
137
- const source = cache.get(cacheKey);
138
- if (source) {
139
- compilation.updateAsset(file, source);
140
- debug("js cache hit: %s", file);
141
- } else {
142
- return false;
143
- }
144
- },
145
- // @ts-ignore
146
- () => __async(this, null, function* () {
147
- const rawSource = originalSource.source().toString();
148
- const mapFilename = `${file}.map`;
149
- const hasMap = Boolean(assets[mapFilename]);
150
- const { code, map } = yield jsHandler(rawSource, runtimeSet, {
151
- generateMap: hasMap
152
- });
153
- const source = new ConcatSource(code);
154
- compilation.updateAsset(file, source);
155
- onUpdate(file, rawSource, code);
156
- debug("js handle: %s", file);
157
- noCachedCount++;
158
- if (hasMap && map) {
159
- const source2 = new RawSource(map.toString());
160
- compilation.updateAsset(mapFilename, source2);
161
- }
162
- return {
163
- key: cacheKey,
164
- source
165
- };
166
- })
167
- );
42
+ patch === null || patch === void 0 ? void 0 : patch();
43
+ function getClassSet() {
44
+ return twPatcher.getClassSet();
168
45
  }
169
- debug("js handle finish, total: %d, no-cached: %d", groupedEntries.js.length, noCachedCount);
170
- }
171
- if (Array.isArray(groupedEntries.css)) {
172
- let noCachedCount = 0;
173
- for (let i = 0; i < groupedEntries.css.length; i++) {
174
- const [file, originalSource] = groupedEntries.css[i];
175
- const rawSource = originalSource.source().toString();
176
- const hash = cache.computeHash(rawSource);
177
- const cacheKey = file;
178
- cache.calcHashValueChanged(cacheKey, hash);
179
- yield cache.process(
180
- cacheKey,
181
- () => {
182
- const source = cache.get(cacheKey);
183
- if (source) {
184
- compilation.updateAsset(file, source);
185
- debug("css cache hit: %s", file);
186
- } else {
187
- return false;
188
- }
46
+ onLoad();
47
+ const loader = runtimeLoaderPath !== null && runtimeLoaderPath !== void 0 ? runtimeLoaderPath : path.resolve(__dirname, './weapp-tw-runtime-loader.js');
48
+ const isExisted = fs.existsSync(loader);
49
+ const WeappTwRuntimeAopLoader = {
50
+ loader,
51
+ options: {
52
+ getClassSet,
189
53
  },
190
- // @ts-ignore
191
- () => __async(this, null, function* () {
192
- const css = yield styleHandler(rawSource, {
193
- isMainChunk: mainCssChunkMatcher(file, this.appType)
194
- });
195
- const source = new ConcatSource(css);
196
- compilation.updateAsset(file, source);
197
- onUpdate(file, rawSource, css);
198
- debug("css handle: %s", file);
199
- noCachedCount++;
200
- return {
201
- key: cacheKey,
202
- source
203
- };
204
- })
205
- );
206
- }
207
- debug("css handle finish, total: %d, no-cached: %d", groupedEntries.css.length, noCachedCount);
208
- }
209
- debug("end");
210
- onEnd();
211
- }));
212
- }
213
- };
214
- export {
215
- UnifiedWebpackPluginV4
216
- };
54
+ ident: null,
55
+ type: null,
56
+ };
57
+ compiler.hooks.compilation.tap(pluginName, (compilation) => {
58
+ compilation.hooks.normalModuleLoader.tap(pluginName, (_loaderContext, module) => {
59
+ if (isExisted) {
60
+ const idx = module.loaders.findIndex(x => x.loader.includes('postcss-loader'));
61
+ if (idx > -1) {
62
+ module.loaders.unshift(WeappTwRuntimeAopLoader);
63
+ }
64
+ }
65
+ });
66
+ });
67
+ compiler.hooks.emit.tapPromise(pluginName, (compilation) => __awaiter(this, void 0, void 0, function* () {
68
+ onStart();
69
+ debug('start');
70
+ for (const chunk of compilation.chunks) {
71
+ if (chunk.id && chunk.hash) {
72
+ cache.calcHashValueChanged(chunk.id, chunk.hash);
73
+ }
74
+ }
75
+ const assets = compilation.assets;
76
+ const entries = Object.entries(assets);
77
+ const groupedEntries = getGroupedEntries(entries, this.options);
78
+ const runtimeSet = getClassSet();
79
+ setMangleRuntimeSet(runtimeSet);
80
+ debug('get runtimeSet, class count: %d', runtimeSet.size);
81
+ if (Array.isArray(groupedEntries.html)) {
82
+ let noCachedCount = 0;
83
+ for (let i = 0; i < groupedEntries.html.length; i++) {
84
+ const [file, originalSource] = groupedEntries.html[i];
85
+ const rawSource = originalSource.source().toString();
86
+ const hash = cache.computeHash(rawSource);
87
+ const cacheKey = file;
88
+ cache.calcHashValueChanged(cacheKey, hash);
89
+ yield cache.process(cacheKey, () => {
90
+ const source = cache.get(cacheKey);
91
+ if (source) {
92
+ compilation.updateAsset(file, source);
93
+ debug('html cache hit: %s', file);
94
+ }
95
+ else {
96
+ return false;
97
+ }
98
+ }, () => __awaiter(this, void 0, void 0, function* () {
99
+ const wxml = yield templateHandler(rawSource, {
100
+ runtimeSet,
101
+ });
102
+ const source = new ConcatSource(wxml);
103
+ compilation.updateAsset(file, source);
104
+ onUpdate(file, rawSource, wxml);
105
+ debug('html handle: %s', file);
106
+ noCachedCount++;
107
+ return {
108
+ key: cacheKey,
109
+ source,
110
+ };
111
+ }));
112
+ }
113
+ debug('html handle finish, total: %d, no-cached: %d', groupedEntries.html.length, noCachedCount);
114
+ }
115
+ if (Array.isArray(groupedEntries.js)) {
116
+ let noCachedCount = 0;
117
+ for (let i = 0; i < groupedEntries.js.length; i++) {
118
+ const [file, originalSource] = groupedEntries.js[i];
119
+ const cacheKey = removeExt(file);
120
+ yield cache.process(cacheKey, () => {
121
+ const source = cache.get(cacheKey);
122
+ if (source) {
123
+ compilation.updateAsset(file, source);
124
+ debug('js cache hit: %s', file);
125
+ }
126
+ else {
127
+ return false;
128
+ }
129
+ }, () => __awaiter(this, void 0, void 0, function* () {
130
+ const rawSource = originalSource.source().toString();
131
+ const mapFilename = `${file}.map`;
132
+ const hasMap = Boolean(assets[mapFilename]);
133
+ const { code, map } = yield jsHandler(rawSource, runtimeSet, {
134
+ generateMap: hasMap,
135
+ });
136
+ const source = new ConcatSource(code);
137
+ compilation.updateAsset(file, source);
138
+ onUpdate(file, rawSource, code);
139
+ debug('js handle: %s', file);
140
+ noCachedCount++;
141
+ if (hasMap && map) {
142
+ const source = new RawSource(map.toString());
143
+ compilation.updateAsset(mapFilename, source);
144
+ }
145
+ return {
146
+ key: cacheKey,
147
+ source,
148
+ };
149
+ }));
150
+ }
151
+ debug('js handle finish, total: %d, no-cached: %d', groupedEntries.js.length, noCachedCount);
152
+ }
153
+ if (Array.isArray(groupedEntries.css)) {
154
+ let noCachedCount = 0;
155
+ for (let i = 0; i < groupedEntries.css.length; i++) {
156
+ const [file, originalSource] = groupedEntries.css[i];
157
+ const rawSource = originalSource.source().toString();
158
+ const hash = cache.computeHash(rawSource);
159
+ const cacheKey = file;
160
+ cache.calcHashValueChanged(cacheKey, hash);
161
+ yield cache.process(cacheKey, () => {
162
+ const source = cache.get(cacheKey);
163
+ if (source) {
164
+ compilation.updateAsset(file, source);
165
+ debug('css cache hit: %s', file);
166
+ }
167
+ else {
168
+ return false;
169
+ }
170
+ }, () => __awaiter(this, void 0, void 0, function* () {
171
+ const css = yield styleHandler(rawSource, {
172
+ isMainChunk: mainCssChunkMatcher(file, this.appType),
173
+ });
174
+ const source = new ConcatSource(css);
175
+ compilation.updateAsset(file, source);
176
+ onUpdate(file, rawSource, css);
177
+ debug('css handle: %s', file);
178
+ noCachedCount++;
179
+ return {
180
+ key: cacheKey,
181
+ source,
182
+ };
183
+ }));
184
+ }
185
+ debug('css handle finish, total: %d, no-cached: %d', groupedEntries.css.length, noCachedCount);
186
+ }
187
+ debug('end');
188
+ onEnd();
189
+ }));
190
+ }
191
+ }
192
+
193
+ export { UnifiedWebpackPluginV4 };
@@ -0,0 +1,31 @@
1
+ export declare enum State {
2
+ START = 0,
3
+ TEXT = 1,
4
+ OPEN_BRACE = 2,
5
+ POTENTIAL_CLOSE = 3,
6
+ BRACES_COMPLETE = 4
7
+ }
8
+ export interface Expression {
9
+ start: number;
10
+ end: number;
11
+ value: string;
12
+ }
13
+ export interface Token {
14
+ start: number;
15
+ end: number;
16
+ value: string;
17
+ expressions: Expression[];
18
+ }
19
+ export declare class Tokenizer {
20
+ private state;
21
+ private buffer;
22
+ private tokens;
23
+ private bufferStartIndex;
24
+ private expressionStartIndex;
25
+ private expressionBuffer;
26
+ private expressions;
27
+ constructor();
28
+ private processChar;
29
+ run(input: string): Token[];
30
+ reset(): void;
31
+ }
@@ -0,0 +1,2 @@
1
+ export { replaceWxml } from './shared';
2
+ export { generateCode, templateReplacer, customTemplateHandler, createTemplateHandler, extractSource } from './utils';
@@ -0,0 +1,2 @@
1
+ import type { ITemplateHandlerOptions } from '@/types';
2
+ export declare function replaceWxml(original: string, options?: ITemplateHandlerOptions): string;
@@ -0,0 +1,13 @@
1
+ import MagicString from 'magic-string';
2
+ import type { Token } from './Tokenizer';
3
+ import type { ItemOrItemArray } from '@/reg';
4
+ import type { ITemplateHandlerOptions, RawSource } from '@/types';
5
+ export declare function generateCode(match: string, options?: ITemplateHandlerOptions): string;
6
+ export declare function extractSource(original: string): RawSource[];
7
+ export declare function handleEachClassFragment(original: string, options?: ITemplateHandlerOptions): string;
8
+ export declare function handleEachClassFragment2(ms: MagicString, tokens: Token[], options?: ITemplateHandlerOptions): void;
9
+ export declare function templateReplacer(original: string, options?: ITemplateHandlerOptions): string;
10
+ export declare function templateReplacer2(original: string, options?: ITemplateHandlerOptions): string;
11
+ export declare function isPropsMatch(props: ItemOrItemArray<string | RegExp>, attr: string): boolean;
12
+ export declare function customTemplateHandler(rawSource: string, options: Required<ITemplateHandlerOptions>): Promise<string>;
13
+ export declare function createTemplateHandler(options?: Omit<ITemplateHandlerOptions, 'runtimeSet'>): (rawSource: string, opt?: Pick<ITemplateHandlerOptions, 'runtimeSet'>) => Promise<string>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "weapp-tailwindcss",
3
- "version": "3.4.0-alpha.0",
3
+ "version": "3.4.0-alpha.2",
4
4
  "description": "把 tailwindcss 原子化样式思想,带给小程序开发者们! bring tailwindcss to miniprogram developers!",
5
5
  "author": "SonOfMagic <qq1324318532@gmail.com>",
6
6
  "license": "MIT",
@@ -148,8 +148,8 @@
148
148
  "webpack-sources": "3.2.3"
149
149
  },
150
150
  "scripts": {
151
- "dev": "tsup --watch --sourcemap",
152
- "build": "tsup",
151
+ "dev": "pnpm clean && pnpm dts && cross-env NODE_ENV=development rollup -c rollup.config.ts --configPlugin typescript -w",
152
+ "build": "pnpm clean && cross-env NODE_ENV=production rollup -c rollup.config.ts --configPlugin typescript && pnpm dts",
153
153
  "build:tsc": "cross-env NODE_ENV=development tsc --build tsconfig.json",
154
154
  "build:cli": "cd plugins/cli && pnpm run build",
155
155
  "dts": "tsc --emitDeclarationOnly -p tsconfig.dts.json",
@@ -1,173 +0,0 @@
1
- import {
2
- createDebug
3
- } from "./chunk-75EWCRQW.mjs";
4
- import {
5
- getOptions
6
- } from "./chunk-PC4B5JJB.mjs";
7
- import {
8
- getGroupedEntries
9
- } from "./chunk-GUE4UCRJ.mjs";
10
- import {
11
- vitePluginName
12
- } from "./chunk-IOYI6MSW.mjs";
13
- import {
14
- __async
15
- } from "./chunk-E7XGHGC7.mjs";
16
-
17
- // src/bundlers/vite/index.ts
18
- var debug = createDebug();
19
- function UnifiedViteWeappTailwindcssPlugin(options = {}) {
20
- const opts = getOptions(options);
21
- const {
22
- disabled,
23
- onEnd,
24
- onLoad,
25
- onStart,
26
- onUpdate,
27
- templateHandler,
28
- styleHandler,
29
- patch,
30
- jsHandler,
31
- mainCssChunkMatcher,
32
- appType,
33
- setMangleRuntimeSet,
34
- cache,
35
- twPatcher
36
- } = opts;
37
- if (disabled) {
38
- return;
39
- }
40
- patch == null ? void 0 : patch();
41
- onLoad();
42
- return {
43
- name: vitePluginName,
44
- enforce: "post",
45
- generateBundle(opt, bundle) {
46
- return __async(this, null, function* () {
47
- debug("start");
48
- onStart();
49
- const entries = Object.entries(bundle);
50
- const groupedEntries = getGroupedEntries(entries, opts);
51
- const runtimeSet = twPatcher.getClassSet();
52
- setMangleRuntimeSet(runtimeSet);
53
- debug("get runtimeSet, class count: %d", runtimeSet.size);
54
- if (Array.isArray(groupedEntries.html)) {
55
- let noCachedCount = 0;
56
- for (let i = 0; i < groupedEntries.html.length; i++) {
57
- const [file, originalSource] = groupedEntries.html[i];
58
- const oldVal = originalSource.source.toString();
59
- const hash = cache.computeHash(oldVal);
60
- cache.calcHashValueChanged(file, hash);
61
- yield cache.process(
62
- file,
63
- () => {
64
- const source = cache.get(file);
65
- if (source) {
66
- originalSource.source = source;
67
- debug("html cache hit: %s", file);
68
- } else {
69
- return false;
70
- }
71
- },
72
- () => __async(this, null, function* () {
73
- originalSource.source = yield templateHandler(oldVal, {
74
- runtimeSet
75
- });
76
- onUpdate(file, oldVal, originalSource.source);
77
- debug("html handle: %s", file);
78
- noCachedCount++;
79
- return {
80
- key: file,
81
- source: originalSource.source
82
- };
83
- })
84
- );
85
- }
86
- debug("html handle finish, total: %d, no-cached: %d", groupedEntries.html.length, noCachedCount);
87
- }
88
- if (Array.isArray(groupedEntries.js)) {
89
- let noCachedCount = 0;
90
- for (let i = 0; i < groupedEntries.js.length; i++) {
91
- const [file, originalSource] = groupedEntries.js[i];
92
- const rawSource = originalSource.code;
93
- const hash = cache.computeHash(rawSource);
94
- cache.calcHashValueChanged(file, hash);
95
- yield cache.process(
96
- file,
97
- () => {
98
- const source = cache.get(file);
99
- if (source) {
100
- originalSource.code = source;
101
- debug("js cache hit: %s", file);
102
- } else {
103
- return false;
104
- }
105
- },
106
- () => __async(this, null, function* () {
107
- const mapFilename = `${file}.map`;
108
- const hasMap = Boolean(bundle[mapFilename]);
109
- const { code, map } = yield jsHandler(rawSource, runtimeSet, {
110
- generateMap: hasMap
111
- });
112
- originalSource.code = code;
113
- onUpdate(file, rawSource, code);
114
- debug("js handle: %s", file);
115
- noCachedCount++;
116
- if (hasMap && map) {
117
- ;
118
- bundle[mapFilename].source = map.toString();
119
- }
120
- return {
121
- key: file,
122
- source: code
123
- };
124
- })
125
- );
126
- }
127
- debug("js handle finish, total: %d, no-cached: %d", groupedEntries.js.length, noCachedCount);
128
- }
129
- if (Array.isArray(groupedEntries.css)) {
130
- let noCachedCount = 0;
131
- for (let i = 0; i < groupedEntries.css.length; i++) {
132
- const [file, originalSource] = groupedEntries.css[i];
133
- const rawSource = originalSource.source.toString();
134
- const hash = cache.computeHash(rawSource);
135
- cache.calcHashValueChanged(file, hash);
136
- yield cache.process(
137
- file,
138
- () => {
139
- const source = cache.get(file);
140
- if (source) {
141
- originalSource.source = source;
142
- debug("css cache hit: %s", file);
143
- } else {
144
- return false;
145
- }
146
- },
147
- () => __async(this, null, function* () {
148
- const css = yield styleHandler(rawSource, {
149
- isMainChunk: mainCssChunkMatcher(originalSource.fileName, appType)
150
- });
151
- originalSource.source = css;
152
- onUpdate(file, rawSource, css);
153
- debug("css handle: %s", file);
154
- noCachedCount++;
155
- return {
156
- key: file,
157
- source: css
158
- };
159
- })
160
- );
161
- }
162
- debug("css handle finish, total: %d, no-cached: %d", groupedEntries.css.length, noCachedCount);
163
- }
164
- onEnd();
165
- debug("end");
166
- });
167
- }
168
- };
169
- }
170
-
171
- export {
172
- UnifiedViteWeappTailwindcssPlugin
173
- };
@@ -1,13 +0,0 @@
1
- // src/debug/index.ts
2
- import _createDebug from "debug";
3
- var _debug = _createDebug("weapp-tw");
4
- function createDebug(prefix) {
5
- function debug(formatter, ...args) {
6
- return _debug((prefix != null ? prefix : "") + formatter, ...args);
7
- }
8
- return debug;
9
- }
10
-
11
- export {
12
- createDebug
13
- };