@unocss/vite 0.20.4 → 0.22.0
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 +26 -0
- package/dist/index.cjs +37 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.mjs +37 -2
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -44,6 +44,10 @@ The generated `css` will be a global stylesheet injected on the `index.html`.
|
|
|
44
44
|
|
|
45
45
|
This mode will inject generated CSS to Vue SFC's `<style scoped>` for isolation.
|
|
46
46
|
|
|
47
|
+
### svelte-scoped (WIP)
|
|
48
|
+
|
|
49
|
+
This mode will inject generated CSS to Svelte's `<style>` for isolation.
|
|
50
|
+
|
|
47
51
|
### per-module (WIP)
|
|
48
52
|
|
|
49
53
|
This mode will generate a CSS sheet for each module, can be scoped.
|
|
@@ -360,6 +364,28 @@ export default {
|
|
|
360
364
|
|
|
361
365
|
You have a `Vite + Solid` example project on [test/fixtures/vite-solid](https://github.com/antfu/unocss/tree/main/test/fixtures/vite-solid) directory.
|
|
362
366
|
|
|
367
|
+
### Elm
|
|
368
|
+
|
|
369
|
+
You need to add the `vite-plugin-elm` plugin before UnoCSS's plugin.
|
|
370
|
+
|
|
371
|
+
```ts
|
|
372
|
+
// vite.config.js
|
|
373
|
+
import { defineConfig } from 'vite'
|
|
374
|
+
import elmPlugin from 'vite-plugin-elm'
|
|
375
|
+
import Unocss from 'unocss/vite'
|
|
376
|
+
|
|
377
|
+
export default defineConfig({
|
|
378
|
+
plugins: [
|
|
379
|
+
elmPlugin(),
|
|
380
|
+
Unocss({
|
|
381
|
+
/* options */
|
|
382
|
+
})
|
|
383
|
+
]
|
|
384
|
+
})
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
You have a `Vite + Elm` example project on [test/fixtures/vite-elm](https://github.com/antfu/unocss/tree/main/test/fixtures/vite-elm) directory.
|
|
388
|
+
|
|
363
389
|
## License
|
|
364
390
|
|
|
365
391
|
MIT License © 2021-PRESENT [Anthony Fu](https://github.com/antfu)
|
package/dist/index.cjs
CHANGED
|
@@ -13,7 +13,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
13
13
|
const UnocssInspector__default = /*#__PURE__*/_interopDefaultLegacy(UnocssInspector);
|
|
14
14
|
|
|
15
15
|
const defaultExclude = [/\.(css|postcss|sass|scss|less|stylus|styl)$/];
|
|
16
|
-
const defaultInclude = [/\.vue$/, /\.vue\?vue/, /\.svelte$/, /\.[jt]sx$/, /\.mdx?$/, /\.astro$/];
|
|
16
|
+
const defaultInclude = [/\.vue$/, /\.vue\?vue/, /\.svelte$/, /\.[jt]sx$/, /\.mdx?$/, /\.astro$/, /\.elm$/];
|
|
17
17
|
|
|
18
18
|
const VIRTUAL_ENTRY_ALIAS = [
|
|
19
19
|
/^(?:virtual:)?uno(?::(.+))?\.css(\?.*)?$/
|
|
@@ -475,6 +475,39 @@ function VueScopedPlugin({ uno, ready }) {
|
|
|
475
475
|
};
|
|
476
476
|
}
|
|
477
477
|
|
|
478
|
+
function SvelteScopedPlugin({ uno, ready }) {
|
|
479
|
+
let filter = pluginutils.createFilter([/\.svelte$/], defaultExclude);
|
|
480
|
+
async function transformSFC(code) {
|
|
481
|
+
const { css } = await uno.generate(code);
|
|
482
|
+
if (!css)
|
|
483
|
+
return null;
|
|
484
|
+
return `${code}
|
|
485
|
+
<style>${css}</style>`;
|
|
486
|
+
}
|
|
487
|
+
return {
|
|
488
|
+
name: "unocss:svelte-scoped",
|
|
489
|
+
enforce: "pre",
|
|
490
|
+
async configResolved() {
|
|
491
|
+
const { config } = await ready;
|
|
492
|
+
filter = pluginutils.createFilter(config.include || [/\.svelte$/], config.exclude || defaultExclude);
|
|
493
|
+
},
|
|
494
|
+
transform(code, id) {
|
|
495
|
+
if (!filter(id))
|
|
496
|
+
return;
|
|
497
|
+
return transformSFC(code);
|
|
498
|
+
},
|
|
499
|
+
handleHotUpdate(ctx) {
|
|
500
|
+
const read = ctx.read;
|
|
501
|
+
if (filter(ctx.file)) {
|
|
502
|
+
ctx.read = async () => {
|
|
503
|
+
const code = await read();
|
|
504
|
+
return await transformSFC(code) || code;
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
|
|
478
511
|
function ShadowDomModuleModePlugin({ uno }) {
|
|
479
512
|
const partExtractorRegex = /^part-\[(.+)]:/;
|
|
480
513
|
const nameRegexp = /<([^\s^!>]+)\s*([^>]*)>/;
|
|
@@ -608,6 +641,8 @@ function UnocssPlugin(configOrPath, defaults = {}) {
|
|
|
608
641
|
plugins.push(PerModuleModePlugin(ctx));
|
|
609
642
|
} else if (mode === "vue-scoped") {
|
|
610
643
|
plugins.push(VueScopedPlugin(ctx));
|
|
644
|
+
} else if (mode === "svelte-scoped") {
|
|
645
|
+
plugins.push(SvelteScopedPlugin(ctx));
|
|
611
646
|
} else if (mode === "shadow-dom") {
|
|
612
647
|
plugins.push(ShadowDomModuleModePlugin(ctx));
|
|
613
648
|
} else if (mode === "global") {
|
|
@@ -625,6 +660,7 @@ exports.GlobalModeBuildPlugin = GlobalModeBuildPlugin;
|
|
|
625
660
|
exports.GlobalModeDevPlugin = GlobalModeDevPlugin;
|
|
626
661
|
exports.GlobalModePlugin = GlobalModePlugin;
|
|
627
662
|
exports.PerModuleModePlugin = PerModuleModePlugin;
|
|
663
|
+
exports.SvelteScopedPlugin = SvelteScopedPlugin;
|
|
628
664
|
exports.VueScopedPlugin = VueScopedPlugin;
|
|
629
665
|
exports["default"] = UnocssPlugin;
|
|
630
666
|
exports.defineConfig = defineConfig;
|
package/dist/index.d.ts
CHANGED
|
@@ -17,11 +17,12 @@ interface VitePluginConfig<Theme extends {} = {}> extends UserConfig<Theme> {
|
|
|
17
17
|
* - `dist-chunk` - generate a CSS sheet for each code chunk on build, great for MPA
|
|
18
18
|
* - `per-module` - generate a CSS sheet for each module, can be scoped
|
|
19
19
|
* - `vue-scoped` - inject generated CSS to Vue SFC's `<style scoped>` for isolation
|
|
20
|
+
* - `svelte-scoped` - inject generated CSS to Svelte's `<style>` for isolation
|
|
20
21
|
* - `shadow-dom` - inject generated CSS to `Shadow DOM` css style block for each web component
|
|
21
22
|
*
|
|
22
23
|
* @default 'global'
|
|
23
24
|
*/
|
|
24
|
-
mode?: 'global' | 'per-module' | 'vue-scoped' | 'dist-chunk' | 'shadow-dom';
|
|
25
|
+
mode?: 'global' | 'per-module' | 'vue-scoped' | 'svelte-scoped' | 'dist-chunk' | 'shadow-dom';
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
interface UnocssPluginContext<Config extends UserConfig = UserConfig> {
|
|
@@ -49,7 +50,9 @@ declare function PerModuleModePlugin({ uno, filter }: UnocssPluginContext): Plug
|
|
|
49
50
|
|
|
50
51
|
declare function VueScopedPlugin({ uno, ready }: UnocssPluginContext): Plugin;
|
|
51
52
|
|
|
53
|
+
declare function SvelteScopedPlugin({ uno, ready }: UnocssPluginContext): Plugin;
|
|
54
|
+
|
|
52
55
|
declare function defineConfig<Theme extends {}>(config: VitePluginConfig<Theme>): VitePluginConfig<Theme>;
|
|
53
56
|
declare function UnocssPlugin(configOrPath?: VitePluginConfig | string, defaults?: UserConfigDefaults): Plugin[];
|
|
54
57
|
|
|
55
|
-
export { ChunkModeBuildPlugin, GlobalModeBuildPlugin, GlobalModeDevPlugin, GlobalModePlugin, PerModuleModePlugin, UnocssPluginContext, VitePluginConfig, VueScopedPlugin, UnocssPlugin as default, defineConfig };
|
|
58
|
+
export { ChunkModeBuildPlugin, GlobalModeBuildPlugin, GlobalModeDevPlugin, GlobalModePlugin, PerModuleModePlugin, SvelteScopedPlugin, UnocssPluginContext, VitePluginConfig, VueScopedPlugin, UnocssPlugin as default, defineConfig };
|
package/dist/index.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { createGenerator, BetterMap } from '@unocss/core';
|
|
|
5
5
|
import { createHash } from 'crypto';
|
|
6
6
|
|
|
7
7
|
const defaultExclude = [/\.(css|postcss|sass|scss|less|stylus|styl)$/];
|
|
8
|
-
const defaultInclude = [/\.vue$/, /\.vue\?vue/, /\.svelte$/, /\.[jt]sx$/, /\.mdx?$/, /\.astro$/];
|
|
8
|
+
const defaultInclude = [/\.vue$/, /\.vue\?vue/, /\.svelte$/, /\.[jt]sx$/, /\.mdx?$/, /\.astro$/, /\.elm$/];
|
|
9
9
|
|
|
10
10
|
const VIRTUAL_ENTRY_ALIAS = [
|
|
11
11
|
/^(?:virtual:)?uno(?::(.+))?\.css(\?.*)?$/
|
|
@@ -467,6 +467,39 @@ function VueScopedPlugin({ uno, ready }) {
|
|
|
467
467
|
};
|
|
468
468
|
}
|
|
469
469
|
|
|
470
|
+
function SvelteScopedPlugin({ uno, ready }) {
|
|
471
|
+
let filter = createFilter([/\.svelte$/], defaultExclude);
|
|
472
|
+
async function transformSFC(code) {
|
|
473
|
+
const { css } = await uno.generate(code);
|
|
474
|
+
if (!css)
|
|
475
|
+
return null;
|
|
476
|
+
return `${code}
|
|
477
|
+
<style>${css}</style>`;
|
|
478
|
+
}
|
|
479
|
+
return {
|
|
480
|
+
name: "unocss:svelte-scoped",
|
|
481
|
+
enforce: "pre",
|
|
482
|
+
async configResolved() {
|
|
483
|
+
const { config } = await ready;
|
|
484
|
+
filter = createFilter(config.include || [/\.svelte$/], config.exclude || defaultExclude);
|
|
485
|
+
},
|
|
486
|
+
transform(code, id) {
|
|
487
|
+
if (!filter(id))
|
|
488
|
+
return;
|
|
489
|
+
return transformSFC(code);
|
|
490
|
+
},
|
|
491
|
+
handleHotUpdate(ctx) {
|
|
492
|
+
const read = ctx.read;
|
|
493
|
+
if (filter(ctx.file)) {
|
|
494
|
+
ctx.read = async () => {
|
|
495
|
+
const code = await read();
|
|
496
|
+
return await transformSFC(code) || code;
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
|
|
470
503
|
function ShadowDomModuleModePlugin({ uno }) {
|
|
471
504
|
const partExtractorRegex = /^part-\[(.+)]:/;
|
|
472
505
|
const nameRegexp = /<([^\s^!>]+)\s*([^>]*)>/;
|
|
@@ -600,6 +633,8 @@ function UnocssPlugin(configOrPath, defaults = {}) {
|
|
|
600
633
|
plugins.push(PerModuleModePlugin(ctx));
|
|
601
634
|
} else if (mode === "vue-scoped") {
|
|
602
635
|
plugins.push(VueScopedPlugin(ctx));
|
|
636
|
+
} else if (mode === "svelte-scoped") {
|
|
637
|
+
plugins.push(SvelteScopedPlugin(ctx));
|
|
603
638
|
} else if (mode === "shadow-dom") {
|
|
604
639
|
plugins.push(ShadowDomModuleModePlugin(ctx));
|
|
605
640
|
} else if (mode === "global") {
|
|
@@ -612,4 +647,4 @@ function UnocssPlugin(configOrPath, defaults = {}) {
|
|
|
612
647
|
return plugins.filter(Boolean);
|
|
613
648
|
}
|
|
614
649
|
|
|
615
|
-
export { ChunkModeBuildPlugin, GlobalModeBuildPlugin, GlobalModeDevPlugin, GlobalModePlugin, PerModuleModePlugin, VueScopedPlugin, UnocssPlugin as default, defineConfig };
|
|
650
|
+
export { ChunkModeBuildPlugin, GlobalModeBuildPlugin, GlobalModeDevPlugin, GlobalModePlugin, PerModuleModePlugin, SvelteScopedPlugin, VueScopedPlugin, UnocssPlugin as default, defineConfig };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/vite",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.0",
|
|
4
4
|
"description": "The Vite plugin for UnoCSS",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"unocss",
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@rollup/pluginutils": "^4.1.2",
|
|
38
|
-
"@unocss/config": "0.
|
|
39
|
-
"@unocss/core": "0.
|
|
40
|
-
"@unocss/inspector": "0.
|
|
41
|
-
"@unocss/scope": "0.
|
|
38
|
+
"@unocss/config": "0.22.0",
|
|
39
|
+
"@unocss/core": "0.22.0",
|
|
40
|
+
"@unocss/inspector": "0.22.0",
|
|
41
|
+
"@unocss/scope": "0.22.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"vite": "^2.7.10"
|