@unocss/vite 0.46.5 → 0.47.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 +39 -6
- package/dist/index.mjs +39 -6
- package/package.json +9 -9
package/dist/index.cjs
CHANGED
|
@@ -231,13 +231,13 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, filter, getConfig
|
|
|
231
231
|
let viteConfig;
|
|
232
232
|
const cssPostPlugins = /* @__PURE__ */ new Map();
|
|
233
233
|
const cssPlugins = /* @__PURE__ */ new Map();
|
|
234
|
-
async function applyCssTransform(css, id, dir) {
|
|
234
|
+
async function applyCssTransform(css, id, dir, ctx) {
|
|
235
235
|
const {
|
|
236
236
|
postcss = true
|
|
237
237
|
} = await getConfig();
|
|
238
238
|
if (!cssPlugins.get(dir) || !postcss)
|
|
239
239
|
return css;
|
|
240
|
-
const result = await cssPlugins.get(dir).transform(css, id);
|
|
240
|
+
const result = await cssPlugins.get(dir).transform.call(ctx, css, id);
|
|
241
241
|
if (!result)
|
|
242
242
|
return css;
|
|
243
243
|
if (typeof result === "string")
|
|
@@ -320,7 +320,7 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, filter, getConfig
|
|
|
320
320
|
}
|
|
321
321
|
let { css } = await generateAll();
|
|
322
322
|
const fakeCssId = `${chunk.fileName}-unocss-hash.css`;
|
|
323
|
-
css = await applyCssTransform(css, fakeCssId, options.dir);
|
|
323
|
+
css = await applyCssTransform(css, fakeCssId, options.dir, this);
|
|
324
324
|
const hash = getHash(css);
|
|
325
325
|
const transformHandler = "handler" in cssPost.transform ? cssPost.transform.handler : cssPost.transform;
|
|
326
326
|
await transformHandler.call({}, getHashPlaceholder(hash), fakeCssId);
|
|
@@ -337,6 +337,25 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, filter, getConfig
|
|
|
337
337
|
{
|
|
338
338
|
name: "unocss:global:build:generate",
|
|
339
339
|
apply: "build",
|
|
340
|
+
async renderChunk(code, chunk, options) {
|
|
341
|
+
const cssPost = cssPostPlugins.get(options.dir);
|
|
342
|
+
if (!cssPost) {
|
|
343
|
+
this.warn("[unocss] failed to find vite:css-post plugin. It might be an internal bug of UnoCSS");
|
|
344
|
+
return null;
|
|
345
|
+
}
|
|
346
|
+
const result = await generateAll();
|
|
347
|
+
const cssWithLayers = Array.from(vfsLayers).map(
|
|
348
|
+
(layer) => `#--unocss-layer-start--${layer}--{start:${layer}} ${layer === LAYER_MARK_ALL ? result.getLayers(void 0, Array.from(vfsLayers)) : result.getLayer(layer) || ""} #--unocss-layer-end--${layer}--{end:${layer}}`
|
|
349
|
+
).join("");
|
|
350
|
+
const fakeCssId = `${chunk.fileName}-unocss-hash.css`;
|
|
351
|
+
const css = await applyCssTransform(cssWithLayers, fakeCssId, options.dir, this);
|
|
352
|
+
const transformHandler = "handler" in cssPost.transform ? cssPost.transform.handler : cssPost.transform;
|
|
353
|
+
await transformHandler.call({}, css, fakeCssId);
|
|
354
|
+
}
|
|
355
|
+
},
|
|
356
|
+
{
|
|
357
|
+
name: "unocss:global:build:bundle",
|
|
358
|
+
apply: "build",
|
|
340
359
|
configResolved(config) {
|
|
341
360
|
viteConfig = config;
|
|
342
361
|
},
|
|
@@ -351,23 +370,37 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, filter, getConfig
|
|
|
351
370
|
this.warn(msg);
|
|
352
371
|
return;
|
|
353
372
|
}
|
|
354
|
-
const result = await generateAll();
|
|
355
373
|
let replaced = false;
|
|
374
|
+
const getLayer = (layer, input, replace = false) => {
|
|
375
|
+
const re = new RegExp(`#--unocss-layer-start--${layer}--\\{start:${layer}\\}([\\s\\S]*?)#--unocss-layer-end--${layer}--\\{end:${layer}\\}`, "g");
|
|
376
|
+
if (replace)
|
|
377
|
+
return input.replace(re, "");
|
|
378
|
+
const match = re.exec(input);
|
|
379
|
+
if (match)
|
|
380
|
+
return match[1];
|
|
381
|
+
return "";
|
|
382
|
+
};
|
|
356
383
|
for (const file of files) {
|
|
357
384
|
const chunk = bundle[file];
|
|
358
385
|
if (chunk.type === "asset" && typeof chunk.source === "string") {
|
|
359
386
|
const css = chunk.source.replace(HASH_PLACEHOLDER_RE, "");
|
|
360
387
|
chunk.source = await replaceAsync(css, LAYER_PLACEHOLDER_RE, async (_, __, layer) => {
|
|
361
388
|
replaced = true;
|
|
362
|
-
return layer
|
|
389
|
+
return getLayer(layer, css);
|
|
390
|
+
});
|
|
391
|
+
Array.from(vfsLayers).forEach((layer) => {
|
|
392
|
+
chunk.source = getLayer(layer, chunk.source, true);
|
|
363
393
|
});
|
|
364
394
|
} else if (chunk.type === "chunk" && typeof chunk.code === "string") {
|
|
365
395
|
const js = chunk.code.replace(HASH_PLACEHOLDER_RE, "");
|
|
366
396
|
chunk.code = await replaceAsync(js, LAYER_PLACEHOLDER_RE, async (_, __, layer) => {
|
|
367
397
|
replaced = true;
|
|
368
|
-
const css = layer
|
|
398
|
+
const css = getLayer(layer, js);
|
|
369
399
|
return css.replace(/\n/g, "").replace(/(?<!\\)(['"])/g, "\\$1");
|
|
370
400
|
});
|
|
401
|
+
Array.from(vfsLayers).forEach((layer) => {
|
|
402
|
+
chunk.code = getLayer(layer, chunk.code, true);
|
|
403
|
+
});
|
|
371
404
|
}
|
|
372
405
|
}
|
|
373
406
|
if (!replaced) {
|
package/dist/index.mjs
CHANGED
|
@@ -220,13 +220,13 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, filter, getConfig
|
|
|
220
220
|
let viteConfig;
|
|
221
221
|
const cssPostPlugins = /* @__PURE__ */ new Map();
|
|
222
222
|
const cssPlugins = /* @__PURE__ */ new Map();
|
|
223
|
-
async function applyCssTransform(css, id, dir) {
|
|
223
|
+
async function applyCssTransform(css, id, dir, ctx) {
|
|
224
224
|
const {
|
|
225
225
|
postcss = true
|
|
226
226
|
} = await getConfig();
|
|
227
227
|
if (!cssPlugins.get(dir) || !postcss)
|
|
228
228
|
return css;
|
|
229
|
-
const result = await cssPlugins.get(dir).transform(css, id);
|
|
229
|
+
const result = await cssPlugins.get(dir).transform.call(ctx, css, id);
|
|
230
230
|
if (!result)
|
|
231
231
|
return css;
|
|
232
232
|
if (typeof result === "string")
|
|
@@ -309,7 +309,7 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, filter, getConfig
|
|
|
309
309
|
}
|
|
310
310
|
let { css } = await generateAll();
|
|
311
311
|
const fakeCssId = `${chunk.fileName}-unocss-hash.css`;
|
|
312
|
-
css = await applyCssTransform(css, fakeCssId, options.dir);
|
|
312
|
+
css = await applyCssTransform(css, fakeCssId, options.dir, this);
|
|
313
313
|
const hash = getHash(css);
|
|
314
314
|
const transformHandler = "handler" in cssPost.transform ? cssPost.transform.handler : cssPost.transform;
|
|
315
315
|
await transformHandler.call({}, getHashPlaceholder(hash), fakeCssId);
|
|
@@ -326,6 +326,25 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, filter, getConfig
|
|
|
326
326
|
{
|
|
327
327
|
name: "unocss:global:build:generate",
|
|
328
328
|
apply: "build",
|
|
329
|
+
async renderChunk(code, chunk, options) {
|
|
330
|
+
const cssPost = cssPostPlugins.get(options.dir);
|
|
331
|
+
if (!cssPost) {
|
|
332
|
+
this.warn("[unocss] failed to find vite:css-post plugin. It might be an internal bug of UnoCSS");
|
|
333
|
+
return null;
|
|
334
|
+
}
|
|
335
|
+
const result = await generateAll();
|
|
336
|
+
const cssWithLayers = Array.from(vfsLayers).map(
|
|
337
|
+
(layer) => `#--unocss-layer-start--${layer}--{start:${layer}} ${layer === LAYER_MARK_ALL ? result.getLayers(void 0, Array.from(vfsLayers)) : result.getLayer(layer) || ""} #--unocss-layer-end--${layer}--{end:${layer}}`
|
|
338
|
+
).join("");
|
|
339
|
+
const fakeCssId = `${chunk.fileName}-unocss-hash.css`;
|
|
340
|
+
const css = await applyCssTransform(cssWithLayers, fakeCssId, options.dir, this);
|
|
341
|
+
const transformHandler = "handler" in cssPost.transform ? cssPost.transform.handler : cssPost.transform;
|
|
342
|
+
await transformHandler.call({}, css, fakeCssId);
|
|
343
|
+
}
|
|
344
|
+
},
|
|
345
|
+
{
|
|
346
|
+
name: "unocss:global:build:bundle",
|
|
347
|
+
apply: "build",
|
|
329
348
|
configResolved(config) {
|
|
330
349
|
viteConfig = config;
|
|
331
350
|
},
|
|
@@ -340,23 +359,37 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, filter, getConfig
|
|
|
340
359
|
this.warn(msg);
|
|
341
360
|
return;
|
|
342
361
|
}
|
|
343
|
-
const result = await generateAll();
|
|
344
362
|
let replaced = false;
|
|
363
|
+
const getLayer = (layer, input, replace = false) => {
|
|
364
|
+
const re = new RegExp(`#--unocss-layer-start--${layer}--\\{start:${layer}\\}([\\s\\S]*?)#--unocss-layer-end--${layer}--\\{end:${layer}\\}`, "g");
|
|
365
|
+
if (replace)
|
|
366
|
+
return input.replace(re, "");
|
|
367
|
+
const match = re.exec(input);
|
|
368
|
+
if (match)
|
|
369
|
+
return match[1];
|
|
370
|
+
return "";
|
|
371
|
+
};
|
|
345
372
|
for (const file of files) {
|
|
346
373
|
const chunk = bundle[file];
|
|
347
374
|
if (chunk.type === "asset" && typeof chunk.source === "string") {
|
|
348
375
|
const css = chunk.source.replace(HASH_PLACEHOLDER_RE, "");
|
|
349
376
|
chunk.source = await replaceAsync(css, LAYER_PLACEHOLDER_RE, async (_, __, layer) => {
|
|
350
377
|
replaced = true;
|
|
351
|
-
return layer
|
|
378
|
+
return getLayer(layer, css);
|
|
379
|
+
});
|
|
380
|
+
Array.from(vfsLayers).forEach((layer) => {
|
|
381
|
+
chunk.source = getLayer(layer, chunk.source, true);
|
|
352
382
|
});
|
|
353
383
|
} else if (chunk.type === "chunk" && typeof chunk.code === "string") {
|
|
354
384
|
const js = chunk.code.replace(HASH_PLACEHOLDER_RE, "");
|
|
355
385
|
chunk.code = await replaceAsync(js, LAYER_PLACEHOLDER_RE, async (_, __, layer) => {
|
|
356
386
|
replaced = true;
|
|
357
|
-
const css = layer
|
|
387
|
+
const css = getLayer(layer, js);
|
|
358
388
|
return css.replace(/\n/g, "").replace(/(?<!\\)(['"])/g, "\\$1");
|
|
359
389
|
});
|
|
390
|
+
Array.from(vfsLayers).forEach((layer) => {
|
|
391
|
+
chunk.code = getLayer(layer, chunk.code, true);
|
|
392
|
+
});
|
|
360
393
|
}
|
|
361
394
|
}
|
|
362
395
|
if (!replaced) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/vite",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.47.1",
|
|
4
4
|
"description": "The Vite plugin for UnoCSS",
|
|
5
5
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,17 +43,17 @@
|
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@ampproject/remapping": "^2.2.0",
|
|
46
|
-
"@rollup/pluginutils": "^5.0.
|
|
47
|
-
"@unocss/config": "0.
|
|
48
|
-
"@unocss/core": "0.
|
|
49
|
-
"@unocss/inspector": "0.
|
|
50
|
-
"@unocss/scope": "0.
|
|
51
|
-
"@unocss/transformer-directives": "0.
|
|
46
|
+
"@rollup/pluginutils": "^5.0.2",
|
|
47
|
+
"@unocss/config": "0.47.1",
|
|
48
|
+
"@unocss/core": "0.47.1",
|
|
49
|
+
"@unocss/inspector": "0.47.1",
|
|
50
|
+
"@unocss/scope": "0.47.1",
|
|
51
|
+
"@unocss/transformer-directives": "0.47.1",
|
|
52
52
|
"magic-string": "^0.26.7"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@unocss/shared-integration": "0.
|
|
56
|
-
"vite": "^3.
|
|
55
|
+
"@unocss/shared-integration": "0.47.1",
|
|
56
|
+
"vite": "^3.2.4"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|
|
59
59
|
"build": "unbuild",
|