@unocss/vite 0.60.3 → 0.61.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.mjs +33 -27
- package/package.json +8 -8
package/dist/index.mjs
CHANGED
|
@@ -5,8 +5,8 @@ import fs from 'node:fs/promises';
|
|
|
5
5
|
import fg from 'fast-glob';
|
|
6
6
|
import MagicString from 'magic-string';
|
|
7
7
|
import remapping from '@ampproject/remapping';
|
|
8
|
-
import { createHash } from 'node:crypto';
|
|
9
8
|
import { cssIdRE, createGenerator, BetterMap, notNull, toEscapedSelector } from '@unocss/core';
|
|
9
|
+
import { createHash } from 'node:crypto';
|
|
10
10
|
import { Buffer } from 'node:buffer';
|
|
11
11
|
import { createFilter } from '@rollup/pluginutils';
|
|
12
12
|
import fs$1 from 'node:fs';
|
|
@@ -184,10 +184,6 @@ function createContext(configOrPath, defaults = {}, extraConfigSources = [], res
|
|
|
184
184
|
function getPath(id) {
|
|
185
185
|
return id.replace(/\?.*$/, "");
|
|
186
186
|
}
|
|
187
|
-
|
|
188
|
-
function getHash(input, length = 8) {
|
|
189
|
-
return createHash("sha256").update(input).digest("hex").slice(0, length);
|
|
190
|
-
}
|
|
191
187
|
function hash(str) {
|
|
192
188
|
let i;
|
|
193
189
|
let l;
|
|
@@ -198,6 +194,26 @@ function hash(str) {
|
|
|
198
194
|
}
|
|
199
195
|
return `00000${(hval >>> 0).toString(36)}`.slice(-6);
|
|
200
196
|
}
|
|
197
|
+
function transformSkipCode(code, map, SKIP_RULES_RE, keyFlag) {
|
|
198
|
+
for (const item of Array.from(code.matchAll(SKIP_RULES_RE))) {
|
|
199
|
+
if (item != null) {
|
|
200
|
+
const matched = item[0];
|
|
201
|
+
const withHashKey = `${keyFlag}${hash(matched)}`;
|
|
202
|
+
map.set(withHashKey, matched);
|
|
203
|
+
code = code.replace(matched, withHashKey);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return code;
|
|
207
|
+
}
|
|
208
|
+
function restoreSkipCode(code, map) {
|
|
209
|
+
for (const [withHashKey, matched] of map.entries())
|
|
210
|
+
code = code.replaceAll(withHashKey, matched);
|
|
211
|
+
return code;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
function getHash(input, length = 8) {
|
|
215
|
+
return createHash("sha256").update(input).digest("hex").slice(0, length);
|
|
216
|
+
}
|
|
201
217
|
|
|
202
218
|
function replaceAsync(string, searchValue, replacer) {
|
|
203
219
|
try {
|
|
@@ -272,7 +288,7 @@ async function applyTransformers(ctx, original, id, enforce = "default") {
|
|
|
272
288
|
return;
|
|
273
289
|
const skipMap = /* @__PURE__ */ new Map();
|
|
274
290
|
let code = original;
|
|
275
|
-
let s = new MagicString(transformSkipCode(code, skipMap));
|
|
291
|
+
let s = new MagicString(transformSkipCode(code, skipMap, SKIP_COMMENT_RE, "@unocss-skip-placeholder-"));
|
|
276
292
|
const maps = [];
|
|
277
293
|
for (const t of transformers) {
|
|
278
294
|
if (t.idFilter) {
|
|
@@ -298,22 +314,6 @@ async function applyTransformers(ctx, original, id, enforce = "default") {
|
|
|
298
314
|
};
|
|
299
315
|
}
|
|
300
316
|
}
|
|
301
|
-
function transformSkipCode(code, map) {
|
|
302
|
-
for (const item of Array.from(code.matchAll(SKIP_COMMENT_RE))) {
|
|
303
|
-
if (item != null) {
|
|
304
|
-
const matched = item[0];
|
|
305
|
-
const withHashKey = `@unocss-skip-placeholder-${hash(matched)}`;
|
|
306
|
-
map.set(withHashKey, matched);
|
|
307
|
-
code = code.replace(matched, withHashKey);
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
return code;
|
|
311
|
-
}
|
|
312
|
-
function restoreSkipCode(code, map) {
|
|
313
|
-
for (const [withHashKey, matched] of map.entries())
|
|
314
|
-
code = code.replace(withHashKey, matched);
|
|
315
|
-
return code;
|
|
316
|
-
}
|
|
317
317
|
|
|
318
318
|
async function setupContentExtractor(ctx, shouldWatch = false) {
|
|
319
319
|
const { content } = await ctx.getConfig();
|
|
@@ -479,7 +479,8 @@ function GlobalModeBuildPlugin(ctx) {
|
|
|
479
479
|
// we inject a hash to chunk before the dist hash calculation to make sure
|
|
480
480
|
// the hash is different when unocss changes
|
|
481
481
|
async renderChunk(_, chunk, options) {
|
|
482
|
-
|
|
482
|
+
const isLegacy = isLegacyChunk(chunk, options);
|
|
483
|
+
if (isLegacy && (!ctx.uno.config.legacy || ctx.uno.config.legacy.renderModernChunks))
|
|
483
484
|
return null;
|
|
484
485
|
if (!Object.keys(chunk.modules).some((i) => RESOLVED_ID_RE.test(i)))
|
|
485
486
|
return null;
|
|
@@ -491,9 +492,13 @@ function GlobalModeBuildPlugin(ctx) {
|
|
|
491
492
|
let { css } = await generateAll();
|
|
492
493
|
const fakeCssId = `${viteConfig.root}/${chunk.fileName}-unocss-hash.css`;
|
|
493
494
|
css = await applyCssTransform(css, fakeCssId, options.dir, this);
|
|
494
|
-
const hash = getHash(css);
|
|
495
495
|
const transformHandler = "handler" in cssPost.transform ? cssPost.transform.handler : cssPost.transform;
|
|
496
|
-
|
|
496
|
+
if (isLegacy) {
|
|
497
|
+
await transformHandler.call({}, css, "/__uno.css");
|
|
498
|
+
} else {
|
|
499
|
+
const hash = getHash(css);
|
|
500
|
+
await transformHandler.call({}, getHashPlaceholder(hash), fakeCssId);
|
|
501
|
+
}
|
|
497
502
|
chunk.modules[fakeCssId] = {
|
|
498
503
|
code: null,
|
|
499
504
|
originalLength: 0,
|
|
@@ -511,7 +516,7 @@ function GlobalModeBuildPlugin(ctx) {
|
|
|
511
516
|
viteConfig = config;
|
|
512
517
|
},
|
|
513
518
|
buildStart() {
|
|
514
|
-
tasks.push(setupContentExtractor(ctx, viteConfig.command === "serve"));
|
|
519
|
+
tasks.push(setupContentExtractor(ctx, viteConfig.mode !== "test" && viteConfig.command === "serve"));
|
|
515
520
|
}
|
|
516
521
|
},
|
|
517
522
|
{
|
|
@@ -1208,7 +1213,8 @@ function defineConfig(config) {
|
|
|
1208
1213
|
function UnocssPlugin(configOrPath, defaults = {}) {
|
|
1209
1214
|
const ctx = createContext(configOrPath, {
|
|
1210
1215
|
envMode: process$1.env.NODE_ENV === "development" ? "dev" : "build",
|
|
1211
|
-
...defaults
|
|
1216
|
+
...defaults,
|
|
1217
|
+
legacy: typeof configOrPath !== "string" ? configOrPath?.legacy || { renderModernChunks: true } : { renderModernChunks: true }
|
|
1212
1218
|
});
|
|
1213
1219
|
const inlineConfig = configOrPath && typeof configOrPath !== "string" ? configOrPath : {};
|
|
1214
1220
|
const mode = inlineConfig.mode ?? "global";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/vite",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.61.0",
|
|
5
5
|
"description": "The Vite plugin for UnoCSS",
|
|
6
6
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -54,15 +54,15 @@
|
|
|
54
54
|
"chokidar": "^3.6.0",
|
|
55
55
|
"fast-glob": "^3.3.2",
|
|
56
56
|
"magic-string": "^0.30.10",
|
|
57
|
-
"@unocss/
|
|
58
|
-
"@unocss/
|
|
59
|
-
"@unocss/
|
|
60
|
-
"@unocss/scope": "0.
|
|
61
|
-
"@unocss/transformer-directives": "0.
|
|
57
|
+
"@unocss/config": "0.61.0",
|
|
58
|
+
"@unocss/inspector": "0.61.0",
|
|
59
|
+
"@unocss/core": "0.61.0",
|
|
60
|
+
"@unocss/scope": "0.61.0",
|
|
61
|
+
"@unocss/transformer-directives": "0.61.0"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
|
-
"vite": "^5.2.
|
|
65
|
-
"@unocss/shared-integration": "0.
|
|
64
|
+
"vite": "^5.2.13",
|
|
65
|
+
"@unocss/shared-integration": "0.61.0"
|
|
66
66
|
},
|
|
67
67
|
"scripts": {
|
|
68
68
|
"build": "unbuild",
|