unplugin-tailwindcss-mangle 1.2.7 → 2.0.0
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/README.md +18 -5
- package/dist/esbuild.cjs +15 -0
- package/dist/esbuild.d.ts +7 -2
- package/dist/esbuild.mjs +8 -7
- package/dist/index.cjs +343 -0
- package/dist/index.d.ts +7 -5
- package/dist/index.mjs +301 -330
- package/dist/nuxt.cjs +24 -0
- package/dist/nuxt.d.ts +6 -2
- package/dist/nuxt.mjs +16 -15
- package/dist/rollup.cjs +15 -0
- package/dist/rollup.d.ts +7 -2
- package/dist/rollup.mjs +8 -7
- package/dist/types-3f814672.d.ts +17 -0
- package/dist/vite.cjs +15 -0
- package/dist/vite.d.ts +7 -2
- package/dist/vite.mjs +8 -7
- package/dist/webpack.cjs +15 -0
- package/dist/webpack.d.ts +7 -2
- package/dist/webpack.mjs +8 -7
- package/package.json +21 -25
- package/dist/constants.d.ts +0 -2
- package/dist/esbuild.js +0 -14
- package/dist/index.js +0 -379
- package/dist/loader/twm-css.d.ts +0 -6
- package/dist/nuxt.js +0 -23
- package/dist/options.d.ts +0 -17
- package/dist/rollup.js +0 -14
- package/dist/twm-css.js +0 -19
- package/dist/twm-css.mjs +0 -17
- package/dist/types.d.ts +0 -31
- package/dist/utils.d.ts +0 -10
- package/dist/vite.js +0 -14
- package/dist/webpack.js +0 -14
package/dist/index.mjs
CHANGED
|
@@ -1,364 +1,335 @@
|
|
|
1
1
|
import { createUnplugin } from 'unplugin';
|
|
2
|
-
import micromatch from 'micromatch';
|
|
3
2
|
import fs from 'node:fs';
|
|
4
|
-
import path from 'node:path';
|
|
5
|
-
import { groupBy, defaultMangleClassFilter } from 'tailwindcss-mangle
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
const pluginName = 'unplugin-tailwindcss-mangle';
|
|
3
|
+
import path, { resolve } from 'node:path';
|
|
4
|
+
import { groupBy, ClassGenerator, defaultMangleClassFilter } from '@tailwindcss-mangle/shared';
|
|
5
|
+
import { getDefaultUserConfig, getConfig } from '@tailwindcss-mangle/config';
|
|
6
|
+
import { sort } from 'fast-sort';
|
|
7
|
+
import { htmlHandler, cssHandler, jsHandler, preProcessJs } from '@tailwindcss-mangle/core';
|
|
8
|
+
import micromatch from 'micromatch';
|
|
11
9
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
10
|
+
function isObject(value) {
|
|
11
|
+
return value !== null && typeof value === "object";
|
|
12
|
+
}
|
|
13
|
+
function _defu(baseObject, defaults, namespace = ".", merger) {
|
|
14
|
+
if (!isObject(defaults)) {
|
|
15
|
+
return _defu(baseObject, {}, namespace, merger);
|
|
16
|
+
}
|
|
17
|
+
const object = Object.assign({}, defaults);
|
|
18
|
+
for (const key in baseObject) {
|
|
19
|
+
if (key === "__proto__" || key === "constructor") {
|
|
20
|
+
continue;
|
|
22
21
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
if (cssMatcher(file)) {
|
|
27
|
-
return 'css';
|
|
28
|
-
}
|
|
29
|
-
else if (htmlMatcher(file)) {
|
|
30
|
-
return 'html';
|
|
31
|
-
}
|
|
32
|
-
else if (jsMatcher(file)) {
|
|
33
|
-
return 'js';
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
return 'other';
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
if (!groupedEntries.css) {
|
|
40
|
-
groupedEntries.css = [];
|
|
22
|
+
const value = baseObject[key];
|
|
23
|
+
if (value === null || value === void 0) {
|
|
24
|
+
continue;
|
|
41
25
|
}
|
|
42
|
-
if (
|
|
43
|
-
|
|
26
|
+
if (merger && merger(object, key, value, namespace)) {
|
|
27
|
+
continue;
|
|
44
28
|
}
|
|
45
|
-
if (
|
|
46
|
-
|
|
29
|
+
if (Array.isArray(value) && Array.isArray(object[key])) {
|
|
30
|
+
object[key] = [...value, ...object[key]];
|
|
31
|
+
} else if (isObject(value) && isObject(object[key])) {
|
|
32
|
+
object[key] = _defu(
|
|
33
|
+
value,
|
|
34
|
+
object[key],
|
|
35
|
+
(namespace ? `${namespace}.` : "") + key.toString(),
|
|
36
|
+
merger
|
|
37
|
+
);
|
|
38
|
+
} else {
|
|
39
|
+
object[key] = value;
|
|
47
40
|
}
|
|
48
|
-
|
|
49
|
-
|
|
41
|
+
}
|
|
42
|
+
return object;
|
|
43
|
+
}
|
|
44
|
+
function createDefu(merger) {
|
|
45
|
+
return (...arguments_) => (
|
|
46
|
+
// eslint-disable-next-line unicorn/no-array-reduce
|
|
47
|
+
arguments_.reduce((p, c) => _defu(p, c, "", merger), {})
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
const defu = createDefu();
|
|
51
|
+
|
|
52
|
+
const pluginName = "unplugin-tailwindcss-mangle";
|
|
53
|
+
|
|
54
|
+
const { isMatch } = micromatch;
|
|
55
|
+
function getGroupedEntries(entries, options = {
|
|
56
|
+
cssMatcher(file) {
|
|
57
|
+
return /\.css$/.test(file);
|
|
58
|
+
},
|
|
59
|
+
htmlMatcher(file) {
|
|
60
|
+
return /\.html?$/.test(file);
|
|
61
|
+
},
|
|
62
|
+
jsMatcher(file) {
|
|
63
|
+
return /\.[cm]?js$/.test(file);
|
|
64
|
+
}
|
|
65
|
+
}) {
|
|
66
|
+
const { cssMatcher, htmlMatcher, jsMatcher } = options;
|
|
67
|
+
const groupedEntries = groupBy(entries, ([file]) => {
|
|
68
|
+
if (cssMatcher(file)) {
|
|
69
|
+
return "css";
|
|
70
|
+
} else if (htmlMatcher(file)) {
|
|
71
|
+
return "html";
|
|
72
|
+
} else if (jsMatcher(file)) {
|
|
73
|
+
return "js";
|
|
74
|
+
} else {
|
|
75
|
+
return "other";
|
|
50
76
|
}
|
|
51
|
-
|
|
77
|
+
});
|
|
78
|
+
if (!groupedEntries.css) {
|
|
79
|
+
groupedEntries.css = [];
|
|
80
|
+
}
|
|
81
|
+
if (!groupedEntries.html) {
|
|
82
|
+
groupedEntries.html = [];
|
|
83
|
+
}
|
|
84
|
+
if (!groupedEntries.js) {
|
|
85
|
+
groupedEntries.js = [];
|
|
86
|
+
}
|
|
87
|
+
if (!groupedEntries.other) {
|
|
88
|
+
groupedEntries.other = [];
|
|
89
|
+
}
|
|
90
|
+
return groupedEntries;
|
|
52
91
|
}
|
|
53
92
|
function createGlobMatcher(pattern, fallbackValue = false) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
return function (file) {
|
|
60
|
-
return isMatch(file, pattern);
|
|
93
|
+
if (pattern === void 0) {
|
|
94
|
+
return function() {
|
|
95
|
+
return fallbackValue;
|
|
61
96
|
};
|
|
97
|
+
}
|
|
98
|
+
return function(file) {
|
|
99
|
+
return isMatch(file, pattern);
|
|
100
|
+
};
|
|
62
101
|
}
|
|
63
102
|
function getCacheDir(basedir = process.cwd()) {
|
|
64
|
-
|
|
103
|
+
return path.resolve(basedir, "node_modules/.cache", pluginName);
|
|
65
104
|
}
|
|
66
105
|
function mkCacheDirectory(cwd = process.cwd()) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
106
|
+
const cacheDirectory = getCacheDir(cwd);
|
|
107
|
+
const exists = fs.existsSync(cacheDirectory);
|
|
108
|
+
if (!exists) {
|
|
109
|
+
fs.mkdirSync(cacheDirectory, {
|
|
110
|
+
recursive: true
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
return cacheDirectory;
|
|
75
114
|
}
|
|
76
115
|
function cacheDump(filename, data, basedir) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
116
|
+
try {
|
|
117
|
+
const dir = mkCacheDirectory(basedir);
|
|
118
|
+
fs.writeFileSync(path.resolve(dir, filename), JSON.stringify([...data], void 0, 2), "utf8");
|
|
119
|
+
} catch (error) {
|
|
120
|
+
console.log(error);
|
|
121
|
+
}
|
|
84
122
|
}
|
|
85
123
|
|
|
86
|
-
function getOptions(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
124
|
+
function getOptions(opts = {}) {
|
|
125
|
+
const {
|
|
126
|
+
include,
|
|
127
|
+
exclude,
|
|
128
|
+
disabled,
|
|
129
|
+
mangleClassFilter,
|
|
130
|
+
classMapOutput,
|
|
131
|
+
classGenerator: classGeneratorOptions,
|
|
132
|
+
classListPath: _classListPath
|
|
133
|
+
} = defu(opts, {
|
|
134
|
+
include: ["**/*.{js,jsx,ts,tsx,svelte,vue}"],
|
|
135
|
+
exclude: ["**/*.{css,scss,less,sass,postcss,html,htm}"],
|
|
136
|
+
disabled: process.env.NODE_ENV === "development"
|
|
137
|
+
});
|
|
138
|
+
const includeMatcher = createGlobMatcher(include, true);
|
|
139
|
+
const excludeMatcher = createGlobMatcher(exclude, false);
|
|
140
|
+
const currentMangleClassFilter = mangleClassFilter ?? defaultMangleClassFilter;
|
|
141
|
+
function isInclude(file) {
|
|
142
|
+
return includeMatcher(file) && !excludeMatcher(file);
|
|
143
|
+
}
|
|
144
|
+
const classSet = /* @__PURE__ */ new Set();
|
|
145
|
+
const replaceMap = /* @__PURE__ */ new Map();
|
|
146
|
+
let userConfig = getDefaultUserConfig();
|
|
147
|
+
const classMapOutputOptions = {
|
|
148
|
+
filename: "classMap.json"
|
|
149
|
+
};
|
|
150
|
+
if (typeof classMapOutput === "object") {
|
|
151
|
+
Object.assign(classMapOutputOptions, classMapOutput);
|
|
152
|
+
}
|
|
153
|
+
const classGenerator = new ClassGenerator(classGeneratorOptions);
|
|
154
|
+
function getCachedClassSet() {
|
|
155
|
+
return classSet;
|
|
156
|
+
}
|
|
157
|
+
function getReplaceMap() {
|
|
158
|
+
return replaceMap;
|
|
159
|
+
}
|
|
160
|
+
async function initConfig() {
|
|
161
|
+
const { config } = await getConfig();
|
|
162
|
+
userConfig = config;
|
|
163
|
+
let classListPath = "";
|
|
164
|
+
if (userConfig) {
|
|
165
|
+
classListPath = resolve(process.cwd(), userConfig.patch?.output?.filename);
|
|
92
166
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const classSetOutputOptions = {
|
|
96
|
-
filename: 'classSet.json',
|
|
97
|
-
type: 'partial'
|
|
98
|
-
};
|
|
99
|
-
const classMapOutputOptions = {
|
|
100
|
-
filename: 'classMap.json'
|
|
101
|
-
};
|
|
102
|
-
if (typeof options.classSetOutput === 'object') {
|
|
103
|
-
Object.assign(classSetOutputOptions, options.classSetOutput);
|
|
167
|
+
if (_classListPath) {
|
|
168
|
+
classListPath = _classListPath;
|
|
104
169
|
}
|
|
105
|
-
if (
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
if (isOutput && classSetOutputOptions.type === 'all') {
|
|
113
|
-
cacheDump(classSetOutputOptions.filename, set, classSetOutputOptions.dir);
|
|
170
|
+
if (classListPath && fs.existsSync(classListPath)) {
|
|
171
|
+
const rawClassList = fs.readFileSync(classListPath, "utf8");
|
|
172
|
+
const list = JSON.parse(rawClassList);
|
|
173
|
+
const classList = sort(list).desc((c) => c.length);
|
|
174
|
+
for (const className of classList) {
|
|
175
|
+
if (currentMangleClassFilter(className)) {
|
|
176
|
+
classSet.add(className);
|
|
114
177
|
}
|
|
115
|
-
|
|
116
|
-
if (!currentMangleClassFilter(c)) {
|
|
117
|
-
set.delete(c);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
if (isOutput && classSetOutputOptions.type === 'partial') {
|
|
121
|
-
cacheDump(classSetOutputOptions.filename, set, classSetOutputOptions.dir);
|
|
122
|
-
}
|
|
123
|
-
classSet = set;
|
|
124
|
-
return classSet;
|
|
178
|
+
}
|
|
125
179
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
180
|
+
for (const cls of classSet) {
|
|
181
|
+
classGenerator.generateClassName(cls);
|
|
182
|
+
}
|
|
183
|
+
for (const x of Object.entries(classGenerator.newClassMap)) {
|
|
184
|
+
replaceMap.set(x[0], x[1].name);
|
|
185
|
+
}
|
|
186
|
+
return config;
|
|
187
|
+
}
|
|
188
|
+
function addToUsedBy(key, file) {
|
|
189
|
+
const hit = classGenerator.newClassMap[key];
|
|
190
|
+
if (hit) {
|
|
191
|
+
hit.usedBy.add(file);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return {
|
|
195
|
+
getCachedClassSet,
|
|
196
|
+
classGenerator,
|
|
197
|
+
includeMatcher,
|
|
198
|
+
excludeMatcher,
|
|
199
|
+
isInclude,
|
|
200
|
+
classMapOutputOptions,
|
|
201
|
+
initConfig,
|
|
202
|
+
getReplaceMap,
|
|
203
|
+
addToUsedBy,
|
|
204
|
+
disabled,
|
|
205
|
+
htmlHandler,
|
|
206
|
+
cssHandler,
|
|
207
|
+
jsHandler,
|
|
208
|
+
preProcessJs
|
|
209
|
+
};
|
|
139
210
|
}
|
|
140
211
|
|
|
141
|
-
const
|
|
142
|
-
const
|
|
143
|
-
|
|
212
|
+
const unplugin = createUnplugin((options = {}) => {
|
|
213
|
+
const { isInclude, initConfig, getReplaceMap, classGenerator, addToUsedBy, classMapOutputOptions, disabled, htmlHandler, cssHandler, jsHandler, preProcessJs } = getOptions(options);
|
|
214
|
+
if (disabled) {
|
|
144
215
|
return {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
classGenerator,
|
|
189
|
-
runtimeSet
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
},
|
|
197
|
-
webpack(compiler) {
|
|
198
|
-
const { NormalModule, Compilation } = compiler.webpack;
|
|
199
|
-
const { ConcatSource } = compiler.webpack.sources;
|
|
200
|
-
function getAssetPath(outputPath, file, abs = true) {
|
|
201
|
-
const fn = abs ? path.resolve : path.relative;
|
|
202
|
-
return fn(compiler.context, path.resolve(outputPath, file));
|
|
216
|
+
name: pluginName
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
return {
|
|
220
|
+
name: pluginName,
|
|
221
|
+
enforce: "pre",
|
|
222
|
+
async buildStart() {
|
|
223
|
+
await initConfig();
|
|
224
|
+
},
|
|
225
|
+
transformInclude(id) {
|
|
226
|
+
return isInclude(id);
|
|
227
|
+
},
|
|
228
|
+
transform(code, id) {
|
|
229
|
+
const replaceMap = getReplaceMap();
|
|
230
|
+
if (id.endsWith(".js") || id.endsWith(".ts") || id.endsWith(".tsx") || id.endsWith(".jsx")) {
|
|
231
|
+
const str = preProcessJs({
|
|
232
|
+
code,
|
|
233
|
+
replaceMap,
|
|
234
|
+
addToUsedBy,
|
|
235
|
+
id
|
|
236
|
+
});
|
|
237
|
+
return str;
|
|
238
|
+
} else {
|
|
239
|
+
for (const [key, value] of replaceMap) {
|
|
240
|
+
code = code.replaceAll(key, value);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return code;
|
|
244
|
+
},
|
|
245
|
+
vite: {
|
|
246
|
+
generateBundle: {
|
|
247
|
+
async handler(options2, bundle) {
|
|
248
|
+
const replaceMap = getReplaceMap();
|
|
249
|
+
const groupedEntries = getGroupedEntries(Object.entries(bundle));
|
|
250
|
+
if (Array.isArray(groupedEntries.css) && groupedEntries.css.length > 0) {
|
|
251
|
+
for (let i = 0; i < groupedEntries.css.length; i++) {
|
|
252
|
+
const [file, cssSource] = groupedEntries.css[i];
|
|
253
|
+
const { css } = await cssHandler(cssSource.source.toString(), {
|
|
254
|
+
file,
|
|
255
|
+
replaceMap,
|
|
256
|
+
classGenerator
|
|
257
|
+
});
|
|
258
|
+
cssSource.source = css;
|
|
203
259
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
},
|
|
264
|
+
webpack(compiler) {
|
|
265
|
+
const { Compilation, sources } = compiler.webpack;
|
|
266
|
+
const { ConcatSource } = sources;
|
|
267
|
+
compiler.hooks.compilation.tap(pluginName, (compilation) => {
|
|
268
|
+
compilation.hooks.processAssets.tapPromise(
|
|
269
|
+
{
|
|
270
|
+
name: pluginName,
|
|
271
|
+
stage: Compilation.PROCESS_ASSETS_STAGE_SUMMARIZE
|
|
272
|
+
},
|
|
273
|
+
async (assets) => {
|
|
274
|
+
const replaceMap = getReplaceMap();
|
|
275
|
+
const groupedEntries = getGroupedEntries(Object.entries(assets));
|
|
276
|
+
if (groupedEntries.js.length > 0) {
|
|
277
|
+
for (let i = 0; i < groupedEntries.js.length; i++) {
|
|
278
|
+
const [file, chunk] = groupedEntries.js[i];
|
|
279
|
+
const code = jsHandler(chunk.source().toString(), {
|
|
280
|
+
replaceMap,
|
|
281
|
+
classGenerator
|
|
282
|
+
}).code;
|
|
283
|
+
if (code) {
|
|
284
|
+
const source = new ConcatSource(code);
|
|
285
|
+
compilation.updateAsset(file, source);
|
|
214
286
|
}
|
|
287
|
+
}
|
|
215
288
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
options: {
|
|
224
|
-
classGenerator,
|
|
225
|
-
getCachedClassSet
|
|
226
|
-
},
|
|
227
|
-
ident: null,
|
|
228
|
-
type: null
|
|
229
|
-
});
|
|
230
|
-
}
|
|
289
|
+
if (groupedEntries.css.length > 0) {
|
|
290
|
+
for (let i = 0; i < groupedEntries.css.length; i++) {
|
|
291
|
+
const [file, cssSource] = groupedEntries.css[i];
|
|
292
|
+
const { css } = await cssHandler(cssSource.source().toString(), {
|
|
293
|
+
replaceMap,
|
|
294
|
+
file,
|
|
295
|
+
classGenerator
|
|
231
296
|
});
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
for (const [file, source] of groupedEntries.css) {
|
|
243
|
-
css.set(file, source);
|
|
244
|
-
}
|
|
245
|
-
for (const [file, source] of groupedEntries.html) {
|
|
246
|
-
html.set(file, source);
|
|
247
|
-
}
|
|
248
|
-
for (const [file, source] of groupedEntries.js) {
|
|
249
|
-
js.set(file, source);
|
|
250
|
-
}
|
|
251
|
-
if (js.size > 0 || css.size > 0 || html.size > 0) {
|
|
252
|
-
outputCachedMap.set(compiler.outputPath, {
|
|
253
|
-
css,
|
|
254
|
-
html,
|
|
255
|
-
js
|
|
256
|
-
});
|
|
257
|
-
}
|
|
258
|
-
return;
|
|
259
|
-
}
|
|
260
|
-
if (groupedEntries.html.length > 0) {
|
|
261
|
-
for (let i = 0; i < groupedEntries.html.length; i++) {
|
|
262
|
-
const [file, asset] = groupedEntries.html[i];
|
|
263
|
-
if (isInclude(file)) {
|
|
264
|
-
const html = htmlHandler(asset.source().toString(), {
|
|
265
|
-
...htmlHandlerOptions,
|
|
266
|
-
classGenerator,
|
|
267
|
-
runtimeSet
|
|
268
|
-
});
|
|
269
|
-
const source = new ConcatSource(html);
|
|
270
|
-
compilation.updateAsset(file, source);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
}
|
|
274
|
-
if (groupedEntries.js.length > 0) {
|
|
275
|
-
for (let i = 0; i < groupedEntries.js.length; i++) {
|
|
276
|
-
const [file, chunk] = groupedEntries.js[i];
|
|
277
|
-
if (isInclude(file)) {
|
|
278
|
-
const code = jsHandler(chunk.source().toString(), {
|
|
279
|
-
...jsHandlerOptions,
|
|
280
|
-
runtimeSet,
|
|
281
|
-
classGenerator
|
|
282
|
-
}).code;
|
|
283
|
-
if (code) {
|
|
284
|
-
const source = new ConcatSource(code);
|
|
285
|
-
compilation.updateAsset(file, source);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
if (groupedEntries.css.length > 0) {
|
|
291
|
-
for (let i = 0; i < groupedEntries.css.length; i++) {
|
|
292
|
-
const [file, css] = groupedEntries.css[i];
|
|
293
|
-
if (isInclude(file)) {
|
|
294
|
-
const newCss = cssHandler(css.source().toString(), {
|
|
295
|
-
...cssHandlerOptions,
|
|
296
|
-
classGenerator,
|
|
297
|
-
runtimeSet
|
|
298
|
-
});
|
|
299
|
-
const source = new ConcatSource(newCss);
|
|
300
|
-
compilation.updateAsset(file, source);
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
for (const [key, { js, html, css }] of outputCachedMap.entries()) {
|
|
305
|
-
if (html.size > 0) {
|
|
306
|
-
for (const [file, asset] of html.entries()) {
|
|
307
|
-
if (isInclude(file)) {
|
|
308
|
-
const html = htmlHandler(asset.source().toString(), {
|
|
309
|
-
...htmlHandlerOptions,
|
|
310
|
-
classGenerator,
|
|
311
|
-
runtimeSet
|
|
312
|
-
});
|
|
313
|
-
overwriteServerSideAsset(key, file, html);
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
html.clear();
|
|
317
|
-
}
|
|
318
|
-
if (js.size > 0) {
|
|
319
|
-
for (const [file, chunk] of js.entries()) {
|
|
320
|
-
if (isInclude(file)) {
|
|
321
|
-
const rawCode = chunk.source().toString();
|
|
322
|
-
const code = jsHandler(rawCode, {
|
|
323
|
-
...jsHandlerOptions,
|
|
324
|
-
runtimeSet,
|
|
325
|
-
classGenerator
|
|
326
|
-
}).code;
|
|
327
|
-
if (code) {
|
|
328
|
-
overwriteServerSideAsset(key, file, code);
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
js.clear();
|
|
333
|
-
}
|
|
334
|
-
if (css.size > 0) {
|
|
335
|
-
for (const [file, style] of css.entries()) {
|
|
336
|
-
if (isInclude(file)) {
|
|
337
|
-
const newCss = cssHandler(style.source().toString(), {
|
|
338
|
-
...cssHandlerOptions,
|
|
339
|
-
classGenerator,
|
|
340
|
-
runtimeSet
|
|
341
|
-
});
|
|
342
|
-
overwriteServerSideAsset(key, file, newCss);
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
css.clear();
|
|
346
|
-
}
|
|
347
|
-
}
|
|
297
|
+
const source = new ConcatSource(css);
|
|
298
|
+
compilation.updateAsset(file, source);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
if (groupedEntries.html.length > 0) {
|
|
302
|
+
for (let i = 0; i < groupedEntries.html.length; i++) {
|
|
303
|
+
const [file, asset] = groupedEntries.html[i];
|
|
304
|
+
const html = htmlHandler(asset.source().toString(), {
|
|
305
|
+
classGenerator,
|
|
306
|
+
replaceMap
|
|
348
307
|
});
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
const entries = Object.entries(classGenerator.newClassMap);
|
|
353
|
-
if (entries.length > 0 && classMapOutputOptions) {
|
|
354
|
-
cacheDump(classMapOutputOptions.filename, entries.map((x) => {
|
|
355
|
-
return [x[0], x[1].name];
|
|
356
|
-
}), classMapOutputOptions.dir);
|
|
308
|
+
const source = new ConcatSource(html);
|
|
309
|
+
compilation.updateAsset(file, source);
|
|
310
|
+
}
|
|
357
311
|
}
|
|
358
|
-
|
|
359
|
-
|
|
312
|
+
}
|
|
313
|
+
);
|
|
314
|
+
});
|
|
315
|
+
},
|
|
316
|
+
writeBundle() {
|
|
317
|
+
const entries = Object.entries(classGenerator.newClassMap);
|
|
318
|
+
if (entries.length > 0 && classMapOutputOptions) {
|
|
319
|
+
cacheDump(
|
|
320
|
+
classMapOutputOptions.filename,
|
|
321
|
+
entries.map((x) => {
|
|
322
|
+
return {
|
|
323
|
+
origin: x[0],
|
|
324
|
+
replacement: x[1].name,
|
|
325
|
+
usedBy: [...x[1].usedBy]
|
|
326
|
+
};
|
|
327
|
+
}),
|
|
328
|
+
classMapOutputOptions.dir
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
};
|
|
360
333
|
});
|
|
361
|
-
const vitePlugin = unplugin.vite;
|
|
362
|
-
const webpackPlugin = unplugin.webpack;
|
|
363
334
|
|
|
364
|
-
export { unplugin
|
|
335
|
+
export { unplugin as default };
|