@unocss/vite 0.50.2 → 0.50.4
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.cjs +16 -15
- package/dist/index.mjs +9 -8
- package/package.json +9 -9
package/dist/index.cjs
CHANGED
|
@@ -6,14 +6,14 @@ const UnocssInspector = require('@unocss/inspector');
|
|
|
6
6
|
const core = require('@unocss/core');
|
|
7
7
|
const pluginutils = require('@rollup/pluginutils');
|
|
8
8
|
const config = require('@unocss/config');
|
|
9
|
-
const
|
|
9
|
+
const node_crypto = require('node:crypto');
|
|
10
10
|
const MagicString = require('magic-string');
|
|
11
|
-
const
|
|
12
|
-
const fs = require('fs/promises');
|
|
11
|
+
const node_path = require('node:path');
|
|
12
|
+
const fs = require('node:fs/promises');
|
|
13
13
|
const fg = require('fast-glob');
|
|
14
14
|
const remapping = require('@ampproject/remapping');
|
|
15
|
-
const fs$1 = require('fs');
|
|
16
|
-
const
|
|
15
|
+
const fs$1 = require('node:fs');
|
|
16
|
+
const node_url = require('node:url');
|
|
17
17
|
|
|
18
18
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
19
19
|
|
|
@@ -168,7 +168,7 @@ function getPath(id) {
|
|
|
168
168
|
}
|
|
169
169
|
|
|
170
170
|
function getHash(input, length = 8) {
|
|
171
|
-
return
|
|
171
|
+
return node_crypto.createHash("sha256").update(input).digest("hex").slice(0, length);
|
|
172
172
|
}
|
|
173
173
|
|
|
174
174
|
function replaceAsync(string, searchValue, replacer) {
|
|
@@ -300,7 +300,7 @@ async function setupExtraContent(ctx, shouldWatch = false) {
|
|
|
300
300
|
});
|
|
301
301
|
watcher.on("all", (type, file) => {
|
|
302
302
|
if (type === "add" || type === "change") {
|
|
303
|
-
const absolutePath =
|
|
303
|
+
const absolutePath = node_path.resolve(root, file);
|
|
304
304
|
tasks.push(extractFile(absolutePath));
|
|
305
305
|
}
|
|
306
306
|
});
|
|
@@ -395,15 +395,15 @@ function GlobalModeBuildPlugin(ctx) {
|
|
|
395
395
|
},
|
|
396
396
|
async configResolved(config) {
|
|
397
397
|
const distDirs = [
|
|
398
|
-
|
|
398
|
+
node_path.resolve(config.root, config.build.outDir)
|
|
399
399
|
];
|
|
400
400
|
if (config.build.rollupOptions.output) {
|
|
401
401
|
const outputOptions = config.build.rollupOptions.output;
|
|
402
402
|
const outputDirs = Array.isArray(outputOptions) ? outputOptions.map((option) => option.dir).filter(Boolean) : outputOptions.dir ? [outputOptions.dir] : [];
|
|
403
403
|
outputDirs.forEach((dir) => {
|
|
404
404
|
distDirs.push(dir);
|
|
405
|
-
if (!
|
|
406
|
-
distDirs.push(
|
|
405
|
+
if (!node_path.isAbsolute(dir))
|
|
406
|
+
distDirs.push(node_path.resolve(config.root, dir));
|
|
407
407
|
});
|
|
408
408
|
}
|
|
409
409
|
const cssPostPlugin = config.plugins.find((i) => i.name === "vite:css-post");
|
|
@@ -948,14 +948,15 @@ async function transformSvelteSFC(code, id, uno, options = {}) {
|
|
|
948
948
|
processedMap.add(start);
|
|
949
949
|
s.overwrite(start, start + match[1].length, `${className}={${token}}`);
|
|
950
950
|
}
|
|
951
|
-
const
|
|
951
|
+
const templateCode = code.replace(/<(script|style)[^>]*>[\s\S]*?<\/\1\s*>/g, (match) => Array(match.length).fill(" ").join(""));
|
|
952
|
+
const { matched } = await uno.generate(templateCode, { preflights: false, safelist: false, minify: true });
|
|
952
953
|
for (const token of matched) {
|
|
953
954
|
const match = token.match(core.attributifyRE);
|
|
954
955
|
if (match) {
|
|
955
956
|
const [, name, value] = match;
|
|
956
957
|
if (!value) {
|
|
957
958
|
let start = 0;
|
|
958
|
-
|
|
959
|
+
templateCode.split(/([\s"'`;*]|:\(|\)"|\)\s)/g).forEach((i) => {
|
|
959
960
|
const end = start + i.length;
|
|
960
961
|
if (i === name && !processedMap.has(start)) {
|
|
961
962
|
const className = queueCompiledClass([name]);
|
|
@@ -966,7 +967,7 @@ async function transformSvelteSFC(code, id, uno, options = {}) {
|
|
|
966
967
|
});
|
|
967
968
|
} else {
|
|
968
969
|
const regex = new RegExp(`(${core.escapeRegExp(name)}=)(['"])[^\\2]*?${core.escapeRegExp(value)}[^\\2]*?\\2`, "g");
|
|
969
|
-
for (const match2 of
|
|
970
|
+
for (const match2 of templateCode.matchAll(regex)) {
|
|
970
971
|
const escaped = match2[1];
|
|
971
972
|
const body = match2[0].slice(escaped.length);
|
|
972
973
|
let bodyIndex = body.match(`[\\b\\s'"]${core.escapeRegExp(value)}[\\b\\s'"]`)?.index ?? -1;
|
|
@@ -1181,7 +1182,7 @@ function createTransformerPlugins(ctx) {
|
|
|
1181
1182
|
}));
|
|
1182
1183
|
}
|
|
1183
1184
|
|
|
1184
|
-
const _dirname = typeof __dirname !== "undefined" ? __dirname :
|
|
1185
|
+
const _dirname = typeof __dirname !== "undefined" ? __dirname : node_path.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('index.cjs', document.baseURI).href))));
|
|
1185
1186
|
const DEVTOOLS_MODULE_ID = "virtual:unocss-devtools";
|
|
1186
1187
|
const MOCK_CLASSES_MODULE_ID = "virtual:unocss-mock-classes";
|
|
1187
1188
|
const MOCK_CLASSES_PATH = "/@unocss/mock-classes";
|
|
@@ -1291,7 +1292,7 @@ function createDevtoolsPlugin(ctx) {
|
|
|
1291
1292
|
if (id === DEVTOOLS_PATH) {
|
|
1292
1293
|
if (!clientCode) {
|
|
1293
1294
|
clientCode = [
|
|
1294
|
-
await fs__default$1.promises.readFile(
|
|
1295
|
+
await fs__default$1.promises.readFile(node_path.resolve(_dirname, "client.mjs"), "utf-8"),
|
|
1295
1296
|
`import('${MOCK_CLASSES_MODULE_ID}')`,
|
|
1296
1297
|
`import('${DEVTOOLS_CSS_PATH}')`
|
|
1297
1298
|
].join("\n").replace("__POST_PATH__", (config.server?.origin ?? "") + POST_PATH);
|
package/dist/index.mjs
CHANGED
|
@@ -2,14 +2,14 @@ import UnocssInspector from '@unocss/inspector';
|
|
|
2
2
|
import { cssIdRE, createGenerator, BetterMap, notNull, expandVariantGroup, attributifyRE, escapeRegExp, toEscapedSelector } from '@unocss/core';
|
|
3
3
|
import { createFilter } from '@rollup/pluginutils';
|
|
4
4
|
import { loadConfig } from '@unocss/config';
|
|
5
|
-
import { createHash } from 'crypto';
|
|
5
|
+
import { createHash } from 'node:crypto';
|
|
6
6
|
import MagicString from 'magic-string';
|
|
7
|
-
import { resolve, isAbsolute, dirname } from 'path';
|
|
8
|
-
import fs from 'fs/promises';
|
|
7
|
+
import { resolve, isAbsolute, dirname } from 'node:path';
|
|
8
|
+
import fs from 'node:fs/promises';
|
|
9
9
|
import fg from 'fast-glob';
|
|
10
10
|
import remapping from '@ampproject/remapping';
|
|
11
|
-
import fs$1 from 'fs';
|
|
12
|
-
import { fileURLToPath } from 'url';
|
|
11
|
+
import fs$1 from 'node:fs';
|
|
12
|
+
import { fileURLToPath } from 'node:url';
|
|
13
13
|
|
|
14
14
|
const defaultExclude = [cssIdRE];
|
|
15
15
|
const defaultInclude = [/\.(vue|svelte|[jt]sx|mdx?|astro|elm|php|phtml|html)($|\?)/];
|
|
@@ -935,14 +935,15 @@ async function transformSvelteSFC(code, id, uno, options = {}) {
|
|
|
935
935
|
processedMap.add(start);
|
|
936
936
|
s.overwrite(start, start + match[1].length, `${className}={${token}}`);
|
|
937
937
|
}
|
|
938
|
-
const
|
|
938
|
+
const templateCode = code.replace(/<(script|style)[^>]*>[\s\S]*?<\/\1\s*>/g, (match) => Array(match.length).fill(" ").join(""));
|
|
939
|
+
const { matched } = await uno.generate(templateCode, { preflights: false, safelist: false, minify: true });
|
|
939
940
|
for (const token of matched) {
|
|
940
941
|
const match = token.match(attributifyRE);
|
|
941
942
|
if (match) {
|
|
942
943
|
const [, name, value] = match;
|
|
943
944
|
if (!value) {
|
|
944
945
|
let start = 0;
|
|
945
|
-
|
|
946
|
+
templateCode.split(/([\s"'`;*]|:\(|\)"|\)\s)/g).forEach((i) => {
|
|
946
947
|
const end = start + i.length;
|
|
947
948
|
if (i === name && !processedMap.has(start)) {
|
|
948
949
|
const className = queueCompiledClass([name]);
|
|
@@ -953,7 +954,7 @@ async function transformSvelteSFC(code, id, uno, options = {}) {
|
|
|
953
954
|
});
|
|
954
955
|
} else {
|
|
955
956
|
const regex = new RegExp(`(${escapeRegExp(name)}=)(['"])[^\\2]*?${escapeRegExp(value)}[^\\2]*?\\2`, "g");
|
|
956
|
-
for (const match2 of
|
|
957
|
+
for (const match2 of templateCode.matchAll(regex)) {
|
|
957
958
|
const escaped = match2[1];
|
|
958
959
|
const body = match2[0].slice(escaped.length);
|
|
959
960
|
let bodyIndex = body.match(`[\\b\\s'"]${escapeRegExp(value)}[\\b\\s'"]`)?.index ?? -1;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/vite",
|
|
3
|
-
"version": "0.50.
|
|
3
|
+
"version": "0.50.4",
|
|
4
4
|
"description": "The Vite plugin for UnoCSS",
|
|
5
5
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -44,18 +44,18 @@
|
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@ampproject/remapping": "^2.2.0",
|
|
46
46
|
"@rollup/pluginutils": "^5.0.2",
|
|
47
|
-
"@unocss/config": "0.50.2",
|
|
48
|
-
"@unocss/core": "0.50.2",
|
|
49
|
-
"@unocss/inspector": "0.50.2",
|
|
50
|
-
"@unocss/scope": "0.50.2",
|
|
51
|
-
"@unocss/transformer-directives": "0.50.2",
|
|
52
47
|
"chokidar": "^3.5.3",
|
|
53
48
|
"fast-glob": "^3.2.12",
|
|
54
|
-
"magic-string": "^0.30.0"
|
|
49
|
+
"magic-string": "^0.30.0",
|
|
50
|
+
"@unocss/config": "0.50.4",
|
|
51
|
+
"@unocss/core": "0.50.4",
|
|
52
|
+
"@unocss/inspector": "0.50.4",
|
|
53
|
+
"@unocss/scope": "0.50.4",
|
|
54
|
+
"@unocss/transformer-directives": "0.50.4"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"
|
|
58
|
-
"
|
|
57
|
+
"vite": "^4.1.4",
|
|
58
|
+
"@unocss/shared-integration": "0.50.4"
|
|
59
59
|
},
|
|
60
60
|
"scripts": {
|
|
61
61
|
"build": "unbuild",
|