@unocss/vite 0.60.4 → 0.61.2
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 +45 -29
- 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,
|
|
@@ -905,10 +910,16 @@ function VueScopedPlugin({ uno, ready }) {
|
|
|
905
910
|
config.content?.pipeline?.exclude ?? config.exclude ?? defaultPipelineExclude
|
|
906
911
|
);
|
|
907
912
|
},
|
|
908
|
-
transform(code, id) {
|
|
913
|
+
async transform(code, id) {
|
|
909
914
|
if (!filter(id) || !id.endsWith(".vue"))
|
|
910
915
|
return;
|
|
911
|
-
|
|
916
|
+
const css = await transformSFC(code);
|
|
917
|
+
if (css) {
|
|
918
|
+
return {
|
|
919
|
+
code: css,
|
|
920
|
+
map: null
|
|
921
|
+
};
|
|
922
|
+
}
|
|
912
923
|
},
|
|
913
924
|
handleHotUpdate(ctx) {
|
|
914
925
|
const read = ctx.read;
|
|
@@ -1011,7 +1022,11 @@ function ShadowDomModuleModePlugin({ uno }) {
|
|
|
1011
1022
|
name: "unocss:shadow-dom",
|
|
1012
1023
|
enforce: "pre",
|
|
1013
1024
|
async transform(code, id) {
|
|
1014
|
-
|
|
1025
|
+
const css = await transformWebComponent(code, id);
|
|
1026
|
+
return {
|
|
1027
|
+
code: css,
|
|
1028
|
+
map: null
|
|
1029
|
+
};
|
|
1015
1030
|
},
|
|
1016
1031
|
handleHotUpdate(ctx) {
|
|
1017
1032
|
const read = ctx.read;
|
|
@@ -1208,7 +1223,8 @@ function defineConfig(config) {
|
|
|
1208
1223
|
function UnocssPlugin(configOrPath, defaults = {}) {
|
|
1209
1224
|
const ctx = createContext(configOrPath, {
|
|
1210
1225
|
envMode: process$1.env.NODE_ENV === "development" ? "dev" : "build",
|
|
1211
|
-
...defaults
|
|
1226
|
+
...defaults,
|
|
1227
|
+
legacy: typeof configOrPath !== "string" ? configOrPath?.legacy || { renderModernChunks: true } : { renderModernChunks: true }
|
|
1212
1228
|
});
|
|
1213
1229
|
const inlineConfig = configOrPath && typeof configOrPath !== "string" ? configOrPath : {};
|
|
1214
1230
|
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.2",
|
|
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/config": "0.
|
|
58
|
-
"@unocss/core": "0.
|
|
59
|
-
"@unocss/
|
|
60
|
-
"@unocss/
|
|
61
|
-
"@unocss/transformer-directives": "0.
|
|
57
|
+
"@unocss/config": "0.61.2",
|
|
58
|
+
"@unocss/core": "0.61.2",
|
|
59
|
+
"@unocss/scope": "0.61.2",
|
|
60
|
+
"@unocss/inspector": "0.61.2",
|
|
61
|
+
"@unocss/transformer-directives": "0.61.2"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
|
-
"vite": "^5.
|
|
65
|
-
"@unocss/shared-integration": "0.
|
|
64
|
+
"vite": "^5.3.1",
|
|
65
|
+
"@unocss/shared-integration": "0.61.2"
|
|
66
66
|
},
|
|
67
67
|
"scripts": {
|
|
68
68
|
"build": "unbuild",
|