@unocss/vite 0.8.1 → 0.9.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 +2 -1
- package/dist/index.d.ts +10 -8
- package/dist/index.js +38 -26
- package/dist/index.mjs +36 -25
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# @unocss/vite
|
|
2
2
|
|
|
3
|
-
The Vite plugin for UnoCSS.
|
|
3
|
+
The Vite plugin for UnoCSS. Ships with the `unocss` package.
|
|
4
4
|
|
|
5
|
+
> This plugin does not come with any default presets. You are are building a meta framework on top of UnoCSS, see [this file](https://github.com/antfu/unocss/blob/main/packages/unocss/src/vite.ts) for an example to bind the default presets.
|
|
5
6
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import * as vite from 'vite';
|
|
2
2
|
import { Plugin } from 'vite';
|
|
3
3
|
import { UserConfig, UnoGenerator, BetterMap, UserConfigDefaults } from '@unocss/core';
|
|
4
|
-
import { FilterPattern } from '@rollup/pluginutils';
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
declare type FilterPattern = ReadonlyArray<string | RegExp> | string | RegExp | null;
|
|
6
|
+
interface PluginOptions<Theme extends {} = {}> extends UserConfig<Theme> {
|
|
7
7
|
include?: FilterPattern;
|
|
8
8
|
exclude?: FilterPattern;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface VitePluginOptions<Theme extends {} = {}> extends PluginOptions<Theme> {
|
|
9
12
|
/**
|
|
10
13
|
* Enable UnoCSS inspector
|
|
11
14
|
*
|
|
@@ -24,17 +27,15 @@ interface VitePluginOptions {
|
|
|
24
27
|
*/
|
|
25
28
|
mode?: 'global' | 'per-module' | 'vue-scoped' | 'dist-chunk';
|
|
26
29
|
}
|
|
27
|
-
interface UnocssPluginOptions extends UserConfig, VitePluginOptions {
|
|
28
|
-
}
|
|
29
30
|
|
|
30
|
-
declare function createContext(uno: UnoGenerator, config:
|
|
31
|
+
declare function createContext(uno: UnoGenerator, config: VitePluginOptions, configFilepath?: string): {
|
|
31
32
|
tokens: Set<string>;
|
|
32
33
|
modules: BetterMap<string, string>;
|
|
33
34
|
invalidate: () => void;
|
|
34
35
|
onInvalidate(fn: () => void): void;
|
|
35
36
|
uno: UnoGenerator;
|
|
36
37
|
scan: (code: string, id?: string | undefined) => Promise<void>;
|
|
37
|
-
config:
|
|
38
|
+
config: VitePluginOptions<{}>;
|
|
38
39
|
configFilepath: string | undefined;
|
|
39
40
|
};
|
|
40
41
|
declare type UnocssPluginContext = ReturnType<typeof createContext>;
|
|
@@ -51,6 +52,7 @@ declare function PerModuleModePlugin({ uno, config }: UnocssPluginContext): Plug
|
|
|
51
52
|
|
|
52
53
|
declare function VueScopedPlugin({ uno, config }: UnocssPluginContext): Plugin;
|
|
53
54
|
|
|
54
|
-
declare function
|
|
55
|
+
declare function defineConfig<Theme extends {}>(config: VitePluginOptions<Theme>): VitePluginOptions<Theme>;
|
|
56
|
+
declare function UnocssPlugin(configOrPath?: VitePluginOptions | string, defaults?: UserConfigDefaults): Plugin[];
|
|
55
57
|
|
|
56
|
-
export { ChunkModeBuildPlugin, GlobalModeBuildPlugin, GlobalModeDevPlugin, GlobalModePlugin, PerModuleModePlugin, UnocssPluginContext,
|
|
58
|
+
export { ChunkModeBuildPlugin, GlobalModeBuildPlugin, GlobalModeDevPlugin, GlobalModePlugin, PerModuleModePlugin, UnocssPluginContext, VitePluginOptions, VueScopedPlugin, UnocssPlugin as default, defineConfig };
|
package/dist/index.js
CHANGED
|
@@ -30,7 +30,8 @@ __export(exports, {
|
|
|
30
30
|
GlobalModePlugin: () => GlobalModePlugin,
|
|
31
31
|
PerModuleModePlugin: () => PerModuleModePlugin,
|
|
32
32
|
VueScopedPlugin: () => VueScopedPlugin,
|
|
33
|
-
default: () => UnocssPlugin
|
|
33
|
+
default: () => UnocssPlugin,
|
|
34
|
+
defineConfig: () => defineConfig
|
|
34
35
|
});
|
|
35
36
|
var import_core2 = __toModule(require("@unocss/core"));
|
|
36
37
|
var import_config2 = __toModule(require("@unocss/config"));
|
|
@@ -68,16 +69,9 @@ function createContext(uno, config, configFilepath) {
|
|
|
68
69
|
// src/modes/chunk-build.ts
|
|
69
70
|
var import_pluginutils = __toModule(require("@rollup/pluginutils"));
|
|
70
71
|
|
|
71
|
-
//
|
|
72
|
-
var import_crypto = __toModule(require("crypto"));
|
|
72
|
+
// ../plugins-common/defaults.ts
|
|
73
73
|
var defaultExclude = [/[\/\\]node_modules[\/\\]/, /[\/\\]dist[\/\\]/, /\.(css|postcss|sass|scss|less|stylus|styl)$/];
|
|
74
74
|
var defaultInclude = [/\.vue$/, /\.vue\?vue/, /\.svelte$/, /\.[jt]sx$/, /\.mdx?$/, /\.astro$/];
|
|
75
|
-
function getHash(input, length = 8) {
|
|
76
|
-
return (0, import_crypto.createHash)("sha256").update(input).digest("hex").substr(0, length);
|
|
77
|
-
}
|
|
78
|
-
function getPath(id) {
|
|
79
|
-
return id.replace(/\?.*$/, "");
|
|
80
|
-
}
|
|
81
75
|
|
|
82
76
|
// src/modes/chunk-build.ts
|
|
83
77
|
function ChunkModeBuildPlugin({ uno, config }) {
|
|
@@ -126,12 +120,21 @@ function ChunkModeBuildPlugin({ uno, config }) {
|
|
|
126
120
|
// src/modes/global/build.ts
|
|
127
121
|
var import_pluginutils2 = __toModule(require("@rollup/pluginutils"));
|
|
128
122
|
|
|
129
|
-
// src/
|
|
130
|
-
var
|
|
131
|
-
|
|
123
|
+
// src/utils.ts
|
|
124
|
+
var import_crypto = __toModule(require("crypto"));
|
|
125
|
+
function getHash(input, length = 8) {
|
|
126
|
+
return (0, import_crypto.createHash)("sha256").update(input).digest("hex").substr(0, length);
|
|
127
|
+
}
|
|
128
|
+
function getPath(id) {
|
|
129
|
+
return id.replace(/\?.*$/, "");
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// ../plugins-common/layers.ts
|
|
132
133
|
var VIRTUAL_ENTRY_ALIAS = [
|
|
133
134
|
/^(?:virtual:)?uno(?::(.+))?\.css(\?.*)?$/
|
|
134
135
|
];
|
|
136
|
+
var LAYER_PLACEHOLDER_RE = /(\\?")?#--unocss--\s*{\s*layer\s*:\s*(.+?);?\s*}/g;
|
|
137
|
+
var LAYER_MARK_ALL = "__ALL__";
|
|
135
138
|
function resolveId(id) {
|
|
136
139
|
for (const alias of VIRTUAL_ENTRY_ALIAS) {
|
|
137
140
|
const match = id.match(alias);
|
|
@@ -141,14 +144,16 @@ function resolveId(id) {
|
|
|
141
144
|
layer: match[1]
|
|
142
145
|
} : {
|
|
143
146
|
id: "/__uno.css",
|
|
144
|
-
layer:
|
|
147
|
+
layer: LAYER_MARK_ALL
|
|
145
148
|
};
|
|
146
149
|
}
|
|
147
150
|
}
|
|
148
151
|
}
|
|
152
|
+
function getLayerPlaceholder(layer) {
|
|
153
|
+
return `#--unocss--{layer:${layer}}`;
|
|
154
|
+
}
|
|
149
155
|
|
|
150
156
|
// src/modes/global/build.ts
|
|
151
|
-
var PLACEHOLDER_RE = /#--unocss--\s*{\s*layer\s*:\s*(.+?);?\s*}/g;
|
|
152
157
|
function GlobalModeBuildPlugin({ uno, config, scan, tokens }) {
|
|
153
158
|
const filter = (0, import_pluginutils2.createFilter)(config.include || defaultInclude, config.exclude || defaultExclude);
|
|
154
159
|
const tasks = [];
|
|
@@ -176,10 +181,10 @@ function GlobalModeBuildPlugin({ uno, config, scan, tokens }) {
|
|
|
176
181
|
return entry.id;
|
|
177
182
|
}
|
|
178
183
|
},
|
|
179
|
-
|
|
184
|
+
load(id) {
|
|
180
185
|
const layer = entries.get(getPath(id));
|
|
181
186
|
if (layer)
|
|
182
|
-
return
|
|
187
|
+
return getLayerPlaceholder(layer);
|
|
183
188
|
}
|
|
184
189
|
},
|
|
185
190
|
{
|
|
@@ -199,12 +204,9 @@ function GlobalModeBuildPlugin({ uno, config, scan, tokens }) {
|
|
|
199
204
|
for (const file of files) {
|
|
200
205
|
const chunk = bundle[file];
|
|
201
206
|
if (chunk.type === "asset" && typeof chunk.source === "string") {
|
|
202
|
-
chunk.source = chunk.source.replace(
|
|
207
|
+
chunk.source = chunk.source.replace(LAYER_PLACEHOLDER_RE, (_, __, layer) => {
|
|
203
208
|
replaced = true;
|
|
204
|
-
|
|
205
|
-
return result.getLayers(Array.from(entries.values()));
|
|
206
|
-
else
|
|
207
|
-
return result.getLayer(layer) || "";
|
|
209
|
+
return layer === LAYER_MARK_ALL ? result.getLayers(void 0, Array.from(entries.values())) : result.getLayer(layer) || "";
|
|
208
210
|
});
|
|
209
211
|
}
|
|
210
212
|
}
|
|
@@ -217,6 +219,11 @@ function GlobalModeBuildPlugin({ uno, config, scan, tokens }) {
|
|
|
217
219
|
|
|
218
220
|
// src/modes/global/dev.ts
|
|
219
221
|
var import_pluginutils3 = __toModule(require("@rollup/pluginutils"));
|
|
222
|
+
|
|
223
|
+
// src/modes/global/shared.ts
|
|
224
|
+
var READY_CALLBACK_DEFAULT = "/__unocss_ready";
|
|
225
|
+
|
|
226
|
+
// src/modes/global/dev.ts
|
|
220
227
|
var WARN_TIMEOUT = 2e3;
|
|
221
228
|
function GlobalModeDevPlugin({ config, uno, tokens, onInvalidate, scan }) {
|
|
222
229
|
const servers = [];
|
|
@@ -316,10 +323,7 @@ function GlobalModeDevPlugin({ config, uno, tokens, onInvalidate, scan }) {
|
|
|
316
323
|
await Promise.all(tasks);
|
|
317
324
|
const result = await uno.generate(tokens);
|
|
318
325
|
lastServed = Date.now();
|
|
319
|
-
|
|
320
|
-
return result.getLayers(Array.from(entries.values()));
|
|
321
|
-
else
|
|
322
|
-
return result.getLayer(layer);
|
|
326
|
+
return layer === LAYER_MARK_ALL ? result.getLayers(void 0, Array.from(entries.values())) : result.getLayer(layer);
|
|
323
327
|
}
|
|
324
328
|
},
|
|
325
329
|
{
|
|
@@ -461,12 +465,19 @@ function ConfigHMRPlugin({ uno, configFilepath: filepath, invalidate, tokens, mo
|
|
|
461
465
|
tokens.clear();
|
|
462
466
|
await Promise.all(modules.map((code, id) => uno.applyExtractors(code, id, tokens)));
|
|
463
467
|
invalidate();
|
|
468
|
+
server.ws.send({
|
|
469
|
+
type: "custom",
|
|
470
|
+
event: "unocss:config-changed"
|
|
471
|
+
});
|
|
464
472
|
});
|
|
465
473
|
}
|
|
466
474
|
};
|
|
467
475
|
}
|
|
468
476
|
|
|
469
477
|
// src/index.ts
|
|
478
|
+
function defineConfig(config) {
|
|
479
|
+
return config;
|
|
480
|
+
}
|
|
470
481
|
function UnocssPlugin(configOrPath, defaults = {}) {
|
|
471
482
|
var _a;
|
|
472
483
|
const { config = {}, filepath } = (0, import_config2.loadConfig)(configOrPath);
|
|
@@ -498,5 +509,6 @@ function UnocssPlugin(configOrPath, defaults = {}) {
|
|
|
498
509
|
GlobalModeDevPlugin,
|
|
499
510
|
GlobalModePlugin,
|
|
500
511
|
PerModuleModePlugin,
|
|
501
|
-
VueScopedPlugin
|
|
512
|
+
VueScopedPlugin,
|
|
513
|
+
defineConfig
|
|
502
514
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -35,16 +35,9 @@ function createContext(uno, config, configFilepath) {
|
|
|
35
35
|
// src/modes/chunk-build.ts
|
|
36
36
|
import { createFilter } from "@rollup/pluginutils";
|
|
37
37
|
|
|
38
|
-
//
|
|
39
|
-
import { createHash } from "crypto";
|
|
38
|
+
// ../plugins-common/defaults.ts
|
|
40
39
|
var defaultExclude = [/[\/\\]node_modules[\/\\]/, /[\/\\]dist[\/\\]/, /\.(css|postcss|sass|scss|less|stylus|styl)$/];
|
|
41
40
|
var defaultInclude = [/\.vue$/, /\.vue\?vue/, /\.svelte$/, /\.[jt]sx$/, /\.mdx?$/, /\.astro$/];
|
|
42
|
-
function getHash(input, length = 8) {
|
|
43
|
-
return createHash("sha256").update(input).digest("hex").substr(0, length);
|
|
44
|
-
}
|
|
45
|
-
function getPath(id) {
|
|
46
|
-
return id.replace(/\?.*$/, "");
|
|
47
|
-
}
|
|
48
41
|
|
|
49
42
|
// src/modes/chunk-build.ts
|
|
50
43
|
function ChunkModeBuildPlugin({ uno, config }) {
|
|
@@ -93,12 +86,21 @@ function ChunkModeBuildPlugin({ uno, config }) {
|
|
|
93
86
|
// src/modes/global/build.ts
|
|
94
87
|
import { createFilter as createFilter2 } from "@rollup/pluginutils";
|
|
95
88
|
|
|
96
|
-
// src/
|
|
97
|
-
|
|
98
|
-
|
|
89
|
+
// src/utils.ts
|
|
90
|
+
import { createHash } from "crypto";
|
|
91
|
+
function getHash(input, length = 8) {
|
|
92
|
+
return createHash("sha256").update(input).digest("hex").substr(0, length);
|
|
93
|
+
}
|
|
94
|
+
function getPath(id) {
|
|
95
|
+
return id.replace(/\?.*$/, "");
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// ../plugins-common/layers.ts
|
|
99
99
|
var VIRTUAL_ENTRY_ALIAS = [
|
|
100
100
|
/^(?:virtual:)?uno(?::(.+))?\.css(\?.*)?$/
|
|
101
101
|
];
|
|
102
|
+
var LAYER_PLACEHOLDER_RE = /(\\?")?#--unocss--\s*{\s*layer\s*:\s*(.+?);?\s*}/g;
|
|
103
|
+
var LAYER_MARK_ALL = "__ALL__";
|
|
102
104
|
function resolveId(id) {
|
|
103
105
|
for (const alias of VIRTUAL_ENTRY_ALIAS) {
|
|
104
106
|
const match = id.match(alias);
|
|
@@ -108,14 +110,16 @@ function resolveId(id) {
|
|
|
108
110
|
layer: match[1]
|
|
109
111
|
} : {
|
|
110
112
|
id: "/__uno.css",
|
|
111
|
-
layer:
|
|
113
|
+
layer: LAYER_MARK_ALL
|
|
112
114
|
};
|
|
113
115
|
}
|
|
114
116
|
}
|
|
115
117
|
}
|
|
118
|
+
function getLayerPlaceholder(layer) {
|
|
119
|
+
return `#--unocss--{layer:${layer}}`;
|
|
120
|
+
}
|
|
116
121
|
|
|
117
122
|
// src/modes/global/build.ts
|
|
118
|
-
var PLACEHOLDER_RE = /#--unocss--\s*{\s*layer\s*:\s*(.+?);?\s*}/g;
|
|
119
123
|
function GlobalModeBuildPlugin({ uno, config, scan, tokens }) {
|
|
120
124
|
const filter = createFilter2(config.include || defaultInclude, config.exclude || defaultExclude);
|
|
121
125
|
const tasks = [];
|
|
@@ -143,10 +147,10 @@ function GlobalModeBuildPlugin({ uno, config, scan, tokens }) {
|
|
|
143
147
|
return entry.id;
|
|
144
148
|
}
|
|
145
149
|
},
|
|
146
|
-
|
|
150
|
+
load(id) {
|
|
147
151
|
const layer = entries.get(getPath(id));
|
|
148
152
|
if (layer)
|
|
149
|
-
return
|
|
153
|
+
return getLayerPlaceholder(layer);
|
|
150
154
|
}
|
|
151
155
|
},
|
|
152
156
|
{
|
|
@@ -166,12 +170,9 @@ function GlobalModeBuildPlugin({ uno, config, scan, tokens }) {
|
|
|
166
170
|
for (const file of files) {
|
|
167
171
|
const chunk = bundle[file];
|
|
168
172
|
if (chunk.type === "asset" && typeof chunk.source === "string") {
|
|
169
|
-
chunk.source = chunk.source.replace(
|
|
173
|
+
chunk.source = chunk.source.replace(LAYER_PLACEHOLDER_RE, (_, __, layer) => {
|
|
170
174
|
replaced = true;
|
|
171
|
-
|
|
172
|
-
return result.getLayers(Array.from(entries.values()));
|
|
173
|
-
else
|
|
174
|
-
return result.getLayer(layer) || "";
|
|
175
|
+
return layer === LAYER_MARK_ALL ? result.getLayers(void 0, Array.from(entries.values())) : result.getLayer(layer) || "";
|
|
175
176
|
});
|
|
176
177
|
}
|
|
177
178
|
}
|
|
@@ -184,6 +185,11 @@ function GlobalModeBuildPlugin({ uno, config, scan, tokens }) {
|
|
|
184
185
|
|
|
185
186
|
// src/modes/global/dev.ts
|
|
186
187
|
import { createFilter as createFilter3 } from "@rollup/pluginutils";
|
|
188
|
+
|
|
189
|
+
// src/modes/global/shared.ts
|
|
190
|
+
var READY_CALLBACK_DEFAULT = "/__unocss_ready";
|
|
191
|
+
|
|
192
|
+
// src/modes/global/dev.ts
|
|
187
193
|
var WARN_TIMEOUT = 2e3;
|
|
188
194
|
function GlobalModeDevPlugin({ config, uno, tokens, onInvalidate, scan }) {
|
|
189
195
|
const servers = [];
|
|
@@ -283,10 +289,7 @@ function GlobalModeDevPlugin({ config, uno, tokens, onInvalidate, scan }) {
|
|
|
283
289
|
await Promise.all(tasks);
|
|
284
290
|
const result = await uno.generate(tokens);
|
|
285
291
|
lastServed = Date.now();
|
|
286
|
-
|
|
287
|
-
return result.getLayers(Array.from(entries.values()));
|
|
288
|
-
else
|
|
289
|
-
return result.getLayer(layer);
|
|
292
|
+
return layer === LAYER_MARK_ALL ? result.getLayers(void 0, Array.from(entries.values())) : result.getLayer(layer);
|
|
290
293
|
}
|
|
291
294
|
},
|
|
292
295
|
{
|
|
@@ -428,12 +431,19 @@ function ConfigHMRPlugin({ uno, configFilepath: filepath, invalidate, tokens, mo
|
|
|
428
431
|
tokens.clear();
|
|
429
432
|
await Promise.all(modules.map((code, id) => uno.applyExtractors(code, id, tokens)));
|
|
430
433
|
invalidate();
|
|
434
|
+
server.ws.send({
|
|
435
|
+
type: "custom",
|
|
436
|
+
event: "unocss:config-changed"
|
|
437
|
+
});
|
|
431
438
|
});
|
|
432
439
|
}
|
|
433
440
|
};
|
|
434
441
|
}
|
|
435
442
|
|
|
436
443
|
// src/index.ts
|
|
444
|
+
function defineConfig(config) {
|
|
445
|
+
return config;
|
|
446
|
+
}
|
|
437
447
|
function UnocssPlugin(configOrPath, defaults = {}) {
|
|
438
448
|
var _a;
|
|
439
449
|
const { config = {}, filepath } = loadConfig2(configOrPath);
|
|
@@ -465,5 +475,6 @@ export {
|
|
|
465
475
|
GlobalModePlugin,
|
|
466
476
|
PerModuleModePlugin,
|
|
467
477
|
VueScopedPlugin,
|
|
468
|
-
UnocssPlugin as default
|
|
478
|
+
UnocssPlugin as default,
|
|
479
|
+
defineConfig
|
|
469
480
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/vite",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.3",
|
|
4
4
|
"description": "The Vite plugin for UnoCSS",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"unocss",
|
|
@@ -34,10 +34,10 @@
|
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@rollup/pluginutils": "^4.1.1",
|
|
37
|
-
"@unocss/config": "0.
|
|
38
|
-
"@unocss/core": "0.
|
|
39
|
-
"@unocss/scope": "0.
|
|
40
|
-
"@unocss/inspector": "0.
|
|
37
|
+
"@unocss/config": "0.9.3",
|
|
38
|
+
"@unocss/core": "0.9.3",
|
|
39
|
+
"@unocss/scope": "0.9.3",
|
|
40
|
+
"@unocss/inspector": "0.9.3"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"vite": "^2.6.13"
|