@unocss/vite 0.45.25 → 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 +10 -8
- package/dist/index.mjs +7 -5
- package/package.json +9 -10
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
|
@@ -8,7 +8,7 @@ const pluginutils = require('@rollup/pluginutils');
|
|
|
8
8
|
const config = require('@unocss/config');
|
|
9
9
|
const crypto = require('crypto');
|
|
10
10
|
const MagicString = require('magic-string');
|
|
11
|
-
const
|
|
11
|
+
const path = require('path');
|
|
12
12
|
const remapping = require('@ampproject/remapping');
|
|
13
13
|
const fs = require('fs');
|
|
14
14
|
const url = require('url');
|
|
@@ -305,7 +305,7 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, filter, getConfig
|
|
|
305
305
|
}
|
|
306
306
|
},
|
|
307
307
|
async configResolved(config) {
|
|
308
|
-
const distDir =
|
|
308
|
+
const distDir = path.resolve(config.root, config.build.outDir);
|
|
309
309
|
cssPostPlugins.set(distDir, config.plugins.find((i) => i.name === "vite:css-post"));
|
|
310
310
|
cssPlugins.set(distDir, config.plugins.find((i) => i.name === "vite:css"));
|
|
311
311
|
await ready;
|
|
@@ -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
|
}
|
|
@@ -874,7 +876,7 @@ function createTransformerPlugins(ctx) {
|
|
|
874
876
|
}));
|
|
875
877
|
}
|
|
876
878
|
|
|
877
|
-
const _dirname = typeof __dirname !== "undefined" ? __dirname :
|
|
879
|
+
const _dirname = typeof __dirname !== "undefined" ? __dirname : path.dirname(url.fileURLToPath((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('index.cjs', document.baseURI).href))));
|
|
878
880
|
const DEVTOOLS_MODULE_ID = "virtual:unocss-devtools";
|
|
879
881
|
const MOCK_CLASSES_MODULE_ID = "virtual:unocss-mock-classes";
|
|
880
882
|
const MOCK_CLASSES_PATH = "/@unocss/mock-classes";
|
|
@@ -984,7 +986,7 @@ function createDevtoolsPlugin(ctx) {
|
|
|
984
986
|
if (id === DEVTOOLS_PATH) {
|
|
985
987
|
if (!clientCode) {
|
|
986
988
|
clientCode = [
|
|
987
|
-
await fs__default.promises.readFile(
|
|
989
|
+
await fs__default.promises.readFile(path.resolve(_dirname, "client.mjs"), "utf-8"),
|
|
988
990
|
`import('${MOCK_CLASSES_MODULE_ID}')`,
|
|
989
991
|
`import('${DEVTOOLS_CSS_PATH}')`
|
|
990
992
|
].join("\n").replace("__POST_PATH__", (config.server?.origin ?? "") + POST_PATH);
|
package/dist/index.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { createFilter } from '@rollup/pluginutils';
|
|
|
4
4
|
import { loadConfig } from '@unocss/config';
|
|
5
5
|
import { createHash } from 'crypto';
|
|
6
6
|
import MagicString from 'magic-string';
|
|
7
|
-
import { resolve, dirname } from '
|
|
7
|
+
import { resolve, dirname } from 'path';
|
|
8
8
|
import remapping from '@ampproject/remapping';
|
|
9
9
|
import fs from 'fs';
|
|
10
10
|
import { fileURLToPath } from 'url';
|
|
@@ -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,17 +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.
|
|
53
|
-
"pathe": "^0.3.7"
|
|
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"
|
|
54
53
|
},
|
|
55
54
|
"devDependencies": {
|
|
56
|
-
"@unocss/shared-integration": "0.45.
|
|
57
|
-
"vite": "^3.1.
|
|
55
|
+
"@unocss/shared-integration": "0.45.28",
|
|
56
|
+
"vite": "^3.1.6"
|
|
58
57
|
},
|
|
59
58
|
"scripts": {
|
|
60
59
|
"build": "unbuild",
|