weapp-tailwindcss 2.3.3
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.
- package/LICENSE +21 -0
- package/README.md +674 -0
- package/bin/weapp-tailwindcss.js +7 -0
- package/dist/babel/index.d.ts +4 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +26 -0
- package/dist/cli.mjs +24 -0
- package/dist/constants.d.ts +6 -0
- package/dist/defaults.d.ts +2 -0
- package/dist/dic.d.ts +44 -0
- package/dist/env.d.ts +2 -0
- package/dist/escape.d.ts +3 -0
- package/dist/extractors/split.d.ts +3 -0
- package/dist/gulp/index.d.ts +8 -0
- package/dist/gulp.d.ts +1 -0
- package/dist/gulp.js +86 -0
- package/dist/gulp.mjs +78 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +31 -0
- package/dist/index.mjs +21 -0
- package/dist/js/index.d.ts +5 -0
- package/dist/mangle/store.d.ts +15 -0
- package/dist/options-3a695e84.js +574 -0
- package/dist/options-ed6f4a3a.mjs +542 -0
- package/dist/options.d.ts +4 -0
- package/dist/postcss/index.d.ts +3 -0
- package/dist/postcss/mp.d.ts +4 -0
- package/dist/postcss/plugin.d.ts +6 -0
- package/dist/postcss/preflight.d.ts +3 -0
- package/dist/postcss/selectorParser.d.ts +3 -0
- package/dist/postcss/shared.d.ts +1 -0
- package/dist/postcss-1f9a5153.mjs +105 -0
- package/dist/postcss-dc9eeafc.js +114 -0
- package/dist/postcss.d.ts +1 -0
- package/dist/postcss.js +22 -0
- package/dist/postcss.mjs +6 -0
- package/dist/reg.d.ts +26 -0
- package/dist/replace.d.ts +4 -0
- package/dist/replace.js +36 -0
- package/dist/replace.mjs +27 -0
- package/dist/shared-c2953d9d.js +354 -0
- package/dist/shared-eae1dc7a.mjs +333 -0
- package/dist/tailwindcss/patcher.d.ts +8 -0
- package/dist/tailwindcss/supportCustomUnit.d.ts +6 -0
- package/dist/types.d.ts +118 -0
- package/dist/utils.d.ts +9 -0
- package/dist/vite/index.d.ts +3 -0
- package/dist/vite.d.ts +1 -0
- package/dist/vite.js +82 -0
- package/dist/vite.mjs +78 -0
- package/dist/webpack/BaseUnifiedPlugin/v5.d.ts +9 -0
- package/dist/webpack/index.d.ts +1 -0
- package/dist/webpack.d.ts +1 -0
- package/dist/webpack.js +101 -0
- package/dist/webpack.mjs +97 -0
- package/dist/wxml/index.d.ts +3 -0
- package/dist/wxml/shared.d.ts +2 -0
- package/dist/wxml/utils.d.ts +7 -0
- package/package.json +224 -0
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
import { ClassGenerator, defaultMangleClassFilter } from 'tailwindcss-mangle-shared';
|
|
2
|
+
|
|
3
|
+
function isRegexp(value) {
|
|
4
|
+
return Object.prototype.toString.call(value) === '[object RegExp]';
|
|
5
|
+
}
|
|
6
|
+
function isMap(value) {
|
|
7
|
+
return Object.prototype.toString.call(value) === '[object Map]';
|
|
8
|
+
}
|
|
9
|
+
const noop = () => { };
|
|
10
|
+
function groupBy(arr, cb) {
|
|
11
|
+
if (!Array.isArray(arr)) {
|
|
12
|
+
throw new Error('expected an array for first argument');
|
|
13
|
+
}
|
|
14
|
+
if (typeof cb !== 'function') {
|
|
15
|
+
throw new Error('expected a function for second argument');
|
|
16
|
+
}
|
|
17
|
+
const result = {};
|
|
18
|
+
for (let i = 0; i < arr.length; i++) {
|
|
19
|
+
const item = arr[i];
|
|
20
|
+
const bucketCategory = cb(item);
|
|
21
|
+
const bucket = result[bucketCategory];
|
|
22
|
+
if (!Array.isArray(bucket)) {
|
|
23
|
+
result[bucketCategory] = [item];
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
result[bucketCategory].push(item);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return result;
|
|
30
|
+
}
|
|
31
|
+
function getGroupedEntries(entries, options) {
|
|
32
|
+
const { cssMatcher, htmlMatcher, jsMatcher } = options;
|
|
33
|
+
const groupedEntries = groupBy(entries, ([file]) => {
|
|
34
|
+
if (cssMatcher(file)) {
|
|
35
|
+
return 'css';
|
|
36
|
+
}
|
|
37
|
+
else if (htmlMatcher(file)) {
|
|
38
|
+
return 'html';
|
|
39
|
+
}
|
|
40
|
+
else if (jsMatcher(file)) {
|
|
41
|
+
return 'js';
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
return 'other';
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return groupedEntries;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const SYMBOL_TABLE = {
|
|
51
|
+
BACKQUOTE: '`',
|
|
52
|
+
TILDE: '~',
|
|
53
|
+
EXCLAM: '!',
|
|
54
|
+
AT: '@',
|
|
55
|
+
NUMBERSIGN: '#',
|
|
56
|
+
DOLLAR: '$',
|
|
57
|
+
PERCENT: '%',
|
|
58
|
+
CARET: '^',
|
|
59
|
+
AMPERSAND: '&',
|
|
60
|
+
ASTERISK: '*',
|
|
61
|
+
PARENLEFT: '(',
|
|
62
|
+
PARENRIGHT: ')',
|
|
63
|
+
MINUS: '-',
|
|
64
|
+
UNDERSCORE: '_',
|
|
65
|
+
EQUAL: '=',
|
|
66
|
+
PLUS: '+',
|
|
67
|
+
BRACKETLEFT: '[',
|
|
68
|
+
BRACELEFT: '{',
|
|
69
|
+
BRACKETRIGHT: ']',
|
|
70
|
+
BRACERIGHT: '}',
|
|
71
|
+
SEMICOLON: ';',
|
|
72
|
+
COLON: ':',
|
|
73
|
+
QUOTE: "'",
|
|
74
|
+
DOUBLEQUOTE: '"',
|
|
75
|
+
BACKSLASH: '\\',
|
|
76
|
+
BAR: '|',
|
|
77
|
+
COMMA: ',',
|
|
78
|
+
LESS: '<',
|
|
79
|
+
PERIOD: '.',
|
|
80
|
+
GREATER: '>',
|
|
81
|
+
SLASH: '/',
|
|
82
|
+
QUESTION: '?',
|
|
83
|
+
SPACE: ' ',
|
|
84
|
+
DOT: '.',
|
|
85
|
+
HASH: '#'
|
|
86
|
+
};
|
|
87
|
+
const MappingChars2String = {
|
|
88
|
+
'[': '_bl_',
|
|
89
|
+
']': '_br_',
|
|
90
|
+
'(': '_pl_',
|
|
91
|
+
')': '_qr_',
|
|
92
|
+
'#': '_h_',
|
|
93
|
+
'!': '_i_',
|
|
94
|
+
'/': '_s_',
|
|
95
|
+
'\\': '_bs_',
|
|
96
|
+
'.': '_d_',
|
|
97
|
+
':': '_c_',
|
|
98
|
+
'%': '_p_',
|
|
99
|
+
',': '_co_',
|
|
100
|
+
"'": '_q_',
|
|
101
|
+
'"': '_dq_',
|
|
102
|
+
'*': '_a_',
|
|
103
|
+
'&': '_am_',
|
|
104
|
+
'@': '_at_',
|
|
105
|
+
'{': '_bal_',
|
|
106
|
+
'}': '_bar_',
|
|
107
|
+
'+': '_plus_',
|
|
108
|
+
';': '_se_',
|
|
109
|
+
'<': '_l_',
|
|
110
|
+
'~': '_t_',
|
|
111
|
+
'=': '_e_',
|
|
112
|
+
'>': '_g_',
|
|
113
|
+
'?': '_qu_',
|
|
114
|
+
'^': '_ca_',
|
|
115
|
+
'`': '_bq_',
|
|
116
|
+
'|': '_b_',
|
|
117
|
+
$: '_do_'
|
|
118
|
+
};
|
|
119
|
+
const MappingChars2StringEntries = Object.entries(MappingChars2String);
|
|
120
|
+
const SimpleMappingChars2String = {
|
|
121
|
+
'[': '_',
|
|
122
|
+
']': '_',
|
|
123
|
+
'(': '_',
|
|
124
|
+
')': '_',
|
|
125
|
+
'{': '_',
|
|
126
|
+
'}': '_',
|
|
127
|
+
'+': 'a',
|
|
128
|
+
',': 'b',
|
|
129
|
+
':': 'c',
|
|
130
|
+
'.': 'd',
|
|
131
|
+
'=': 'e',
|
|
132
|
+
';': 'f',
|
|
133
|
+
'>': 'g',
|
|
134
|
+
'#': 'h',
|
|
135
|
+
'!': 'i',
|
|
136
|
+
'@': 'j',
|
|
137
|
+
'^': 'k',
|
|
138
|
+
'<': 'l',
|
|
139
|
+
'*': 'm',
|
|
140
|
+
'&': 'n',
|
|
141
|
+
'?': 'o',
|
|
142
|
+
'%': 'p',
|
|
143
|
+
"'": 'q',
|
|
144
|
+
$: 'r',
|
|
145
|
+
'/': 's',
|
|
146
|
+
'~': 't',
|
|
147
|
+
'|': 'u',
|
|
148
|
+
'`': 'v',
|
|
149
|
+
'\\': 'w',
|
|
150
|
+
'"': 'x'
|
|
151
|
+
};
|
|
152
|
+
const SimpleMappingChars2StringEntries = Object.entries(SimpleMappingChars2String);
|
|
153
|
+
|
|
154
|
+
function escape(selectors, options = {
|
|
155
|
+
map: SimpleMappingChars2String
|
|
156
|
+
}) {
|
|
157
|
+
const { map = SimpleMappingChars2String } = options;
|
|
158
|
+
const sb = selectors.split('');
|
|
159
|
+
for (let i = 0; i < sb.length; i++) {
|
|
160
|
+
const char = sb[i];
|
|
161
|
+
const code = char.charCodeAt(0);
|
|
162
|
+
if (code > 127) {
|
|
163
|
+
sb[i] = 'u' + Number(code).toString(16);
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
const hit = map[char];
|
|
167
|
+
if (hit) {
|
|
168
|
+
sb[i] = hit;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
const res = sb.join('');
|
|
173
|
+
return res;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const validateFilterRE = /[\w\u00A0-\uFFFF-_:%-?]/;
|
|
177
|
+
function isValidSelector(selector = '') {
|
|
178
|
+
return validateFilterRE.test(selector);
|
|
179
|
+
}
|
|
180
|
+
const splitCode = (code) => {
|
|
181
|
+
return code.split(/[\s]+/).filter(isValidSelector);
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
function escapeStringRegexp(str) {
|
|
185
|
+
if (typeof str !== 'string') {
|
|
186
|
+
throw new TypeError('Expected a string');
|
|
187
|
+
}
|
|
188
|
+
return str.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&').replace(/-/g, '\\x2d');
|
|
189
|
+
}
|
|
190
|
+
const templateClassExactRegexp = /(?:(?<=^|\s)(?:hover-)?class)=(?:["']\W+\s*(?:\w+)\()?["']([^"]+)['"]/gs;
|
|
191
|
+
const tagWithEitherClassAndHoverClassRegexp = /<(?:[a-z][-a-z]*[a-z]*)\s+[^>]*?(?:(?:hover-)?class="(?:[^"]*)")[^>]*?\/?>/g;
|
|
192
|
+
function handleRegexp(reg) {
|
|
193
|
+
return `(?:${reg.source})`;
|
|
194
|
+
}
|
|
195
|
+
function getSourceString(input) {
|
|
196
|
+
let result;
|
|
197
|
+
if (typeof input === 'string') {
|
|
198
|
+
result = input;
|
|
199
|
+
}
|
|
200
|
+
else if (isRegexp(input)) {
|
|
201
|
+
result = input.source;
|
|
202
|
+
}
|
|
203
|
+
else {
|
|
204
|
+
result = input.toString();
|
|
205
|
+
}
|
|
206
|
+
return result;
|
|
207
|
+
}
|
|
208
|
+
function makePattern(arr) {
|
|
209
|
+
let pattern = '';
|
|
210
|
+
if (Array.isArray(arr)) {
|
|
211
|
+
pattern = arr
|
|
212
|
+
.reduce((acc, cur) => {
|
|
213
|
+
if (typeof cur === 'string') {
|
|
214
|
+
acc.push(cur);
|
|
215
|
+
}
|
|
216
|
+
else if (isRegexp(cur)) {
|
|
217
|
+
acc.push(handleRegexp(cur));
|
|
218
|
+
}
|
|
219
|
+
return acc;
|
|
220
|
+
}, [])
|
|
221
|
+
.join('|');
|
|
222
|
+
}
|
|
223
|
+
else if (typeof arr === 'string') {
|
|
224
|
+
pattern = arr;
|
|
225
|
+
}
|
|
226
|
+
else if (isRegexp(arr)) {
|
|
227
|
+
pattern = handleRegexp(arr);
|
|
228
|
+
}
|
|
229
|
+
return pattern;
|
|
230
|
+
}
|
|
231
|
+
function createTempleteHandlerMatchRegexp(tag, attrs, options = {}) {
|
|
232
|
+
const { exact = true } = options;
|
|
233
|
+
const prefix = exact ? '(?<=^|\\s)' : '';
|
|
234
|
+
const pattern = makePattern(attrs);
|
|
235
|
+
let tagPattern = getSourceString(tag);
|
|
236
|
+
if (tagPattern === '*') {
|
|
237
|
+
tagPattern = '[a-z][-a-z]*[a-z]*';
|
|
238
|
+
}
|
|
239
|
+
const source = `<(${tagPattern})\\s+[^>]*?(?:${prefix}(${pattern})="(?:[^"]*)")[^>]*?\\/?>`;
|
|
240
|
+
return new RegExp(source, 'g');
|
|
241
|
+
}
|
|
242
|
+
function createTemplateClassRegexp(attrs, options = {}) {
|
|
243
|
+
const { exact = true } = options;
|
|
244
|
+
const prefix = exact ? '(?<=^|\\s)' : '';
|
|
245
|
+
const pattern = makePattern(attrs);
|
|
246
|
+
const source = `(?:${prefix}${pattern})=(?:["']\\W+\\s*(?:\\w+)\\()?["']([^"]+)['"]`;
|
|
247
|
+
return new RegExp(source, 'gs');
|
|
248
|
+
}
|
|
249
|
+
function makeCustomAttributes(entries) {
|
|
250
|
+
if (Array.isArray(entries)) {
|
|
251
|
+
return entries.map(([k, v]) => {
|
|
252
|
+
return {
|
|
253
|
+
tagRegexp: createTempleteHandlerMatchRegexp(k, v),
|
|
254
|
+
attrRegexp: createTemplateClassRegexp(v),
|
|
255
|
+
tag: getSourceString(k),
|
|
256
|
+
attrs: v
|
|
257
|
+
};
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
const variableRegExp = /{{(.*?)}}/gs;
|
|
262
|
+
function variableMatch(original) {
|
|
263
|
+
return variableRegExp.exec(original);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function getSelf(x) {
|
|
267
|
+
return x;
|
|
268
|
+
}
|
|
269
|
+
const defaultScopedStore = {
|
|
270
|
+
rawOptions: false,
|
|
271
|
+
runtimeSet: new Set(),
|
|
272
|
+
classGenerator: new ClassGenerator(),
|
|
273
|
+
filter: defaultMangleClassFilter,
|
|
274
|
+
cssHandler: getSelf,
|
|
275
|
+
jsHandler: getSelf,
|
|
276
|
+
wxmlHandler: getSelf
|
|
277
|
+
};
|
|
278
|
+
const store = Object.assign({}, defaultScopedStore);
|
|
279
|
+
function useStore() {
|
|
280
|
+
return store;
|
|
281
|
+
}
|
|
282
|
+
function handleValue(rawSource) {
|
|
283
|
+
const arr = splitCode(rawSource);
|
|
284
|
+
for (let i = 0; i < arr.length; i++) {
|
|
285
|
+
const x = arr[i];
|
|
286
|
+
if (store.runtimeSet.has(x)) {
|
|
287
|
+
rawSource = rawSource.replace(new RegExp(escapeStringRegexp(x), 'g'), store.classGenerator.generateClassName(x).name);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
return rawSource;
|
|
291
|
+
}
|
|
292
|
+
function initStore(options) {
|
|
293
|
+
var _a;
|
|
294
|
+
store.rawOptions = options;
|
|
295
|
+
if (options) {
|
|
296
|
+
if (options === true) {
|
|
297
|
+
options = {
|
|
298
|
+
classGenerator: {},
|
|
299
|
+
mangleClassFilter: defaultMangleClassFilter
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
store.classGenerator = new ClassGenerator(options.classGenerator);
|
|
303
|
+
store.filter = (_a = options.mangleClassFilter) !== null && _a !== void 0 ? _a : defaultMangleClassFilter;
|
|
304
|
+
store.jsHandler = (rawSource) => {
|
|
305
|
+
return handleValue(rawSource);
|
|
306
|
+
};
|
|
307
|
+
store.cssHandler = (rawSource) => {
|
|
308
|
+
return handleValue(rawSource);
|
|
309
|
+
};
|
|
310
|
+
store.wxmlHandler = (rawSource) => {
|
|
311
|
+
return handleValue(rawSource);
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
function setRuntimeSet(runtimeSet) {
|
|
316
|
+
const newSet = new Set();
|
|
317
|
+
runtimeSet.forEach((c) => {
|
|
318
|
+
if (store.filter(c)) {
|
|
319
|
+
newSet.add(c);
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
store.runtimeSet = newSet;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
function internalCssSelectorReplacer(selectors, map = SimpleMappingChars2String) {
|
|
326
|
+
const { cssHandler } = useStore();
|
|
327
|
+
selectors = cssHandler(selectors);
|
|
328
|
+
return escape(selectors, {
|
|
329
|
+
map
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export { MappingChars2String as M, SimpleMappingChars2String as S, templateClassExactRegexp as a, variableRegExp as b, initStore as c, setRuntimeSet as d, escapeStringRegexp as e, internalCssSelectorReplacer as f, getGroupedEntries as g, escape as h, isMap as i, SYMBOL_TABLE as j, MappingChars2StringEntries as k, SimpleMappingChars2StringEntries as l, makeCustomAttributes as m, noop as n, splitCode as s, tagWithEitherClassAndHoverClassRegexp as t, useStore as u, variableMatch as v };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ILengthUnitsPatchOptions, InternalPatchResult } from "../types";
|
|
2
|
+
import { TailwindcssPatcher } from 'tailwindcss-patch';
|
|
3
|
+
export declare function getInstalledPkgJsonPath(options: ILengthUnitsPatchOptions): string | undefined;
|
|
4
|
+
export declare function createPatch(options: false | ILengthUnitsPatchOptions): () => void;
|
|
5
|
+
export declare function monkeyPatchForSupportingCustomUnit(rootDir: string, options: ILengthUnitsPatchOptions): string | undefined;
|
|
6
|
+
export declare function internalPatch(pkgJsonPath: string | undefined, options: ILengthUnitsPatchOptions, overwrite?: boolean): InternalPatchResult | undefined;
|
|
7
|
+
export declare function mkCacheDirectory(cwd?: string): string;
|
|
8
|
+
export declare function createTailwindcssPatcher(): TailwindcssPatcher;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import type { InjectPreflight } from './postcss/preflight';
|
|
2
|
+
import type { Rule } from 'postcss';
|
|
3
|
+
import type { IClassGeneratorOptions } from 'tailwindcss-mangle-shared';
|
|
4
|
+
import type { GeneratorResult } from '@babel/generator';
|
|
5
|
+
export type ItemOrItemArray<T> = T | T[];
|
|
6
|
+
export type { TraverseOptions } from '@babel/traverse';
|
|
7
|
+
export type { Node } from '@babel/types';
|
|
8
|
+
export type AppType = 'uni-app' | 'uni-app-vite' | 'taro' | 'remax' | 'rax' | 'native' | 'kbone' | 'mpx';
|
|
9
|
+
export interface IPropValue {
|
|
10
|
+
prop: string;
|
|
11
|
+
value: string;
|
|
12
|
+
}
|
|
13
|
+
export type CssPresetProps = string;
|
|
14
|
+
export type CssPreflightOptions = {
|
|
15
|
+
[key: CssPresetProps]: string | number | boolean;
|
|
16
|
+
} | false;
|
|
17
|
+
type RequiredStyleHandlerOptions = {
|
|
18
|
+
isMainChunk: boolean;
|
|
19
|
+
cssInjectPreflight?: InjectPreflight;
|
|
20
|
+
cssPreflightRange?: 'view' | 'all';
|
|
21
|
+
replaceUniversalSelectorWith?: string | false;
|
|
22
|
+
escapeMap?: Record<string, string>;
|
|
23
|
+
};
|
|
24
|
+
export type CustomRuleCallback = (node: Rule, options: Readonly<RequiredStyleHandlerOptions>) => void;
|
|
25
|
+
export type IStyleHandlerOptions = {
|
|
26
|
+
customRuleCallback?: CustomRuleCallback;
|
|
27
|
+
} & RequiredStyleHandlerOptions;
|
|
28
|
+
export type ICustomAttributes = Record<string, ItemOrItemArray<string | RegExp>> | Map<string | RegExp, ItemOrItemArray<string | RegExp>>;
|
|
29
|
+
export type ICustomAttributesEntities = [string | RegExp, ItemOrItemArray<string | RegExp>][];
|
|
30
|
+
export type IJsHandlerOptions = {
|
|
31
|
+
escapeMap?: Record<string, string>;
|
|
32
|
+
classNameSet: Set<string>;
|
|
33
|
+
minifiedJs?: boolean;
|
|
34
|
+
};
|
|
35
|
+
export interface RawSource {
|
|
36
|
+
start: number;
|
|
37
|
+
end: number;
|
|
38
|
+
raw: string;
|
|
39
|
+
source?: string;
|
|
40
|
+
prevConcatenated: boolean;
|
|
41
|
+
nextConcatenated: boolean;
|
|
42
|
+
}
|
|
43
|
+
export interface ILengthUnitsPatchDangerousOptions {
|
|
44
|
+
packageName?: string;
|
|
45
|
+
gteVersion?: string;
|
|
46
|
+
lengthUnitsFilePath?: string;
|
|
47
|
+
variableName?: string;
|
|
48
|
+
overwrite?: boolean;
|
|
49
|
+
destPath?: string;
|
|
50
|
+
}
|
|
51
|
+
export interface ILengthUnitsPatchOptions {
|
|
52
|
+
units: string[];
|
|
53
|
+
paths?: string[];
|
|
54
|
+
dangerousOptions?: ILengthUnitsPatchDangerousOptions;
|
|
55
|
+
basedir?: string;
|
|
56
|
+
}
|
|
57
|
+
export interface IMangleOptions {
|
|
58
|
+
classGenerator?: IClassGeneratorOptions;
|
|
59
|
+
mangleClassFilter?: (className: string) => boolean;
|
|
60
|
+
}
|
|
61
|
+
export interface UserDefinedOptions {
|
|
62
|
+
htmlMatcher?: ((name: string) => boolean) | string | string[];
|
|
63
|
+
cssMatcher?: ((name: string) => boolean) | string | string[];
|
|
64
|
+
jsMatcher?: ((name: string) => boolean) | string | string[];
|
|
65
|
+
mainCssChunkMatcher?: ((name: string, appType?: AppType) => boolean) | string | string[];
|
|
66
|
+
cssPreflight?: CssPreflightOptions;
|
|
67
|
+
cssPreflightRange?: 'view' | 'all';
|
|
68
|
+
replaceUniversalSelectorWith?: string | false;
|
|
69
|
+
disabled?: boolean;
|
|
70
|
+
customRuleCallback?: CustomRuleCallback;
|
|
71
|
+
onLoad?: () => void;
|
|
72
|
+
onStart?: () => void;
|
|
73
|
+
onUpdate?: (filename: string, oldVal: string, newVal: string) => void;
|
|
74
|
+
onEnd?: () => void;
|
|
75
|
+
customAttributes?: ICustomAttributes;
|
|
76
|
+
customReplaceDictionary?: 'simple' | 'complex' | Record<string, string>;
|
|
77
|
+
supportCustomLengthUnitsPatch?: ILengthUnitsPatchOptions | boolean;
|
|
78
|
+
appType?: AppType;
|
|
79
|
+
minifiedJs?: boolean;
|
|
80
|
+
mangle?: boolean | IMangleOptions;
|
|
81
|
+
}
|
|
82
|
+
export interface ICommonReplaceOptions {
|
|
83
|
+
keepEOL?: boolean;
|
|
84
|
+
escapeMap?: Record<string, string>;
|
|
85
|
+
}
|
|
86
|
+
export type ICustomRegexp = {
|
|
87
|
+
tagRegexp: RegExp;
|
|
88
|
+
attrRegexp: RegExp;
|
|
89
|
+
tag: string;
|
|
90
|
+
attrs: ItemOrItemArray<string | RegExp>;
|
|
91
|
+
};
|
|
92
|
+
export interface ITempleteHandlerOptions extends ICommonReplaceOptions {
|
|
93
|
+
customAttributesEntities?: ICustomAttributesEntities;
|
|
94
|
+
escapeMap?: Record<string, string>;
|
|
95
|
+
}
|
|
96
|
+
export type GlobOrFunctionMatchers = 'htmlMatcher' | 'cssMatcher' | 'jsMatcher' | 'mainCssChunkMatcher';
|
|
97
|
+
export type InternalUserDefinedOptions = Required<Omit<UserDefinedOptions, GlobOrFunctionMatchers | 'supportCustomLengthUnitsPatch' | 'customReplaceDictionary'> & {
|
|
98
|
+
[K in GlobOrFunctionMatchers]: K extends 'mainCssChunkMatcher' ? (name: string, appType?: AppType) => boolean : (name: string) => boolean;
|
|
99
|
+
} & {
|
|
100
|
+
supportCustomLengthUnitsPatch: ILengthUnitsPatchOptions | false;
|
|
101
|
+
templeteHandler: (rawSource: string, options?: ITempleteHandlerOptions) => string;
|
|
102
|
+
styleHandler: (rawSource: string, options: IStyleHandlerOptions) => string;
|
|
103
|
+
jsHandler: (rawSource: string, set: Set<string>) => GeneratorResult;
|
|
104
|
+
escapeMap: Record<string, string>;
|
|
105
|
+
patch: () => void;
|
|
106
|
+
customReplaceDictionary: Record<string, string>;
|
|
107
|
+
}>;
|
|
108
|
+
export type InternalPostcssOptions = Pick<UserDefinedOptions, 'cssMatcher' | 'mainCssChunkMatcher' | 'cssPreflight' | 'replaceUniversalSelectorWith' | 'cssPreflightRange' | 'customRuleCallback' | 'disabled'>;
|
|
109
|
+
export interface IBaseWebpackPlugin {
|
|
110
|
+
options: InternalUserDefinedOptions;
|
|
111
|
+
appType?: AppType;
|
|
112
|
+
apply: (compiler: any) => void;
|
|
113
|
+
}
|
|
114
|
+
export interface InternalPatchResult {
|
|
115
|
+
dataTypes?: string;
|
|
116
|
+
processTailwindFeatures?: string;
|
|
117
|
+
plugin?: string;
|
|
118
|
+
}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { InternalUserDefinedOptions } from "./types";
|
|
2
|
+
import defu from 'defu';
|
|
3
|
+
export declare function isRegexp(value: unknown): boolean;
|
|
4
|
+
export declare function isMap(value: unknown): boolean;
|
|
5
|
+
export declare function regExpTest(arr: (string | RegExp)[] | undefined, str: string): boolean;
|
|
6
|
+
export declare const noop: () => void;
|
|
7
|
+
export declare function isAscii(str: string): boolean;
|
|
8
|
+
export { defu };
|
|
9
|
+
export declare function getGroupedEntries<T>(entries: [string, T][], options: InternalUserDefinedOptions): Record<"css" | "html" | "js" | "other", [string, T][]>;
|
package/dist/vite.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './vite/index';
|
package/dist/vite.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var options = require('./options-3a695e84.js');
|
|
6
|
+
var postcss = require('./postcss-dc9eeafc.js');
|
|
7
|
+
var shared = require('./shared-c2953d9d.js');
|
|
8
|
+
require('micromatch');
|
|
9
|
+
require('@babel/generator');
|
|
10
|
+
require('@babel/parser');
|
|
11
|
+
require('@babel/traverse');
|
|
12
|
+
require('./replace.js');
|
|
13
|
+
require('tailwindcss-mangle-shared');
|
|
14
|
+
require('@babel/types');
|
|
15
|
+
require('postcss');
|
|
16
|
+
require('@csstools/postcss-is-pseudo-class');
|
|
17
|
+
require('path');
|
|
18
|
+
require('fs');
|
|
19
|
+
require('semver');
|
|
20
|
+
require('tailwindcss-patch');
|
|
21
|
+
require('postcss-selector-parser');
|
|
22
|
+
|
|
23
|
+
function UnifiedViteWeappTailwindcssPlugin(options$1 = {}) {
|
|
24
|
+
if (typeof options$1.customReplaceDictionary === 'undefined') {
|
|
25
|
+
options$1.customReplaceDictionary = 'simple';
|
|
26
|
+
}
|
|
27
|
+
const opts = options.getOptions(options$1, ['patch', 'style', 'templete', 'js']);
|
|
28
|
+
const { disabled, onEnd, onLoad, onStart, onUpdate, templeteHandler, styleHandler, patch, jsHandler, mainCssChunkMatcher, appType, mangle } = opts;
|
|
29
|
+
if (disabled) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
patch === null || patch === void 0 ? void 0 : patch();
|
|
33
|
+
shared.initStore(mangle);
|
|
34
|
+
const twPatcher = options.createTailwindcssPatcher();
|
|
35
|
+
onLoad();
|
|
36
|
+
return {
|
|
37
|
+
name: postcss.vitePluginName,
|
|
38
|
+
enforce: 'post',
|
|
39
|
+
buildStart() {
|
|
40
|
+
onStart();
|
|
41
|
+
},
|
|
42
|
+
generateBundle(opt, bundle, isWrite) {
|
|
43
|
+
const entries = Object.entries(bundle);
|
|
44
|
+
const groupedEntries = shared.getGroupedEntries(entries, opts);
|
|
45
|
+
const set = twPatcher.getClassSet();
|
|
46
|
+
shared.setRuntimeSet(set);
|
|
47
|
+
if (Array.isArray(groupedEntries.html)) {
|
|
48
|
+
for (let i = 0; i < groupedEntries.html.length; i++) {
|
|
49
|
+
const [file, originalSource] = groupedEntries.html[i];
|
|
50
|
+
const oldVal = originalSource.source.toString();
|
|
51
|
+
originalSource.source = templeteHandler(oldVal);
|
|
52
|
+
onUpdate(file, oldVal, originalSource.source);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (Array.isArray(groupedEntries.css)) {
|
|
56
|
+
for (let i = 0; i < groupedEntries.css.length; i++) {
|
|
57
|
+
const [file, originalSource] = groupedEntries.css[i];
|
|
58
|
+
const rawSource = originalSource.source.toString();
|
|
59
|
+
const css = styleHandler(rawSource, {
|
|
60
|
+
isMainChunk: mainCssChunkMatcher(originalSource.fileName, appType)
|
|
61
|
+
});
|
|
62
|
+
originalSource.source = css;
|
|
63
|
+
onUpdate(file, rawSource, css);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if (Array.isArray(groupedEntries.js)) {
|
|
67
|
+
for (let i = 0; i < groupedEntries.js.length; i++) {
|
|
68
|
+
const [file, originalSource] = groupedEntries.js[i];
|
|
69
|
+
const rawSource = originalSource.code;
|
|
70
|
+
const { code } = jsHandler(rawSource, set);
|
|
71
|
+
originalSource.code = code;
|
|
72
|
+
onUpdate(file, rawSource, code);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
buildEnd() {
|
|
77
|
+
onEnd();
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
exports.UnifiedViteWeappTailwindcssPlugin = UnifiedViteWeappTailwindcssPlugin;
|
package/dist/vite.mjs
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { g as getOptions, a as createTailwindcssPatcher } from './options-ed6f4a3a.mjs';
|
|
2
|
+
import { v as vitePluginName } from './postcss-1f9a5153.mjs';
|
|
3
|
+
import { c as initStore, g as getGroupedEntries, d as setRuntimeSet } from './shared-eae1dc7a.mjs';
|
|
4
|
+
import 'micromatch';
|
|
5
|
+
import '@babel/generator';
|
|
6
|
+
import '@babel/parser';
|
|
7
|
+
import '@babel/traverse';
|
|
8
|
+
import './replace.mjs';
|
|
9
|
+
import 'tailwindcss-mangle-shared';
|
|
10
|
+
import '@babel/types';
|
|
11
|
+
import 'postcss';
|
|
12
|
+
import '@csstools/postcss-is-pseudo-class';
|
|
13
|
+
import 'path';
|
|
14
|
+
import 'fs';
|
|
15
|
+
import 'semver';
|
|
16
|
+
import 'tailwindcss-patch';
|
|
17
|
+
import 'postcss-selector-parser';
|
|
18
|
+
|
|
19
|
+
function UnifiedViteWeappTailwindcssPlugin(options = {}) {
|
|
20
|
+
if (typeof options.customReplaceDictionary === 'undefined') {
|
|
21
|
+
options.customReplaceDictionary = 'simple';
|
|
22
|
+
}
|
|
23
|
+
const opts = getOptions(options, ['patch', 'style', 'templete', 'js']);
|
|
24
|
+
const { disabled, onEnd, onLoad, onStart, onUpdate, templeteHandler, styleHandler, patch, jsHandler, mainCssChunkMatcher, appType, mangle } = opts;
|
|
25
|
+
if (disabled) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
patch === null || patch === void 0 ? void 0 : patch();
|
|
29
|
+
initStore(mangle);
|
|
30
|
+
const twPatcher = createTailwindcssPatcher();
|
|
31
|
+
onLoad();
|
|
32
|
+
return {
|
|
33
|
+
name: vitePluginName,
|
|
34
|
+
enforce: 'post',
|
|
35
|
+
buildStart() {
|
|
36
|
+
onStart();
|
|
37
|
+
},
|
|
38
|
+
generateBundle(opt, bundle, isWrite) {
|
|
39
|
+
const entries = Object.entries(bundle);
|
|
40
|
+
const groupedEntries = getGroupedEntries(entries, opts);
|
|
41
|
+
const set = twPatcher.getClassSet();
|
|
42
|
+
setRuntimeSet(set);
|
|
43
|
+
if (Array.isArray(groupedEntries.html)) {
|
|
44
|
+
for (let i = 0; i < groupedEntries.html.length; i++) {
|
|
45
|
+
const [file, originalSource] = groupedEntries.html[i];
|
|
46
|
+
const oldVal = originalSource.source.toString();
|
|
47
|
+
originalSource.source = templeteHandler(oldVal);
|
|
48
|
+
onUpdate(file, oldVal, originalSource.source);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (Array.isArray(groupedEntries.css)) {
|
|
52
|
+
for (let i = 0; i < groupedEntries.css.length; i++) {
|
|
53
|
+
const [file, originalSource] = groupedEntries.css[i];
|
|
54
|
+
const rawSource = originalSource.source.toString();
|
|
55
|
+
const css = styleHandler(rawSource, {
|
|
56
|
+
isMainChunk: mainCssChunkMatcher(originalSource.fileName, appType)
|
|
57
|
+
});
|
|
58
|
+
originalSource.source = css;
|
|
59
|
+
onUpdate(file, rawSource, css);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (Array.isArray(groupedEntries.js)) {
|
|
63
|
+
for (let i = 0; i < groupedEntries.js.length; i++) {
|
|
64
|
+
const [file, originalSource] = groupedEntries.js[i];
|
|
65
|
+
const rawSource = originalSource.code;
|
|
66
|
+
const { code } = jsHandler(rawSource, set);
|
|
67
|
+
originalSource.code = code;
|
|
68
|
+
onUpdate(file, rawSource, code);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
buildEnd() {
|
|
73
|
+
onEnd();
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export { UnifiedViteWeappTailwindcssPlugin };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AppType, UserDefinedOptions, InternalUserDefinedOptions, IBaseWebpackPlugin } from "../../types";
|
|
2
|
+
import type { Compiler } from 'webpack';
|
|
3
|
+
export declare class UnifiedWebpackPluginV5 implements IBaseWebpackPlugin {
|
|
4
|
+
options: InternalUserDefinedOptions;
|
|
5
|
+
appType?: AppType;
|
|
6
|
+
static NS: string;
|
|
7
|
+
constructor(options?: UserDefinedOptions);
|
|
8
|
+
apply(compiler: Compiler): void;
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './BaseUnifiedPlugin/v5';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './webpack/index';
|