@unocss/vite 0.12.15 → 0.13.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.d.ts +6 -5
- package/dist/index.js +46 -29
- package/dist/index.mjs +47 -30
- package/package.json +5 -5
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
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 { LoadConfigResult } from '@unocss/config';
|
|
4
5
|
|
|
5
6
|
declare type FilterPattern = ReadonlyArray<string | RegExp> | string | RegExp | null;
|
|
6
7
|
interface PluginConfig<Theme extends {} = {}> extends UserConfig<Theme> {
|
|
@@ -35,14 +36,14 @@ interface VitePluginConfig<Theme extends {} = {}> extends PluginConfig<Theme> {
|
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
interface UnocssPluginContext<Config extends PluginConfig = PluginConfig> {
|
|
39
|
+
ready: Promise<LoadConfigResult<Config>>;
|
|
38
40
|
uno: UnoGenerator;
|
|
39
|
-
config: Config;
|
|
40
41
|
tokens: Set<string>;
|
|
41
42
|
modules: BetterMap<string, string>;
|
|
42
43
|
filter: (code: string, id: string) => boolean;
|
|
43
|
-
reloadConfig: () => Promise<void>;
|
|
44
44
|
extract: (code: string, id?: string) => Promise<void>;
|
|
45
|
-
|
|
45
|
+
reloadConfig: () => Promise<LoadConfigResult<Config>>;
|
|
46
|
+
getConfig: () => Promise<Config>;
|
|
46
47
|
invalidate: () => void;
|
|
47
48
|
onInvalidate: (fn: () => void) => void;
|
|
48
49
|
}
|
|
@@ -51,13 +52,13 @@ declare function ChunkModeBuildPlugin({ uno, filter }: UnocssPluginContext): Plu
|
|
|
51
52
|
|
|
52
53
|
declare function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }: UnocssPluginContext): Plugin[];
|
|
53
54
|
|
|
54
|
-
declare function GlobalModeBuildPlugin({ uno, extract, tokens, modules, filter }: UnocssPluginContext): Plugin[];
|
|
55
|
+
declare function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, filter }: UnocssPluginContext): Plugin[];
|
|
55
56
|
|
|
56
57
|
declare function GlobalModePlugin(ctx: UnocssPluginContext): vite.Plugin[];
|
|
57
58
|
|
|
58
59
|
declare function PerModuleModePlugin({ uno, filter }: UnocssPluginContext): Plugin;
|
|
59
60
|
|
|
60
|
-
declare function VueScopedPlugin({ uno,
|
|
61
|
+
declare function VueScopedPlugin({ uno, ready }: UnocssPluginContext): Plugin;
|
|
61
62
|
|
|
62
63
|
declare function defineConfig<Theme extends {}>(config: VitePluginConfig<Theme>): VitePluginConfig<Theme>;
|
|
63
64
|
declare function UnocssPlugin(configOrPath?: VitePluginConfig | string, defaults?: UserConfigDefaults): Plugin[];
|
package/dist/index.js
CHANGED
|
@@ -75,12 +75,25 @@ var import_pluginutils = __toModule(require("@rollup/pluginutils"));
|
|
|
75
75
|
var import_config = __toModule(require("@unocss/config"));
|
|
76
76
|
var import_core = __toModule(require("@unocss/core"));
|
|
77
77
|
function createContext(configOrPath, defaults = {}) {
|
|
78
|
-
const
|
|
79
|
-
|
|
78
|
+
const loadConfig = (0, import_config.createConfigLoader)(configOrPath);
|
|
79
|
+
let rawConfig = {};
|
|
80
|
+
const uno = (0, import_core.createGenerator)(rawConfig, defaults);
|
|
81
|
+
let rollupFilter = (0, import_pluginutils.createFilter)(defaultInclude, defaultExclude);
|
|
80
82
|
const invalidations = [];
|
|
81
83
|
const modules = new import_core.BetterMap();
|
|
82
84
|
const tokens = new Set();
|
|
83
|
-
|
|
85
|
+
const ready = reloadConfig();
|
|
86
|
+
async function reloadConfig() {
|
|
87
|
+
const result = await loadConfig();
|
|
88
|
+
rawConfig = result.config;
|
|
89
|
+
uno.setConfig(rawConfig);
|
|
90
|
+
uno.config.envMode = "dev";
|
|
91
|
+
rollupFilter = (0, import_pluginutils.createFilter)(rawConfig.include || defaultInclude, rawConfig.exclude || defaultExclude);
|
|
92
|
+
tokens.clear();
|
|
93
|
+
await Promise.all(modules.map((code, id) => uno.applyExtractors(code, id, tokens)));
|
|
94
|
+
invalidate();
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
84
97
|
function invalidate() {
|
|
85
98
|
invalidations.forEach((cb) => cb());
|
|
86
99
|
}
|
|
@@ -92,20 +105,15 @@ function createContext(configOrPath, defaults = {}) {
|
|
|
92
105
|
if (tokens.size > len)
|
|
93
106
|
invalidate();
|
|
94
107
|
}
|
|
95
|
-
async function reloadConfig() {
|
|
96
|
-
if (!filepath)
|
|
97
|
-
return;
|
|
98
|
-
uno.setConfig((0, import_config.loadConfig)(filepath).config);
|
|
99
|
-
uno.config.envMode = "dev";
|
|
100
|
-
rollupFilter = (0, import_pluginutils.createFilter)(config.include || defaultInclude, config.exclude || defaultExclude);
|
|
101
|
-
tokens.clear();
|
|
102
|
-
await Promise.all(modules.map((code, id) => uno.applyExtractors(code, id, tokens)));
|
|
103
|
-
invalidate();
|
|
104
|
-
}
|
|
105
108
|
const filter = (code, id) => {
|
|
106
109
|
return code.includes(INCLUDE_COMMENT) || rollupFilter(id);
|
|
107
110
|
};
|
|
111
|
+
async function getConfig() {
|
|
112
|
+
await ready;
|
|
113
|
+
return rawConfig;
|
|
114
|
+
}
|
|
108
115
|
return {
|
|
116
|
+
ready,
|
|
109
117
|
tokens,
|
|
110
118
|
modules,
|
|
111
119
|
invalidate,
|
|
@@ -116,8 +124,7 @@ function createContext(configOrPath, defaults = {}) {
|
|
|
116
124
|
reloadConfig,
|
|
117
125
|
uno,
|
|
118
126
|
extract,
|
|
119
|
-
|
|
120
|
-
configFilepath: filepath
|
|
127
|
+
getConfig
|
|
121
128
|
};
|
|
122
129
|
}
|
|
123
130
|
|
|
@@ -174,7 +181,7 @@ function ChunkModeBuildPlugin({ uno, filter }) {
|
|
|
174
181
|
}
|
|
175
182
|
|
|
176
183
|
// src/modes/global/build.ts
|
|
177
|
-
function GlobalModeBuildPlugin({ uno, extract, tokens, modules, filter }) {
|
|
184
|
+
function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, filter }) {
|
|
178
185
|
const vfsLayerMap = new Map();
|
|
179
186
|
let tasks = [];
|
|
180
187
|
let cssPlugin;
|
|
@@ -210,8 +217,9 @@ function GlobalModeBuildPlugin({ uno, extract, tokens, modules, filter }) {
|
|
|
210
217
|
if (layer)
|
|
211
218
|
return getLayerPlaceholder(layer);
|
|
212
219
|
},
|
|
213
|
-
configResolved(config) {
|
|
220
|
+
async configResolved(config) {
|
|
214
221
|
cssPlugin = config.plugins.find((i) => i.name === "vite:css-post");
|
|
222
|
+
await ready;
|
|
215
223
|
},
|
|
216
224
|
async renderChunk(_, chunk) {
|
|
217
225
|
if (!cssPlugin)
|
|
@@ -328,7 +336,7 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
|
|
|
328
336
|
name: "unocss:global",
|
|
329
337
|
apply: "serve",
|
|
330
338
|
enforce: "pre",
|
|
331
|
-
configureServer(_server) {
|
|
339
|
+
async configureServer(_server) {
|
|
332
340
|
servers.push(_server);
|
|
333
341
|
_server.middlewares.use(async (req, res, next) => {
|
|
334
342
|
var _a;
|
|
@@ -463,8 +471,8 @@ ${css}`;
|
|
|
463
471
|
|
|
464
472
|
// src/modes/vue-scoped.ts
|
|
465
473
|
var import_pluginutils2 = __toModule(require("@rollup/pluginutils"));
|
|
466
|
-
function VueScopedPlugin({ uno,
|
|
467
|
-
|
|
474
|
+
function VueScopedPlugin({ uno, ready }) {
|
|
475
|
+
let filter = (0, import_pluginutils2.createFilter)([/\.vue$/], defaultExclude);
|
|
468
476
|
async function transformSFC(code) {
|
|
469
477
|
const { css } = await uno.generate(code);
|
|
470
478
|
if (!css)
|
|
@@ -475,6 +483,10 @@ function VueScopedPlugin({ uno, config }) {
|
|
|
475
483
|
return {
|
|
476
484
|
name: "unocss:vue-scoped",
|
|
477
485
|
enforce: "pre",
|
|
486
|
+
async configResolved() {
|
|
487
|
+
const { config } = await ready;
|
|
488
|
+
filter = (0, import_pluginutils2.createFilter)(config.include || [/\.vue$/], config.exclude || defaultExclude);
|
|
489
|
+
},
|
|
478
490
|
transform(code, id) {
|
|
479
491
|
if (!filter(id))
|
|
480
492
|
return;
|
|
@@ -493,18 +505,23 @@ function VueScopedPlugin({ uno, config }) {
|
|
|
493
505
|
}
|
|
494
506
|
|
|
495
507
|
// src/config-hmr.ts
|
|
496
|
-
function ConfigHMRPlugin(
|
|
508
|
+
function ConfigHMRPlugin(ctx) {
|
|
509
|
+
const { ready, uno } = ctx;
|
|
497
510
|
return {
|
|
498
511
|
name: "unocss:config",
|
|
499
|
-
|
|
512
|
+
async configResolved() {
|
|
513
|
+
await ready;
|
|
514
|
+
},
|
|
515
|
+
async configureServer(server) {
|
|
500
516
|
uno.config.envMode = "dev";
|
|
501
|
-
|
|
517
|
+
const { sources } = await ready;
|
|
518
|
+
if (!sources.length)
|
|
502
519
|
return;
|
|
503
|
-
server.watcher.add(
|
|
520
|
+
server.watcher.add(sources);
|
|
504
521
|
server.watcher.on("change", async (p) => {
|
|
505
|
-
if (p
|
|
522
|
+
if (!sources.includes(p))
|
|
506
523
|
return;
|
|
507
|
-
reloadConfig();
|
|
524
|
+
await ctx.reloadConfig();
|
|
508
525
|
server.ws.send({
|
|
509
526
|
type: "custom",
|
|
510
527
|
event: "unocss:config-changed"
|
|
@@ -520,12 +537,12 @@ function defineConfig(config) {
|
|
|
520
537
|
}
|
|
521
538
|
function UnocssPlugin(configOrPath, defaults = {}) {
|
|
522
539
|
const ctx = createContext(configOrPath, defaults);
|
|
523
|
-
const
|
|
524
|
-
const mode =
|
|
540
|
+
const inlineConfig = configOrPath && typeof configOrPath !== "string" ? configOrPath : {};
|
|
541
|
+
const mode = inlineConfig.mode ?? "global";
|
|
525
542
|
const plugins = [
|
|
526
543
|
ConfigHMRPlugin(ctx)
|
|
527
544
|
];
|
|
528
|
-
if (
|
|
545
|
+
if (inlineConfig.inspector !== false)
|
|
529
546
|
plugins.push((0, import_inspector.default)(ctx));
|
|
530
547
|
if (mode === "per-module") {
|
|
531
548
|
plugins.push(PerModuleModePlugin(ctx));
|
package/dist/index.mjs
CHANGED
|
@@ -38,15 +38,28 @@ var INCLUDE_COMMENT = "@unocss-include";
|
|
|
38
38
|
|
|
39
39
|
// ../plugins-common/context.ts
|
|
40
40
|
import { createFilter } from "@rollup/pluginutils";
|
|
41
|
-
import {
|
|
41
|
+
import { createConfigLoader } from "@unocss/config";
|
|
42
42
|
import { BetterMap, createGenerator } from "@unocss/core";
|
|
43
43
|
function createContext(configOrPath, defaults = {}) {
|
|
44
|
-
const
|
|
45
|
-
|
|
44
|
+
const loadConfig = createConfigLoader(configOrPath);
|
|
45
|
+
let rawConfig = {};
|
|
46
|
+
const uno = createGenerator(rawConfig, defaults);
|
|
47
|
+
let rollupFilter = createFilter(defaultInclude, defaultExclude);
|
|
46
48
|
const invalidations = [];
|
|
47
49
|
const modules = new BetterMap();
|
|
48
50
|
const tokens = new Set();
|
|
49
|
-
|
|
51
|
+
const ready = reloadConfig();
|
|
52
|
+
async function reloadConfig() {
|
|
53
|
+
const result = await loadConfig();
|
|
54
|
+
rawConfig = result.config;
|
|
55
|
+
uno.setConfig(rawConfig);
|
|
56
|
+
uno.config.envMode = "dev";
|
|
57
|
+
rollupFilter = createFilter(rawConfig.include || defaultInclude, rawConfig.exclude || defaultExclude);
|
|
58
|
+
tokens.clear();
|
|
59
|
+
await Promise.all(modules.map((code, id) => uno.applyExtractors(code, id, tokens)));
|
|
60
|
+
invalidate();
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
50
63
|
function invalidate() {
|
|
51
64
|
invalidations.forEach((cb) => cb());
|
|
52
65
|
}
|
|
@@ -58,20 +71,15 @@ function createContext(configOrPath, defaults = {}) {
|
|
|
58
71
|
if (tokens.size > len)
|
|
59
72
|
invalidate();
|
|
60
73
|
}
|
|
61
|
-
async function reloadConfig() {
|
|
62
|
-
if (!filepath)
|
|
63
|
-
return;
|
|
64
|
-
uno.setConfig(loadConfig(filepath).config);
|
|
65
|
-
uno.config.envMode = "dev";
|
|
66
|
-
rollupFilter = createFilter(config.include || defaultInclude, config.exclude || defaultExclude);
|
|
67
|
-
tokens.clear();
|
|
68
|
-
await Promise.all(modules.map((code, id) => uno.applyExtractors(code, id, tokens)));
|
|
69
|
-
invalidate();
|
|
70
|
-
}
|
|
71
74
|
const filter = (code, id) => {
|
|
72
75
|
return code.includes(INCLUDE_COMMENT) || rollupFilter(id);
|
|
73
76
|
};
|
|
77
|
+
async function getConfig() {
|
|
78
|
+
await ready;
|
|
79
|
+
return rawConfig;
|
|
80
|
+
}
|
|
74
81
|
return {
|
|
82
|
+
ready,
|
|
75
83
|
tokens,
|
|
76
84
|
modules,
|
|
77
85
|
invalidate,
|
|
@@ -82,8 +90,7 @@ function createContext(configOrPath, defaults = {}) {
|
|
|
82
90
|
reloadConfig,
|
|
83
91
|
uno,
|
|
84
92
|
extract,
|
|
85
|
-
|
|
86
|
-
configFilepath: filepath
|
|
93
|
+
getConfig
|
|
87
94
|
};
|
|
88
95
|
}
|
|
89
96
|
|
|
@@ -140,7 +147,7 @@ function ChunkModeBuildPlugin({ uno, filter }) {
|
|
|
140
147
|
}
|
|
141
148
|
|
|
142
149
|
// src/modes/global/build.ts
|
|
143
|
-
function GlobalModeBuildPlugin({ uno, extract, tokens, modules, filter }) {
|
|
150
|
+
function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, filter }) {
|
|
144
151
|
const vfsLayerMap = new Map();
|
|
145
152
|
let tasks = [];
|
|
146
153
|
let cssPlugin;
|
|
@@ -176,8 +183,9 @@ function GlobalModeBuildPlugin({ uno, extract, tokens, modules, filter }) {
|
|
|
176
183
|
if (layer)
|
|
177
184
|
return getLayerPlaceholder(layer);
|
|
178
185
|
},
|
|
179
|
-
configResolved(config) {
|
|
186
|
+
async configResolved(config) {
|
|
180
187
|
cssPlugin = config.plugins.find((i) => i.name === "vite:css-post");
|
|
188
|
+
await ready;
|
|
181
189
|
},
|
|
182
190
|
async renderChunk(_, chunk) {
|
|
183
191
|
if (!cssPlugin)
|
|
@@ -294,7 +302,7 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
|
|
|
294
302
|
name: "unocss:global",
|
|
295
303
|
apply: "serve",
|
|
296
304
|
enforce: "pre",
|
|
297
|
-
configureServer(_server) {
|
|
305
|
+
async configureServer(_server) {
|
|
298
306
|
servers.push(_server);
|
|
299
307
|
_server.middlewares.use(async (req, res, next) => {
|
|
300
308
|
var _a;
|
|
@@ -429,8 +437,8 @@ ${css}`;
|
|
|
429
437
|
|
|
430
438
|
// src/modes/vue-scoped.ts
|
|
431
439
|
import { createFilter as createFilter2 } from "@rollup/pluginutils";
|
|
432
|
-
function VueScopedPlugin({ uno,
|
|
433
|
-
|
|
440
|
+
function VueScopedPlugin({ uno, ready }) {
|
|
441
|
+
let filter = createFilter2([/\.vue$/], defaultExclude);
|
|
434
442
|
async function transformSFC(code) {
|
|
435
443
|
const { css } = await uno.generate(code);
|
|
436
444
|
if (!css)
|
|
@@ -441,6 +449,10 @@ function VueScopedPlugin({ uno, config }) {
|
|
|
441
449
|
return {
|
|
442
450
|
name: "unocss:vue-scoped",
|
|
443
451
|
enforce: "pre",
|
|
452
|
+
async configResolved() {
|
|
453
|
+
const { config } = await ready;
|
|
454
|
+
filter = createFilter2(config.include || [/\.vue$/], config.exclude || defaultExclude);
|
|
455
|
+
},
|
|
444
456
|
transform(code, id) {
|
|
445
457
|
if (!filter(id))
|
|
446
458
|
return;
|
|
@@ -459,18 +471,23 @@ function VueScopedPlugin({ uno, config }) {
|
|
|
459
471
|
}
|
|
460
472
|
|
|
461
473
|
// src/config-hmr.ts
|
|
462
|
-
function ConfigHMRPlugin(
|
|
474
|
+
function ConfigHMRPlugin(ctx) {
|
|
475
|
+
const { ready, uno } = ctx;
|
|
463
476
|
return {
|
|
464
477
|
name: "unocss:config",
|
|
465
|
-
|
|
478
|
+
async configResolved() {
|
|
479
|
+
await ready;
|
|
480
|
+
},
|
|
481
|
+
async configureServer(server) {
|
|
466
482
|
uno.config.envMode = "dev";
|
|
467
|
-
|
|
483
|
+
const { sources } = await ready;
|
|
484
|
+
if (!sources.length)
|
|
468
485
|
return;
|
|
469
|
-
server.watcher.add(
|
|
486
|
+
server.watcher.add(sources);
|
|
470
487
|
server.watcher.on("change", async (p) => {
|
|
471
|
-
if (p
|
|
488
|
+
if (!sources.includes(p))
|
|
472
489
|
return;
|
|
473
|
-
reloadConfig();
|
|
490
|
+
await ctx.reloadConfig();
|
|
474
491
|
server.ws.send({
|
|
475
492
|
type: "custom",
|
|
476
493
|
event: "unocss:config-changed"
|
|
@@ -486,12 +503,12 @@ function defineConfig(config) {
|
|
|
486
503
|
}
|
|
487
504
|
function UnocssPlugin(configOrPath, defaults = {}) {
|
|
488
505
|
const ctx = createContext(configOrPath, defaults);
|
|
489
|
-
const
|
|
490
|
-
const mode =
|
|
506
|
+
const inlineConfig = configOrPath && typeof configOrPath !== "string" ? configOrPath : {};
|
|
507
|
+
const mode = inlineConfig.mode ?? "global";
|
|
491
508
|
const plugins = [
|
|
492
509
|
ConfigHMRPlugin(ctx)
|
|
493
510
|
];
|
|
494
|
-
if (
|
|
511
|
+
if (inlineConfig.inspector !== false)
|
|
495
512
|
plugins.push(UnocssInspector(ctx));
|
|
496
513
|
if (mode === "per-module") {
|
|
497
514
|
plugins.push(PerModuleModePlugin(ctx));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/vite",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.13.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.1",
|
|
38
|
-
"@unocss/config": "0.
|
|
39
|
-
"@unocss/core": "0.
|
|
40
|
-
"@unocss/inspector": "0.
|
|
41
|
-
"@unocss/scope": "0.
|
|
38
|
+
"@unocss/config": "0.13.0",
|
|
39
|
+
"@unocss/core": "0.13.0",
|
|
40
|
+
"@unocss/inspector": "0.13.0",
|
|
41
|
+
"@unocss/scope": "0.13.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"vite": "^2.6.14"
|