@unocss/vite 0.24.3 → 0.26.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/dist/index.cjs CHANGED
@@ -290,6 +290,8 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
290
290
  function setWarnTimer() {
291
291
  if (!resolved && !resolvedWarnTimer) {
292
292
  resolvedWarnTimer = setTimeout(() => {
293
+ if (process.env.TEST || process.env.NODE_ENV === "test")
294
+ return;
293
295
  if (!resolved) {
294
296
  const msg = "[unocss] entry module not found, have you add `import 'uno.css'` in your main entry?";
295
297
  console.warn(msg);
@@ -626,6 +628,58 @@ function ConfigHMRPlugin(ctx) {
626
628
  };
627
629
  }
628
630
 
631
+ function initTransformerPlugins(ctx) {
632
+ async function applyTransformers(c, _code, id, enforce) {
633
+ const transformers = (ctx.uno.config.transformers || []).filter((i) => i.enforce === enforce);
634
+ if (!transformers.length)
635
+ return void 0;
636
+ let code = _code;
637
+ for (const t of transformers) {
638
+ if (t.idFilter) {
639
+ if (!t.idFilter(id))
640
+ continue;
641
+ } else if (!ctx.filter(code, id)) {
642
+ continue;
643
+ }
644
+ const result = await t.transform(code, id, ctx);
645
+ if (result == null)
646
+ continue;
647
+ if (typeof result === "string") {
648
+ code = result;
649
+ } else {
650
+ code = result.code;
651
+ if (result.map && "sourcemapChain" in c)
652
+ c.sourcemapChain.push(result.map);
653
+ }
654
+ }
655
+ if (code === _code)
656
+ return null;
657
+ return code;
658
+ }
659
+ return [
660
+ {
661
+ name: "unocss:transformers:deafult",
662
+ transform(code, id) {
663
+ return applyTransformers(this, code, id);
664
+ }
665
+ },
666
+ {
667
+ name: "unocss:transformers:pre",
668
+ enforce: "pre",
669
+ transform(code, id) {
670
+ return applyTransformers(this, code, id, "pre");
671
+ }
672
+ },
673
+ {
674
+ name: "unocss:transformers:post",
675
+ enforce: "post",
676
+ transform(code, id) {
677
+ return applyTransformers(this, code, id, "post");
678
+ }
679
+ }
680
+ ];
681
+ }
682
+
629
683
  function defineConfig(config) {
630
684
  return config;
631
685
  }
@@ -634,6 +688,7 @@ function UnocssPlugin(configOrPath, defaults = {}) {
634
688
  const inlineConfig = configOrPath && typeof configOrPath !== "string" ? configOrPath : {};
635
689
  const mode = inlineConfig.mode ?? "global";
636
690
  const plugins = [
691
+ ...initTransformerPlugins(ctx),
637
692
  ConfigHMRPlugin(ctx)
638
693
  ];
639
694
  if (inlineConfig.inspector !== false)
package/dist/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import * as vite from 'vite';
2
2
  import { Plugin } from 'vite';
3
- import { UserConfig, UnoGenerator, BetterMap, UserConfigDefaults } from '@unocss/core';
4
- import { LoadConfigResult } from '@unocss/config';
3
+ import { UserConfig, UnocssPluginContext, UserConfigDefaults } from '@unocss/core';
5
4
 
6
5
  interface VitePluginConfig<Theme extends {} = {}> extends UserConfig<Theme> {
7
6
  /**
@@ -23,19 +22,13 @@ interface VitePluginConfig<Theme extends {} = {}> extends UserConfig<Theme> {
23
22
  * @default 'global'
24
23
  */
25
24
  mode?: 'global' | 'per-module' | 'vue-scoped' | 'svelte-scoped' | 'dist-chunk' | 'shadow-dom';
26
- }
27
-
28
- interface UnocssPluginContext<Config extends UserConfig = UserConfig> {
29
- ready: Promise<LoadConfigResult<Config>>;
30
- uno: UnoGenerator;
31
- tokens: Set<string>;
32
- modules: BetterMap<string, string>;
33
- filter: (code: string, id: string) => boolean;
34
- extract: (code: string, id?: string) => Promise<void>;
35
- reloadConfig: () => Promise<LoadConfigResult<Config>>;
36
- getConfig: () => Promise<Config>;
37
- invalidate: () => void;
38
- onInvalidate: (fn: () => void) => void;
25
+ /**
26
+ * Transform CSS for `@apply` directive
27
+ *
28
+ * @experimental
29
+ * @default false
30
+ */
31
+ transformCSS?: boolean | 'pre' | 'post';
39
32
  }
40
33
 
41
34
  declare function ChunkModeBuildPlugin({ uno, filter }: UnocssPluginContext): Plugin;
@@ -55,4 +48,4 @@ declare function SvelteScopedPlugin({ uno, ready }: UnocssPluginContext): Plugin
55
48
  declare function defineConfig<Theme extends {}>(config: VitePluginConfig<Theme>): VitePluginConfig<Theme>;
56
49
  declare function UnocssPlugin(configOrPath?: VitePluginConfig | string, defaults?: UserConfigDefaults): Plugin[];
57
50
 
58
- export { ChunkModeBuildPlugin, GlobalModeBuildPlugin, GlobalModeDevPlugin, GlobalModePlugin, PerModuleModePlugin, SvelteScopedPlugin, UnocssPluginContext, VitePluginConfig, VueScopedPlugin, UnocssPlugin as default, defineConfig };
51
+ export { ChunkModeBuildPlugin, GlobalModeBuildPlugin, GlobalModeDevPlugin, GlobalModePlugin, PerModuleModePlugin, SvelteScopedPlugin, VitePluginConfig, VueScopedPlugin, UnocssPlugin as default, defineConfig };
package/dist/index.mjs CHANGED
@@ -282,6 +282,8 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
282
282
  function setWarnTimer() {
283
283
  if (!resolved && !resolvedWarnTimer) {
284
284
  resolvedWarnTimer = setTimeout(() => {
285
+ if (process.env.TEST || process.env.NODE_ENV === "test")
286
+ return;
285
287
  if (!resolved) {
286
288
  const msg = "[unocss] entry module not found, have you add `import 'uno.css'` in your main entry?";
287
289
  console.warn(msg);
@@ -618,6 +620,58 @@ function ConfigHMRPlugin(ctx) {
618
620
  };
619
621
  }
620
622
 
623
+ function initTransformerPlugins(ctx) {
624
+ async function applyTransformers(c, _code, id, enforce) {
625
+ const transformers = (ctx.uno.config.transformers || []).filter((i) => i.enforce === enforce);
626
+ if (!transformers.length)
627
+ return void 0;
628
+ let code = _code;
629
+ for (const t of transformers) {
630
+ if (t.idFilter) {
631
+ if (!t.idFilter(id))
632
+ continue;
633
+ } else if (!ctx.filter(code, id)) {
634
+ continue;
635
+ }
636
+ const result = await t.transform(code, id, ctx);
637
+ if (result == null)
638
+ continue;
639
+ if (typeof result === "string") {
640
+ code = result;
641
+ } else {
642
+ code = result.code;
643
+ if (result.map && "sourcemapChain" in c)
644
+ c.sourcemapChain.push(result.map);
645
+ }
646
+ }
647
+ if (code === _code)
648
+ return null;
649
+ return code;
650
+ }
651
+ return [
652
+ {
653
+ name: "unocss:transformers:deafult",
654
+ transform(code, id) {
655
+ return applyTransformers(this, code, id);
656
+ }
657
+ },
658
+ {
659
+ name: "unocss:transformers:pre",
660
+ enforce: "pre",
661
+ transform(code, id) {
662
+ return applyTransformers(this, code, id, "pre");
663
+ }
664
+ },
665
+ {
666
+ name: "unocss:transformers:post",
667
+ enforce: "post",
668
+ transform(code, id) {
669
+ return applyTransformers(this, code, id, "post");
670
+ }
671
+ }
672
+ ];
673
+ }
674
+
621
675
  function defineConfig(config) {
622
676
  return config;
623
677
  }
@@ -626,6 +680,7 @@ function UnocssPlugin(configOrPath, defaults = {}) {
626
680
  const inlineConfig = configOrPath && typeof configOrPath !== "string" ? configOrPath : {};
627
681
  const mode = inlineConfig.mode ?? "global";
628
682
  const plugins = [
683
+ ...initTransformerPlugins(ctx),
629
684
  ConfigHMRPlugin(ctx)
630
685
  ];
631
686
  if (inlineConfig.inspector !== false)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/vite",
3
- "version": "0.24.3",
3
+ "version": "0.26.0",
4
4
  "description": "The Vite plugin for UnoCSS",
5
5
  "keywords": [
6
6
  "unocss",
@@ -11,15 +11,18 @@
11
11
  "bugs": {
12
12
  "url": "https://github.com/unocss/unocss/issues"
13
13
  },
14
+ "license": "MIT",
14
15
  "repository": {
15
16
  "type": "git",
16
17
  "url": "git+https://github.com/unocss/unocss.git",
17
18
  "directory": "packages/vite"
18
19
  },
19
20
  "funding": "https://github.com/sponsors/antfu",
20
- "license": "MIT",
21
21
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
22
22
  "sideEffects": false,
23
+ "files": [
24
+ "dist"
25
+ ],
23
26
  "exports": {
24
27
  ".": {
25
28
  "require": "./dist/index.cjs",
@@ -30,15 +33,13 @@
30
33
  "main": "dist/index.cjs",
31
34
  "module": "dist/index.mjs",
32
35
  "types": "dist/index.d.ts",
33
- "files": [
34
- "dist"
35
- ],
36
36
  "dependencies": {
37
37
  "@rollup/pluginutils": "^4.1.2",
38
- "@unocss/config": "0.24.3",
39
- "@unocss/core": "0.24.3",
40
- "@unocss/inspector": "0.24.3",
41
- "@unocss/scope": "0.24.3"
38
+ "@unocss/config": "0.26.0",
39
+ "@unocss/core": "0.26.0",
40
+ "@unocss/transformer-directives": "0.26.0",
41
+ "@unocss/inspector": "0.26.0",
42
+ "@unocss/scope": "0.26.0"
42
43
  },
43
44
  "devDependencies": {
44
45
  "vite": "^2.7.13"