@unocss/vite 0.43.1 → 0.44.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/README.md +10 -16
- package/dist/index.cjs +75 -41
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +75 -41
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -251,26 +251,20 @@ To support `class:foo` and `class:foo={bar}` add the plugin and configure `extra
|
|
|
251
251
|
You can use simple rules with `class:`, for example `class:bg-red-500={foo}` or using `shorcuts` to include multiples rules, see `src/routes/__layout.svelte` on linked example project below.
|
|
252
252
|
|
|
253
253
|
```ts
|
|
254
|
-
//
|
|
255
|
-
import
|
|
254
|
+
// vite.config.js
|
|
255
|
+
import { sveltekit } from '@sveltejs/kit/vite'
|
|
256
256
|
import UnoCss from 'unocss/vite'
|
|
257
257
|
import { extractorSvelte } from '@unocss/core'
|
|
258
258
|
|
|
259
|
-
/** @type {import('
|
|
259
|
+
/** @type {import('vite').UserConfig} */
|
|
260
260
|
const config = {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
extractors: [extractorSvelte],
|
|
269
|
-
/* more options */
|
|
270
|
-
}),
|
|
271
|
-
],
|
|
272
|
-
},
|
|
273
|
-
},
|
|
261
|
+
plugins: [
|
|
262
|
+
sveltekit(),
|
|
263
|
+
UnoCss({
|
|
264
|
+
extractors: [extractorSvelte],
|
|
265
|
+
/* more options */
|
|
266
|
+
}),
|
|
267
|
+
],
|
|
274
268
|
}
|
|
275
269
|
```
|
|
276
270
|
|
package/dist/index.cjs
CHANGED
|
@@ -326,9 +326,10 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, filter, getConfig
|
|
|
326
326
|
},
|
|
327
327
|
enforce: "post",
|
|
328
328
|
async generateBundle(options, bundle) {
|
|
329
|
-
const files = Object.
|
|
330
|
-
const cssFiles = files.filter((i) => i.endsWith(".css"));
|
|
331
|
-
|
|
329
|
+
const files = Object.entries(bundle);
|
|
330
|
+
const cssFiles = files.filter((i) => i[0].endsWith(".css"));
|
|
331
|
+
const jsFiles = files.filter((i) => i[0].endsWith(".js"));
|
|
332
|
+
if (!cssFiles.length && !jsFiles.length)
|
|
332
333
|
return;
|
|
333
334
|
if (!vfsLayers.size) {
|
|
334
335
|
const msg = "[unocss] entry module not found, have you add `import 'uno.css'` in your main entry?";
|
|
@@ -337,13 +338,23 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, filter, getConfig
|
|
|
337
338
|
}
|
|
338
339
|
const result = await generateAll();
|
|
339
340
|
let replaced = false;
|
|
340
|
-
for (const
|
|
341
|
-
const chunk = bundle[file];
|
|
341
|
+
for (const [, chunk] of cssFiles) {
|
|
342
342
|
if (chunk.type === "asset" && typeof chunk.source === "string") {
|
|
343
343
|
const css = chunk.source.replace(HASH_PLACEHOLDER_RE, "");
|
|
344
344
|
chunk.source = await replaceAsync(css, LAYER_PLACEHOLDER_RE, async (_, __, layer) => {
|
|
345
345
|
replaced = true;
|
|
346
|
-
|
|
346
|
+
const css2 = layer === LAYER_MARK_ALL ? result.getLayers(void 0, Array.from(vfsLayers)) : result.getLayer(layer) || "";
|
|
347
|
+
return await applyCssTransform(css2, `${chunk.fileName}.css`, options.dir);
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
for (const [, chunk] of jsFiles) {
|
|
352
|
+
if (chunk.type === "chunk" && typeof chunk.code === "string") {
|
|
353
|
+
const js = chunk.code.replace(HASH_PLACEHOLDER_RE, "");
|
|
354
|
+
chunk.code = await replaceAsync(js, LAYER_PLACEHOLDER_RE, async (_, __, layer) => {
|
|
355
|
+
replaced = true;
|
|
356
|
+
const css = layer === LAYER_MARK_ALL ? result.getLayers(void 0, Array.from(vfsLayers)) : result.getLayer(layer) || "";
|
|
357
|
+
return css.replace(/\n/g, "").replace(/(?<!\\)(['"])/g, "\\$1");
|
|
347
358
|
});
|
|
348
359
|
}
|
|
349
360
|
}
|
|
@@ -517,44 +528,67 @@ function PerModuleModePlugin({ uno, filter }) {
|
|
|
517
528
|
}]
|
|
518
529
|
});
|
|
519
530
|
};
|
|
520
|
-
return
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
};
|
|
542
|
-
},
|
|
543
|
-
resolveId(id) {
|
|
544
|
-
return id.startsWith(VIRTUAL_PREFIX) ? id : null;
|
|
531
|
+
return [
|
|
532
|
+
{
|
|
533
|
+
name: "unocss:module-scope:pre",
|
|
534
|
+
enforce: "pre",
|
|
535
|
+
async transform(code, id) {
|
|
536
|
+
if (!filter(code, id))
|
|
537
|
+
return;
|
|
538
|
+
const hash = getHash(id);
|
|
539
|
+
const { css } = await uno.generate(code, {
|
|
540
|
+
id,
|
|
541
|
+
preflights: true
|
|
542
|
+
});
|
|
543
|
+
if (!css)
|
|
544
|
+
return null;
|
|
545
|
+
moduleMap.set(hash, [id, css]);
|
|
546
|
+
invalidate(hash);
|
|
547
|
+
return {
|
|
548
|
+
code: `import "${VIRTUAL_PREFIX}${hash}.css";${code}`,
|
|
549
|
+
map: null
|
|
550
|
+
};
|
|
551
|
+
}
|
|
545
552
|
},
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
553
|
+
{
|
|
554
|
+
name: "unocss:module-scope",
|
|
555
|
+
enforce: "post",
|
|
556
|
+
configureServer(_server) {
|
|
557
|
+
server = _server;
|
|
558
|
+
},
|
|
559
|
+
async transform(code, id) {
|
|
560
|
+
if (!filter(code, id))
|
|
561
|
+
return;
|
|
562
|
+
const hash = getHash(id);
|
|
563
|
+
const hasScope = code.match(SCOPE_IMPORT_RE);
|
|
564
|
+
const { css } = await uno.generate(code, { id, scope: hasScope ? `.${hash}` : void 0, preflights: false });
|
|
565
|
+
if (!css && !hasScope)
|
|
566
|
+
return null;
|
|
567
|
+
if (hasScope)
|
|
568
|
+
code = code.replace(SCOPE_IMPORT_RE, ` from 'data:text/javascript;base64,${Buffer.from(`export default () => "${hash}"`).toString("base64")}'`);
|
|
569
|
+
moduleMap.set(hash, [id, css]);
|
|
570
|
+
invalidate(hash);
|
|
571
|
+
return {
|
|
572
|
+
code: `import "${VIRTUAL_PREFIX}${hash}.css";${code}`,
|
|
573
|
+
map: null
|
|
574
|
+
};
|
|
575
|
+
},
|
|
576
|
+
resolveId(id) {
|
|
577
|
+
return id.startsWith(VIRTUAL_PREFIX) ? id : null;
|
|
578
|
+
},
|
|
579
|
+
load(id) {
|
|
580
|
+
if (!id.startsWith(VIRTUAL_PREFIX))
|
|
581
|
+
return null;
|
|
582
|
+
const hash = id.slice(VIRTUAL_PREFIX.length, -".css".length);
|
|
583
|
+
const [source, css] = moduleMap.get(hash) || [];
|
|
584
|
+
if (source)
|
|
585
|
+
this.addWatchFile(source);
|
|
586
|
+
return `
|
|
554
587
|
/* unocss ${source} */
|
|
555
588
|
${css}`;
|
|
589
|
+
}
|
|
556
590
|
}
|
|
557
|
-
|
|
591
|
+
];
|
|
558
592
|
}
|
|
559
593
|
|
|
560
594
|
function VueScopedPlugin({ uno, ready }) {
|
|
@@ -945,7 +979,7 @@ function UnocssPlugin(configOrPath, defaults = {}) {
|
|
|
945
979
|
if (inlineConfig.inspector !== false)
|
|
946
980
|
plugins.push(UnocssInspector__default(ctx));
|
|
947
981
|
if (mode === "per-module") {
|
|
948
|
-
plugins.push(PerModuleModePlugin(ctx));
|
|
982
|
+
plugins.push(...PerModuleModePlugin(ctx));
|
|
949
983
|
} else if (mode === "vue-scoped") {
|
|
950
984
|
plugins.push(VueScopedPlugin(ctx));
|
|
951
985
|
} else if (mode === "svelte-scoped") {
|
package/dist/index.d.ts
CHANGED
|
@@ -45,7 +45,7 @@ declare function GlobalModeBuildPlugin({ uno, ready, extract, tokens, filter, ge
|
|
|
45
45
|
|
|
46
46
|
declare function GlobalModePlugin(ctx: UnocssPluginContext): vite.Plugin[];
|
|
47
47
|
|
|
48
|
-
declare function PerModuleModePlugin({ uno, filter }: UnocssPluginContext): Plugin;
|
|
48
|
+
declare function PerModuleModePlugin({ uno, filter }: UnocssPluginContext): Plugin[];
|
|
49
49
|
|
|
50
50
|
declare function VueScopedPlugin({ uno, ready }: UnocssPluginContext): Plugin;
|
|
51
51
|
|
package/dist/index.mjs
CHANGED
|
@@ -316,9 +316,10 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, filter, getConfig
|
|
|
316
316
|
},
|
|
317
317
|
enforce: "post",
|
|
318
318
|
async generateBundle(options, bundle) {
|
|
319
|
-
const files = Object.
|
|
320
|
-
const cssFiles = files.filter((i) => i.endsWith(".css"));
|
|
321
|
-
|
|
319
|
+
const files = Object.entries(bundle);
|
|
320
|
+
const cssFiles = files.filter((i) => i[0].endsWith(".css"));
|
|
321
|
+
const jsFiles = files.filter((i) => i[0].endsWith(".js"));
|
|
322
|
+
if (!cssFiles.length && !jsFiles.length)
|
|
322
323
|
return;
|
|
323
324
|
if (!vfsLayers.size) {
|
|
324
325
|
const msg = "[unocss] entry module not found, have you add `import 'uno.css'` in your main entry?";
|
|
@@ -327,13 +328,23 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, filter, getConfig
|
|
|
327
328
|
}
|
|
328
329
|
const result = await generateAll();
|
|
329
330
|
let replaced = false;
|
|
330
|
-
for (const
|
|
331
|
-
const chunk = bundle[file];
|
|
331
|
+
for (const [, chunk] of cssFiles) {
|
|
332
332
|
if (chunk.type === "asset" && typeof chunk.source === "string") {
|
|
333
333
|
const css = chunk.source.replace(HASH_PLACEHOLDER_RE, "");
|
|
334
334
|
chunk.source = await replaceAsync(css, LAYER_PLACEHOLDER_RE, async (_, __, layer) => {
|
|
335
335
|
replaced = true;
|
|
336
|
-
|
|
336
|
+
const css2 = layer === LAYER_MARK_ALL ? result.getLayers(void 0, Array.from(vfsLayers)) : result.getLayer(layer) || "";
|
|
337
|
+
return await applyCssTransform(css2, `${chunk.fileName}.css`, options.dir);
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
for (const [, chunk] of jsFiles) {
|
|
342
|
+
if (chunk.type === "chunk" && typeof chunk.code === "string") {
|
|
343
|
+
const js = chunk.code.replace(HASH_PLACEHOLDER_RE, "");
|
|
344
|
+
chunk.code = await replaceAsync(js, LAYER_PLACEHOLDER_RE, async (_, __, layer) => {
|
|
345
|
+
replaced = true;
|
|
346
|
+
const css = layer === LAYER_MARK_ALL ? result.getLayers(void 0, Array.from(vfsLayers)) : result.getLayer(layer) || "";
|
|
347
|
+
return css.replace(/\n/g, "").replace(/(?<!\\)(['"])/g, "\\$1");
|
|
337
348
|
});
|
|
338
349
|
}
|
|
339
350
|
}
|
|
@@ -507,44 +518,67 @@ function PerModuleModePlugin({ uno, filter }) {
|
|
|
507
518
|
}]
|
|
508
519
|
});
|
|
509
520
|
};
|
|
510
|
-
return
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
};
|
|
532
|
-
},
|
|
533
|
-
resolveId(id) {
|
|
534
|
-
return id.startsWith(VIRTUAL_PREFIX) ? id : null;
|
|
521
|
+
return [
|
|
522
|
+
{
|
|
523
|
+
name: "unocss:module-scope:pre",
|
|
524
|
+
enforce: "pre",
|
|
525
|
+
async transform(code, id) {
|
|
526
|
+
if (!filter(code, id))
|
|
527
|
+
return;
|
|
528
|
+
const hash = getHash(id);
|
|
529
|
+
const { css } = await uno.generate(code, {
|
|
530
|
+
id,
|
|
531
|
+
preflights: true
|
|
532
|
+
});
|
|
533
|
+
if (!css)
|
|
534
|
+
return null;
|
|
535
|
+
moduleMap.set(hash, [id, css]);
|
|
536
|
+
invalidate(hash);
|
|
537
|
+
return {
|
|
538
|
+
code: `import "${VIRTUAL_PREFIX}${hash}.css";${code}`,
|
|
539
|
+
map: null
|
|
540
|
+
};
|
|
541
|
+
}
|
|
535
542
|
},
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
543
|
+
{
|
|
544
|
+
name: "unocss:module-scope",
|
|
545
|
+
enforce: "post",
|
|
546
|
+
configureServer(_server) {
|
|
547
|
+
server = _server;
|
|
548
|
+
},
|
|
549
|
+
async transform(code, id) {
|
|
550
|
+
if (!filter(code, id))
|
|
551
|
+
return;
|
|
552
|
+
const hash = getHash(id);
|
|
553
|
+
const hasScope = code.match(SCOPE_IMPORT_RE);
|
|
554
|
+
const { css } = await uno.generate(code, { id, scope: hasScope ? `.${hash}` : void 0, preflights: false });
|
|
555
|
+
if (!css && !hasScope)
|
|
556
|
+
return null;
|
|
557
|
+
if (hasScope)
|
|
558
|
+
code = code.replace(SCOPE_IMPORT_RE, ` from 'data:text/javascript;base64,${Buffer.from(`export default () => "${hash}"`).toString("base64")}'`);
|
|
559
|
+
moduleMap.set(hash, [id, css]);
|
|
560
|
+
invalidate(hash);
|
|
561
|
+
return {
|
|
562
|
+
code: `import "${VIRTUAL_PREFIX}${hash}.css";${code}`,
|
|
563
|
+
map: null
|
|
564
|
+
};
|
|
565
|
+
},
|
|
566
|
+
resolveId(id) {
|
|
567
|
+
return id.startsWith(VIRTUAL_PREFIX) ? id : null;
|
|
568
|
+
},
|
|
569
|
+
load(id) {
|
|
570
|
+
if (!id.startsWith(VIRTUAL_PREFIX))
|
|
571
|
+
return null;
|
|
572
|
+
const hash = id.slice(VIRTUAL_PREFIX.length, -".css".length);
|
|
573
|
+
const [source, css] = moduleMap.get(hash) || [];
|
|
574
|
+
if (source)
|
|
575
|
+
this.addWatchFile(source);
|
|
576
|
+
return `
|
|
544
577
|
/* unocss ${source} */
|
|
545
578
|
${css}`;
|
|
579
|
+
}
|
|
546
580
|
}
|
|
547
|
-
|
|
581
|
+
];
|
|
548
582
|
}
|
|
549
583
|
|
|
550
584
|
function VueScopedPlugin({ uno, ready }) {
|
|
@@ -935,7 +969,7 @@ function UnocssPlugin(configOrPath, defaults = {}) {
|
|
|
935
969
|
if (inlineConfig.inspector !== false)
|
|
936
970
|
plugins.push(UnocssInspector(ctx));
|
|
937
971
|
if (mode === "per-module") {
|
|
938
|
-
plugins.push(PerModuleModePlugin(ctx));
|
|
972
|
+
plugins.push(...PerModuleModePlugin(ctx));
|
|
939
973
|
} else if (mode === "vue-scoped") {
|
|
940
974
|
plugins.push(VueScopedPlugin(ctx));
|
|
941
975
|
} else if (mode === "svelte-scoped") {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/vite",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.44.1",
|
|
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.
|
|
47
|
-
"@unocss/core": "0.
|
|
48
|
-
"@unocss/inspector": "0.
|
|
49
|
-
"@unocss/scope": "0.
|
|
50
|
-
"@unocss/transformer-directives": "0.
|
|
46
|
+
"@unocss/config": "0.44.1",
|
|
47
|
+
"@unocss/core": "0.44.1",
|
|
48
|
+
"@unocss/inspector": "0.44.1",
|
|
49
|
+
"@unocss/scope": "0.44.1",
|
|
50
|
+
"@unocss/transformer-directives": "0.44.1",
|
|
51
51
|
"magic-string": "^0.26.2"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|
|
54
|
-
"@unocss/shared-integration": "0.
|
|
54
|
+
"@unocss/shared-integration": "0.44.1",
|
|
55
55
|
"vite": "^2.9.12"
|
|
56
56
|
},
|
|
57
57
|
"scripts": {
|