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