@unocss/webpack 66.5.7 → 66.5.10-beta.1
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.cjs
CHANGED
package/dist/index.mjs
CHANGED
package/dist/rspack.cjs
CHANGED
package/dist/rspack.mjs
CHANGED
|
@@ -22,8 +22,6 @@ const VIRTUAL_ENTRY_ALIAS = [
|
|
|
22
22
|
/^(?:virtual:)?uno(?::(.+))?\.css(\?.*)?$/
|
|
23
23
|
];
|
|
24
24
|
const LAYER_MARK_ALL = "__ALL__";
|
|
25
|
-
const RESOLVED_ID_WITH_QUERY_RE = /[/\\]__uno(_.*?)?\.css(\?.*)?$/;
|
|
26
|
-
const RESOLVED_ID_RE = /[/\\]__uno(?:_(.*?))?\.css$/;
|
|
27
25
|
|
|
28
26
|
function getPath(id) {
|
|
29
27
|
return id.replace(/\?.*$/, "");
|
|
@@ -225,6 +223,22 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
|
|
|
225
223
|
if (tasks[0] === _tasks[0])
|
|
226
224
|
tasks.splice(0, _tasks.length);
|
|
227
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
|
+
}
|
|
228
242
|
return {
|
|
229
243
|
get ready() {
|
|
230
244
|
return ready;
|
|
@@ -254,7 +268,8 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
|
|
|
254
268
|
return root;
|
|
255
269
|
},
|
|
256
270
|
updateRoot,
|
|
257
|
-
getConfigFileList: () => configFileList
|
|
271
|
+
getConfigFileList: () => configFileList,
|
|
272
|
+
getVMPRegexes
|
|
258
273
|
};
|
|
259
274
|
}
|
|
260
275
|
|
|
@@ -263,23 +278,27 @@ function getHash(input, length = 8) {
|
|
|
263
278
|
return hash("sha256", input, "hex").substring(0, length);
|
|
264
279
|
}
|
|
265
280
|
|
|
266
|
-
function resolveId(id, importer) {
|
|
267
|
-
|
|
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)) {
|
|
268
284
|
return id;
|
|
285
|
+
}
|
|
269
286
|
for (const alias of VIRTUAL_ENTRY_ALIAS) {
|
|
270
287
|
const match = id.match(alias);
|
|
271
288
|
if (match) {
|
|
272
|
-
let virtual = match[1] ?
|
|
289
|
+
let virtual = match[1] ? `${prefix}_${match[1]}.css` : `${prefix}.css`;
|
|
273
290
|
virtual += match[2] || "";
|
|
274
291
|
virtual = `/${virtual}`;
|
|
275
292
|
return virtual;
|
|
276
293
|
}
|
|
277
294
|
}
|
|
278
295
|
}
|
|
279
|
-
function resolveLayer(id) {
|
|
296
|
+
async function resolveLayer(ctx, id) {
|
|
297
|
+
const { RESOLVED_ID_RE } = await ctx.getVMPRegexes();
|
|
280
298
|
const match = id.match(RESOLVED_ID_RE);
|
|
281
|
-
if (match)
|
|
299
|
+
if (match) {
|
|
282
300
|
return match[1] || LAYER_MARK_ALL;
|
|
301
|
+
}
|
|
283
302
|
}
|
|
284
303
|
const LAYER_PLACEHOLDER_RE = /#--unocss--\s*\{\s*layer\s*:\s*(.+?)\s*(?:;\s*escape-view\s*:\s*(.+?)\s*)?;?\s*\}/g;
|
|
285
304
|
function getLayerPlaceholder(layer) {
|
|
@@ -323,10 +342,10 @@ function unplugin(configOrPath, defaults) {
|
|
|
323
342
|
const plugin = {
|
|
324
343
|
name: "unocss:webpack",
|
|
325
344
|
enforce: "pre",
|
|
326
|
-
transformInclude(id) {
|
|
327
|
-
return filter("", id) && !id.endsWith(".html") && !RESOLVED_ID_RE.test(id);
|
|
328
|
-
},
|
|
329
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;
|
|
330
349
|
const result = await applyTransformers(ctx, code, id, "pre");
|
|
331
350
|
if (isCssId(id))
|
|
332
351
|
return result;
|
|
@@ -336,8 +355,8 @@ function unplugin(configOrPath, defaults) {
|
|
|
336
355
|
tasks.push(extract(result.code, id));
|
|
337
356
|
return result;
|
|
338
357
|
},
|
|
339
|
-
resolveId(id) {
|
|
340
|
-
const entry = resolveId(id);
|
|
358
|
+
async resolveId(id) {
|
|
359
|
+
const entry = await resolveId(ctx, id);
|
|
341
360
|
if (entry === id)
|
|
342
361
|
return;
|
|
343
362
|
if (entry) {
|
|
@@ -349,16 +368,13 @@ function unplugin(configOrPath, defaults) {
|
|
|
349
368
|
return entry + query;
|
|
350
369
|
}
|
|
351
370
|
},
|
|
352
|
-
loadInclude(id) {
|
|
353
|
-
const layer = getLayer(id);
|
|
354
|
-
return !!layer;
|
|
355
|
-
},
|
|
356
371
|
// serve the placeholders in virtual module
|
|
357
|
-
load(id) {
|
|
358
|
-
const layer = getLayer(id);
|
|
372
|
+
async load(id) {
|
|
373
|
+
const layer = await getLayer(ctx, id);
|
|
374
|
+
if (!layer)
|
|
375
|
+
return;
|
|
359
376
|
const hash = hashes.get(id);
|
|
360
|
-
|
|
361
|
-
return (hash ? getHashPlaceholder(hash) : "") + getLayerPlaceholder(layer);
|
|
377
|
+
return (hash ? getHashPlaceholder(hash) : "") + getLayerPlaceholder(layer);
|
|
362
378
|
},
|
|
363
379
|
webpack(compiler) {
|
|
364
380
|
compiler.hooks.beforeCompile.tapPromise(PLUGIN_NAME, async () => {
|
|
@@ -378,6 +394,7 @@ function unplugin(configOrPath, defaults) {
|
|
|
378
394
|
const files = Object.keys(compilation.assets);
|
|
379
395
|
await flushTasks();
|
|
380
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);
|
|
381
398
|
for (const file of files) {
|
|
382
399
|
if (file === "*")
|
|
383
400
|
return;
|
|
@@ -387,7 +404,7 @@ function unplugin(configOrPath, defaults) {
|
|
|
387
404
|
code = code.replace(HASH_PLACEHOLDER_RE, "");
|
|
388
405
|
code = code.replace(LAYER_PLACEHOLDER_RE, (_, layer, escapeView) => {
|
|
389
406
|
replaced = true;
|
|
390
|
-
const css = layer.trim() === LAYER_MARK_ALL ? result.getLayers(void 0,
|
|
407
|
+
const css = layer.trim() === LAYER_MARK_ALL ? result.getLayers(void 0, resolvedLayers) : result.getLayer(layer) || "";
|
|
391
408
|
escapeCss = escapeCss ?? getCssEscaperForJsContent(escapeView.trim());
|
|
392
409
|
return escapeCss(css);
|
|
393
410
|
});
|
|
@@ -416,27 +433,28 @@ function unplugin(configOrPath, defaults) {
|
|
|
416
433
|
} else {
|
|
417
434
|
virtualModules = Array.from(plugin.__vfsModules);
|
|
418
435
|
}
|
|
419
|
-
|
|
436
|
+
const resolvedLayers = (await Promise.all(Array.from(entries).map((i) => resolveLayer(ctx, i)))).filter((i) => !!i);
|
|
437
|
+
for (const id of virtualModules) {
|
|
420
438
|
let path = decodeURIComponent(id.startsWith(plugin.__virtualModulePrefix) ? id.slice(plugin.__virtualModulePrefix.length) : id);
|
|
421
439
|
path = normalizeAbsolutePath(path);
|
|
422
|
-
const layer = resolveLayer(path);
|
|
440
|
+
const layer = await resolveLayer(ctx, path);
|
|
423
441
|
if (!layer)
|
|
424
|
-
|
|
425
|
-
const code = layer === LAYER_MARK_ALL ? result.getLayers(void 0,
|
|
442
|
+
continue;
|
|
443
|
+
const code = layer === LAYER_MARK_ALL ? result.getLayers(void 0, resolvedLayers) : result.getLayer(layer) || "";
|
|
426
444
|
const hash = getHash(code);
|
|
427
445
|
hashes.set(path, hash);
|
|
428
446
|
plugin.__vfs.writeModule(id, code);
|
|
429
|
-
}
|
|
447
|
+
}
|
|
430
448
|
}
|
|
431
449
|
return plugin;
|
|
432
450
|
});
|
|
433
451
|
}
|
|
434
|
-
function getLayer(id) {
|
|
435
|
-
let layer = resolveLayer(getPath(id));
|
|
452
|
+
async function getLayer(ctx, id) {
|
|
453
|
+
let layer = await resolveLayer(ctx, getPath(id));
|
|
436
454
|
if (!layer) {
|
|
437
|
-
const entry = resolveId(id);
|
|
455
|
+
const entry = await resolveId(ctx, id);
|
|
438
456
|
if (entry)
|
|
439
|
-
layer = resolveLayer(entry);
|
|
457
|
+
layer = await resolveLayer(ctx, entry);
|
|
440
458
|
}
|
|
441
459
|
return layer;
|
|
442
460
|
}
|
|
@@ -33,8 +33,6 @@ const VIRTUAL_ENTRY_ALIAS = [
|
|
|
33
33
|
/^(?:virtual:)?uno(?::(.+))?\.css(\?.*)?$/
|
|
34
34
|
];
|
|
35
35
|
const LAYER_MARK_ALL = "__ALL__";
|
|
36
|
-
const RESOLVED_ID_WITH_QUERY_RE = /[/\\]__uno(_.*?)?\.css(\?.*)?$/;
|
|
37
|
-
const RESOLVED_ID_RE = /[/\\]__uno(?:_(.*?))?\.css$/;
|
|
38
36
|
|
|
39
37
|
function getPath(id) {
|
|
40
38
|
return id.replace(/\?.*$/, "");
|
|
@@ -236,6 +234,22 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
|
|
|
236
234
|
if (tasks[0] === _tasks[0])
|
|
237
235
|
tasks.splice(0, _tasks.length);
|
|
238
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
|
+
}
|
|
239
253
|
return {
|
|
240
254
|
get ready() {
|
|
241
255
|
return ready;
|
|
@@ -265,7 +279,8 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
|
|
|
265
279
|
return root;
|
|
266
280
|
},
|
|
267
281
|
updateRoot,
|
|
268
|
-
getConfigFileList: () => configFileList
|
|
282
|
+
getConfigFileList: () => configFileList,
|
|
283
|
+
getVMPRegexes
|
|
269
284
|
};
|
|
270
285
|
}
|
|
271
286
|
|
|
@@ -274,23 +289,27 @@ function getHash(input, length = 8) {
|
|
|
274
289
|
return hash("sha256", input, "hex").substring(0, length);
|
|
275
290
|
}
|
|
276
291
|
|
|
277
|
-
function resolveId(id, importer) {
|
|
278
|
-
|
|
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)) {
|
|
279
295
|
return id;
|
|
296
|
+
}
|
|
280
297
|
for (const alias of VIRTUAL_ENTRY_ALIAS) {
|
|
281
298
|
const match = id.match(alias);
|
|
282
299
|
if (match) {
|
|
283
|
-
let virtual = match[1] ?
|
|
300
|
+
let virtual = match[1] ? `${prefix}_${match[1]}.css` : `${prefix}.css`;
|
|
284
301
|
virtual += match[2] || "";
|
|
285
302
|
virtual = `/${virtual}`;
|
|
286
303
|
return virtual;
|
|
287
304
|
}
|
|
288
305
|
}
|
|
289
306
|
}
|
|
290
|
-
function resolveLayer(id) {
|
|
307
|
+
async function resolveLayer(ctx, id) {
|
|
308
|
+
const { RESOLVED_ID_RE } = await ctx.getVMPRegexes();
|
|
291
309
|
const match = id.match(RESOLVED_ID_RE);
|
|
292
|
-
if (match)
|
|
310
|
+
if (match) {
|
|
293
311
|
return match[1] || LAYER_MARK_ALL;
|
|
312
|
+
}
|
|
294
313
|
}
|
|
295
314
|
const LAYER_PLACEHOLDER_RE = /#--unocss--\s*\{\s*layer\s*:\s*(.+?)\s*(?:;\s*escape-view\s*:\s*(.+?)\s*)?;?\s*\}/g;
|
|
296
315
|
function getLayerPlaceholder(layer) {
|
|
@@ -334,10 +353,10 @@ function unplugin(configOrPath, defaults) {
|
|
|
334
353
|
const plugin = {
|
|
335
354
|
name: "unocss:webpack",
|
|
336
355
|
enforce: "pre",
|
|
337
|
-
transformInclude(id) {
|
|
338
|
-
return filter("", id) && !id.endsWith(".html") && !RESOLVED_ID_RE.test(id);
|
|
339
|
-
},
|
|
340
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;
|
|
341
360
|
const result = await applyTransformers(ctx, code, id, "pre");
|
|
342
361
|
if (isCssId(id))
|
|
343
362
|
return result;
|
|
@@ -347,8 +366,8 @@ function unplugin(configOrPath, defaults) {
|
|
|
347
366
|
tasks.push(extract(result.code, id));
|
|
348
367
|
return result;
|
|
349
368
|
},
|
|
350
|
-
resolveId(id) {
|
|
351
|
-
const entry = resolveId(id);
|
|
369
|
+
async resolveId(id) {
|
|
370
|
+
const entry = await resolveId(ctx, id);
|
|
352
371
|
if (entry === id)
|
|
353
372
|
return;
|
|
354
373
|
if (entry) {
|
|
@@ -360,16 +379,13 @@ function unplugin(configOrPath, defaults) {
|
|
|
360
379
|
return entry + query;
|
|
361
380
|
}
|
|
362
381
|
},
|
|
363
|
-
loadInclude(id) {
|
|
364
|
-
const layer = getLayer(id);
|
|
365
|
-
return !!layer;
|
|
366
|
-
},
|
|
367
382
|
// serve the placeholders in virtual module
|
|
368
|
-
load(id) {
|
|
369
|
-
const layer = getLayer(id);
|
|
383
|
+
async load(id) {
|
|
384
|
+
const layer = await getLayer(ctx, id);
|
|
385
|
+
if (!layer)
|
|
386
|
+
return;
|
|
370
387
|
const hash = hashes.get(id);
|
|
371
|
-
|
|
372
|
-
return (hash ? getHashPlaceholder(hash) : "") + getLayerPlaceholder(layer);
|
|
388
|
+
return (hash ? getHashPlaceholder(hash) : "") + getLayerPlaceholder(layer);
|
|
373
389
|
},
|
|
374
390
|
webpack(compiler) {
|
|
375
391
|
compiler.hooks.beforeCompile.tapPromise(PLUGIN_NAME, async () => {
|
|
@@ -389,6 +405,7 @@ function unplugin(configOrPath, defaults) {
|
|
|
389
405
|
const files = Object.keys(compilation.assets);
|
|
390
406
|
await flushTasks();
|
|
391
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);
|
|
392
409
|
for (const file of files) {
|
|
393
410
|
if (file === "*")
|
|
394
411
|
return;
|
|
@@ -398,7 +415,7 @@ function unplugin(configOrPath, defaults) {
|
|
|
398
415
|
code = code.replace(HASH_PLACEHOLDER_RE, "");
|
|
399
416
|
code = code.replace(LAYER_PLACEHOLDER_RE, (_, layer, escapeView) => {
|
|
400
417
|
replaced = true;
|
|
401
|
-
const css = layer.trim() === LAYER_MARK_ALL ? result.getLayers(void 0,
|
|
418
|
+
const css = layer.trim() === LAYER_MARK_ALL ? result.getLayers(void 0, resolvedLayers) : result.getLayer(layer) || "";
|
|
402
419
|
escapeCss = escapeCss ?? getCssEscaperForJsContent(escapeView.trim());
|
|
403
420
|
return escapeCss(css);
|
|
404
421
|
});
|
|
@@ -427,27 +444,28 @@ function unplugin(configOrPath, defaults) {
|
|
|
427
444
|
} else {
|
|
428
445
|
virtualModules = Array.from(plugin.__vfsModules);
|
|
429
446
|
}
|
|
430
|
-
|
|
447
|
+
const resolvedLayers = (await Promise.all(Array.from(entries).map((i) => resolveLayer(ctx, i)))).filter((i) => !!i);
|
|
448
|
+
for (const id of virtualModules) {
|
|
431
449
|
let path = decodeURIComponent(id.startsWith(plugin.__virtualModulePrefix) ? id.slice(plugin.__virtualModulePrefix.length) : id);
|
|
432
450
|
path = normalizeAbsolutePath(path);
|
|
433
|
-
const layer = resolveLayer(path);
|
|
451
|
+
const layer = await resolveLayer(ctx, path);
|
|
434
452
|
if (!layer)
|
|
435
|
-
|
|
436
|
-
const code = layer === LAYER_MARK_ALL ? result.getLayers(void 0,
|
|
453
|
+
continue;
|
|
454
|
+
const code = layer === LAYER_MARK_ALL ? result.getLayers(void 0, resolvedLayers) : result.getLayer(layer) || "";
|
|
437
455
|
const hash = getHash(code);
|
|
438
456
|
hashes.set(path, hash);
|
|
439
457
|
plugin.__vfs.writeModule(id, code);
|
|
440
|
-
}
|
|
458
|
+
}
|
|
441
459
|
}
|
|
442
460
|
return plugin;
|
|
443
461
|
});
|
|
444
462
|
}
|
|
445
|
-
function getLayer(id) {
|
|
446
|
-
let layer = resolveLayer(getPath(id));
|
|
463
|
+
async function getLayer(ctx, id) {
|
|
464
|
+
let layer = await resolveLayer(ctx, getPath(id));
|
|
447
465
|
if (!layer) {
|
|
448
|
-
const entry = resolveId(id);
|
|
466
|
+
const entry = await resolveId(ctx, id);
|
|
449
467
|
if (entry)
|
|
450
|
-
layer = resolveLayer(entry);
|
|
468
|
+
layer = await resolveLayer(ctx, entry);
|
|
451
469
|
}
|
|
452
470
|
return layer;
|
|
453
471
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/webpack",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "66.5.
|
|
4
|
+
"version": "66.5.10-beta.1",
|
|
5
5
|
"description": "The Webpack plugin for UnoCSS",
|
|
6
6
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -68,8 +68,8 @@
|
|
|
68
68
|
"unplugin": "^2.3.10",
|
|
69
69
|
"unplugin-utils": "^0.3.1",
|
|
70
70
|
"webpack-sources": "^3.3.3",
|
|
71
|
-
"@unocss/config": "66.5.
|
|
72
|
-
"@unocss/core": "66.5.
|
|
71
|
+
"@unocss/config": "66.5.10-beta.1",
|
|
72
|
+
"@unocss/core": "66.5.10-beta.1"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"@types/webpack": "^5.28.5",
|