@unocss/webpack 66.5.10 → 66.5.11
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/dist/index-CgVajxkl.d.cts +961 -0
- package/dist/index-DLa_c6IJ.d.mts +961 -0
- package/dist/index.cjs +7 -18
- package/dist/index.d.cts +2 -15
- package/dist/index.d.mts +2 -15
- package/dist/index.mjs +5 -16
- package/dist/rspack.cjs +5 -18
- package/dist/rspack.d.cts +4 -5
- package/dist/rspack.d.mts +4 -5
- package/dist/rspack.mjs +5 -16
- package/dist/unplugin-BuJ92w8F.mjs +431 -0
- package/dist/unplugin-DecJv6sA.cjs +469 -0
- package/package.json +10 -10
- package/dist/index.d.ts +0 -15
- package/dist/rspack.d.ts +0 -7
- package/dist/shared/webpack.CM0t2xuW.mjs +0 -468
- package/dist/shared/webpack.CUaiXpSS.cjs +0 -479
|
@@ -1,479 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const node_path = require('node:path');
|
|
4
|
-
const process = require('node:process');
|
|
5
|
-
const fs = require('node:fs/promises');
|
|
6
|
-
const tinyglobby = require('tinyglobby');
|
|
7
|
-
const remapping = require('@jridgewell/remapping');
|
|
8
|
-
const MagicString = require('magic-string');
|
|
9
|
-
const core = require('@unocss/core');
|
|
10
|
-
const config = require('@unocss/config');
|
|
11
|
-
const unpluginUtils = require('unplugin-utils');
|
|
12
|
-
const crypto = require('node:crypto');
|
|
13
|
-
require('pathe');
|
|
14
|
-
const unplugin$1 = require('unplugin');
|
|
15
|
-
const WebpackSources = require('webpack-sources');
|
|
16
|
-
|
|
17
|
-
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
18
|
-
|
|
19
|
-
const process__default = /*#__PURE__*/_interopDefaultCompat(process);
|
|
20
|
-
const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
|
|
21
|
-
const remapping__default = /*#__PURE__*/_interopDefaultCompat(remapping);
|
|
22
|
-
const MagicString__default = /*#__PURE__*/_interopDefaultCompat(MagicString);
|
|
23
|
-
const crypto__default = /*#__PURE__*/_interopDefaultCompat(crypto);
|
|
24
|
-
const WebpackSources__default = /*#__PURE__*/_interopDefaultCompat(WebpackSources);
|
|
25
|
-
|
|
26
|
-
const INCLUDE_COMMENT = "@unocss-include";
|
|
27
|
-
const IGNORE_COMMENT = "@unocss-ignore";
|
|
28
|
-
const CSS_PLACEHOLDER = "@unocss-placeholder";
|
|
29
|
-
const SKIP_START_COMMENT = "@unocss-skip-start";
|
|
30
|
-
const SKIP_END_COMMENT = "@unocss-skip-end";
|
|
31
|
-
const SKIP_COMMENT_RE = new RegExp(`(//\\s*?${SKIP_START_COMMENT}\\s*?|\\/\\*\\s*?${SKIP_START_COMMENT}\\s*?\\*\\/|<!--\\s*?${SKIP_START_COMMENT}\\s*?-->)[\\s\\S]*?(//\\s*?${SKIP_END_COMMENT}\\s*?|\\/\\*\\s*?${SKIP_END_COMMENT}\\s*?\\*\\/|<!--\\s*?${SKIP_END_COMMENT}\\s*?-->)`, "g");
|
|
32
|
-
const VIRTUAL_ENTRY_ALIAS = [
|
|
33
|
-
/^(?:virtual:)?uno(?::(.+))?\.css(\?.*)?$/
|
|
34
|
-
];
|
|
35
|
-
const LAYER_MARK_ALL = "__ALL__";
|
|
36
|
-
|
|
37
|
-
function getPath(id) {
|
|
38
|
-
return id.replace(/\?.*$/, "");
|
|
39
|
-
}
|
|
40
|
-
function isCssId(id) {
|
|
41
|
-
return core.cssIdRE.test(id);
|
|
42
|
-
}
|
|
43
|
-
function hash$1(str) {
|
|
44
|
-
let i;
|
|
45
|
-
let l;
|
|
46
|
-
let hval = 2166136261;
|
|
47
|
-
for (i = 0, l = str.length; i < l; i++) {
|
|
48
|
-
hval ^= str.charCodeAt(i);
|
|
49
|
-
hval += (hval << 1) + (hval << 4) + (hval << 7) + (hval << 8) + (hval << 24);
|
|
50
|
-
}
|
|
51
|
-
return `00000${(hval >>> 0).toString(36)}`.slice(-6);
|
|
52
|
-
}
|
|
53
|
-
function transformSkipCode(code, map, SKIP_RULES_RE, keyFlag) {
|
|
54
|
-
for (const item of Array.from(code.matchAll(SKIP_RULES_RE))) {
|
|
55
|
-
if (item != null) {
|
|
56
|
-
const matched = item[0];
|
|
57
|
-
const withHashKey = `${keyFlag}${hash$1(matched)}`;
|
|
58
|
-
map.set(withHashKey, matched);
|
|
59
|
-
code = code.replace(matched, withHashKey);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return code;
|
|
63
|
-
}
|
|
64
|
-
function restoreSkipCode(code, map) {
|
|
65
|
-
for (const [withHashKey, matched] of map.entries())
|
|
66
|
-
code = code.replaceAll(withHashKey, matched);
|
|
67
|
-
return code;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
async function applyTransformers(ctx, original, id, enforce = "default") {
|
|
71
|
-
if (original.includes(IGNORE_COMMENT))
|
|
72
|
-
return;
|
|
73
|
-
const transformers = (ctx.uno.config.transformers || []).filter((i) => (i.enforce || "default") === enforce);
|
|
74
|
-
if (!transformers.length)
|
|
75
|
-
return;
|
|
76
|
-
const skipMap = /* @__PURE__ */ new Map();
|
|
77
|
-
let code = original;
|
|
78
|
-
let s = new MagicString__default(transformSkipCode(code, skipMap, SKIP_COMMENT_RE, "@unocss-skip-placeholder-"));
|
|
79
|
-
const maps = [];
|
|
80
|
-
for (const t of transformers) {
|
|
81
|
-
if (t.idFilter) {
|
|
82
|
-
if (!t.idFilter(id))
|
|
83
|
-
continue;
|
|
84
|
-
} else if (!ctx.filter(code, id)) {
|
|
85
|
-
continue;
|
|
86
|
-
}
|
|
87
|
-
await t.transform(s, id, ctx);
|
|
88
|
-
if (s.hasChanged()) {
|
|
89
|
-
code = restoreSkipCode(s.toString(), skipMap);
|
|
90
|
-
maps.push(s.generateMap({ hires: true, source: id }));
|
|
91
|
-
s = new MagicString__default(code);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
if (code !== original) {
|
|
95
|
-
return {
|
|
96
|
-
code,
|
|
97
|
-
map: remapping__default(maps, (_, ctx2) => {
|
|
98
|
-
ctx2.content = code;
|
|
99
|
-
return null;
|
|
100
|
-
})
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
async function setupContentExtractor(ctx, shouldWatch = false) {
|
|
106
|
-
const { content } = await ctx.getConfig();
|
|
107
|
-
const { extract, tasks, root, filter } = ctx;
|
|
108
|
-
if (content?.inline) {
|
|
109
|
-
await Promise.all(
|
|
110
|
-
content.inline.map(async (c, idx) => {
|
|
111
|
-
if (typeof c === "function")
|
|
112
|
-
c = await c();
|
|
113
|
-
if (typeof c === "string")
|
|
114
|
-
c = { code: c };
|
|
115
|
-
return extract(c.code, c.id ?? `__plain_content_${idx}__`);
|
|
116
|
-
})
|
|
117
|
-
);
|
|
118
|
-
}
|
|
119
|
-
if (content?.filesystem) {
|
|
120
|
-
const files = await tinyglobby.glob(content.filesystem, { cwd: root, expandDirectories: false });
|
|
121
|
-
async function extractFile(file) {
|
|
122
|
-
file = node_path.isAbsolute(file) ? file : node_path.resolve(root, file);
|
|
123
|
-
const code = await fs__default.readFile(file, "utf-8");
|
|
124
|
-
if (!filter(code, file))
|
|
125
|
-
return;
|
|
126
|
-
const preTransform = await applyTransformers(ctx, code, file, "pre");
|
|
127
|
-
const defaultTransform = await applyTransformers(ctx, preTransform?.code || code, file);
|
|
128
|
-
await applyTransformers(ctx, defaultTransform?.code || preTransform?.code || code, file, "post");
|
|
129
|
-
return await extract(preTransform?.code || code, file);
|
|
130
|
-
}
|
|
131
|
-
if (shouldWatch) {
|
|
132
|
-
const { watch } = await import('chokidar');
|
|
133
|
-
const ignored = ["**/{.git,node_modules}/**"];
|
|
134
|
-
const watcher = watch(files, {
|
|
135
|
-
ignorePermissionErrors: true,
|
|
136
|
-
ignored,
|
|
137
|
-
cwd: root,
|
|
138
|
-
ignoreInitial: true
|
|
139
|
-
});
|
|
140
|
-
watcher.on("all", (type, file) => {
|
|
141
|
-
if (type === "add" || type === "change") {
|
|
142
|
-
const absolutePath = node_path.resolve(root, file);
|
|
143
|
-
tasks.push(extractFile(absolutePath));
|
|
144
|
-
}
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
await Promise.all(files.map(extractFile));
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
const defaultPipelineExclude = [core.cssIdRE];
|
|
152
|
-
const defaultPipelineInclude = [/\.(vue|svelte|[jt]sx|vine.ts|mdx?|astro|elm|php|phtml|marko|html)($|\?)/];
|
|
153
|
-
|
|
154
|
-
function deprecationCheck(config) {
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
function createContext(configOrPath, defaults = {}, extraConfigSources = [], resolveConfigResult = () => {
|
|
158
|
-
}) {
|
|
159
|
-
let root = process__default.cwd();
|
|
160
|
-
let rawConfig = {};
|
|
161
|
-
let configFileList = [];
|
|
162
|
-
let uno;
|
|
163
|
-
const _uno = core.createGenerator(rawConfig, defaults).then((r) => {
|
|
164
|
-
uno = r;
|
|
165
|
-
return r;
|
|
166
|
-
});
|
|
167
|
-
let rollupFilter = unpluginUtils.createFilter(
|
|
168
|
-
defaultPipelineInclude,
|
|
169
|
-
defaultPipelineExclude,
|
|
170
|
-
{ resolve: typeof configOrPath === "string" ? configOrPath : root }
|
|
171
|
-
);
|
|
172
|
-
const invalidations = [];
|
|
173
|
-
const reloadListeners = [];
|
|
174
|
-
const modules = new core.BetterMap();
|
|
175
|
-
const tokens = /* @__PURE__ */ new Set();
|
|
176
|
-
const tasks = [];
|
|
177
|
-
const affectedModules = /* @__PURE__ */ new Set();
|
|
178
|
-
const loadConfig = config.createRecoveryConfigLoader();
|
|
179
|
-
let ready = reloadConfig();
|
|
180
|
-
async function reloadConfig() {
|
|
181
|
-
await _uno;
|
|
182
|
-
const result = await loadConfig(root, configOrPath, extraConfigSources, defaults);
|
|
183
|
-
resolveConfigResult(result);
|
|
184
|
-
deprecationCheck(result.config);
|
|
185
|
-
rawConfig = result.config;
|
|
186
|
-
configFileList = result.sources;
|
|
187
|
-
await uno.setConfig(rawConfig);
|
|
188
|
-
uno.config.envMode = "dev";
|
|
189
|
-
rollupFilter = rawConfig.content?.pipeline === false ? () => false : unpluginUtils.createFilter(
|
|
190
|
-
rawConfig.content?.pipeline?.include || defaultPipelineInclude,
|
|
191
|
-
rawConfig.content?.pipeline?.exclude || defaultPipelineExclude,
|
|
192
|
-
{ resolve: typeof configOrPath === "string" ? configOrPath : root }
|
|
193
|
-
);
|
|
194
|
-
tokens.clear();
|
|
195
|
-
await Promise.all(modules.map((code, id) => uno.applyExtractors(code.replace(SKIP_COMMENT_RE, ""), id, tokens)));
|
|
196
|
-
invalidate();
|
|
197
|
-
dispatchReload();
|
|
198
|
-
return result;
|
|
199
|
-
}
|
|
200
|
-
async function updateRoot(newRoot) {
|
|
201
|
-
if (newRoot !== root) {
|
|
202
|
-
root = newRoot;
|
|
203
|
-
ready = reloadConfig();
|
|
204
|
-
}
|
|
205
|
-
return await ready;
|
|
206
|
-
}
|
|
207
|
-
function invalidate() {
|
|
208
|
-
invalidations.forEach((cb) => cb());
|
|
209
|
-
}
|
|
210
|
-
function dispatchReload() {
|
|
211
|
-
reloadListeners.forEach((cb) => cb());
|
|
212
|
-
}
|
|
213
|
-
async function extract(code, id) {
|
|
214
|
-
const uno2 = await _uno;
|
|
215
|
-
if (id)
|
|
216
|
-
modules.set(id, code);
|
|
217
|
-
const len = tokens.size;
|
|
218
|
-
await uno2.applyExtractors(code.replace(SKIP_COMMENT_RE, ""), id, tokens);
|
|
219
|
-
if (tokens.size > len)
|
|
220
|
-
invalidate();
|
|
221
|
-
}
|
|
222
|
-
function filter(code, id) {
|
|
223
|
-
if (code.includes(IGNORE_COMMENT))
|
|
224
|
-
return false;
|
|
225
|
-
return code.includes(INCLUDE_COMMENT) || code.includes(CSS_PLACEHOLDER) || rollupFilter(id.replace(/\?v=\w+$/, ""));
|
|
226
|
-
}
|
|
227
|
-
async function getConfig() {
|
|
228
|
-
await ready;
|
|
229
|
-
return rawConfig;
|
|
230
|
-
}
|
|
231
|
-
async function flushTasks() {
|
|
232
|
-
const _tasks = [...tasks];
|
|
233
|
-
await Promise.all(_tasks);
|
|
234
|
-
if (tasks[0] === _tasks[0])
|
|
235
|
-
tasks.splice(0, _tasks.length);
|
|
236
|
-
}
|
|
237
|
-
const vmpCache = /* @__PURE__ */ new Map();
|
|
238
|
-
async function getVMPRegexes() {
|
|
239
|
-
const config = await getConfig();
|
|
240
|
-
const prefix = config.virtualModulePrefix || "__uno";
|
|
241
|
-
if (vmpCache.has(prefix))
|
|
242
|
-
return vmpCache.get(prefix);
|
|
243
|
-
const RESOLVED_ID_WITH_QUERY_RE = new RegExp(`[/\\\\]${prefix}(_.*?)?\\.css(\\?.*)?$`);
|
|
244
|
-
const RESOLVED_ID_RE = new RegExp(`[/\\\\]${prefix}(?:_(.*?))?.css$`);
|
|
245
|
-
const regexes = {
|
|
246
|
-
prefix,
|
|
247
|
-
RESOLVED_ID_WITH_QUERY_RE,
|
|
248
|
-
RESOLVED_ID_RE
|
|
249
|
-
};
|
|
250
|
-
vmpCache.set(prefix, regexes);
|
|
251
|
-
return regexes;
|
|
252
|
-
}
|
|
253
|
-
return {
|
|
254
|
-
get ready() {
|
|
255
|
-
return ready;
|
|
256
|
-
},
|
|
257
|
-
tokens,
|
|
258
|
-
modules,
|
|
259
|
-
affectedModules,
|
|
260
|
-
tasks,
|
|
261
|
-
flushTasks,
|
|
262
|
-
invalidate,
|
|
263
|
-
onInvalidate(fn) {
|
|
264
|
-
invalidations.push(fn);
|
|
265
|
-
},
|
|
266
|
-
filter,
|
|
267
|
-
reloadConfig,
|
|
268
|
-
onReload(fn) {
|
|
269
|
-
reloadListeners.push(fn);
|
|
270
|
-
},
|
|
271
|
-
get uno() {
|
|
272
|
-
if (!uno)
|
|
273
|
-
throw new Error("Run `await context.ready` before accessing `context.uno`");
|
|
274
|
-
return uno;
|
|
275
|
-
},
|
|
276
|
-
extract,
|
|
277
|
-
getConfig,
|
|
278
|
-
get root() {
|
|
279
|
-
return root;
|
|
280
|
-
},
|
|
281
|
-
updateRoot,
|
|
282
|
-
getConfigFileList: () => configFileList,
|
|
283
|
-
getVMPRegexes
|
|
284
|
-
};
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
const hash = crypto__default.hash ?? ((algorithm, data, outputEncoding) => crypto__default.createHash(algorithm).update(data).digest(outputEncoding));
|
|
288
|
-
function getHash(input, length = 8) {
|
|
289
|
-
return hash("sha256", input, "hex").substring(0, length);
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
async function resolveId(ctx, id, importer) {
|
|
293
|
-
const { RESOLVED_ID_WITH_QUERY_RE, prefix } = await ctx.getVMPRegexes();
|
|
294
|
-
if (id.match(RESOLVED_ID_WITH_QUERY_RE)) {
|
|
295
|
-
return id;
|
|
296
|
-
}
|
|
297
|
-
for (const alias of VIRTUAL_ENTRY_ALIAS) {
|
|
298
|
-
const match = id.match(alias);
|
|
299
|
-
if (match) {
|
|
300
|
-
let virtual = match[1] ? `${prefix}_${match[1]}.css` : `${prefix}.css`;
|
|
301
|
-
virtual += match[2] || "";
|
|
302
|
-
virtual = `/${virtual}`;
|
|
303
|
-
return virtual;
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
async function resolveLayer(ctx, id) {
|
|
308
|
-
const { RESOLVED_ID_RE } = await ctx.getVMPRegexes();
|
|
309
|
-
const match = id.match(RESOLVED_ID_RE);
|
|
310
|
-
if (match) {
|
|
311
|
-
return match[1] || LAYER_MARK_ALL;
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
const LAYER_PLACEHOLDER_RE = /#--unocss--\s*\{\s*layer\s*:\s*(.+?)\s*(?:;\s*escape-view\s*:\s*(.+?)\s*)?;?\s*\}/g;
|
|
315
|
-
function getLayerPlaceholder(layer) {
|
|
316
|
-
return `#--unocss--{layer:${layer};escape-view:\\"\\'\\\`\\\\}`;
|
|
317
|
-
}
|
|
318
|
-
function getCssEscaperForJsContent(view) {
|
|
319
|
-
if (!view)
|
|
320
|
-
return (css) => css;
|
|
321
|
-
const prefix = {};
|
|
322
|
-
const escapeViewRe = /(\\*)\\(["'`\\])/g;
|
|
323
|
-
view.trim().replace(escapeViewRe, (_, bs, char) => {
|
|
324
|
-
prefix[char] = bs.replace(/\\\\/g, "\\");
|
|
325
|
-
return "";
|
|
326
|
-
});
|
|
327
|
-
return (css) => css.replace(/["'`\\]/g, (v) => {
|
|
328
|
-
return (prefix[v] || "") + v;
|
|
329
|
-
});
|
|
330
|
-
}
|
|
331
|
-
const HASH_PLACEHOLDER_RE = /#--unocss-hash--\s*\{\s*content\s*:\s*\\*"([^\\"]+)\\*";?\s*\}/g;
|
|
332
|
-
function getHashPlaceholder(hash) {
|
|
333
|
-
return `#--unocss-hash--{content:"${hash}"}`;
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
const PLUGIN_NAME = "unocss:webpack";
|
|
337
|
-
const UPDATE_DEBOUNCE = 10;
|
|
338
|
-
function unplugin(configOrPath, defaults) {
|
|
339
|
-
return unplugin$1.createUnplugin(() => {
|
|
340
|
-
const ctx = createContext(configOrPath, {
|
|
341
|
-
envMode: process__default.env.NODE_ENV === "development" ? "dev" : "build",
|
|
342
|
-
...defaults
|
|
343
|
-
});
|
|
344
|
-
const { tokens, filter, extract, onInvalidate, tasks, flushTasks } = ctx;
|
|
345
|
-
let timer;
|
|
346
|
-
onInvalidate(() => {
|
|
347
|
-
clearTimeout(timer);
|
|
348
|
-
timer = setTimeout(updateModules, UPDATE_DEBOUNCE);
|
|
349
|
-
});
|
|
350
|
-
tasks.push(setupContentExtractor(ctx, typeof configOrPath === "object" && configOrPath?.watch));
|
|
351
|
-
const entries = /* @__PURE__ */ new Set();
|
|
352
|
-
const hashes = /* @__PURE__ */ new Map();
|
|
353
|
-
const plugin = {
|
|
354
|
-
name: "unocss:webpack",
|
|
355
|
-
enforce: "pre",
|
|
356
|
-
async transform(code, id) {
|
|
357
|
-
const { RESOLVED_ID_RE } = await ctx.getVMPRegexes();
|
|
358
|
-
if (RESOLVED_ID_RE.test(id) || !filter("", id) || id.endsWith(".html"))
|
|
359
|
-
return;
|
|
360
|
-
const result = await applyTransformers(ctx, code, id, "pre");
|
|
361
|
-
if (isCssId(id))
|
|
362
|
-
return result;
|
|
363
|
-
if (result == null)
|
|
364
|
-
tasks.push(extract(code, id));
|
|
365
|
-
else
|
|
366
|
-
tasks.push(extract(result.code, id));
|
|
367
|
-
return result;
|
|
368
|
-
},
|
|
369
|
-
async resolveId(id) {
|
|
370
|
-
const entry = await resolveId(ctx, id);
|
|
371
|
-
if (entry === id)
|
|
372
|
-
return;
|
|
373
|
-
if (entry) {
|
|
374
|
-
let query = "";
|
|
375
|
-
const queryIndex = id.indexOf("?");
|
|
376
|
-
if (queryIndex >= 0)
|
|
377
|
-
query = id.slice(queryIndex);
|
|
378
|
-
entries.add(entry);
|
|
379
|
-
return entry + query;
|
|
380
|
-
}
|
|
381
|
-
},
|
|
382
|
-
// serve the placeholders in virtual module
|
|
383
|
-
async load(id) {
|
|
384
|
-
const layer = await getLayer(ctx, id);
|
|
385
|
-
if (!layer)
|
|
386
|
-
return;
|
|
387
|
-
const hash = hashes.get(id);
|
|
388
|
-
return (hash ? getHashPlaceholder(hash) : "") + getLayerPlaceholder(layer);
|
|
389
|
-
},
|
|
390
|
-
webpack(compiler) {
|
|
391
|
-
compiler.hooks.beforeCompile.tapPromise(PLUGIN_NAME, async () => {
|
|
392
|
-
await ctx.ready;
|
|
393
|
-
const nonPreTransformers = ctx.uno.config.transformers?.filter((i) => i.enforce !== "pre");
|
|
394
|
-
if (nonPreTransformers?.length) {
|
|
395
|
-
console.warn(
|
|
396
|
-
// eslint-disable-next-line prefer-template
|
|
397
|
-
'[unocss] webpack integration only supports "pre" enforce transformers currently.the following transformers will be ignored\n' + nonPreTransformers.map((i) => ` - ${i.name}`).join("\n")
|
|
398
|
-
);
|
|
399
|
-
}
|
|
400
|
-
});
|
|
401
|
-
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
|
|
402
|
-
const optimizeAssetsHook = compilation.hooks.processAssets || compilation.hooks.optimizeAssets;
|
|
403
|
-
optimizeAssetsHook.tapPromise(PLUGIN_NAME, async () => {
|
|
404
|
-
await ctx.ready;
|
|
405
|
-
const files = Object.keys(compilation.assets);
|
|
406
|
-
await flushTasks();
|
|
407
|
-
const result = await ctx.uno.generate(tokens, { minify: true });
|
|
408
|
-
const resolvedLayers = (await Promise.all(Array.from(entries).map((i) => resolveLayer(ctx, i)))).filter((i) => !!i);
|
|
409
|
-
for (const file of files) {
|
|
410
|
-
if (file === "*")
|
|
411
|
-
return;
|
|
412
|
-
let code = compilation.assets[file].source().toString();
|
|
413
|
-
let escapeCss;
|
|
414
|
-
let replaced = false;
|
|
415
|
-
code = code.replace(HASH_PLACEHOLDER_RE, "");
|
|
416
|
-
code = code.replace(LAYER_PLACEHOLDER_RE, (_, layer, escapeView) => {
|
|
417
|
-
replaced = true;
|
|
418
|
-
const css = layer.trim() === LAYER_MARK_ALL ? result.getLayers(void 0, resolvedLayers) : result.getLayer(layer) || "";
|
|
419
|
-
escapeCss = escapeCss ?? getCssEscaperForJsContent(escapeView.trim());
|
|
420
|
-
return escapeCss(css);
|
|
421
|
-
});
|
|
422
|
-
if (replaced)
|
|
423
|
-
compilation.assets[file] = new WebpackSources__default.SourceMapSource(code, file, compilation.assets[file].map());
|
|
424
|
-
}
|
|
425
|
-
});
|
|
426
|
-
});
|
|
427
|
-
},
|
|
428
|
-
get rspack() {
|
|
429
|
-
return this.webpack;
|
|
430
|
-
}
|
|
431
|
-
};
|
|
432
|
-
let lastTokenSize = tokens.size;
|
|
433
|
-
async function updateModules() {
|
|
434
|
-
if (!plugin.__vfsModules)
|
|
435
|
-
return;
|
|
436
|
-
await flushTasks();
|
|
437
|
-
const result = await ctx.uno.generate(tokens);
|
|
438
|
-
if (lastTokenSize === tokens.size)
|
|
439
|
-
return;
|
|
440
|
-
lastTokenSize = tokens.size;
|
|
441
|
-
let virtualModules;
|
|
442
|
-
if (plugin.__vfsModules instanceof Map) {
|
|
443
|
-
virtualModules = Array.from(plugin.__vfsModules.keys());
|
|
444
|
-
} else {
|
|
445
|
-
virtualModules = Array.from(plugin.__vfsModules);
|
|
446
|
-
}
|
|
447
|
-
const resolvedLayers = (await Promise.all(Array.from(entries).map((i) => resolveLayer(ctx, i)))).filter((i) => !!i);
|
|
448
|
-
for (const id of virtualModules) {
|
|
449
|
-
let path = decodeURIComponent(id.startsWith(plugin.__virtualModulePrefix) ? id.slice(plugin.__virtualModulePrefix.length) : id);
|
|
450
|
-
path = normalizeAbsolutePath(path);
|
|
451
|
-
const layer = await resolveLayer(ctx, path);
|
|
452
|
-
if (!layer)
|
|
453
|
-
continue;
|
|
454
|
-
const code = layer === LAYER_MARK_ALL ? result.getLayers(void 0, resolvedLayers) : result.getLayer(layer) || "";
|
|
455
|
-
const hash = getHash(code);
|
|
456
|
-
hashes.set(path, hash);
|
|
457
|
-
plugin.__vfs.writeModule(id, code);
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
return plugin;
|
|
461
|
-
});
|
|
462
|
-
}
|
|
463
|
-
async function getLayer(ctx, id) {
|
|
464
|
-
let layer = await resolveLayer(ctx, getPath(id));
|
|
465
|
-
if (!layer) {
|
|
466
|
-
const entry = await resolveId(ctx, id);
|
|
467
|
-
if (entry)
|
|
468
|
-
layer = await resolveLayer(ctx, entry);
|
|
469
|
-
}
|
|
470
|
-
return layer;
|
|
471
|
-
}
|
|
472
|
-
function normalizeAbsolutePath(path) {
|
|
473
|
-
if (node_path.isAbsolute(path))
|
|
474
|
-
return node_path.normalize(path);
|
|
475
|
-
else
|
|
476
|
-
return path;
|
|
477
|
-
}
|
|
478
|
-
|
|
479
|
-
exports.unplugin = unplugin;
|