@unocss/vite 0.48.3 → 0.48.5

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/README.md CHANGED
@@ -10,11 +10,11 @@ npm i -D unocss
10
10
 
11
11
  ```ts
12
12
  // vite.config.ts
13
- import Unocss from 'unocss/vite'
13
+ import UnoCSS from 'unocss/vite'
14
14
 
15
15
  export default {
16
16
  plugins: [
17
- Unocss({ /* options */ }),
17
+ UnoCSS({ /* options */ }),
18
18
  ],
19
19
  }
20
20
  ```
@@ -37,11 +37,11 @@ npm i -D @unocss/vite
37
37
 
38
38
  ```ts
39
39
  // vite.config.ts
40
- import Unocss from '@unocss/vite'
40
+ import UnoCSS from '@unocss/vite'
41
41
 
42
42
  export default {
43
43
  plugins: [
44
- Unocss({
44
+ UnoCSS({
45
45
  presets: [
46
46
  /* no presets by default */
47
47
  ],
@@ -111,12 +111,12 @@ If you're using `@vitejs/plugin-react`:
111
111
  ```ts
112
112
  // vite.config.js
113
113
  import react from '@vitejs/plugin-react'
114
- import Unocss from 'unocss/vite'
114
+ import UnoCSS from 'unocss/vite'
115
115
 
