@unocss/vite 0.45.26 → 0.45.28
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 +17 -4
- package/dist/index.cjs +6 -4
- package/dist/index.mjs +6 -4
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -249,28 +249,41 @@ You have a `Vite + Svelte` example project on [examples/vite-svelte](https://git
|
|
|
249
249
|
|
|
250
250
|
To support `class:foo` and `class:foo={bar}` add the plugin and configure `extractorSvelte` on `extractors` option.
|
|
251
251
|
|
|
252
|
-
You can use simple rules with `class:`, for example `class:bg-red-500={foo}` or using `
|
|
252
|
+
You can use simple rules with `class:`, for example `class:bg-red-500={foo}` or using `shortcuts` to include multiples rules, see `src/routes/+layout.svelte` on linked example project below.
|
|
253
253
|
|
|
254
254
|
```ts
|
|
255
255
|
// vite.config.js
|
|
256
256
|
import { sveltekit } from '@sveltejs/kit/vite'
|
|
257
|
-
import
|
|
257
|
+
import UnoCSS from 'unocss/vite'
|
|
258
258
|
import { extractorSvelte } from '@unocss/core'
|
|
259
259
|
|
|
260
260
|
/** @type {import('vite').UserConfig} */
|
|
261
261
|
const config = {
|
|
262
262
|
plugins: [
|
|
263
|
-
|
|
264
|
-
UnoCss({
|
|
263
|
+
UnoCSS({
|
|
265
264
|
extractors: [extractorSvelte],
|
|
266
265
|
/* more options */
|
|
267
266
|
}),
|
|
267
|
+
sveltekit(),
|
|
268
268
|
],
|
|
269
269
|
}
|
|
270
270
|
```
|
|
271
271
|
|
|
272
272
|
You have a `SvelteKit` example project on [examples/sveltekit](https://github.com/unocss/unocss/tree/main/examples/sveltekit) directory.
|
|
273
273
|
|
|
274
|
+
### Svelte/SvelteKit Scoped Mode
|
|
275
|
+
|
|
276
|
+
Adding `mode: 'svelte-scoped'` to your UnoCSS config options will place styles right inside of each component's style block instead of in a global `uno.css` file. Because there is no `import 'uno.css'` in your root `+layout.svelte` preflights and safelist classes have no where to be placed. Add the `uno:preflights` or `uno:safelist` attributes to the style block of any component where you want to place them. To use both globally, add the following to your root `+layout.svelte`:
|
|
277
|
+
|
|
278
|
+
```html
|
|
279
|
+
<style uno:preflights uno:safelist global></style>
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
Alternatively, if you only want them to apply to a specific component just add them to that component's `style` tag and don't add the `global` attribute.
|
|
283
|
+
|
|
284
|
+
You have a `SvelteKit scoped` example project on [examples/sveltekit-scoped](https://github.com/unocss/unocss/tree/main/examples/sveltekit-scoped) directory.
|
|
285
|
+
|
|
286
|
+
|
|
274
287
|
### Web Components
|
|
275
288
|
|
|
276
289
|
To work with web components you need to enable `shadow-dom` mode on the plugin.
|
package/dist/index.cjs
CHANGED
|
@@ -665,8 +665,10 @@ function VueScopedPlugin({ uno, ready }) {
|
|
|
665
665
|
|
|
666
666
|
function SvelteScopedPlugin({ uno, ready }) {
|
|
667
667
|
let filter = pluginutils.createFilter([/\.svelte$/], defaultExclude);
|
|
668
|
-
async function transformSFC(code) {
|
|
669
|
-
const
|
|
668
|
+
async function transformSFC(code, id) {
|
|
669
|
+
const preflights = code.includes("uno:preflights");
|
|
670
|
+
const safelist = code.includes("uno:safelist");
|
|
671
|
+
const { css } = await uno.generate(code, { id, preflights, safelist });
|
|
670
672
|
if (!css)
|
|
671
673
|
return null;
|
|
672
674
|
if (code.match(/<style[^>]*>[\s\S]*?<\/style\s*>/))
|
|
@@ -687,14 +689,14 @@ function SvelteScopedPlugin({ uno, ready }) {
|
|
|
687
689
|
transform(code, id) {
|
|
688
690
|
if (!filter(id))
|
|
689
691
|
return;
|
|
690
|
-
return transformSFC(code);
|
|
692
|
+
return transformSFC(code, id);
|
|
691
693
|
},
|
|
692
694
|
handleHotUpdate(ctx) {
|
|
693
695
|
const read = ctx.read;
|
|
694
696
|
if (filter(ctx.file)) {
|
|
695
697
|
ctx.read = async () => {
|
|
696
698
|
const code = await read();
|
|
697
|
-
return await transformSFC(code) || code;
|
|
699
|
+
return await transformSFC(code, ctx.file) || code;
|
|
698
700
|
};
|
|
699
701
|
}
|
|
700
702
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -654,8 +654,10 @@ function VueScopedPlugin({ uno, ready }) {
|
|
|
654
654
|
|
|
655
655
|
function SvelteScopedPlugin({ uno, ready }) {
|
|
656
656
|
let filter = createFilter([/\.svelte$/], defaultExclude);
|
|
657
|
-
async function transformSFC(code) {
|
|
658
|
-
const
|
|
657
|
+
async function transformSFC(code, id) {
|
|
658
|
+
const preflights = code.includes("uno:preflights");
|
|
659
|
+
const safelist = code.includes("uno:safelist");
|
|
660
|
+
const { css } = await uno.generate(code, { id, preflights, safelist });
|
|
659
661
|
if (!css)
|
|
660
662
|
return null;
|
|
661
663
|
if (code.match(/<style[^>]*>[\s\S]*?<\/style\s*>/))
|
|
@@ -676,14 +678,14 @@ function SvelteScopedPlugin({ uno, ready }) {
|
|
|
676
678
|
transform(code, id) {
|
|
677
679
|
if (!filter(id))
|
|
678
680
|
return;
|
|
679
|
-
return transformSFC(code);
|
|
681
|
+
return transformSFC(code, id);
|
|
680
682
|
},
|
|
681
683
|
handleHotUpdate(ctx) {
|
|
682
684
|
const read = ctx.read;
|
|
683
685
|
if (filter(ctx.file)) {
|
|
684
686
|
ctx.read = async () => {
|
|
685
687
|
const code = await read();
|
|
686
|
-
return await transformSFC(code) || code;
|
|
688
|
+
return await transformSFC(code, ctx.file) || code;
|
|
687
689
|
};
|
|
688
690
|
}
|
|
689
691
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/vite",
|
|
3
|
-
"version": "0.45.
|
|
3
|
+
"version": "0.45.28",
|
|
4
4
|
"description": "The Vite plugin for UnoCSS",
|
|
5
5
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -44,16 +44,16 @@
|
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@ampproject/remapping": "^2.2.0",
|
|
46
46
|
"@rollup/pluginutils": "^4.2.1",
|
|
47
|
-
"@unocss/config": "0.45.
|
|
48
|
-
"@unocss/core": "0.45.
|
|
49
|
-
"@unocss/inspector": "0.45.
|
|
50
|
-
"@unocss/scope": "0.45.
|
|
51
|
-
"@unocss/transformer-directives": "0.45.
|
|
52
|
-
"magic-string": "^0.26.
|
|
47
|
+
"@unocss/config": "0.45.28",
|
|
48
|
+
"@unocss/core": "0.45.28",
|
|
49
|
+
"@unocss/inspector": "0.45.28",
|
|
50
|
+
"@unocss/scope": "0.45.28",
|
|
51
|
+
"@unocss/transformer-directives": "0.45.28",
|
|
52
|
+
"magic-string": "^0.26.6"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@unocss/shared-integration": "0.45.
|
|
56
|
-
"vite": "^3.1.
|
|
55
|
+
"@unocss/shared-integration": "0.45.28",
|
|
56
|
+
"vite": "^3.1.6"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"build": "unbuild",
|