@unocss/vite 0.44.0 → 0.44.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/README.md CHANGED
@@ -251,26 +251,20 @@ To support `class:foo` and `class:foo={bar}` add the plugin and configure `extra
251
251
  You can use simple rules with `class:`, for example `class:bg-red-500={foo}` or using `shorcuts` to include multiples rules, see `src/routes/__layout.svelte` on linked example project below.
252
252
 
253
253
  ```ts
254
- // svelte.config.js
255
- import preprocess from 'svelte-preprocess'
254
+ // vite.config.js
255
+ import { sveltekit } from '@sveltejs/kit/vite'
256
256
  import UnoCss from 'unocss/vite'
257
257
  import { extractorSvelte } from '@unocss/core'
258
258
 
259
- /** @type {import('@sveltejs/kit').Config} */
259
+ /** @type {import('vite').UserConfig} */
260
260
  const config = {
261
- // Consult https://github.com/sveltejs/svelte-preprocess
262
- // for more information about preprocessors
263
- preprocess: preprocess(),
264
- kit: {
265
- vite: {
266
- plugins: [
267
- UnoCss({
268
- extractors: [extractorSvelte],
269
- /* more options */
270
- }),
271
- ],
272
- },
273
- },
261
+ plugins: [
262
+ sveltekit(),
263
+ UnoCss({
264
+ extractors: [extractorSvelte],
265
+ /* more options */
266
+ }),
267
+ ],
274
268
  }
275
269
  ```
276
270
 
package/dist/index.cjs CHANGED
@@ -354,7 +354,7 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, filter, getConfig
354
354
  chunk.code = await replaceAsync(js, LAYER_PLACEHOLDER_RE, async (_, __, layer) => {
355
355
  replaced = true;
356
356
  const css = layer === LAYER_MARK_ALL ? result.getLayers(void 0, Array.from(vfsLayers)) : result.getLayer(layer) || "";
357
- return css;
357
+ return css.replace(/\n/g, "").replace(/(?<!\\)(['"])/g, "\\$1");
358
358
  });
359
359
  }
360
360
  }
@@ -528,44 +528,67 @@ function PerModuleModePlugin({ uno, filter }) {
528
528
  }]
529
529
  });
530
530
  };
531
- return {
532
- name: "unocss:module-scope",
533
- enforce: "post",
534
- configureServer(_server) {
535
- server = _server;
536
- },
537
- async transform(code, id) {
538
- if (!filter(code, id))
539
- return;
540
- const hash = getHash(id);
541
- const hasScope = code.match(SCOPE_IMPORT_RE);
542
- const { css } = await uno.generate(code, { id, scope: hasScope ? `.${hash}` : void 0, preflights: false });
543
- if (!css && !hasScope)
544
- return null;
545
- if (hasScope)
546
- code = code.replace(SCOPE_IMPORT_RE, ` from 'data:text/javascript;base64,${Buffer.from(`export default () => "${hash}"`).toString("base64")}'`);
547
- moduleMap.set(hash, [id, css]);
548
- invalidate(hash);
549
- return {
550
- code: `import "${VIRTUAL_PREFIX}${hash}.css";${code}`,
551
- map: null
552
- };
553
- },
554
- resolveId(id) {
555
- return id.startsWith(VIRTUAL_PREFIX) ? id : null;
531
+ return [
532
+ {
533
+ name: "unocss:module-scope:pre",
534
+ enforce: "pre",
535
+ async transform(code, id) {
536
+ if (!filter(code, id))
537
+ return;
538
+ const hash = getHash(id);
539
+ const { css } = await uno.generate(code, {
540
+ id,
541
+ preflights: true
542
+ });
543
+ if (!css)
544
+ return null;
545
+ moduleMap.set(hash, [id, css]);
546
+ invalidate(hash);
547
+ return {
548
+ code: `import "${VIRTUAL_PREFIX}${hash}.css";${code}`,
549
+ map: null
550
+ };
551
+ }
556
552
  },
557
- load(id) {
558
- if (!id.startsWith(VIRTUAL_PREFIX))
559
- return null;
560
- const hash = id.slice(VIRTUAL_PREFIX.length, -".css".length);
561
- const [source, css] = moduleMap.get(hash) || [];
562
- if (source)
563
- this.addWatchFile(source);
564
- return `
553
+ {
554
+ name: "unocss:module-scope",
555
+ enforce: "post",
556
+ configureServer(_server) {
557
+ server = _server;
558
+ },
559
+ async transform(code, id) {
560
+ if (!filter(code, id))
561
+ return;
562
+ const hash = getHash(id);
563
+ const hasScope = code.match(SCOPE_IMPORT_RE);
564
+ const { css } = await uno.generate(code, { id, scope: hasScope ? `.${hash}` : void 0, preflights: false });
565
+ if (!css && !hasScope)
566
+ return null;
567
+ if (hasScope)
568
+ code = code.replace(SCOPE_IMPORT_RE, ` from 'data:text/javascript;base64,${Buffer.from(`export default () => "${hash}"`).toString("base64")}'`);
569
+ moduleMap.set(hash, [id, css]);
570
+ invalidate(hash);
571
+ return {
572
+ code: `import "${VIRTUAL_PREFIX}${hash}.css";${code}`,
573
+ map: null
574
+ };
575
+ },
576
+ resolveId(id) {
577
+ return id.startsWith(VIRTUAL_PREFIX) ? id : null;
578
+ },
579
+ load(id) {
580
+ if (!id.startsWith(VIRTUAL_PREFIX))
581
+ return null;
582
+ const hash = id.slice(VIRTUAL_PREFIX.length, -".css".length);
583
+ const [source, css] = moduleMap.get(hash) || [];
584
+ if (source)
585
+ this.addWatchFile(source);
586
+ return `
565
587
  /* unocss ${source} */
566
588
  ${css}`;
589
+ }
567
590
  }
