@unocss/vite 0.48.2 → 0.48.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 +17 -9
- package/dist/index.d.ts +13 -2
- package/dist/index.mjs +17 -9
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -516,7 +516,7 @@ function GlobalModeBuildPlugin(ctx) {
|
|
|
516
516
|
const WARN_TIMEOUT = 2e4;
|
|
517
517
|
const WS_EVENT_PREFIX = "unocss:hmr";
|
|
518
518
|
const HASH_LENGTH = 6;
|
|
519
|
-
function GlobalModeDevPlugin({ uno, tokens, tasks, flushTasks, affectedModules, onInvalidate, extract, filter }) {
|
|
519
|
+
function GlobalModeDevPlugin({ uno, tokens, tasks, flushTasks, affectedModules, onInvalidate, extract, filter, getConfig }) {
|
|
520
520
|
const servers = [];
|
|
521
521
|
let base = "";
|
|
522
522
|
const entries = /* @__PURE__ */ new Set();
|
|
@@ -652,16 +652,24 @@ function GlobalModeDevPlugin({ uno, tokens, tasks, flushTasks, affectedModules,
|
|
|
652
652
|
return env.command === "serve" && !config.build?.ssr;
|
|
653
653
|
},
|
|
654
654
|
enforce: "post",
|
|
655
|
-
transform(code, id) {
|
|
655
|
+
async transform(code, id) {
|
|
656
656
|
const layer = resolveLayer(getPath(id));
|
|
657
657
|
if (layer && code.includes("import.meta.hot")) {
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
658
|
+
let hmr = `
|
|
659
|
+
try {
|
|
660
|
+
await import.meta.hot.send('${WS_EVENT_PREFIX}', ['${layer}', __vite__css.slice(2,${2 + HASH_LENGTH})]);
|
|
661
|
+
} catch (e) {
|
|
662
|
+
console.warn('[unocss-hmr]', e)
|
|
663
|
+
}
|
|
664
|
+
if (!import.meta.url.includes('?'))
|
|
665
|
+
await new Promise(resolve => setTimeout(resolve, 100))`;
|
|
666
|
+
const config = await getConfig();
|
|
667
|
+
if (config.hmrTopLevelAwait === false)
|
|
668
|
+
hmr = `;(async function() {${hmr}
|
|
669
|
+
})()`;
|
|
670
|
+
hmr = `
|
|
671
|
+
if (import.meta.hot) {${hmr}}`;
|
|
672
|
+
return code + hmr;
|
|
665
673
|
}
|
|
666
674
|
}
|
|
667
675
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -30,16 +30,27 @@ interface VitePluginConfig<Theme extends {} = {}> extends UserConfig<Theme> {
|
|
|
30
30
|
*/
|
|
31
31
|
transformCSS?: boolean | 'pre' | 'post';
|
|
32
32
|
/**
|
|
33
|
+
* Make the generated css processed by postcss (https://vitejs.dev/guide/features.html#postcss)
|
|
33
34
|
*
|
|
34
|
-
* make the generated css processed by postcss (https://vitejs.dev/guide/features.html#postcss)
|
|
35
35
|
* @default true
|
|
36
36
|
*/
|
|
37
37
|
postcss?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Use top level await in HMR code to avoid FOUC on dev time.
|
|
40
|
+
*
|
|
41
|
+
* You usually don't need to disable this, unless you are developing on
|
|
42
|
+
* a browser that does not support top level await.
|
|
43
|
+
*
|
|
44
|
+
* This will only affect on dev time.
|
|
45
|
+
*
|
|
46
|
+
* @default true
|
|
47
|
+
*/
|
|
48
|
+
hmrTopLevelAwait?: boolean;
|
|
38
49
|
}
|
|
39
50
|
|
|
40
51
|
declare function ChunkModeBuildPlugin({ uno, filter }: UnocssPluginContext): Plugin;
|
|
41
52
|
|
|
42
|
-
declare function GlobalModeDevPlugin({ uno, tokens, tasks, flushTasks, affectedModules, onInvalidate, extract, filter }: UnocssPluginContext): Plugin[];
|
|
53
|
+
declare function GlobalModeDevPlugin({ uno, tokens, tasks, flushTasks, affectedModules, onInvalidate, extract, filter, getConfig }: UnocssPluginContext): Plugin[];
|
|
43
54
|
|
|
44
55
|
declare function GlobalModeBuildPlugin(ctx: UnocssPluginContext<VitePluginConfig>): Plugin[];
|
|
45
56
|
|
package/dist/index.mjs
CHANGED
|
@@ -503,7 +503,7 @@ function GlobalModeBuildPlugin(ctx) {
|
|
|
503
503
|
const WARN_TIMEOUT = 2e4;
|
|
504
504
|
const WS_EVENT_PREFIX = "unocss:hmr";
|
|
505
505
|
const HASH_LENGTH = 6;
|
|
506
|
-
function GlobalModeDevPlugin({ uno, tokens, tasks, flushTasks, affectedModules, onInvalidate, extract, filter }) {
|
|
506
|
+
function GlobalModeDevPlugin({ uno, tokens, tasks, flushTasks, affectedModules, onInvalidate, extract, filter, getConfig }) {
|
|
507
507
|
const servers = [];
|
|
508
508
|
let base = "";
|
|
509
509
|
const entries = /* @__PURE__ */ new Set();
|
|
@@ -639,16 +639,24 @@ function GlobalModeDevPlugin({ uno, tokens, tasks, flushTasks, affectedModules,
|
|
|
639
639
|
return env.command === "serve" && !config.build?.ssr;
|
|
640
640
|
},
|
|
641
641
|
enforce: "post",
|
|
642
|
-
transform(code, id) {
|
|
642
|
+
async transform(code, id) {
|
|
643
643
|
const layer = resolveLayer(getPath(id));
|
|
644
644
|
if (layer && code.includes("import.meta.hot")) {
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
645
|
+
let hmr = `
|
|
646
|
+
try {
|
|
647
|
+
await import.meta.hot.send('${WS_EVENT_PREFIX}', ['${layer}', __vite__css.slice(2,${2 + HASH_LENGTH})]);
|
|
648
|
+
} catch (e) {
|
|
649
|
+
console.warn('[unocss-hmr]', e)
|
|
650
|
+
}
|
|
651
|
+
if (!import.meta.url.includes('?'))
|
|
652
|
+
await new Promise(resolve => setTimeout(resolve, 100))`;
|
|
653
|
+
const config = await getConfig();
|
|
654
|
+
if (config.hmrTopLevelAwait === false)
|
|
655
|
+
hmr = `;(async function() {${hmr}
|
|
656
|
+
})()`;
|
|
657
|
+
hmr = `
|
|
658
|
+
if (import.meta.hot) {${hmr}}`;
|
|
659
|
+
return code + hmr;
|
|
652
660
|
}
|
|
653
661
|
}
|
|
654
662
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unocss/vite",
|
|
3
|
-
"version": "0.48.
|
|
3
|
+
"version": "0.48.4",
|
|
4
4
|
"description": "The Vite plugin for UnoCSS",
|
|
5
5
|
"author": "Anthony Fu <anthonyfu117@hotmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -44,17 +44,17 @@
|
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"@ampproject/remapping": "^2.2.0",
|
|
46
46
|
"@rollup/pluginutils": "^5.0.2",
|
|
47
|
-
"@unocss/config": "0.48.
|
|
48
|
-
"@unocss/core": "0.48.
|
|
49
|
-
"@unocss/inspector": "0.48.
|
|
50
|
-
"@unocss/scope": "0.48.
|
|
51
|
-
"@unocss/transformer-directives": "0.48.
|
|
47
|
+
"@unocss/config": "0.48.4",
|
|
48
|
+
"@unocss/core": "0.48.4",
|
|
49
|
+
"@unocss/inspector": "0.48.4",
|
|
50
|
+
"@unocss/scope": "0.48.4",
|
|
51
|
+
"@unocss/transformer-directives": "0.48.4",
|
|
52
52
|
"chokidar": "^3.5.3",
|
|
53
53
|
"fast-glob": "^3.2.12",
|
|
54
54
|
"magic-string": "^0.27.0"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@unocss/shared-integration": "0.48.
|
|
57
|
+
"@unocss/shared-integration": "0.48.4",
|
|
58
58
|
"vite": "^4.0.4"
|
|
59
59
|
},
|
|
60
60
|
"scripts": {
|