@unocss/vite 0.24.4 → 0.26.1
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 +57 -1
- package/dist/index.d.ts +9 -16
- package/dist/index.mjs +57 -1
- package/package.json +10 -9
package/dist/index.cjs
CHANGED
|
@@ -12,7 +12,8 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
12
12
|
|
|
13
13
|
const UnocssInspector__default = /*#__PURE__*/_interopDefaultLegacy(UnocssInspector);
|
|
14
14
|
|
|
15
|
-
const
|
|
15
|
+
const regexCssId = /\.(css|postcss|sass|scss|less|stylus|styl)$/;
|
|
16
|
+
const defaultExclude = [regexCssId];
|
|
16
17
|
const defaultInclude = [/\.vue$/, /\.vue\?vue/, /\.svelte$/, /\.[jt]sx$/, /\.mdx?$/, /\.astro$/, /\.elm$/];
|
|
17
18
|
|
|
18
19
|
const VIRTUAL_ENTRY_ALIAS = [
|
|
@@ -290,6 +291,8 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
|
|
|
290
291
|
function setWarnTimer() {
|
|
291
292
|
if (!resolved && !resolvedWarnTimer) {
|
|
292
293
|
resolvedWarnTimer = setTimeout(() => {
|
|
294
|
+
if (process.env.TEST || process.env.NODE_ENV === "test")
|
|
295
|
+
return;
|
|
293
296
|
if (!resolved) {
|
|
294
297
|
const msg = "[unocss] entry module not found, have you add `import 'uno.css'` in your main entry?";
|
|
295
298
|
console.warn(msg);
|
|
@@ -626,6 +629,58 @@ function ConfigHMRPlugin(ctx) {
|
|
|
626
629
|
};
|
|
627
630
|
}
|
|
628
631
|
|
|
632
|
+
function initTransformerPlugins(ctx) {
|
|
633
|
+
async function applyTransformers(c, _code, id, enforce) {
|
|
634
|
+
const transformers = (ctx.uno.config.transformers || []).filter((i) => i.enforce === enforce);
|
|
635
|
+
if (!transformers.length)
|
|
636
|
+
return void 0;
|
|
637
|
+
let code = _code;
|
|
638
|
+
for (const t of transformers) {
|
|
639
|
+
if (t.idFilter) {
|
|
640
|
+
if (!t.idFilter(id))
|
|
641
|
+
continue;
|
|
642
|
+
} else if (!ctx.filter(code, id)) {
|
|
643
|
+
continue;
|
|
644
|
+
}
|
|
645
|
+
const result = await t.transform(code, id, ctx);
|
|
646
|
+
if (result == null)
|
|
647
|
+
continue;
|
|
648
|
+
if (typeof result === "string") {
|
|
649
|
+
code = result;
|
|
650
|
+
} else {
|
|
651
|
+
code = result.code;
|
|
652
|
+
if (result.map && "sourcemapChain" in c)
|
|
653
|
+
c.sourcemapChain.push(result.map);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
if (code === _code)
|
|
657
|
+
return null;
|
|
658
|
+
return code;
|
|
659
|
+
}
|
|
660
|
+
return [
|
|
661
|
+
{
|
|
662
|
+
name: "unocss:transformers:deafult",
|
|
663
|
+
transform(code, id) {
|
|
664
|
+
return applyTransformers(this, code, id);
|
|
665
|
+
}
|
|
666
|
+
},
|
|
667
|
+
{
|
|
668
|
+
name: "unocss:transformers:pre",
|
|
669
|
+
enforce: "pre",
|
|
670
|
+
transform(code, id) {
|
|
671
|
+
return applyTransformers(this, code, id, "pre");
|
|
672
|
+
}
|
|
673
|
+
},
|
|
674
|
+
{
|
|
675
|
+
name: "unocss:transformers:post",
|
|
676
|
+
enforce: "post",
|
|
677
|
+
transform(code, id) {
|
|
678
|
+
return applyTransformers(this, code, id, "post");
|
|
679
|
+
}
|
|
680
|
+
}
|
|
681
|
+
];
|
|
682
|
+
}
|
|
683
|
+
|
|
629
684
|
function defineConfig(config) {
|
|
630
685
|
return config;
|
|
631
686
|
}
|
|
@@ -634,6 +689,7 @@ function UnocssPlugin(configOrPath, defaults = {}) {
|
|
|
634
689
|
const inlineConfig = configOrPath && typeof configOrPath !== "string" ? configOrPath : {};
|
|
635
690
|
const mode = inlineConfig.mode ?? "global";
|
|
636
691
|
const plugins = [
|
|
692
|
+
...initTransformerPlugins(ctx),
|
|
637
693
|
ConfigHMRPlugin(ctx)
|
|
638
694
|
];
|
|
639
695
|
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,
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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,
|
|
51
|
+
export { ChunkModeBuildPlugin, GlobalModeBuildPlugin, GlobalModeDevPlugin, GlobalModePlugin, PerModuleModePlugin, SvelteScopedPlugin, VitePluginConfig, VueScopedPlugin, UnocssPlugin as default, defineConfig };
|
package/dist/index.mjs
CHANGED
|
@@ -4,7 +4,8 @@ import { createConfigLoader } from '@unocss/config';
|
|
|
4
4
|
import { createGenerator, BetterMap } from '@unocss/core';
|
|
5
5
|
import { createHash } from 'crypto';
|
|
6
6
|
|
|
7
|
-
const
|
|
7
|
+
const regexCssId = /\.(css|postcss|sass|scss|less|stylus|styl)$/;
|
|
8
|
+
const defaultExclude = [regexCssId];
|
|
8
9
|
const defaultInclude = [/\.vue$/, /\.vue\?vue/, /\.svelte$/, /\.[jt]sx$/, /\.mdx?$/, /\.astro$/, /\.elm$/];
|
|
9
10
|
|
|
10
11
|
const VIRTUAL_ENTRY_ALIAS = [
|
|
@@ -282,6 +283,8 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
|
|
|
282
283
|
function setWarnTimer() {
|
|
283
284
|
if (!resolved && !resolvedWarnTimer) {
|
|
284
285
|
resolvedWarnTimer = setTimeout(() => {
|
|
286
|
+
if (process.env.TEST || process.env.NODE_ENV === "test")
|
|
287
|
+
return;
|
|
285
288
|
if (!resolved) {
|
|
286
289
|
const msg = "[unocss] entry module not found, have you add `import 'uno.css'` in your main entry?";
|
|
287
290
|
console.warn(msg);
|
|
@@ -618,6 +621,58 @@ function ConfigHMRPlugin(ctx) {
|
|
|
618
621
|
};
|
|
619
622
|
}
|
|
620
623
|
|
|
624
|
+
function initTransformerPlugins(ctx) {
|
|
625
|
+
async function applyTransformers(c, _code, id, enforce) {
|
|
626
|
+
const transformers = (ctx.uno.config.transformers || []).filter((i) => i.enforce === enforce);
|
|
627
|
+
if (!transformers.length)
|
|
628
|
+
return void 0;
|
|
629
|
+
let code = _code;
|
|
630
|
+
for (const t of transformers) {
|
|
631
|
+
if (t.idFilter) {
|
|
632
|
+
if (!t.idFilter(id))
|
|
633
|
+
continue;
|
|
634
|
+
} else if (!ctx.filter(code, id)) {
|
|
635
|
+
continue;
|
|
636
|
+
}
|
|
637
|
+
const result = await t.transform(code, id, ctx);
|
|
638
|
+
if (result == null)
|
|
639
|
+
continue;
|
|
640
|
+
if (typeof result === "string") {
|
|
641
|
+
code = result;
|
|
642
|
+
} else {
|
|
643
|
+
code = result.code;
|
|
644
|
+
if (result.map && "sourcemapChain" in c)
|
|
645
|
+
c.sourcemapChain.push(result.map);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
if (code === _code)
|
|
649
|
+
return null;
|
|
650
|
+
return code;
|
|
651
|
+
}
|
|
652
|
+
return [
|
|
653
|
+
{
|
|
654
|
+
name: "unocss:transformers:deafult",
|
|
655
|
+
transform(code, id) {
|
|
656
|
+
return applyTransformers(this, code, id);
|
|
657
|
+
}
|
|
658
|
+
},
|
|
659
|
+
{
|
|
660
|
+
name: "unocss:transformers:pre",
|
|
661
|
+
enforce: "pre",
|
|
662
|
+
transform(code, id) {
|
|
663
|
+
return applyTransformers(this, code, id, "pre");
|
|
664
|
+
}
|
|
665
|
+
},
|
|
666
|
+
{
|
|
667
|
+
name: "unocss:transformers:post",
|
|
668
|
+
enforce: "post",
|
|
669
|
+
transform(code, id) {
|
|
670
|
+
return applyTransformers(this, code, id, "post");
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
];
|
|
674
|
+
}
|
|
675
|
+
|
|
621
676
|
function defineConfig(config) {
|
|
622
677
|
return config;
|
|
623
678
|
}
|
|
@@ -626,6 +681,7 @@ function UnocssPlugin(configOrPath, defaults = {}) {
|
|
|
626
681
|
const inlineConfig = configOrPath && typeof configOrPath !== "string" ? configOrPath : {};
|
|
627
682
|
const mode = inlineConfig.mode ?? "global";
|
|
628
683
|
const plugins = [
|
|
684
|
+
...initTransformerPlugins(ctx),
|
|
629
685
|
ConfigHMRPlugin(ctx)
|
|
630
686
|
];
|
|
631
687
|
if (inlineConfig.inspector !== false)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/vite",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.1",
|
|
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.
|
|
39
|
-
"@unocss/core": "0.
|
|
40
|
-
"@unocss/
|
|
41
|
-
"@unocss/
|
|
38
|
+
"@unocss/config": "0.26.1",
|
|
39
|
+
"@unocss/core": "0.26.1",
|
|
40
|
+
"@unocss/transformer-directives": "0.26.1",
|
|
41
|
+
"@unocss/inspector": "0.26.1",
|
|
42
|
+
"@unocss/scope": "0.26.1"
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
44
45
|
"vite": "^2.7.13"
|