116
116
  export default {
117
117
  plugins: [
118
118
  react(),
119
- Unocss({
119
+ UnoCSS({
120
120
  /* options */
121
121
  }),
122
122
  ],
@@ -128,12 +128,12 @@ or if you're using `@vitejs/plugin-react-refresh`:
128
128
  ```ts
129
129
  // vite.config.js
130
130
  import reactRefresh from '@vitejs/plugin-react-refresh'
131
- import Unocss from 'unocss/vite'
131
+ import UnoCSS from 'unocss/vite'
132
132
 
133
133
  export default {
134
134
  plugins: [
135
135
  reactRefresh(),
136
- Unocss({
136
+ UnoCSS({
137
137
  /* options */
138
138
  }),
139
139
  ],
@@ -147,11 +147,11 @@ If you are using `@vitejs/plugin-react` with `@unocss/preset-attributify`, you m
147
147
  ```ts
148
148
  // vite.config.js
149
149
  import react from '@vitejs/plugin-react'
150
- import Unocss from 'unocss/vite'
150
+ import UnoCSS from 'unocss/vite'
151
151
 
152
152
  export default {
153
153
  plugins: [
154
- Unocss({
154
+ UnoCSS({
155
155
  /* options */
156
156
  }),
157
157
  react(),
@@ -168,12 +168,12 @@ If you're using `@preact/preset-vite`:
168
168
  ```ts
169
169
  // vite.config.js
170
170
  import preact from '@preact/preset-vite'
171
- import Unocss from 'unocss/vite'
171
+ import UnoCSS from 'unocss/vite'
172
172
 
173
173
  export default {
174
174
  plugins: [
175
175
  preact(),
176
- Unocss({
176
+ UnoCSS({
177
177
  /* options */
178
178
  }),
179
179
  ],
@@ -185,12 +185,12 @@ or if you're using `@prefresh/vite`:
185
185
  ```ts
186
186
  // vite.config.js
187
187
  import prefresh from '@prefresh/vite'
188
- import Unocss from 'unocss/vite'
188
+ import UnoCSS from 'unocss/vite'
189
189
 
190
190
  export default {
191
191
  plugins: [
192
192
  prefresh(),
193
- Unocss({
193
+ UnoCSS({
194
194
  /* options */
195
195
  }),
196
196
  ],
@@ -204,11 +204,11 @@ If you are using `@preact/preset-vite` with `@unocss/preset-attributify`, you mu
204
204
  ```ts
205
205
  // vite.config.js
206
206
  import preact from '@preact/preset-vite'
207
- import Unocss from 'unocss/vite'
207
+ import UnoCSS from 'unocss/vite'
208
208
 
209
209
  export default {
210
210
  plugins: [
211
- Unocss({
211
+ UnoCSS({
212
212
  /* options */
213
213
  }),
214
214
  preact(),
@@ -224,17 +224,17 @@ You must add the plugin before `@sveltejs/vite-plugin-svelte`.
224
224
 
225
225
  To support `class:foo` and `class:foo={bar}` add the plugin and configure `extractorSvelte` on `extractors` option.
226
226
 
227
- You can use simple rules with `class:`, for example `class:bg-red-500={foo}` or using `shorcuts` to include multiples rules, see `src/App.svelte` on linked example project below.
227
+ You can use simple rules with `class:`, for example `class:bg-red-500={foo}` or using `shortcuts` to include multiples rules, see `src/App.svelte` on linked example project below.
228
228
 
229
229
  ```ts
230
230
  // vite.config.js
231
231
  import { svelte } from '@sveltejs/vite-plugin-svelte'
232
- import Unocss from 'unocss/vite'
232
+ import UnoCSS from 'unocss/vite'
233
233
  import { extractorSvelte } from '@unocss/core'
234
234
 
235
235
  export default {
236
236
  plugins: [
237
- Unocss({
237
+ UnoCSS({
238
238
  extractors: [extractorSvelte],
239
239
  /* more options */
240
240
  }),
@@ -312,11 +312,11 @@ Don't forget to remove the import for `uno.css` since the `shadow-dom` mode will
312
312
 
313
313
  ```ts
314
314
  // vite.config.js
315
- import Unocss from 'unocss/vite'
315
+ import UnoCSS from 'unocss/vite'
316
316
 
317
317
  export default {
318
318
  plugins: [
319
- Unocss({
319
+ UnoCSS({
320
320
  mode: 'shadow-dom',
321
321
  /* more options */
322
322
  }),
@@ -363,11 +363,11 @@ The plugin uses `nth-of-type` to avoid collisions with multiple parts in the sam
363
363
 
364
364
  ```ts
365
365
  // vite.config.js
366
- import Unocss from 'unocss/vite'
366
+ import UnoCSS from 'unocss/vite'
367
367
 
368
368
  export default {
369
369
  plugins: [
370
- Unocss({
370
+ UnoCSS({
371
371
  mode: 'shadow-dom',
372
372
  shortcuts: [
373
373
  { 'cool-blue': 'bg-blue-500 text-white' },
@@ -413,12 +413,12 @@ template.innerHTML = `
413
413
  ```ts
414
414
  // vite.config.js
415
415
  import solidPlugin from 'vite-plugin-solid'
416
- import Unocss from 'unocss/vite'
416
+ import UnoCSS from 'unocss/vite'
417
417
 
418
418
  export default {
419
419
  plugins: [
420
420
  solidPlugin(),
421
- Unocss({
421
+ UnoCSS({
422
422
  /* options */
423
423
  }),
424
424
  ],
@@ -435,12 +435,12 @@ You need to add the `vite-plugin-elm` plugin before UnoCSS's plugin.
435
435
  // vite.config.js
436
436
  import { defineConfig } from 'vite'
437
437
  import elmPlugin from 'vite-plugin-elm'
438
- import Unocss from 'unocss/vite'
438
+ import UnoCSS from 'unocss/vite'
439
439
 
440
440
  export default defineConfig({
441
441
  plugins: [
442
442
  elmPlugin(),
443
- Unocss({
443
+ UnoCSS({
444
444
  /* options */
445
445
  }),
446
446
  ],
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
- return `${code}
659
- if (import.meta.hot) {
660
- try { await import.meta.hot.send('${WS_EVENT_PREFIX}', ['${layer}', __vite__css.slice(2,${2 + HASH_LENGTH})]); }
661
- catch (e) { console.warn('[unocss-hmr]', e) }
662
- if (!import.meta.url.includes('?'))
663
- await new Promise(resolve => setTimeout(resolve, 100))
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
- return `${code}
646
- if (import.meta.hot) {
647
- try { await import.meta.hot.send('${WS_EVENT_PREFIX}', ['${layer}', __vite__css.slice(2,${2 + HASH_LENGTH})]); }
648
- catch (e) { console.warn('[unocss-hmr]', e) }
649
- if (!import.meta.url.includes('?'))
650
- await new Promise(resolve => setTimeout(resolve, 100))
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",
3
+ "version": "0.48.5",
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.3",
48
- "@unocss/core": "0.48.3",
49
- "@unocss/inspector": "0.48.3",
50
- "@unocss/scope": "0.48.3",
51
- "@unocss/transformer-directives": "0.48.3",
47
+ "@unocss/config": "0.48.5",
48
+ "@unocss/core": "0.48.5",
49
+ "@unocss/inspector": "0.48.5",
50
+ "@unocss/scope": "0.48.5",
51
+ "@unocss/transformer-directives": "0.48.5",
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.3",
57
+ "@unocss/shared-integration": "0.48.5",
58
58
  "vite": "^4.0.4"
59
59
  },
60
60
  "scripts": {