568
- };
591
+ ];
569
592
  }
570
593
 
571
594
  function VueScopedPlugin({ uno, ready }) {
@@ -956,7 +979,7 @@ function UnocssPlugin(configOrPath, defaults = {}) {
956
979
  if (inlineConfig.inspector !== false)
957
980
  plugins.push(UnocssInspector__default(ctx));
958
981
  if (mode === "per-module") {
959
- plugins.push(PerModuleModePlugin(ctx));
982
+ plugins.push(...PerModuleModePlugin(ctx));
960
983
  } else if (mode === "vue-scoped") {
961
984
  plugins.push(VueScopedPlugin(ctx));
962
985
  } else if (mode === "svelte-scoped") {
package/dist/index.d.ts CHANGED
@@ -45,7 +45,7 @@ declare function GlobalModeBuildPlugin({ uno, ready, extract, tokens, filter, ge
45
45
 
46
46
  declare function GlobalModePlugin(ctx: UnocssPluginContext): vite.Plugin[];
47
47
 
48
- declare function PerModuleModePlugin({ uno, filter }: UnocssPluginContext): Plugin;
48
+ declare function PerModuleModePlugin({ uno, filter }: UnocssPluginContext): Plugin[];
49
49
 
50
50
  declare function VueScopedPlugin({ uno, ready }: UnocssPluginContext): Plugin;
51
51
 
package/dist/index.mjs CHANGED
@@ -344,7 +344,7 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, filter, getConfig
344
344
  chunk.code = await replaceAsync(js, LAYER_PLACEHOLDER_RE, async (_, __, layer) => {
345
345
  replaced = true;
346
346
  const css = layer === LAYER_MARK_ALL ? result.getLayers(void 0, Array.from(vfsLayers)) : result.getLayer(layer) || "";
347
- return css;
347
+ return css.replace(/\n/g, "").replace(/(?<!\\)(['"])/g, "\\$1");
348
348
  });
349
349
  }
350
350
  }
@@ -518,44 +518,67 @@ function PerModuleModePlugin({ uno, filter }) {
518
518
  }]
519
519
  });
520
520
  };
521
- return {
522
- name: "unocss:module-scope",
523
- enforce: "post",
524
- configureServer(_server) {
525
- server = _server;
526
- },
527
- async transform(code, id) {
528
- if (!filter(code, id))
529
- return;
530
- const hash = getHash(id);
531
- const hasScope = code.match(SCOPE_IMPORT_RE);
532
- const { css } = await uno.generate(code, { id, scope: hasScope ? `.${hash}` : void 0, preflights: false });
533
- if (!css && !hasScope)
534
- return null;
535
- if (hasScope)
536
- code = code.replace(SCOPE_IMPORT_RE, ` from 'data:text/javascript;base64,${Buffer.from(`export default () => "${hash}"`).toString("base64")}'`);
537
- moduleMap.set(hash, [id, css]);
538
- invalidate(hash);
539
- return {
540
- code: `import "${VIRTUAL_PREFIX}${hash}.css";${code}`,
541
- map: null
542
- };
543
- },
544
- resolveId(id) {
545
- return id.startsWith(VIRTUAL_PREFIX) ? id : null;
521
+ return [
522
+ {
523
+ name: "unocss:module-scope:pre",
524
+ enforce: "pre",
525
+ async transform(code, id) {
526
+ if (!filter(code, id))
527
+ return;
528
+ const hash = getHash(id);
529
+ const { css } = await uno.generate(code, {
530
+ id,
531
+ preflights: true
532
+ });
533
+ if (!css)
534
+ return null;
535
+ moduleMap.set(hash, [id, css]);
536
+ invalidate(hash);
537
+ return {
538
+ code: `import "${VIRTUAL_PREFIX}${hash}.css";${code}`,
539
+ map: null
540
+ };
541
+ }
546
542
  },
547
- load(id) {
548
- if (!id.startsWith(VIRTUAL_PREFIX))
549
- return null;
550
- const hash = id.slice(VIRTUAL_PREFIX.length, -".css".length);
551
- const [source, css] = moduleMap.get(hash) || [];
552
- if (source)
553
- this.addWatchFile(source);
554
- return `
543
+ {
544
+ name: "unocss:module-scope",
545
+ enforce: "post",
546
+ configureServer(_server) {
547
+ server = _server;
548
+ },
549
+ async transform(code, id) {
550
+ if (!filter(code, id))
551
+ return;
552
+ const hash = getHash(id);
553
+ const hasScope = code.match(SCOPE_IMPORT_RE);
554
+ const { css } = await uno.generate(code, { id, scope: hasScope ? `.${hash}` : void 0, preflights: false });
555
+ if (!css && !hasScope)
556
+ return null;
557
+ if (hasScope)
558
+ code = code.replace(SCOPE_IMPORT_RE, ` from 'data:text/javascript;base64,${Buffer.from(`export default () => "${hash}"`).toString("base64")}'`);
559
+ moduleMap.set(hash, [id, css]);
560
+ invalidate(hash);
561
+ return {
562
+ code: `import "${VIRTUAL_PREFIX}${hash}.css";${code}`,
563
+ map: null
564
+ };
565
+ },
566
+ resolveId(id) {
567
+ return id.startsWith(VIRTUAL_PREFIX) ? id : null;
568
+ },
569
+ load(id) {
570
+ if (!id.startsWith(VIRTUAL_PREFIX))
571
+ return null;
572
+ const hash = id.slice(VIRTUAL_PREFIX.length, -".css".length);
573
+ const [source, css] = moduleMap.get(hash) || [];
574
+ if (source)
575
+ this.addWatchFile(source);
576
+ return `
555
577
  /* unocss ${source} */
556
578
  ${css}`;
579
+ }
557
580
  }
558
- };
581
+ ];
559
582
  }
560
583
 
561
584
  function VueScopedPlugin({ uno, ready }) {
@@ -946,7 +969,7 @@ function UnocssPlugin(configOrPath, defaults = {}) {
946
969
  if (inlineConfig.inspector !== false)
947
970
  plugins.push(UnocssInspector(ctx));
948
971
  if (mode === "per-module") {
949
- plugins.push(PerModuleModePlugin(ctx));
972
+ plugins.push(...PerModuleModePlugin(ctx));
950
973
  } else if (mode === "vue-scoped") {
951
974
  plugins.push(VueScopedPlugin(ctx));
952
975
  } else if (mode === "svelte-scoped") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/vite",
3
- "version": "0.44.0",
3
+ "version": "0.44.1",
4
4
  "description": "The Vite plugin for UnoCSS",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",
@@ -43,15 +43,15 @@
43
43
  },
44
44
  "dependencies": {
45
45
  "@rollup/pluginutils": "^4.2.1",
46
- "@unocss/config": "0.44.0",
47
- "@unocss/core": "0.44.0",
48
- "@unocss/inspector": "0.44.0",
49
- "@unocss/scope": "0.44.0",
50
- "@unocss/transformer-directives": "0.44.0",
46
+ "@unocss/config": "0.44.1",
47
+ "@unocss/core": "0.44.1",
48
+ "@unocss/inspector": "0.44.1",
49
+ "@unocss/scope": "0.44.1",
50
+ "@unocss/transformer-directives": "0.44.1",
51
51
  "magic-string": "^0.26.2"
52
52
  },
53
53
  "devDependencies": {
54
- "@unocss/shared-integration": "0.44.0",
54
+ "@unocss/shared-integration": "0.44.1",
55
55
  "vite": "^2.9.12"
56
56
  },
57
57
  "scripts": {