@unocss/vite 65.4.0 → 65.4.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/dist/index.mjs +229 -233
- package/package.json +7 -8
package/dist/index.mjs
CHANGED
|
@@ -1,17 +1,158 @@
|
|
|
1
1
|
import process$1 from 'node:process';
|
|
2
|
+
import { createFilter } from '@rollup/pluginutils';
|
|
3
|
+
import { createRecoveryConfigLoader } from '@unocss/config';
|
|
4
|
+
import { cssIdRE, createGenerator, BetterMap, toEscapedSelector, LAYER_IMPORTS, LAYER_PREFLIGHTS, notNull } from '@unocss/core';
|
|
2
5
|
import UnocssInspector from '@unocss/inspector';
|
|
3
6
|
import fs from 'node:fs';
|
|
4
7
|
import { dirname, resolve, isAbsolute } from 'node:path';
|
|
5
8
|
import { fileURLToPath } from 'node:url';
|
|
6
|
-
import { toEscapedSelector, cssIdRE, createGenerator, BetterMap, notNull } from '@unocss/core';
|
|
7
9
|
import fs$1 from 'node:fs/promises';
|
|
8
10
|
import { glob } from 'tinyglobby';
|
|
9
11
|
import remapping from '@ampproject/remapping';
|
|
10
12
|
import MagicString from 'magic-string';
|
|
11
13
|
import { createHash } from 'node:crypto';
|
|
12
14
|
import { Buffer } from 'node:buffer';
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
|
|
16
|
+
const INCLUDE_COMMENT = "@unocss-include";
|
|
17
|
+
const IGNORE_COMMENT = "@unocss-ignore";
|
|
18
|
+
const CSS_PLACEHOLDER = "@unocss-placeholder";
|
|
19
|
+
const SKIP_START_COMMENT = "@unocss-skip-start";
|
|
20
|
+
const SKIP_END_COMMENT = "@unocss-skip-end";
|
|
21
|
+
const SKIP_COMMENT_RE = new RegExp(`(//\\s*?${SKIP_START_COMMENT}\\s*?|\\/\\*\\s*?${SKIP_START_COMMENT}\\s*?\\*\\/|<!--\\s*?${SKIP_START_COMMENT}\\s*?-->)[\\s\\S]*?(//\\s*?${SKIP_END_COMMENT}\\s*?|\\/\\*\\s*?${SKIP_END_COMMENT}\\s*?\\*\\/|<!--\\s*?${SKIP_END_COMMENT}\\s*?-->)`, "g");
|
|
22
|
+
|
|
23
|
+
const defaultPipelineExclude = [cssIdRE];
|
|
24
|
+
const defaultPipelineInclude = [/\.(vue|svelte|[jt]sx|mdx?|astro|elm|php|phtml|html)($|\?)/];
|
|
25
|
+
|
|
26
|
+
function deprecationCheck(config) {
|
|
27
|
+
let warned = false;
|
|
28
|
+
function warn(msg) {
|
|
29
|
+
warned = true;
|
|
30
|
+
console.warn(`[unocss] ${msg}`);
|
|
31
|
+
}
|
|
32
|
+
if (config.include)
|
|
33
|
+
warn("`include` option is deprecated, use `content.pipeline.include` instead.");
|
|
34
|
+
if (config.exclude)
|
|
35
|
+
warn("`exclude` option is deprecated, use `content.pipeline.exclude` instead.");
|
|
36
|
+
if (config.extraContent)
|
|
37
|
+
warn("`extraContent` option is deprecated, use `content` instead.");
|
|
38
|
+
if (config.content?.plain)
|
|
39
|
+
warn("`content.plain` option is renamed to `content.inline`.");
|
|
40
|
+
if (warned && typeof process !== "undefined" && process.env.CI)
|
|
41
|
+
throw new Error("deprecation warning");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function createContext(configOrPath, defaults = {}, extraConfigSources = [], resolveConfigResult = () => {
|
|
45
|
+
}) {
|
|
46
|
+
let root = process$1.cwd();
|
|
47
|
+
let rawConfig = {};
|
|
48
|
+
let configFileList = [];
|
|
49
|
+
let uno;
|
|
50
|
+
const _uno = createGenerator(rawConfig, defaults).then((r) => {
|
|
51
|
+
uno = r;
|
|
52
|
+
return r;
|
|
53
|
+
});
|
|
54
|
+
let rollupFilter = createFilter(
|
|
55
|
+
defaultPipelineInclude,
|
|
56
|
+
defaultPipelineExclude,
|
|
57
|
+
{ resolve: typeof configOrPath === "string" ? configOrPath : root }
|
|
58
|
+
);
|
|
59
|
+
const invalidations = [];
|
|
60
|
+
const reloadListeners = [];
|
|
61
|
+
const modules = new BetterMap();
|
|
62
|
+
const tokens = /* @__PURE__ */ new Set();
|
|
63
|
+
const tasks = [];
|
|
64
|
+
const affectedModules = /* @__PURE__ */ new Set();
|
|
65
|
+
const loadConfig = createRecoveryConfigLoader();
|
|
66
|
+
let ready = reloadConfig();
|
|
67
|
+
async function reloadConfig() {
|
|
68
|
+
await _uno;
|
|
69
|
+
const result = await loadConfig(root, configOrPath, extraConfigSources, defaults);
|
|
70
|
+
resolveConfigResult(result);
|
|
71
|
+
deprecationCheck(result.config);
|
|
72
|
+
rawConfig = result.config;
|
|
73
|
+
configFileList = result.sources;
|
|
74
|
+
await uno.setConfig(rawConfig);
|
|
75
|
+
uno.config.envMode = "dev";
|
|
76
|
+
rollupFilter = rawConfig.content?.pipeline === false ? () => false : createFilter(
|
|
77
|
+
rawConfig.content?.pipeline?.include || rawConfig.include || defaultPipelineInclude,
|
|
78
|
+
rawConfig.content?.pipeline?.exclude || rawConfig.exclude || defaultPipelineExclude,
|
|
79
|
+
{ resolve: typeof configOrPath === "string" ? configOrPath : root }
|
|
80
|
+
);
|
|
81
|
+
tokens.clear();
|
|
82
|
+
await Promise.all(modules.map((code, id) => uno.applyExtractors(code.replace(SKIP_COMMENT_RE, ""), id, tokens)));
|
|
83
|
+
invalidate();
|
|
84
|
+
dispatchReload();
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
async function updateRoot(newRoot) {
|
|
88
|
+
if (newRoot !== root) {
|
|
89
|
+
root = newRoot;
|
|
90
|
+
ready = reloadConfig();
|
|
91
|
+
}
|
|
92
|
+
return await ready;
|
|
93
|
+
}
|
|
94
|
+
function invalidate() {
|
|
95
|
+
invalidations.forEach((cb) => cb());
|
|
96
|
+
}
|
|
97
|
+
function dispatchReload() {
|
|
98
|
+
reloadListeners.forEach((cb) => cb());
|
|
99
|
+
}
|
|
100
|
+
async function extract(code, id) {
|
|
101
|
+
const uno2 = await _uno;
|
|
102
|
+
if (id)
|
|
103
|
+
modules.set(id, code);
|
|
104
|
+
const len = tokens.size;
|
|
105
|
+
await uno2.applyExtractors(code.replace(SKIP_COMMENT_RE, ""), id, tokens);
|
|
106
|
+
if (tokens.size > len)
|
|
107
|
+
invalidate();
|
|
108
|
+
}
|
|
109
|
+
function filter(code, id) {
|
|
110
|
+
if (code.includes(IGNORE_COMMENT))
|
|
111
|
+
return false;
|
|
112
|
+
return code.includes(INCLUDE_COMMENT) || code.includes(CSS_PLACEHOLDER) || rollupFilter(id.replace(/\?v=\w+$/, ""));
|
|
113
|
+
}
|
|
114
|
+
async function getConfig() {
|
|
115
|
+
await ready;
|
|
116
|
+
return rawConfig;
|
|
117
|
+
}
|
|
118
|
+
async function flushTasks() {
|
|
119
|
+
const _tasks = [...tasks];
|
|
120
|
+
await Promise.all(_tasks);
|
|
121
|
+
if (tasks[0] === _tasks[0])
|
|
122
|
+
tasks.splice(0, _tasks.length);
|
|
123
|
+
}
|
|
124
|
+
return {
|
|
125
|
+
get ready() {
|
|
126
|
+
return ready;
|
|
127
|
+
},
|
|
128
|
+
tokens,
|
|
129
|
+
modules,
|
|
130
|
+
affectedModules,
|
|
131
|
+
tasks,
|
|
132
|
+
flushTasks,
|
|
133
|
+
invalidate,
|
|
134
|
+
onInvalidate(fn) {
|
|
135
|
+
invalidations.push(fn);
|
|
136
|
+
},
|
|
137
|
+
filter,
|
|
138
|
+
reloadConfig,
|
|
139
|
+
onReload(fn) {
|
|
140
|
+
reloadListeners.push(fn);
|
|
141
|
+
},
|
|
142
|
+
get uno() {
|
|
143
|
+
if (!uno)
|
|
144
|
+
throw new Error("Run `await context.ready` before accessing `context.uno`");
|
|
145
|
+
return uno;
|
|
146
|
+
},
|
|
147
|
+
extract,
|
|
148
|
+
getConfig,
|
|
149
|
+
get root() {
|
|
150
|
+
return root;
|
|
151
|
+
},
|
|
152
|
+
updateRoot,
|
|
153
|
+
getConfigFileList: () => configFileList
|
|
154
|
+
};
|
|
155
|
+
}
|
|
15
156
|
|
|
16
157
|
function ConfigHMRPlugin(ctx) {
|
|
17
158
|
const { ready } = ctx;
|
|
@@ -168,6 +309,51 @@ function createDevtoolsPlugin(ctx, pluginConfig) {
|
|
|
168
309
|
];
|
|
169
310
|
}
|
|
170
311
|
|
|
312
|
+
function ChunkModeBuildPlugin(ctx) {
|
|
313
|
+
let cssPlugin;
|
|
314
|
+
const files = {};
|
|
315
|
+
return {
|
|
316
|
+
name: "unocss:chunk",
|
|
317
|
+
apply: "build",
|
|
318
|
+
enforce: "pre",
|
|
319
|
+
configResolved(config) {
|
|
320
|
+
cssPlugin = config.plugins.find((i) => i.name === "vite:css-post");
|
|
321
|
+
},
|
|
322
|
+
async transform(code, id) {
|
|
323
|
+
await ctx.ready;
|
|
324
|
+
if (!ctx.filter(code, id))
|
|
325
|
+
return;
|
|
326
|
+
files[id] = code;
|
|
327
|
+
return null;
|
|
328
|
+
},
|
|
329
|
+
async renderChunk(_, chunk) {
|
|
330
|
+
const chunks = Object.keys(chunk.modules).map((i) => files[i]).filter(Boolean);
|
|
331
|
+
if (!chunks.length)
|
|
332
|
+
return null;
|
|
333
|
+
await ctx.ready;
|
|
334
|
+
const tokens = /* @__PURE__ */ new Set();
|
|
335
|
+
await Promise.all(chunks.map((c) => ctx.uno.applyExtractors(c, undefined, tokens)));
|
|
336
|
+
const { css } = await ctx.uno.generate(tokens);
|
|
337
|
+
const fakeCssId = `${chunk.fileName}.css`;
|
|
338
|
+
await cssPlugin.transform(css, fakeCssId);
|
|
339
|
+
chunk.modules[fakeCssId] = {
|
|
340
|
+
code: null,
|
|
341
|
+
originalLength: 0,
|
|
342
|
+
removedExports: [],
|
|
343
|
+
renderedExports: [],
|
|
344
|
+
renderedLength: 0
|
|
345
|
+
};
|
|
346
|
+
return null;
|
|
347
|
+
},
|
|
348
|
+
async transformIndexHtml(code) {
|
|
349
|
+
await ctx.ready;
|
|
350
|
+
const { css } = await ctx.uno.generate(code);
|
|
351
|
+
if (css)
|
|
352
|
+
return `${code}<style>${css}</style>`;
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
|
|
171
357
|
function getPath(id) {
|
|
172
358
|
return id.replace(/\?.*$/, "");
|
|
173
359
|
}
|
|
@@ -197,7 +383,6 @@ function restoreSkipCode(code, map) {
|
|
|
197
383
|
code = code.replaceAll(withHashKey, matched);
|
|
198
384
|
return code;
|
|
199
385
|
}
|
|
200
|
-
|
|
201
386
|
function replaceAsync(string, searchValue, replacer) {
|
|
202
387
|
try {
|
|
203
388
|
if (typeof replacer === "function") {
|
|
@@ -221,229 +406,6 @@ function replaceAsync(string, searchValue, replacer) {
|
|
|
221
406
|
}
|
|
222
407
|
}
|
|
223
408
|
|
|
224
|
-
const INCLUDE_COMMENT = "@unocss-include";
|
|
225
|
-
const IGNORE_COMMENT = "@unocss-ignore";
|
|
226
|
-
const CSS_PLACEHOLDER = "@unocss-placeholder";
|
|
227
|
-
const SKIP_START_COMMENT = "@unocss-skip-start";
|
|
228
|
-
const SKIP_END_COMMENT = "@unocss-skip-end";
|
|
229
|
-
const SKIP_COMMENT_RE = new RegExp(`(//\\s*?${SKIP_START_COMMENT}\\s*?|\\/\\*\\s*?${SKIP_START_COMMENT}\\s*?\\*\\/|<!--\\s*?${SKIP_START_COMMENT}\\s*?-->)[\\s\\S]*?(//\\s*?${SKIP_END_COMMENT}\\s*?|\\/\\*\\s*?${SKIP_END_COMMENT}\\s*?\\*\\/|<!--\\s*?${SKIP_END_COMMENT}\\s*?-->)`, "g");
|
|
230
|
-
|
|
231
|
-
const defaultPipelineExclude = [cssIdRE];
|
|
232
|
-
const defaultPipelineInclude = [/\.(vue|svelte|[jt]sx|mdx?|astro|elm|php|phtml|html)($|\?)/];
|
|
233
|
-
|
|
234
|
-
function deprecationCheck(config) {
|
|
235
|
-
let warned = false;
|
|
236
|
-
function warn(msg) {
|
|
237
|
-
warned = true;
|
|
238
|
-
console.warn(`[unocss] ${msg}`);
|
|
239
|
-
}
|
|
240
|
-
if (config.include)
|
|
241
|
-
warn("`include` option is deprecated, use `content.pipeline.include` instead.");
|
|
242
|
-
if (config.exclude)
|
|
243
|
-
warn("`exclude` option is deprecated, use `content.pipeline.exclude` instead.");
|
|
244
|
-
if (config.extraContent)
|
|
245
|
-
warn("`extraContent` option is deprecated, use `content` instead.");
|
|
246
|
-
if (config.content?.plain)
|
|
247
|
-
warn("`content.plain` option is renamed to `content.inline`.");
|
|
248
|
-
if (warned && typeof process !== "undefined" && process.env.CI)
|
|
249
|
-
throw new Error("deprecation warning");
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
function createContext(configOrPath, defaults = {}, extraConfigSources = [], resolveConfigResult = () => {
|
|
253
|
-
}) {
|
|
254
|
-
let root = process$1.cwd();
|
|
255
|
-
let rawConfig = {};
|
|
256
|
-
let configFileList = [];
|
|
257
|
-
let uno;
|
|
258
|
-
const _uno = createGenerator(rawConfig, defaults).then((r) => {
|
|
259
|
-
uno = r;
|
|
260
|
-
return r;
|
|
261
|
-
});
|
|
262
|
-
let rollupFilter = createFilter(
|
|
263
|
-
defaultPipelineInclude,
|
|
264
|
-
defaultPipelineExclude,
|
|
265
|
-
{ resolve: typeof configOrPath === "string" ? configOrPath : root }
|
|
266
|
-
);
|
|
267
|
-
const invalidations = [];
|
|
268
|
-
const reloadListeners = [];
|
|
269
|
-
const modules = new BetterMap();
|
|
270
|
-
const tokens = /* @__PURE__ */ new Set();
|
|
271
|
-
const tasks = [];
|
|
272
|
-
const affectedModules = /* @__PURE__ */ new Set();
|
|
273
|
-
const loadConfig = createRecoveryConfigLoader();
|
|
274
|
-
let ready = reloadConfig();
|
|
275
|
-
async function reloadConfig() {
|
|
276
|
-
await _uno;
|
|
277
|
-
const result = await loadConfig(root, configOrPath, extraConfigSources, defaults);
|
|
278
|
-
resolveConfigResult(result);
|
|
279
|
-
deprecationCheck(result.config);
|
|
280
|
-
rawConfig = result.config;
|
|
281
|
-
configFileList = result.sources;
|
|
282
|
-
await uno.setConfig(rawConfig);
|
|
283
|
-
uno.config.envMode = "dev";
|
|
284
|
-
rollupFilter = rawConfig.content?.pipeline === false ? () => false : createFilter(
|
|
285
|
-
rawConfig.content?.pipeline?.include || rawConfig.include || defaultPipelineInclude,
|
|
286
|
-
rawConfig.content?.pipeline?.exclude || rawConfig.exclude || defaultPipelineExclude,
|
|
287
|
-
{ resolve: typeof configOrPath === "string" ? configOrPath : root }
|
|
288
|
-
);
|
|
289
|
-
tokens.clear();
|
|
290
|
-
await Promise.all(modules.map((code, id) => uno.applyExtractors(code.replace(SKIP_COMMENT_RE, ""), id, tokens)));
|
|
291
|
-
invalidate();
|
|
292
|
-
dispatchReload();
|
|
293
|
-
return result;
|
|
294
|
-
}
|
|
295
|
-
async function updateRoot(newRoot) {
|
|
296
|
-
if (newRoot !== root) {
|
|
297
|
-
root = newRoot;
|
|
298
|
-
ready = reloadConfig();
|
|
299
|
-
}
|
|
300
|
-
return await ready;
|
|
301
|
-
}
|
|
302
|
-
function invalidate() {
|
|
303
|
-
invalidations.forEach((cb) => cb());
|
|
304
|
-
}
|
|
305
|
-
function dispatchReload() {
|
|
306
|
-
reloadListeners.forEach((cb) => cb());
|
|
307
|
-
}
|
|
308
|
-
async function extract(code, id) {
|
|
309
|
-
const uno2 = await _uno;
|
|
310
|
-
if (id)
|
|
311
|
-
modules.set(id, code);
|
|
312
|
-
const len = tokens.size;
|
|
313
|
-
await uno2.applyExtractors(code.replace(SKIP_COMMENT_RE, ""), id, tokens);
|
|
314
|
-
if (tokens.size > len)
|
|
315
|
-
invalidate();
|
|
316
|
-
}
|
|
317
|
-
function filter(code, id) {
|
|
318
|
-
if (code.includes(IGNORE_COMMENT))
|
|
319
|
-
return false;
|
|
320
|
-
return code.includes(INCLUDE_COMMENT) || code.includes(CSS_PLACEHOLDER) || rollupFilter(id.replace(/\?v=\w+$/, ""));
|
|
321
|
-
}
|
|
322
|
-
async function getConfig() {
|
|
323
|
-
await ready;
|
|
324
|
-
return rawConfig;
|
|
325
|
-
}
|
|
326
|
-
async function flushTasks() {
|
|
327
|
-
const _tasks = [...tasks];
|
|
328
|
-
await Promise.all(_tasks);
|
|
329
|
-
if (tasks[0] === _tasks[0])
|
|
330
|
-
tasks.splice(0, _tasks.length);
|
|
331
|
-
}
|
|
332
|
-
return {
|
|
333
|
-
get ready() {
|
|
334
|
-
return ready;
|
|
335
|
-
},
|
|
336
|
-
tokens,
|
|
337
|
-
modules,
|
|
338
|
-
affectedModules,
|
|
339
|
-
tasks,
|
|
340
|
-
flushTasks,
|
|
341
|
-
invalidate,
|
|
342
|
-
onInvalidate(fn) {
|
|
343
|
-
invalidations.push(fn);
|
|
344
|
-
},
|
|
345
|
-
filter,
|
|
346
|
-
reloadConfig,
|
|
347
|
-
onReload(fn) {
|
|
348
|
-
reloadListeners.push(fn);
|
|
349
|
-
},
|
|
350
|
-
get uno() {
|
|
351
|
-
if (!uno)
|
|
352
|
-
throw new Error("Run `await context.ready` before accessing `context.uno`");
|
|
353
|
-
return uno;
|
|
354
|
-
},
|
|
355
|
-
extract,
|
|
356
|
-
getConfig,
|
|
357
|
-
get root() {
|
|
358
|
-
return root;
|
|
359
|
-
},
|
|
360
|
-
updateRoot,
|
|
361
|
-
getConfigFileList: () => configFileList
|
|
362
|
-
};
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
function getHash(input, length = 8) {
|
|
366
|
-
return createHash("sha256").update(input).digest("hex").slice(0, length);
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
const VIRTUAL_ENTRY_ALIAS = [
|
|
370
|
-
/^(?:virtual:)?uno(?::(.+))?\.css(\?.*)?$/
|
|
371
|
-
];
|
|
372
|
-
const LAYER_MARK_ALL = "__ALL__";
|
|
373
|
-
const RESOLVED_ID_WITH_QUERY_RE = /[/\\]__uno(_.*?)?\.css(\?.*)?$/;
|
|
374
|
-
const RESOLVED_ID_RE = /[/\\]__uno(?:_(.*?))?\.css$/;
|
|
375
|
-
function resolveId(id) {
|
|
376
|
-
if (id.match(RESOLVED_ID_WITH_QUERY_RE))
|
|
377
|
-
return id;
|
|
378
|
-
for (const alias of VIRTUAL_ENTRY_ALIAS) {
|
|
379
|
-
const match = id.match(alias);
|
|
380
|
-
if (match) {
|
|
381
|
-
return match[1] ? `/__uno_${match[1]}.css` : "/__uno.css";
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
function resolveLayer(id) {
|
|
386
|
-
const match = id.match(RESOLVED_ID_RE);
|
|
387
|
-
if (match)
|
|
388
|
-
return match[1] || LAYER_MARK_ALL;
|
|
389
|
-
}
|
|
390
|
-
const LAYER_PLACEHOLDER_RE = /#--unocss--\s*\{\s*layer\s*:\s*(.+?)\s*(?:;\s*escape-view\s*:\s*(.+?)\s*)?;?\s*\}/g;
|
|
391
|
-
function getLayerPlaceholder(layer) {
|
|
392
|
-
return `#--unocss--{layer:${layer};escape-view:\\"\\'\\\`\\\\}`;
|
|
393
|
-
}
|
|
394
|
-
const HASH_PLACEHOLDER_RE = /#--unocss-hash--\s*\{\s*content\s*:\s*\\*"([^\\"]+)\\*";?\s*\}/g;
|
|
395
|
-
function getHashPlaceholder(hash) {
|
|
396
|
-
return `#--unocss-hash--{content:"${hash}"}`;
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
function ChunkModeBuildPlugin(ctx) {
|
|
400
|
-
let cssPlugin;
|
|
401
|
-
const files = {};
|
|
402
|
-
return {
|
|
403
|
-
name: "unocss:chunk",
|
|
404
|
-
apply: "build",
|
|
405
|
-
enforce: "pre",
|
|
406
|
-
configResolved(config) {
|
|
407
|
-
cssPlugin = config.plugins.find((i) => i.name === "vite:css-post");
|
|
408
|
-
},
|
|
409
|
-
async transform(code, id) {
|
|
410
|
-
await ctx.ready;
|
|
411
|
-
if (!ctx.filter(code, id))
|
|
412
|
-
return;
|
|
413
|
-
files[id] = code;
|
|
414
|
-
return null;
|
|
415
|
-
},
|
|
416
|
-
async renderChunk(_, chunk) {
|
|
417
|
-
const chunks = Object.keys(chunk.modules).map((i) => files[i]).filter(Boolean);
|
|
418
|
-
if (!chunks.length)
|
|
419
|
-
return null;
|
|
420
|
-
await ctx.ready;
|
|
421
|
-
const tokens = /* @__PURE__ */ new Set();
|
|
422
|
-
await Promise.all(chunks.map((c) => ctx.uno.applyExtractors(c, void 0, tokens)));
|
|
423
|
-
const { css } = await ctx.uno.generate(tokens);
|
|
424
|
-
const fakeCssId = `${chunk.fileName}.css`;
|
|
425
|
-
await cssPlugin.transform(css, fakeCssId);
|
|
426
|
-
chunk.modules[fakeCssId] = {
|
|
427
|
-
code: null,
|
|
428
|
-
originalLength: 0,
|
|
429
|
-
removedExports: [],
|
|
430
|
-
renderedExports: [],
|
|
431
|
-
renderedLength: 0
|
|
432
|
-
};
|
|
433
|
-
return null;
|
|
434
|
-
},
|
|
435
|
-
async transformIndexHtml(code) {
|
|
436
|
-
await ctx.ready;
|
|
437
|
-
const { css } = await ctx.uno.generate(code);
|
|
438
|
-
if (css)
|
|
439
|
-
return `${code}<style>${css}</style>`;
|
|
440
|
-
}
|
|
441
|
-
};
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
const LAYER_PREFLIGHTS = "preflights";
|
|
445
|
-
const LAYER_IMPORTS = "imports";
|
|
446
|
-
|
|
447
409
|
async function applyTransformers(ctx, original, id, enforce = "default") {
|
|
448
410
|
if (original.includes(IGNORE_COMMENT))
|
|
449
411
|
return;
|
|
@@ -525,6 +487,40 @@ async function setupContentExtractor(ctx, shouldWatch = false) {
|
|
|
525
487
|
}
|
|
526
488
|
}
|
|
527
489
|
|
|
490
|
+
function getHash(input, length = 8) {
|
|
491
|
+
return createHash("sha256").update(input).digest("hex").slice(0, length);
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
const VIRTUAL_ENTRY_ALIAS = [
|
|
495
|
+
/^(?:virtual:)?uno(?::(.+))?\.css(\?.*)?$/
|
|
496
|
+
];
|
|
497
|
+
const LAYER_MARK_ALL = "__ALL__";
|
|
498
|
+
const RESOLVED_ID_WITH_QUERY_RE = /[/\\]__uno(_.*?)?\.css(\?.*)?$/;
|
|
499
|
+
const RESOLVED_ID_RE = /[/\\]__uno(?:_(.*?))?\.css$/;
|
|
500
|
+
function resolveId(id) {
|
|
501
|
+
if (id.match(RESOLVED_ID_WITH_QUERY_RE))
|
|
502
|
+
return id;
|
|
503
|
+
for (const alias of VIRTUAL_ENTRY_ALIAS) {
|
|
504
|
+
const match = id.match(alias);
|
|
505
|
+
if (match) {
|
|
506
|
+
return match[1] ? `/__uno_${match[1]}.css` : "/__uno.css";
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
function resolveLayer(id) {
|
|
511
|
+
const match = id.match(RESOLVED_ID_RE);
|
|
512
|
+
if (match)
|
|
513
|
+
return match[1] || LAYER_MARK_ALL;
|
|
514
|
+
}
|
|
515
|
+
const LAYER_PLACEHOLDER_RE = /#--unocss--\s*\{\s*layer\s*:\s*(.+?)\s*(?:;\s*escape-view\s*:\s*(.+?)\s*)?;?\s*\}/g;
|
|
516
|
+
function getLayerPlaceholder(layer) {
|
|
517
|
+
return `#--unocss--{layer:${layer};escape-view:\\"\\'\\\`\\\\}`;
|
|
518
|
+
}
|
|
519
|
+
const HASH_PLACEHOLDER_RE = /#--unocss-hash--\s*\{\s*content\s*:\s*\\*"([^\\"]+)\\*";?\s*\}/g;
|
|
520
|
+
function getHashPlaceholder(hash) {
|
|
521
|
+
return `#--unocss-hash--{content:"${hash}"}`;
|
|
522
|
+
}
|
|
523
|
+
|
|
528
524
|
const MESSAGE_UNOCSS_ENTRY_NOT_FOUND = "[unocss] Entry module not found. Did you add `import 'uno.css'` in your main entry?";
|
|
529
525
|
|
|
530
526
|
function isLegacyChunk(chunk, options) {
|
|
@@ -573,7 +569,7 @@ function GlobalModeBuildPlugin(ctx) {
|
|
|
573
569
|
vfsLayers.clear();
|
|
574
570
|
tasks.length = 0;
|
|
575
571
|
lastTokenSize = 0;
|
|
576
|
-
lastResult =
|
|
572
|
+
lastResult = undefined;
|
|
577
573
|
},
|
|
578
574
|
transform(code, id) {
|
|
579
575
|
if (filter(code, id))
|
|
@@ -711,7 +707,7 @@ function GlobalModeBuildPlugin(ctx) {
|
|
|
711
707
|
const layerEnd = `#--unocss-layer-end--${layer}--{end:${layer}}`;
|
|
712
708
|
let layerContent;
|
|
713
709
|
if (layer === LAYER_MARK_ALL) {
|
|
714
|
-
layerContent = result.getLayers(
|
|
710
|
+
layerContent = result.getLayers(undefined, [...vfsLayers, LAYER_IMPORTS]);
|
|
715
711
|
} else {
|
|
716
712
|
layerContent = result.getLayer(layer) || "";
|
|
717
713
|
}
|
|
@@ -807,7 +803,7 @@ function GlobalModeDevPlugin(ctx) {
|
|
|
807
803
|
break;
|
|
808
804
|
tokensSize = tokens.size;
|
|
809
805
|
} while (true);
|
|
810
|
-
const css = layer === LAYER_MARK_ALL ? result.getLayers(
|
|
806
|
+
const css = layer === LAYER_MARK_ALL ? result.getLayers(undefined, Array.from(entries).map((i) => resolveLayer(i)).filter((i) => !!i)) : result.getLayer(layer);
|
|
811
807
|
const hash = getHash(css || "", HASH_LENGTH);
|
|
812
808
|
lastServedHash.set(layer, hash);
|
|
813
809
|
lastServedTime = Date.now();
|
|
@@ -864,7 +860,7 @@ function GlobalModeDevPlugin(ctx) {
|
|
|
864
860
|
function clearWarnTimer() {
|
|
865
861
|
if (resolvedWarnTimer) {
|
|
866
862
|
clearTimeout(resolvedWarnTimer);
|
|
867
|
-
resolvedWarnTimer =
|
|
863
|
+
resolvedWarnTimer = undefined;
|
|
868
864
|
}
|
|
869
865
|
}
|
|
870
866
|
onInvalidate(() => {
|
|
@@ -1027,7 +1023,7 @@ function PerModuleModePlugin(ctx) {
|
|
|
1027
1023
|
return;
|
|
1028
1024
|
const hash = getHash(id);
|
|
1029
1025
|
const hasScope = SCOPE_IMPORT_RE.test(code);
|
|
1030
|
-
const { css } = await ctx.uno.generate(code, { id, scope: hasScope ? `.${hash}` :
|
|
1026
|
+
const { css } = await ctx.uno.generate(code, { id, scope: hasScope ? `.${hash}` : undefined, preflights: false });
|
|
1031
1027
|
if (!css && !hasScope)
|
|
1032
1028
|
return null;
|
|
1033
1029
|
if (hasScope)
|
|
@@ -1227,7 +1223,7 @@ function VueScopedPlugin(ctx) {
|
|
|
1227
1223
|
function createTransformerPlugins(ctx) {
|
|
1228
1224
|
const orders = ["default", "pre", "post"];
|
|
1229
1225
|
return orders.map((_order) => {
|
|
1230
|
-
const order = _order === "default" ?
|
|
1226
|
+
const order = _order === "default" ? undefined : _order;
|
|
1231
1227
|
const htmlHandler = (code) => {
|
|
1232
1228
|
return applyTransformers(ctx, code, "index.html", order).then((t) => t?.code);
|
|
1233
1229
|
};
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/vite",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "65.4.
|
|
4
|
+
"version": "65.4.3",
|
|
5
5
|
"description": "The Vite plugin for UnoCSS",
|
|
6
6
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"funding": "https://github.com/sponsors/antfu",
|
|
9
|
-
"homepage": "https://
|
|
9
|
+
"homepage": "https://unocss.dev",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
12
|
"url": "https://github.com/unocss/unocss",
|
|
13
|
-
"directory": "packages/vite"
|
|
13
|
+
"directory": "packages-integrations/vite"
|
|
14
14
|
},
|
|
15
15
|
"bugs": {
|
|
16
16
|
"url": "https://github.com/unocss/unocss/issues"
|
|
@@ -54,13 +54,12 @@
|
|
|
54
54
|
"chokidar": "^3.6.0",
|
|
55
55
|
"magic-string": "^0.30.17",
|
|
56
56
|
"tinyglobby": "^0.2.10",
|
|
57
|
-
"@unocss/
|
|
58
|
-
"@unocss/
|
|
59
|
-
"@unocss/inspector": "65.4.
|
|
57
|
+
"@unocss/core": "65.4.3",
|
|
58
|
+
"@unocss/config": "65.4.3",
|
|
59
|
+
"@unocss/inspector": "65.4.3"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"vite": "^6.0.
|
|
63
|
-
"@unocss/shared-integration": "65.4.0"
|
|
62
|
+
"vite": "^6.0.11"
|
|
64
63
|
},
|
|
65
64
|
"scripts": {
|
|
66
65
|
"build": "unbuild",
|