@unocss/vite 0.32.0 → 0.32.1
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 +23 -3
- package/dist/index.mjs +23 -3
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -125,6 +125,26 @@ function getHash(input, length = 8) {
|
|
|
125
125
|
function getPath(id) {
|
|
126
126
|
return id.replace(/\?.*$/, "");
|
|
127
127
|
}
|
|
128
|
+
function replaceAsync(string, searchValue, replacer) {
|
|
129
|
+
try {
|
|
130
|
+
if (typeof replacer === "function") {
|
|
131
|
+
const values = [];
|
|
132
|
+
String.prototype.replace.call(string, searchValue, (...args) => {
|
|
133
|
+
values.push(replacer(...args));
|
|
134
|
+
return "";
|
|
135
|
+
});
|
|
136
|
+
return Promise.all(values).then((resolvedValues) => {
|
|
137
|
+
return String.prototype.replace.call(string, searchValue, () => {
|
|
138
|
+
return resolvedValues.shift() || "";
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
} else {
|
|
142
|
+
return Promise.resolve(String.prototype.replace.call(string, searchValue, replacer));
|
|
143
|
+
}
|
|
144
|
+
} catch (error) {
|
|
145
|
+
return Promise.reject(error);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
128
148
|
|
|
129
149
|
function ChunkModeBuildPlugin({ uno, filter }) {
|
|
130
150
|
let cssPlugin;
|
|
@@ -268,11 +288,11 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, filter, g
|
|
|
268
288
|
for (const file of cssFiles) {
|
|
269
289
|
const chunk = bundle[file];
|
|
270
290
|
if (chunk.type === "asset" && typeof chunk.source === "string") {
|
|
271
|
-
const css = chunk.source.replace(HASH_PLACEHOLDER_RE, "")
|
|
291
|
+
const css = chunk.source.replace(HASH_PLACEHOLDER_RE, "");
|
|
292
|
+
chunk.source = await replaceAsync(css, LAYER_PLACEHOLDER_RE, async (_2, __, layer) => {
|
|
272
293
|
replaced = true;
|
|
273
|
-
return layer === LAYER_MARK_ALL ? result.getLayers(void 0, Array.from(vfsLayerMap.values())) : result.getLayer(layer) || "";
|
|
294
|
+
return await transformCSS(layer === LAYER_MARK_ALL ? result.getLayers(void 0, Array.from(vfsLayerMap.values())) : result.getLayer(layer) || "", `${chunk.fileName}.css`);
|
|
274
295
|
});
|
|
275
|
-
chunk.source = await transformCSS(css, `${chunk.fileName}.css`);
|
|
276
296
|
}
|
|
277
297
|
}
|
|
278
298
|
if (!replaced)
|
package/dist/index.mjs
CHANGED
|
@@ -115,6 +115,26 @@ function getHash(input, length = 8) {
|
|
|
115
115
|
function getPath(id) {
|
|
116
116
|
return id.replace(/\?.*$/, "");
|
|
117
117
|
}
|
|
118
|
+
function replaceAsync(string, searchValue, replacer) {
|
|
119
|
+
try {
|
|
120
|
+
if (typeof replacer === "function") {
|
|
121
|
+
const values = [];
|
|
122
|
+
String.prototype.replace.call(string, searchValue, (...args) => {
|
|
123
|
+
values.push(replacer(...args));
|
|
124
|
+
return "";
|
|
125
|
+
});
|
|
126
|
+
return Promise.all(values).then((resolvedValues) => {
|
|
127
|
+
return String.prototype.replace.call(string, searchValue, () => {
|
|
128
|
+
return resolvedValues.shift() || "";
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
} else {
|
|
132
|
+
return Promise.resolve(String.prototype.replace.call(string, searchValue, replacer));
|
|
133
|
+
}
|
|
134
|
+
} catch (error) {
|
|
135
|
+
return Promise.reject(error);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
118
138
|
|
|
119
139
|
function ChunkModeBuildPlugin({ uno, filter }) {
|
|
120
140
|
let cssPlugin;
|
|
@@ -258,11 +278,11 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, modules, filter, g
|
|
|
258
278
|
for (const file of cssFiles) {
|
|
259
279
|
const chunk = bundle[file];
|
|
260
280
|
if (chunk.type === "asset" && typeof chunk.source === "string") {
|
|
261
|
-
const css = chunk.source.replace(HASH_PLACEHOLDER_RE, "")
|
|
281
|
+
const css = chunk.source.replace(HASH_PLACEHOLDER_RE, "");
|
|
282
|
+
chunk.source = await replaceAsync(css, LAYER_PLACEHOLDER_RE, async (_2, __, layer) => {
|
|
262
283
|
replaced = true;
|
|
263
|
-
return layer === LAYER_MARK_ALL ? result.getLayers(void 0, Array.from(vfsLayerMap.values())) : result.getLayer(layer) || "";
|
|
284
|
+
return await transformCSS(layer === LAYER_MARK_ALL ? result.getLayers(void 0, Array.from(vfsLayerMap.values())) : result.getLayer(layer) || "", `${chunk.fileName}.css`);
|
|
264
285
|
});
|
|
265
|
-
chunk.source = await transformCSS(css, `${chunk.fileName}.css`);
|
|
266
286
|
}
|
|
267
287
|
}
|
|
268
288
|
if (!replaced)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/vite",
|
|
3
|
-
"version": "0.32.
|
|
3
|
+
"version": "0.32.1",
|
|
4
4
|
"description": "The Vite plugin for UnoCSS",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"unocss",
|
|
@@ -43,11 +43,11 @@
|
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@rollup/pluginutils": "^4.2.1",
|
|
46
|
-
"@unocss/config": "0.32.
|
|
47
|
-
"@unocss/core": "0.32.
|
|
48
|
-
"@unocss/inspector": "0.32.
|
|
49
|
-
"@unocss/scope": "0.32.
|
|
50
|
-
"@unocss/transformer-directives": "0.32.
|
|
46
|
+
"@unocss/config": "0.32.1",
|
|
47
|
+
"@unocss/core": "0.32.1",
|
|
48
|
+
"@unocss/inspector": "0.32.1",
|
|
49
|
+
"@unocss/scope": "0.32.1",
|
|
50
|
+
"@unocss/transformer-directives": "0.32.1",
|
|
51
51
|
"magic-string": "^0.26.1"
|
|
52
52
|
},
|
|
53
53
|
"devDependencies": {
|