@unocss/vite 0.45.5 → 0.45.8
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 +19 -13
- package/dist/index.mjs +19 -13
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -222,6 +222,7 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, filter, getConfig
|
|
|
222
222
|
const vfsLayers = /* @__PURE__ */ new Set();
|
|
223
223
|
const layerImporterMap = /* @__PURE__ */ new Map();
|
|
224
224
|
let tasks = [];
|
|
225
|
+
let viteConfig;
|
|
225
226
|
const cssPostPlugins = /* @__PURE__ */ new Map();
|
|
226
227
|
const cssPlugins = /* @__PURE__ */ new Map();
|
|
227
228
|
async function applyCssTransform(css, id, dir) {
|
|
@@ -331,12 +332,14 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, filter, getConfig
|
|
|
331
332
|
apply(options, { command }) {
|
|
332
333
|
return command === "build" && !options.build?.ssr;
|
|
333
334
|
},
|
|
335
|
+
configResolved(config) {
|
|
336
|
+
viteConfig = config;
|
|
337
|
+
},
|
|
334
338
|
enforce: "post",
|
|
335
339
|
async generateBundle(options, bundle) {
|
|
336
|
-
const
|
|
337
|
-
const
|
|
338
|
-
|
|
339
|
-
if (!cssFiles.length && !jsFiles.length)
|
|
340
|
+
const checkJs = ["umd", "amd", "iife"].includes(options.format);
|
|
341
|
+
const files = Object.keys(bundle).filter((i) => i.endsWith(".css") || checkJs && i.endsWith(".js"));
|
|
342
|
+
if (!files.length)
|
|
340
343
|
return;
|
|
341
344
|
if (!vfsLayers.size) {
|
|
342
345
|
const msg = "[unocss] entry module not found, have you add `import 'uno.css'` in your main entry?";
|
|
@@ -345,18 +348,15 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, filter, getConfig
|
|
|
345
348
|
}
|
|
346
349
|
const result = await generateAll();
|
|
347
350
|
let replaced = false;
|
|
348
|
-
for (const
|
|
351
|
+
for (const file of files) {
|
|
352
|
+
const chunk = bundle[file];
|
|
349
353
|
if (chunk.type === "asset" && typeof chunk.source === "string") {
|
|
350
354
|
const css = chunk.source.replace(HASH_PLACEHOLDER_RE, "");
|
|
351
355
|
chunk.source = await replaceAsync(css, LAYER_PLACEHOLDER_RE, async (_, __, layer) => {
|
|
352
356
|
replaced = true;
|
|
353
|
-
|
|
354
|
-
return await applyCssTransform(css2, `${chunk.fileName}.css`, options.dir);
|
|
357
|
+
return await applyCssTransform(layer === LAYER_MARK_ALL ? result.getLayers(void 0, Array.from(vfsLayers)) : result.getLayer(layer) || "", `${chunk.fileName}.css`, options.dir);
|
|
355
358
|
});
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
for (const [, chunk] of jsFiles) {
|
|
359
|
-
if (chunk.type === "chunk" && typeof chunk.code === "string") {
|
|
359
|
+
} else if (chunk.type === "chunk" && typeof chunk.code === "string") {
|
|
360
360
|
const js = chunk.code.replace(HASH_PLACEHOLDER_RE, "");
|
|
361
361
|
chunk.code = await replaceAsync(js, LAYER_PLACEHOLDER_RE, async (_, __, layer) => {
|
|
362
362
|
replaced = true;
|
|
@@ -365,8 +365,14 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, filter, getConfig
|
|
|
365
365
|
});
|
|
366
366
|
}
|
|
367
367
|
}
|
|
368
|
-
if (!replaced)
|
|
369
|
-
|
|
368
|
+
if (!replaced) {
|
|
369
|
+
let msg = "[unocss] does not found CSS placeholder in the generated chunks";
|
|
370
|
+
if (viteConfig.build.lib && checkJs)
|
|
371
|
+
msg += "\nIt seems you are building in library mode, it's recommanded to set `build.cssCodeSplit` to true.\nSee https://github.com/vitejs/vite/issues/1579";
|
|
372
|
+
else
|
|
373
|
+
msg += "\nThis is likely an internal bug of unocss vite plugin";
|
|
374
|
+
this.error(new Error(msg));
|
|
375
|
+
}
|
|
370
376
|
}
|
|
371
377
|
}
|
|
372
378
|
];
|
package/dist/index.mjs
CHANGED
|
@@ -211,6 +211,7 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, filter, getConfig
|
|
|
211
211
|
const vfsLayers = /* @__PURE__ */ new Set();
|
|
212
212
|
const layerImporterMap = /* @__PURE__ */ new Map();
|
|
213
213
|
let tasks = [];
|
|
214
|
+
let viteConfig;
|
|
214
215
|
const cssPostPlugins = /* @__PURE__ */ new Map();
|
|
215
216
|
const cssPlugins = /* @__PURE__ */ new Map();
|
|
216
217
|
async function applyCssTransform(css, id, dir) {
|
|
@@ -320,12 +321,14 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, filter, getConfig
|
|
|
320
321
|
apply(options, { command }) {
|
|
321
322
|
return command === "build" && !options.build?.ssr;
|
|
322
323
|
},
|
|
324
|
+
configResolved(config) {
|
|
325
|
+
viteConfig = config;
|
|
326
|
+
},
|
|
323
327
|
enforce: "post",
|
|
324
328
|
async generateBundle(options, bundle) {
|
|
325
|
-
const
|
|
326
|
-
const
|
|
327
|
-
|
|
328
|
-
if (!cssFiles.length && !jsFiles.length)
|
|
329
|
+
const checkJs = ["umd", "amd", "iife"].includes(options.format);
|
|
330
|
+
const files = Object.keys(bundle).filter((i) => i.endsWith(".css") || checkJs && i.endsWith(".js"));
|
|
331
|
+
if (!files.length)
|
|
329
332
|
return;
|
|
330
333
|
if (!vfsLayers.size) {
|
|
331
334
|
const msg = "[unocss] entry module not found, have you add `import 'uno.css'` in your main entry?";
|
|
@@ -334,18 +337,15 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, filter, getConfig
|
|
|
334
337
|
}
|
|
335
338
|
const result = await generateAll();
|
|
336
339
|
let replaced = false;
|
|
337
|
-
for (const
|
|
340
|
+
for (const file of files) {
|
|
341
|
+
const chunk = bundle[file];
|
|
338
342
|
if (chunk.type === "asset" && typeof chunk.source === "string") {
|
|
339
343
|
const css = chunk.source.replace(HASH_PLACEHOLDER_RE, "");
|
|
340
344
|
chunk.source = await replaceAsync(css, LAYER_PLACEHOLDER_RE, async (_, __, layer) => {
|
|
341
345
|
replaced = true;
|
|
342
|
-
|
|
343
|
-
return await applyCssTransform(css2, `${chunk.fileName}.css`, options.dir);
|
|
346
|
+
return await applyCssTransform(layer === LAYER_MARK_ALL ? result.getLayers(void 0, Array.from(vfsLayers)) : result.getLayer(layer) || "", `${chunk.fileName}.css`, options.dir);
|
|
344
347
|
});
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
for (const [, chunk] of jsFiles) {
|
|
348
|
-
if (chunk.type === "chunk" && typeof chunk.code === "string") {
|
|
348
|
+
} else if (chunk.type === "chunk" && typeof chunk.code === "string") {
|
|
349
349
|
const js = chunk.code.replace(HASH_PLACEHOLDER_RE, "");
|
|
350
350
|
chunk.code = await replaceAsync(js, LAYER_PLACEHOLDER_RE, async (_, __, layer) => {
|
|
351
351
|
replaced = true;
|
|
@@ -354,8 +354,14 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, filter, getConfig
|
|
|
354
354
|
});
|
|
355
355
|
}
|
|
356
356
|
}
|
|
357
|
-
if (!replaced)
|
|
358
|
-
|
|
357
|
+
if (!replaced) {
|
|
358
|
+
let msg = "[unocss] does not found CSS placeholder in the generated chunks";
|
|
359
|
+
if (viteConfig.build.lib && checkJs)
|
|
360
|
+
msg += "\nIt seems you are building in library mode, it's recommanded to set `build.cssCodeSplit` to true.\nSee https://github.com/vitejs/vite/issues/1579";
|
|
361
|
+
else
|
|
362
|
+
msg += "\nThis is likely an internal bug of unocss vite plugin";
|
|
363
|
+
this.error(new Error(msg));
|
|
364
|
+
}
|
|
359
365
|
}
|
|
360
366
|
}
|
|
361
367
|
];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/vite",
|
|
3
|
-
"version": "0.45.
|
|
3
|
+
"version": "0.45.8",
|
|
4
4
|
"description": "The Vite plugin for UnoCSS",
|
|
5
5
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -44,15 +44,15 @@
|
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@ampproject/remapping": "^2.2.0",
|
|
46
46
|
"@rollup/pluginutils": "^4.2.1",
|
|
47
|
-
"@unocss/config": "0.45.
|
|
48
|
-
"@unocss/core": "0.45.
|
|
49
|
-
"@unocss/inspector": "0.45.
|
|
50
|
-
"@unocss/scope": "0.45.
|
|
51
|
-
"@unocss/transformer-directives": "0.45.
|
|
47
|
+
"@unocss/config": "0.45.8",
|
|
48
|
+
"@unocss/core": "0.45.8",
|
|
49
|
+
"@unocss/inspector": "0.45.8",
|
|
50
|
+
"@unocss/scope": "0.45.8",
|
|
51
|
+
"@unocss/transformer-directives": "0.45.8",
|
|
52
52
|
"magic-string": "^0.26.2"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"@unocss/shared-integration": "0.45.
|
|
55
|
+
"@unocss/shared-integration": "0.45.8",
|
|
56
56
|
"vite": "^3.0.4"
|
|
57
57
|
},
|
|
58
58
|
"scripts": {
|