@unocss/vite 0.26.4 → 0.27.2

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 CHANGED
@@ -7,10 +7,12 @@ const pluginutils = require('@rollup/pluginutils');
7
7
  const config = require('@unocss/config');
8
8
  const core = require('@unocss/core');
9
9
  const crypto = require('crypto');
10
+ const MagicString = require('magic-string');
10
11
 
11
12
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
12
13
 
13
14
  const UnocssInspector__default = /*#__PURE__*/_interopDefaultLegacy(UnocssInspector);
15
+ const MagicString__default = /*#__PURE__*/_interopDefaultLegacy(MagicString);
14
16
 
15
17
  const regexCssId = /\.(css|postcss|sass|scss|less|stylus|styl)$/;
16
18
  const defaultExclude = [regexCssId];
@@ -630,11 +632,11 @@ function ConfigHMRPlugin(ctx) {
630
632
  }
631
633
 
632
634
  function initTransformerPlugins(ctx) {
633
- async function applyTransformers(c, _code, id, enforce) {
635
+ async function applyTransformers(code, id, enforce) {
634
636
  const transformers = (ctx.uno.config.transformers || []).filter((i) => i.enforce === enforce);
635
637
  if (!transformers.length)
636
- return void 0;
637
- let code = _code;
638
+ return;
639
+ const s = new MagicString__default(code);
638
640
  for (const t of transformers) {
639
641
  if (t.idFilter) {
640
642
  if (!t.idFilter(id))
@@ -642,40 +644,34 @@ function initTransformerPlugins(ctx) {
642
644
  } else if (!ctx.filter(code, id)) {
643
645
  continue;
644
646
  }
645
- const result = await t.transform(code, id, ctx);
646
- if (result == null)
647
- continue;
648
- if (typeof result === "string") {
649
- code = result;
650
- } else {
651
- code = result.code;
652
- if (result.map && "sourcemapChain" in c)
653
- c.sourcemapChain.push(result.map);
654
- }
647
+ await t.transform(s, id, ctx);
648
+ }
649
+ if (s.hasChanged()) {
650
+ return {
651
+ code: s.toString(),
652
+ map: s.generateMap({ hires: true, source: id })
653
+ };
655
654
  }
656
- if (code === _code)
657
- return null;
658
- return code;
659
655
  }
660
656
  return [
661
657
  {
662
- name: "unocss:transformers:deafult",
658
+ name: "unocss:transformers:default",
663
659
  transform(code, id) {
664
- return applyTransformers(this, code, id);
660
+ return applyTransformers(code, id);
665
661
  }
666
662
  },
667
663
  {
668
664
  name: "unocss:transformers:pre",
669
665
  enforce: "pre",
670
666
  transform(code, id) {
671
- return applyTransformers(this, code, id, "pre");
667
+ return applyTransformers(code, id, "pre");
672
668
  }
673
669
  },
674
670
  {
675
671
  name: "unocss:transformers:post",
676
672
  enforce: "post",
677
673
  transform(code, id) {
678
- return applyTransformers(this, code, id, "post");
674
+ return applyTransformers(code, id, "post");
679
675
  }
680
676
  }
681
677
  ];
package/dist/index.mjs CHANGED
@@ -3,6 +3,7 @@ import { createFilter } from '@rollup/pluginutils';
3
3
  import { createConfigLoader } from '@unocss/config';
4
4
  import { createGenerator, BetterMap } from '@unocss/core';
5
5
  import { createHash } from 'crypto';
6
+ import MagicString from 'magic-string';
6
7
 
7
8
  const regexCssId = /\.(css|postcss|sass|scss|less|stylus|styl)$/;
8
9
  const defaultExclude = [regexCssId];
@@ -622,11 +623,11 @@ function ConfigHMRPlugin(ctx) {
622
623
  }
623
624
 
624
625
  function initTransformerPlugins(ctx) {
625
- async function applyTransformers(c, _code, id, enforce) {
626
+ async function applyTransformers(code, id, enforce) {
626
627
  const transformers = (ctx.uno.config.transformers || []).filter((i) => i.enforce === enforce);
627
628
  if (!transformers.length)
628
- return void 0;
629
- let code = _code;
629
+ return;
630
+ const s = new MagicString(code);
630
631
  for (const t of transformers) {
631
632
  if (t.idFilter) {
632
633
  if (!t.idFilter(id))
@@ -634,40 +635,34 @@ function initTransformerPlugins(ctx) {
634
635
  } else if (!ctx.filter(code, id)) {
635
636
  continue;
636
637
  }
637
- const result = await t.transform(code, id, ctx);
638
- if (result == null)
639
- continue;
640
- if (typeof result === "string") {
641
- code = result;
642
- } else {
643
- code = result.code;
644
- if (result.map && "sourcemapChain" in c)
645
- c.sourcemapChain.push(result.map);
646
- }
638
+ await t.transform(s, id, ctx);
639
+ }
640
+ if (s.hasChanged()) {
641
+ return {
642
+ code: s.toString(),
643
+ map: s.generateMap({ hires: true, source: id })
644
+ };
647
645
  }
648
- if (code === _code)
649
- return null;
650
- return code;
651
646
  }
652
647
  return [
653
648
  {
654
- name: "unocss:transformers:deafult",
649
+ name: "unocss:transformers:default",
655
650
  transform(code, id) {
656
- return applyTransformers(this, code, id);
651
+ return applyTransformers(code, id);
657
652
  }
658
653
  },
659
654
  {
660
655
  name: "unocss:transformers:pre",
661
656
  enforce: "pre",
662
657
  transform(code, id) {
663
- return applyTransformers(this, code, id, "pre");
658
+ return applyTransformers(code, id, "pre");
664
659
  }
665
660
  },
666
661
  {
667
662
  name: "unocss:transformers:post",
668
663
  enforce: "post",
669
664
  transform(code, id) {
670
- return applyTransformers(this, code, id, "post");
665
+ return applyTransformers(code, id, "post");
671
666
  }
672
667
  }
673
668
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/vite",
3
- "version": "0.26.4",
3
+ "version": "0.27.2",
4
4
  "description": "The Vite plugin for UnoCSS",
5
5
  "keywords": [
6
6
  "unocss",
@@ -35,14 +35,15 @@
35
35
  "types": "dist/index.d.ts",
36
36
  "dependencies": {
37
37
  "@rollup/pluginutils": "^4.1.2",
38
- "@unocss/config": "0.26.4",
39
- "@unocss/core": "0.26.4",
40
- "@unocss/inspector": "0.26.4",
41
- "@unocss/scope": "0.26.4",
42
- "@unocss/transformer-directives": "0.26.4"
38
+ "@unocss/config": "0.27.2",
39
+ "@unocss/core": "0.27.2",
40
+ "@unocss/inspector": "0.27.2",
41
+ "@unocss/scope": "0.27.2",
42
+ "@unocss/transformer-directives": "0.27.2",
43
+ "magic-string": "^0.26.1"
43
44
  },
44
45
  "devDependencies": {
45
- "vite": "^2.8.4"
46
+ "vite": "^2.8.6"
46
47
  },
47
48
  "scripts": {
48
49
  "build": "unbuild",