@unocss/vite 0.39.0 → 0.39.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/dist/index.cjs +38 -25
- package/dist/index.mjs +38 -25
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -29,17 +29,16 @@ function resolveId(id) {
|
|
|
29
29
|
for (const alias of VIRTUAL_ENTRY_ALIAS) {
|
|
30
30
|
const match = id.match(alias);
|
|
31
31
|
if (match) {
|
|
32
|
-
return match[1] ? {
|
|
33
|
-
id: `/__uno_${match[1]}.css`,
|
|
34
|
-
layer: match[1]
|
|
35
|
-
} : {
|
|
36
|
-
id: "/__uno.css",
|
|
37
|
-
layer: LAYER_MARK_ALL
|
|
38
|
-
};
|
|
32
|
+
return match[1] ? `/__uno_${match[1]}.css` : "/__uno.css";
|
|
39
33
|
}
|
|
40
34
|
}
|
|
41
35
|
}
|
|
42
|
-
const RESOLVED_ID_RE = /\/__uno(_.*?)?\.css$/;
|
|
36
|
+
const RESOLVED_ID_RE = /\/__uno(?:(_.*?))?\.css$/;
|
|
37
|
+
function resolveLayer(id) {
|
|
38
|
+
const match = id.match(RESOLVED_ID_RE);
|
|
39
|
+
if (match)
|
|
40
|
+
return match[1] || LAYER_MARK_ALL;
|
|
41
|
+
}
|
|
43
42
|
const LAYER_PLACEHOLDER_RE = /(\\?")?#--unocss--\s*{\s*layer\s*:\s*(.+?);?\s*}/g;
|
|
44
43
|
function getLayerPlaceholder(layer) {
|
|
45
44
|
return `#--unocss--{layer:${layer}}`;
|
|
@@ -60,6 +59,7 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
|
|
|
60
59
|
const uno = core.createGenerator(rawConfig, defaults);
|
|
61
60
|
let rollupFilter = pluginutils.createFilter(defaultInclude, defaultExclude);
|
|
62
61
|
const invalidations = [];
|
|
62
|
+
const reloadListeners = [];
|
|
63
63
|
const modules = new core.BetterMap();
|
|
64
64
|
const tokens = /* @__PURE__ */ new Set();
|
|
65
65
|
let ready = reloadConfig();
|
|
@@ -73,6 +73,7 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
|
|
|
73
73
|
tokens.clear();
|
|
74
74
|
await Promise.all(modules.map((code, id) => uno.applyExtractors(code, id, tokens)));
|
|
75
75
|
invalidate();
|
|
76
|
+
dispatchReload();
|
|
76
77
|
const presets = /* @__PURE__ */ new Set();
|
|
77
78
|
uno.config.presets.forEach((i) => {
|
|
78
79
|
if (!i.name)
|
|
@@ -94,6 +95,9 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
|
|
|
94
95
|
function invalidate() {
|
|
95
96
|
invalidations.forEach((cb) => cb());
|
|
96
97
|
}
|
|
98
|
+
function dispatchReload() {
|
|
99
|
+
reloadListeners.forEach((cb) => cb());
|
|
100
|
+
}
|
|
97
101
|
async function extract(code, id) {
|
|
98
102
|
if (id)
|
|
99
103
|
modules.set(id, code);
|
|
@@ -123,6 +127,9 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
|
|
|
123
127
|
},
|
|
124
128
|
filter,
|
|
125
129
|
reloadConfig,
|
|
130
|
+
onReload(fn) {
|
|
131
|
+
reloadListeners.push(fn);
|
|
132
|
+
},
|
|
126
133
|
uno,
|
|
127
134
|
extract,
|
|
128
135
|
getConfig,
|
|
@@ -203,7 +210,7 @@ function ChunkModeBuildPlugin({ uno, filter }) {
|
|
|
203
210
|
}
|
|
204
211
|
|
|
205
212
|
function GlobalModeBuildPlugin({ uno, ready, extract, tokens, filter, getConfig }) {
|
|
206
|
-
const
|
|
213
|
+
const vfsLayers = /* @__PURE__ */ new Set();
|
|
207
214
|
const layerImporterMap = /* @__PURE__ */ new Map();
|
|
208
215
|
let tasks = [];
|
|
209
216
|
const cssPostPlugins = /* @__PURE__ */ new Map();
|
|
@@ -258,14 +265,17 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, filter, getConfig
|
|
|
258
265
|
resolveId(id, importer) {
|
|
259
266
|
const entry = resolveId(id);
|
|
260
267
|
if (entry) {
|
|
261
|
-
|
|
262
|
-
if (
|
|
263
|
-
|
|
264
|
-
|
|
268
|
+
const layer = resolveLayer(entry);
|
|
269
|
+
if (layer) {
|
|
270
|
+
vfsLayers.add(layer);
|
|
271
|
+
if (importer)
|
|
272
|
+
layerImporterMap.set(importer, entry);
|
|
273
|
+
}
|
|
274
|
+
return entry;
|
|
265
275
|
}
|
|
266
276
|
},
|
|
267
277
|
load(id) {
|
|
268
|
-
const layer =
|
|
278
|
+
const layer = resolveLayer(getPath(id));
|
|
269
279
|
if (layer)
|
|
270
280
|
return getLayerPlaceholder(layer);
|
|
271
281
|
},
|
|
@@ -275,7 +285,7 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, filter, getConfig
|
|
|
275
285
|
const layerKey = layerImporterMap.get(id);
|
|
276
286
|
if (!importedIds.includes(layerKey)) {
|
|
277
287
|
layerImporterMap.delete(id);
|
|
278
|
-
|
|
288
|
+
vfsLayers.delete(resolveLayer(layerKey));
|
|
279
289
|
}
|
|
280
290
|
},
|
|
281
291
|
async configResolved(config) {
|
|
@@ -318,7 +328,7 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, filter, getConfig
|
|
|
318
328
|
const cssFiles = files.filter((i) => i.endsWith(".css"));
|
|
319
329
|
if (!cssFiles.length)
|
|
320
330
|
return;
|
|
321
|
-
if (!
|
|
331
|
+
if (!vfsLayers.size) {
|
|
322
332
|
const msg = "[unocss] entry module not found, have you add `import 'uno.css'` in your main entry?";
|
|
323
333
|
this.warn(msg);
|
|
324
334
|
return;
|
|
@@ -331,7 +341,7 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, filter, getConfig
|
|
|
331
341
|
const css = chunk.source.replace(HASH_PLACEHOLDER_RE, "");
|
|
332
342
|
chunk.source = await replaceAsync(css, LAYER_PLACEHOLDER_RE, async (_, __, layer) => {
|
|
333
343
|
replaced = true;
|
|
334
|
-
return await applyCssTransform(layer === LAYER_MARK_ALL ? result.getLayers(void 0, Array.from(
|
|
344
|
+
return await applyCssTransform(layer === LAYER_MARK_ALL ? result.getLayers(void 0, Array.from(vfsLayers)) : result.getLayer(layer) || "", `${chunk.fileName}.css`, options.dir);
|
|
335
345
|
});
|
|
336
346
|
}
|
|
337
347
|
}
|
|
@@ -348,7 +358,7 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
|
|
|
348
358
|
const servers = [];
|
|
349
359
|
let base = "";
|
|
350
360
|
const tasks = [];
|
|
351
|
-
const entries = /* @__PURE__ */ new
|
|
361
|
+
const entries = /* @__PURE__ */ new Set();
|
|
352
362
|
let invalidateTimer;
|
|
353
363
|
let lastUpdate = Date.now();
|
|
354
364
|
let lastServed = 0;
|
|
@@ -363,7 +373,7 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
|
|
|
363
373
|
}
|
|
364
374
|
function invalidate(timer = 10) {
|
|
365
375
|
for (const server of servers) {
|
|
366
|
-
for (const id of entries
|
|
376
|
+
for (const id of entries) {
|
|
367
377
|
const mod = server.moduleGraph.getModuleById(id);
|
|
368
378
|
if (!mod)
|
|
369
379
|
continue;
|
|
@@ -378,7 +388,7 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
|
|
|
378
388
|
for (const server of servers) {
|
|
379
389
|
server.ws.send({
|
|
380
390
|
type: "update",
|
|
381
|
-
updates: Array.from(entries
|
|
391
|
+
updates: Array.from(entries).map((i) => ({
|
|
382
392
|
acceptedPath: i,
|
|
383
393
|
path: i,
|
|
384
394
|
timestamp: lastUpdate,
|
|
@@ -436,18 +446,18 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
|
|
|
436
446
|
const entry = resolveId(id);
|
|
437
447
|
if (entry) {
|
|
438
448
|
resolved = true;
|
|
439
|
-
entries.
|
|
440
|
-
return entry
|
|
449
|
+
entries.add(entry);
|
|
450
|
+
return entry;
|
|
441
451
|
}
|
|
442
452
|
},
|
|
443
453
|
async load(id) {
|
|
444
|
-
const layer =
|
|
454
|
+
const layer = resolveLayer(getPath(id));
|
|
445
455
|
if (!layer)
|
|
446
456
|
return null;
|
|
447
457
|
await Promise.all(tasks);
|
|
448
458
|
const result = await uno.generate(tokens);
|
|
449
459
|
lastServed = Date.now();
|
|
450
|
-
return layer === LAYER_MARK_ALL ? result.getLayers(void 0, Array.from(entries.
|
|
460
|
+
return layer === LAYER_MARK_ALL ? result.getLayers(void 0, Array.from(entries).map((i) => resolveLayer(i)).filter((i) => !!i)) : result.getLayer(layer);
|
|
451
461
|
}
|
|
452
462
|
},
|
|
453
463
|
{
|
|
@@ -644,7 +654,10 @@ function ShadowDomModuleModePlugin({ uno }) {
|
|
|
644
654
|
const transformWebComponent = async (code) => {
|
|
645
655
|
if (!code.match(CSS_PLACEHOLDER))
|
|
646
656
|
return code;
|
|
647
|
-
let { css, matched } = await uno.generate(code, {
|
|
657
|
+
let { css, matched } = await uno.generate(code, {
|
|
658
|
+
preflights: true,
|
|
659
|
+
safelist: true
|
|
660
|
+
});
|
|
648
661
|
if (css && matched) {
|
|
649
662
|
const useParts = Array.from(matched).reduce((acc, rule) => {
|
|
650
663
|
const matcher = rule.match(partExtractorRegex);
|
package/dist/index.mjs
CHANGED
|
@@ -19,17 +19,16 @@ function resolveId(id) {
|
|
|
19
19
|
for (const alias of VIRTUAL_ENTRY_ALIAS) {
|
|
20
20
|
const match = id.match(alias);
|
|
21
21
|
if (match) {
|
|
22
|
-
return match[1] ? {
|
|
23
|
-
id: `/__uno_${match[1]}.css`,
|
|
24
|
-
layer: match[1]
|
|
25
|
-
} : {
|
|
26
|
-
id: "/__uno.css",
|
|
27
|
-
layer: LAYER_MARK_ALL
|
|
28
|
-
};
|
|
22
|
+
return match[1] ? `/__uno_${match[1]}.css` : "/__uno.css";
|
|
29
23
|
}
|
|
30
24
|
}
|
|
31
25
|
}
|
|
32
|
-
const RESOLVED_ID_RE = /\/__uno(_.*?)?\.css$/;
|
|
26
|
+
const RESOLVED_ID_RE = /\/__uno(?:(_.*?))?\.css$/;
|
|
27
|
+
function resolveLayer(id) {
|
|
28
|
+
const match = id.match(RESOLVED_ID_RE);
|
|
29
|
+
if (match)
|
|
30
|
+
return match[1] || LAYER_MARK_ALL;
|
|
31
|
+
}
|
|
33
32
|
const LAYER_PLACEHOLDER_RE = /(\\?")?#--unocss--\s*{\s*layer\s*:\s*(.+?);?\s*}/g;
|
|
34
33
|
function getLayerPlaceholder(layer) {
|
|
35
34
|
return `#--unocss--{layer:${layer}}`;
|
|
@@ -50,6 +49,7 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
|
|
|
50
49
|
const uno = createGenerator(rawConfig, defaults);
|
|
51
50
|
let rollupFilter = createFilter(defaultInclude, defaultExclude);
|
|
52
51
|
const invalidations = [];
|
|
52
|
+
const reloadListeners = [];
|
|
53
53
|
const modules = new BetterMap();
|
|
54
54
|
const tokens = /* @__PURE__ */ new Set();
|
|
55
55
|
let ready = reloadConfig();
|
|
@@ -63,6 +63,7 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
|
|
|
63
63
|
tokens.clear();
|
|
64
64
|
await Promise.all(modules.map((code, id) => uno.applyExtractors(code, id, tokens)));
|
|
65
65
|
invalidate();
|
|
66
|
+
dispatchReload();
|
|
66
67
|
const presets = /* @__PURE__ */ new Set();
|
|
67
68
|
uno.config.presets.forEach((i) => {
|
|
68
69
|
if (!i.name)
|
|
@@ -84,6 +85,9 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
|
|
|
84
85
|
function invalidate() {
|
|
85
86
|
invalidations.forEach((cb) => cb());
|
|
86
87
|
}
|
|
88
|
+
function dispatchReload() {
|
|
89
|
+
reloadListeners.forEach((cb) => cb());
|
|
90
|
+
}
|
|
87
91
|
async function extract(code, id) {
|
|
88
92
|
if (id)
|
|
89
93
|
modules.set(id, code);
|
|
@@ -113,6 +117,9 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
|
|
|
113
117
|
},
|
|
114
118
|
filter,
|
|
115
119
|
reloadConfig,
|
|
120
|
+
onReload(fn) {
|
|
121
|
+
reloadListeners.push(fn);
|
|
122
|
+
},
|
|
116
123
|
uno,
|
|
117
124
|
extract,
|
|
118
125
|
getConfig,
|
|
@@ -193,7 +200,7 @@ function ChunkModeBuildPlugin({ uno, filter }) {
|
|
|
193
200
|
}
|
|
194
201
|
|
|
195
202
|
function GlobalModeBuildPlugin({ uno, ready, extract, tokens, filter, getConfig }) {
|
|
196
|
-
const
|
|
203
|
+
const vfsLayers = /* @__PURE__ */ new Set();
|
|
197
204
|
const layerImporterMap = /* @__PURE__ */ new Map();
|
|
198
205
|
let tasks = [];
|
|
199
206
|
const cssPostPlugins = /* @__PURE__ */ new Map();
|
|
@@ -248,14 +255,17 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, filter, getConfig
|
|
|
248
255
|
resolveId(id, importer) {
|
|
249
256
|
const entry = resolveId(id);
|
|
250
257
|
if (entry) {
|
|
251
|
-
|
|
252
|
-
if (
|
|
253
|
-
|
|
254
|
-
|
|
258
|
+
const layer = resolveLayer(entry);
|
|
259
|
+
if (layer) {
|
|
260
|
+
vfsLayers.add(layer);
|
|
261
|
+
if (importer)
|
|
262
|
+
layerImporterMap.set(importer, entry);
|
|
263
|
+
}
|
|
264
|
+
return entry;
|
|
255
265
|
}
|
|
256
266
|
},
|
|
257
267
|
load(id) {
|
|
258
|
-
const layer =
|
|
268
|
+
const layer = resolveLayer(getPath(id));
|
|
259
269
|
if (layer)
|
|
260
270
|
return getLayerPlaceholder(layer);
|
|
261
271
|
},
|
|
@@ -265,7 +275,7 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, filter, getConfig
|
|
|
265
275
|
const layerKey = layerImporterMap.get(id);
|
|
266
276
|
if (!importedIds.includes(layerKey)) {
|
|
267
277
|
layerImporterMap.delete(id);
|
|
268
|
-
|
|
278
|
+
vfsLayers.delete(resolveLayer(layerKey));
|
|
269
279
|
}
|
|
270
280
|
},
|
|
271
281
|
async configResolved(config) {
|
|
@@ -308,7 +318,7 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, filter, getConfig
|
|
|
308
318
|
const cssFiles = files.filter((i) => i.endsWith(".css"));
|
|
309
319
|
if (!cssFiles.length)
|
|
310
320
|
return;
|
|
311
|
-
if (!
|
|
321
|
+
if (!vfsLayers.size) {
|
|
312
322
|
const msg = "[unocss] entry module not found, have you add `import 'uno.css'` in your main entry?";
|
|
313
323
|
this.warn(msg);
|
|
314
324
|
return;
|
|
@@ -321,7 +331,7 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, filter, getConfig
|
|
|
321
331
|
const css = chunk.source.replace(HASH_PLACEHOLDER_RE, "");
|
|
322
332
|
chunk.source = await replaceAsync(css, LAYER_PLACEHOLDER_RE, async (_, __, layer) => {
|
|
323
333
|
replaced = true;
|
|
324
|
-
return await applyCssTransform(layer === LAYER_MARK_ALL ? result.getLayers(void 0, Array.from(
|
|
334
|
+
return await applyCssTransform(layer === LAYER_MARK_ALL ? result.getLayers(void 0, Array.from(vfsLayers)) : result.getLayer(layer) || "", `${chunk.fileName}.css`, options.dir);
|
|
325
335
|
});
|
|
326
336
|
}
|
|
327
337
|
}
|
|
@@ -338,7 +348,7 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
|
|
|
338
348
|
const servers = [];
|
|
339
349
|
let base = "";
|
|
340
350
|
const tasks = [];
|
|
341
|
-
const entries = /* @__PURE__ */ new
|
|
351
|
+
const entries = /* @__PURE__ */ new Set();
|
|
342
352
|
let invalidateTimer;
|
|
343
353
|
let lastUpdate = Date.now();
|
|
344
354
|
let lastServed = 0;
|
|
@@ -353,7 +363,7 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
|
|
|
353
363
|
}
|
|
354
364
|
function invalidate(timer = 10) {
|
|
355
365
|
for (const server of servers) {
|
|
356
|
-
for (const id of entries
|
|
366
|
+
for (const id of entries) {
|
|
357
367
|
const mod = server.moduleGraph.getModuleById(id);
|
|
358
368
|
if (!mod)
|
|
359
369
|
continue;
|
|
@@ -368,7 +378,7 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
|
|
|
368
378
|
for (const server of servers) {
|
|
369
379
|
server.ws.send({
|
|
370
380
|
type: "update",
|
|
371
|
-
updates: Array.from(entries
|
|
381
|
+
updates: Array.from(entries).map((i) => ({
|
|
372
382
|
acceptedPath: i,
|
|
373
383
|
path: i,
|
|
374
384
|
timestamp: lastUpdate,
|
|
@@ -426,18 +436,18 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
|
|
|
426
436
|
const entry = resolveId(id);
|
|
427
437
|
if (entry) {
|
|
428
438
|
resolved = true;
|
|
429
|
-
entries.
|
|
430
|
-
return entry
|
|
439
|
+
entries.add(entry);
|
|
440
|
+
return entry;
|
|
431
441
|
}
|
|
432
442
|
},
|
|
433
443
|
async load(id) {
|
|
434
|
-
const layer =
|
|
444
|
+
const layer = resolveLayer(getPath(id));
|
|
435
445
|
if (!layer)
|
|
436
446
|
return null;
|
|
437
447
|
await Promise.all(tasks);
|
|
438
448
|
const result = await uno.generate(tokens);
|
|
439
449
|
lastServed = Date.now();
|
|
440
|
-
return layer === LAYER_MARK_ALL ? result.getLayers(void 0, Array.from(entries.
|
|
450
|
+
return layer === LAYER_MARK_ALL ? result.getLayers(void 0, Array.from(entries).map((i) => resolveLayer(i)).filter((i) => !!i)) : result.getLayer(layer);
|
|
441
451
|
}
|
|
442
452
|
},
|
|
443
453
|
{
|
|
@@ -634,7 +644,10 @@ function ShadowDomModuleModePlugin({ uno }) {
|
|
|
634
644
|
const transformWebComponent = async (code) => {
|
|
635
645
|
if (!code.match(CSS_PLACEHOLDER))
|
|
636
646
|
return code;
|
|
637
|
-
let { css, matched } = await uno.generate(code, {
|
|
647
|
+
let { css, matched } = await uno.generate(code, {
|
|
648
|
+
preflights: true,
|
|
649
|
+
safelist: true
|
|
650
|
+
});
|
|
638
651
|
if (css && matched) {
|
|
639
652
|
const useParts = Array.from(matched).reduce((acc, rule) => {
|
|
640
653
|
const matcher = rule.match(partExtractorRegex);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/vite",
|
|
3
|
-
"version": "0.39.
|
|
3
|
+
"version": "0.39.3",
|
|
4
4
|
"description": "The Vite plugin for UnoCSS",
|
|
5
5
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,15 +43,15 @@
|
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@rollup/pluginutils": "^4.2.1",
|
|
46
|
-
"@unocss/config": "0.39.
|
|
47
|
-
"@unocss/core": "0.39.
|
|
48
|
-
"@unocss/inspector": "0.39.
|
|
49
|
-
"@unocss/scope": "0.39.
|
|
50
|
-
"@unocss/transformer-directives": "0.39.
|
|
46
|
+
"@unocss/config": "0.39.3",
|
|
47
|
+
"@unocss/core": "0.39.3",
|
|
48
|
+
"@unocss/inspector": "0.39.3",
|
|
49
|
+
"@unocss/scope": "0.39.3",
|
|
50
|
+
"@unocss/transformer-directives": "0.39.3",
|
|
51
51
|
"magic-string": "^0.26.2"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@unocss/shared-integration": "0.39.
|
|
54
|
+
"@unocss/shared-integration": "0.39.3",
|
|
55
55
|
"vite": "^2.9.9"
|
|
56
56
|
},
|
|
57
57
|
"scripts": {
|