@unocss/vite 0.21.2 → 0.22.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/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,41 @@ 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
+ if (code.match(/<style[^>]*>[\s\S]*?<\/style\s*>/))
485
+ return code.replace(/(<style[^>]*>)/, `$1${css}`);
486
+ return `${code}
487
+ <style>${css}</style>`;
488
+ }
489
+ return {
490
+ name: "unocss:svelte-scoped",
491
+ enforce: "pre",
492
+ async configResolved() {
493
+ const { config } = await ready;
494
+ filter = pluginutils.createFilter(config.include || [/\.svelte$/], config.exclude || defaultExclude);
495
+ },
496
+ transform(code, id) {
497
+ if (!filter(id))
498
+ return;
499
+ return transformSFC(code);
500
+ },
501
+ handleHotUpdate(ctx) {
502
+ const read = ctx.read;
503
+ if (filter(ctx.file)) {
504
+ ctx.read = async () => {
505
+ const code = await read();
506
+ return await transformSFC(code) || code;
507
+ };
508
+ }
509
+ }
510
+ };
511
+ }
512
+
478
513
  function ShadowDomModuleModePlugin({ uno }) {
479
514
  const partExtractorRegex = /^part-\[(.+)]:/;
480
515
  const nameRegexp = /<([^\s^!>]+)\s*([^>]*)>/;
@@ -608,6 +643,8 @@ function UnocssPlugin(configOrPath, defaults = {}) {
608
643
  plugins.push(PerModuleModePlugin(ctx));
609
644
  } else if (mode === "vue-scoped") {
610
645
  plugins.push(VueScopedPlugin(ctx));
646
+ } else if (mode === "svelte-scoped") {
647
+ plugins.push(SvelteScopedPlugin(ctx));
611
648
  } else if (mode === "shadow-dom") {
612
649
  plugins.push(ShadowDomModuleModePlugin(ctx));
613
650
  } else if (mode === "global") {
@@ -625,6 +662,7 @@ exports.GlobalModeBuildPlugin = GlobalModeBuildPlugin;
625
662
  exports.GlobalModeDevPlugin = GlobalModeDevPlugin;
626
663
  exports.GlobalModePlugin = GlobalModePlugin;
627
664
  exports.PerModuleModePlugin = PerModuleModePlugin;
665
+ exports.SvelteScopedPlugin = SvelteScopedPlugin;
628
666
  exports.VueScopedPlugin = VueScopedPlugin;
629
667
  exports["default"] = UnocssPlugin;
630
668
  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,41 @@ 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
+ if (code.match(/<style[^>]*>[\s\S]*?<\/style\s*>/))
477
+ return code.replace(/(<style[^>]*>)/, `$1${css}`);
478
+ return `${code}
479
+ <style>${css}</style>`;
480
+ }
481
+ return {
482
+ name: "unocss:svelte-scoped",
483
+ enforce: "pre",
484
+ async configResolved() {
485
+ const { config } = await ready;
486
+ filter = createFilter(config.include || [/\.svelte$/], config.exclude || defaultExclude);
487
+ },
488
+ transform(code, id) {
489
+ if (!filter(id))
490
+ return;
491
+ return transformSFC(code);
492
+ },
493
+ handleHotUpdate(ctx) {
494
+ const read = ctx.read;
495
+ if (filter(ctx.file)) {
496
+ ctx.read = async () => {
497
+ const code = await read();
498
+ return await transformSFC(code) || code;
499
+ };
500
+ }
501
+ }
502
+ };
503
+ }
504
+
470
505
  function ShadowDomModuleModePlugin({ uno }) {
471
506
  const partExtractorRegex = /^part-\[(.+)]:/;
472
507
  const nameRegexp = /<([^\s^!>]+)\s*([^>]*)>/;
@@ -600,6 +635,8 @@ function UnocssPlugin(configOrPath, defaults = {}) {
600
635
  plugins.push(PerModuleModePlugin(ctx));
601
636
  } else if (mode === "vue-scoped") {
602
637
  plugins.push(VueScopedPlugin(ctx));
638
+ } else if (mode === "svelte-scoped") {
639
+ plugins.push(SvelteScopedPlugin(ctx));
603
640
  } else if (mode === "shadow-dom") {
604
641
  plugins.push(ShadowDomModuleModePlugin(ctx));
605
642
  } else if (mode === "global") {
@@ -612,4 +649,4 @@ function UnocssPlugin(configOrPath, defaults = {}) {
612
649
  return plugins.filter(Boolean);
613
650
  }
614
651
 
615
- export { ChunkModeBuildPlugin, GlobalModeBuildPlugin, GlobalModeDevPlugin, GlobalModePlugin, PerModuleModePlugin, VueScopedPlugin, UnocssPlugin as default, defineConfig };
652
+ 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.21.2",
3
+ "version": "0.22.3",
4
4
  "description": "The Vite plugin for UnoCSS",
5
5
  "keywords": [
6
6
  "unocss",
@@ -35,13 +35,13 @@
35
35
  ],
36
36
  "dependencies": {
37
37
  "@rollup/pluginutils": "^4.1.2",
38
- "@unocss/config": "0.21.2",
39
- "@unocss/core": "0.21.2",
40
- "@unocss/inspector": "0.21.2",
41
- "@unocss/scope": "0.21.2"
38
+ "@unocss/config": "0.22.3",
39
+ "@unocss/core": "0.22.3",
40
+ "@unocss/inspector": "0.22.3",
41
+ "@unocss/scope": "0.22.3"
42
42
  },
43
43
  "devDependencies": {
44
- "vite": "^2.7.10"
44
+ "vite": "^2.7.12"
45
45
  },
46
46
  "scripts": {
47
47
  "build": "unbuild",