@unocss/vite 0.12.18 → 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 +44 -38
- package/dist/index.mjs +45 -39
- 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,13 +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
|
-
let rawConfig =
|
|
80
|
-
const uno = (0, import_core.createGenerator)(
|
|
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);
|
|
81
82
|
const invalidations = [];
|
|
82
83
|
const modules = new import_core.BetterMap();
|
|
83
84
|
const tokens = new Set();
|
|
84
|
-
|
|
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
|
+
}
|
|
85
97
|
function invalidate() {
|
|
86
98
|
invalidations.forEach((cb) => cb());
|
|
87
99
|
}
|
|
@@ -93,21 +105,15 @@ function createContext(configOrPath, defaults = {}) {
|
|
|
93
105
|
if (tokens.size > len)
|
|
94
106
|
invalidate();
|
|
95
107
|
}
|
|
96
|
-
async function reloadConfig() {
|
|
97
|
-
if (!filepath)
|
|
98
|
-
return;
|
|
99
|
-
rawConfig = (0, import_config.loadConfig)(filepath).config;
|
|
100
|
-
uno.setConfig(rawConfig);
|
|
101
|
-
uno.config.envMode = "dev";
|
|
102
|
-
rollupFilter = (0, import_pluginutils.createFilter)(config.include || defaultInclude, config.exclude || defaultExclude);
|
|
103
|
-
tokens.clear();
|
|
104
|
-
await Promise.all(modules.map((code, id) => uno.applyExtractors(code, id, tokens)));
|
|
105
|
-
invalidate();
|
|
106
|
-
}
|
|
107
108
|
const filter = (code, id) => {
|
|
108
109
|
return code.includes(INCLUDE_COMMENT) || rollupFilter(id);
|
|
109
110
|
};
|
|
111
|
+
async function getConfig() {
|
|
112
|
+
await ready;
|
|
113
|
+
return rawConfig;
|
|
114
|
+
}
|
|
110
115
|
return {
|
|
116
|
+
ready,
|
|
111
117
|
tokens,
|
|
112
118
|
modules,
|
|
113
119
|
invalidate,
|
|
@@ -118,10 +124,7 @@ function createContext(configOrPath, defaults = {}) {
|
|
|
118
124
|
reloadConfig,
|
|
119
125
|
uno,
|
|
120
126
|
extract,
|
|
121
|
-
|
|
122
|
-
return rawConfig;
|
|
123
|
-
},
|
|
124
|
-
configFilepath: filepath
|
|
127
|
+
getConfig
|
|
125
128
|
};
|
|
126
129
|
}
|
|
127
130
|
|
|
@@ -178,7 +181,7 @@ function ChunkModeBuildPlugin({ uno, filter }) {
|
|
|
178
181
|
}
|
|
179
182
|
|
|
180
183
|
// src/modes/global/build.ts
|
|
181
|
-
function GlobalModeBuildPlugin({ uno, extract, tokens, modules, filter }) {
|
|
184
|
+
function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, filter }) {
|
|
182
185
|
const vfsLayerMap = new Map();
|
|
183
186
|
let tasks = [];
|
|
184
187
|
let cssPlugin;
|
|
@@ -214,8 +217,9 @@ function GlobalModeBuildPlugin({ uno, extract, tokens, modules, filter }) {
|
|
|
214
217
|
if (layer)
|
|
215
218
|
return getLayerPlaceholder(layer);
|
|
216
219
|
},
|
|
217
|
-
configResolved(config) {
|
|
220
|
+
async configResolved(config) {
|
|
218
221
|
cssPlugin = config.plugins.find((i) => i.name === "vite:css-post");
|
|
222
|
+
await ready;
|
|
219
223
|
},
|
|
220
224
|
async renderChunk(_, chunk) {
|
|
221
225
|
if (!cssPlugin)
|
|
@@ -332,7 +336,7 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
|
|
|
332
336
|
name: "unocss:global",
|
|
333
337
|
apply: "serve",
|
|
334
338
|
enforce: "pre",
|
|
335
|
-
configureServer(_server) {
|
|
339
|
+
async configureServer(_server) {
|
|
336
340
|
servers.push(_server);
|
|
337
341
|
_server.middlewares.use(async (req, res, next) => {
|
|
338
342
|
var _a;
|
|
@@ -467,8 +471,8 @@ ${css}`;
|
|
|
467
471
|
|
|
468
472
|
// src/modes/vue-scoped.ts
|
|
469
473
|
var import_pluginutils2 = __toModule(require("@rollup/pluginutils"));
|
|
470
|
-
function VueScopedPlugin({ uno,
|
|
471
|
-
|
|
474
|
+
function VueScopedPlugin({ uno, ready }) {
|
|
475
|
+
let filter = (0, import_pluginutils2.createFilter)([/\.vue$/], defaultExclude);
|
|
472
476
|
async function transformSFC(code) {
|
|
473
477
|
const { css } = await uno.generate(code);
|
|
474
478
|
if (!css)
|
|
@@ -479,6 +483,10 @@ function VueScopedPlugin({ uno, config }) {
|
|
|
479
483
|
return {
|
|
480
484
|
name: "unocss:vue-scoped",
|
|
481
485
|
enforce: "pre",
|
|
486
|
+
async configResolved() {
|
|
487
|
+
const { config } = await ready;
|
|
488
|
+
filter = (0, import_pluginutils2.createFilter)(config.include || [/\.vue$/], config.exclude || defaultExclude);
|
|
489
|
+
},
|
|
482
490
|
transform(code, id) {
|
|
483
491
|
if (!filter(id))
|
|
484
492
|
return;
|
|
@@ -498,24 +506,22 @@ function VueScopedPlugin({ uno, config }) {
|
|
|
498
506
|
|
|
499
507
|
// src/config-hmr.ts
|
|
500
508
|
function ConfigHMRPlugin(ctx) {
|
|
501
|
-
const {
|
|
509
|
+
const { ready, uno } = ctx;
|
|
502
510
|
return {
|
|
503
511
|
name: "unocss:config",
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
if (!configFilepath)
|
|
507
|
-
return ctx.config;
|
|
508
|
-
}
|
|
512
|
+
async configResolved() {
|
|
513
|
+
await ready;
|
|
509
514
|
},
|
|
510
|
-
configureServer(server) {
|
|
515
|
+
async configureServer(server) {
|
|
511
516
|
uno.config.envMode = "dev";
|
|
512
|
-
|
|
517
|
+
const { sources } = await ready;
|
|
518
|
+
if (!sources.length)
|
|
513
519
|
return;
|
|
514
|
-
server.watcher.add(
|
|
520
|
+
server.watcher.add(sources);
|
|
515
521
|
server.watcher.on("change", async (p) => {
|
|
516
|
-
if (p
|
|
522
|
+
if (!sources.includes(p))
|
|
517
523
|
return;
|
|
518
|
-
reloadConfig();
|
|
524
|
+
await ctx.reloadConfig();
|
|
519
525
|
server.ws.send({
|
|
520
526
|
type: "custom",
|
|
521
527
|
event: "unocss:config-changed"
|
|
@@ -531,12 +537,12 @@ function defineConfig(config) {
|
|
|
531
537
|
}
|
|
532
538
|
function UnocssPlugin(configOrPath, defaults = {}) {
|
|
533
539
|
const ctx = createContext(configOrPath, defaults);
|
|
534
|
-
const
|
|
535
|
-
const mode =
|
|
540
|
+
const inlineConfig = configOrPath && typeof configOrPath !== "string" ? configOrPath : {};
|
|
541
|
+
const mode = inlineConfig.mode ?? "global";
|
|
536
542
|
const plugins = [
|
|
537
543
|
ConfigHMRPlugin(ctx)
|
|
538
544
|
];
|
|
539
|
-
if (
|
|
545
|
+
if (inlineConfig.inspector !== false)
|
|
540
546
|
plugins.push((0, import_inspector.default)(ctx));
|
|
541
547
|
if (mode === "per-module") {
|
|
542
548
|
plugins.push(PerModuleModePlugin(ctx));
|
package/dist/index.mjs
CHANGED
|
@@ -38,16 +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
|
-
let rawConfig =
|
|
46
|
-
const uno = createGenerator(
|
|
44
|
+
const loadConfig = createConfigLoader(configOrPath);
|
|
45
|
+
let rawConfig = {};
|
|
46
|
+
const uno = createGenerator(rawConfig, defaults);
|
|
47
|
+
let rollupFilter = createFilter(defaultInclude, defaultExclude);
|
|
47
48
|
const invalidations = [];
|
|
48
49
|
const modules = new BetterMap();
|
|
49
50
|
const tokens = new Set();
|
|
50
|
-
|
|
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
|
+
}
|
|
51
63
|
function invalidate() {
|
|
52
64
|
invalidations.forEach((cb) => cb());
|
|
53
65
|
}
|
|
@@ -59,21 +71,15 @@ function createContext(configOrPath, defaults = {}) {
|
|
|
59
71
|
if (tokens.size > len)
|
|
60
72
|
invalidate();
|
|
61
73
|
}
|
|
62
|
-
async function reloadConfig() {
|
|
63
|
-
if (!filepath)
|
|
64
|
-
return;
|
|
65
|
-
rawConfig = loadConfig(filepath).config;
|
|
66
|
-
uno.setConfig(rawConfig);
|
|
67
|
-
uno.config.envMode = "dev";
|
|
68
|
-
rollupFilter = createFilter(config.include || defaultInclude, config.exclude || defaultExclude);
|
|
69
|
-
tokens.clear();
|
|
70
|
-
await Promise.all(modules.map((code, id) => uno.applyExtractors(code, id, tokens)));
|
|
71
|
-
invalidate();
|
|
72
|
-
}
|
|
73
74
|
const filter = (code, id) => {
|
|
74
75
|
return code.includes(INCLUDE_COMMENT) || rollupFilter(id);
|
|
75
76
|
};
|
|
77
|
+
async function getConfig() {
|
|
78
|
+
await ready;
|
|
79
|
+
return rawConfig;
|
|
80
|
+
}
|
|
76
81
|
return {
|
|
82
|
+
ready,
|
|
77
83
|
tokens,
|
|
78
84
|
modules,
|
|
79
85
|
invalidate,
|
|
@@ -84,10 +90,7 @@ function createContext(configOrPath, defaults = {}) {
|
|
|
84
90
|
reloadConfig,
|
|
85
91
|
uno,
|
|
86
92
|
extract,
|
|
87
|
-
|
|
88
|
-
return rawConfig;
|
|
89
|
-
},
|
|
90
|
-
configFilepath: filepath
|
|
93
|
+
getConfig
|
|
91
94
|
};
|
|
92
95
|
}
|
|
93
96
|
|
|
@@ -144,7 +147,7 @@ function ChunkModeBuildPlugin({ uno, filter }) {
|
|
|
144
147
|
}
|
|
145
148
|
|
|
146
149
|
// src/modes/global/build.ts
|
|
147
|
-
function GlobalModeBuildPlugin({ uno, extract, tokens, modules, filter }) {
|
|
150
|
+
function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, filter }) {
|
|
148
151
|
const vfsLayerMap = new Map();
|
|
149
152
|
let tasks = [];
|
|
150
153
|
let cssPlugin;
|
|
@@ -180,8 +183,9 @@ function GlobalModeBuildPlugin({ uno, extract, tokens, modules, filter }) {
|
|
|
180
183
|
if (layer)
|
|
181
184
|
return getLayerPlaceholder(layer);
|
|
182
185
|
},
|
|
183
|
-
configResolved(config) {
|
|
186
|
+
async configResolved(config) {
|
|
184
187
|
cssPlugin = config.plugins.find((i) => i.name === "vite:css-post");
|
|
188
|
+
await ready;
|
|
185
189
|
},
|
|
186
190
|
async renderChunk(_, chunk) {
|
|
187
191
|
if (!cssPlugin)
|
|
@@ -298,7 +302,7 @@ function GlobalModeDevPlugin({ uno, tokens, onInvalidate, extract, filter }) {
|
|
|
298
302
|
name: "unocss:global",
|
|
299
303
|
apply: "serve",
|
|
300
304
|
enforce: "pre",
|
|
301
|
-
configureServer(_server) {
|
|
305
|
+
async configureServer(_server) {
|
|
302
306
|
servers.push(_server);
|
|
303
307
|
_server.middlewares.use(async (req, res, next) => {
|
|
304
308
|
var _a;
|
|
@@ -433,8 +437,8 @@ ${css}`;
|
|
|
433
437
|
|
|
434
438
|
// src/modes/vue-scoped.ts
|
|
435
439
|
import { createFilter as createFilter2 } from "@rollup/pluginutils";
|
|
436
|
-
function VueScopedPlugin({ uno,
|
|
437
|
-
|
|
440
|
+
function VueScopedPlugin({ uno, ready }) {
|
|
441
|
+
let filter = createFilter2([/\.vue$/], defaultExclude);
|
|
438
442
|
async function transformSFC(code) {
|
|
439
443
|
const { css } = await uno.generate(code);
|
|
440
444
|
if (!css)
|
|
@@ -445,6 +449,10 @@ function VueScopedPlugin({ uno, config }) {
|
|
|
445
449
|
return {
|
|
446
450
|
name: "unocss:vue-scoped",
|
|
447
451
|
enforce: "pre",
|
|
452
|
+
async configResolved() {
|
|
453
|
+
const { config } = await ready;
|
|
454
|
+
filter = createFilter2(config.include || [/\.vue$/], config.exclude || defaultExclude);
|
|
455
|
+
},
|
|
448
456
|
transform(code, id) {
|
|
449
457
|
if (!filter(id))
|
|
450
458
|
return;
|
|
@@ -464,24 +472,22 @@ function VueScopedPlugin({ uno, config }) {
|
|
|
464
472
|
|
|
465
473
|
// src/config-hmr.ts
|
|
466
474
|
function ConfigHMRPlugin(ctx) {
|
|
467
|
-
const {
|
|
475
|
+
const { ready, uno } = ctx;
|
|
468
476
|
return {
|
|
469
477
|
name: "unocss:config",
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
if (!configFilepath)
|
|
473
|
-
return ctx.config;
|
|
474
|
-
}
|
|
478
|
+
async configResolved() {
|
|
479
|
+
await ready;
|
|
475
480
|
},
|
|
476
|
-
configureServer(server) {
|
|
481
|
+
async configureServer(server) {
|
|
477
482
|
uno.config.envMode = "dev";
|
|
478
|
-
|
|
483
|
+
const { sources } = await ready;
|
|
484
|
+
if (!sources.length)
|
|
479
485
|
return;
|
|
480
|
-
server.watcher.add(
|
|
486
|
+
server.watcher.add(sources);
|
|
481
487
|
server.watcher.on("change", async (p) => {
|
|
482
|
-
if (p
|
|
488
|
+
if (!sources.includes(p))
|
|
483
489
|
return;
|
|
484
|
-
reloadConfig();
|
|
490
|
+
await ctx.reloadConfig();
|
|
485
491
|
server.ws.send({
|
|
486
492
|
type: "custom",
|
|
487
493
|
event: "unocss:config-changed"
|
|
@@ -497,12 +503,12 @@ function defineConfig(config) {
|
|
|
497
503
|
}
|
|
498
504
|
function UnocssPlugin(configOrPath, defaults = {}) {
|
|
499
505
|
const ctx = createContext(configOrPath, defaults);
|
|
500
|
-
const
|
|
501
|
-
const mode =
|
|
506
|
+
const inlineConfig = configOrPath && typeof configOrPath !== "string" ? configOrPath : {};
|
|
507
|
+
const mode = inlineConfig.mode ?? "global";
|
|
502
508
|
const plugins = [
|
|
503
509
|
ConfigHMRPlugin(ctx)
|
|
504
510
|
];
|
|
505
|
-
if (
|
|
511
|
+
if (inlineConfig.inspector !== false)
|
|
506
512
|
plugins.push(UnocssInspector(ctx));
|
|
507
513
|
if (mode === "per-module") {
|
|
508
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"
|