@unocss/vite 0.44.1 → 0.44.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 CHANGED
@@ -8,6 +8,7 @@ const crypto = require('crypto');
8
8
  const core = require('@unocss/core');
9
9
  const pluginutils = require('@rollup/pluginutils');
10
10
  const MagicString = require('magic-string');
11
+ const remapping = require('@ampproject/remapping');
11
12
  const fs = require('fs');
12
13
  const url = require('url');
13
14
  const config = require('@unocss/config');
@@ -16,10 +17,11 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
16
17
 
17
18
  const UnocssInspector__default = /*#__PURE__*/_interopDefaultLegacy(UnocssInspector);
18
19
  const MagicString__default = /*#__PURE__*/_interopDefaultLegacy(MagicString);
20
+ const remapping__default = /*#__PURE__*/_interopDefaultLegacy(remapping);
19
21
  const fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
20
22
 
21
23
  const defaultExclude = [core.cssIdRE];
22
- const defaultInclude = [/\.vue$/, /\.vue\?vue/, /\.svelte$/, /\.[jt]sx$/, /\.mdx?$/, /\.astro$/, /\.elm$/];
24
+ const defaultInclude = [/\.vue$/, /\.vue\?vue/, /\.svelte$/, /\.[jt]sx$/, /\.mdx?$/, /\.astro$/, /\.elm$/, /\.html$/];
23
25
 
24
26
  const VIRTUAL_ENTRY_ALIAS = [
25
27
  /^(?:virtual:)?uno(?::(.+))?\.css(\?.*)?$/
@@ -779,62 +781,53 @@ function ConfigHMRPlugin(ctx) {
779
781
  };
780
782
  }
781
783
 
782
- function initTransformerPlugins(ctx) {
783
- async function applyTransformers(code, id, enforce) {
784
- if (code.includes(IGNORE_COMMENT))
785
- return;
786
- const transformers = (ctx.uno.config.transformers || []).filter((i) => i.enforce === enforce);
787
- if (!transformers.length)
788
- return;
789
- const s = new MagicString__default(code);
790
- for (const t of transformers) {
791
- if (t.idFilter) {
792
- if (!t.idFilter(id))
793
- continue;
794
- } else if (!ctx.filter(code, id)) {
784
+ async function applyTransformers(ctx, original, id, enforce = "default") {
785
+ if (original.includes(IGNORE_COMMENT))
786
+ return;
787
+ const transformers = (ctx.uno.config.transformers || []).filter((i) => (i.enforce || "default") === enforce);
788
+ if (!transformers.length)
789
+ return;
790
+ let code = original;
791
+ let s = new MagicString__default(code);
792
+ const maps = [];
793
+ for (const t of transformers) {
794
+ if (t.idFilter) {
795
+ if (!t.idFilter(id))
795
796
  continue;
796
- }
797
- await t.transform(s, id, ctx);
797
+ } else if (!ctx.filter(code, id)) {
798
+ continue;
798
799
  }
800
+ await t.transform(s, id, ctx);
799
801
  if (s.hasChanged()) {
800
- ctx.affectedModules.add(id);
801
- return {
802
- code: s.toString(),
803
- map: s.generateMap({ hires: true, source: id })
804
- };
802
+ code = s.toString();
803
+ maps.push(s.generateMap({ hires: true, source: id }));
804
+ s = new MagicString__default(code);
805
805
  }
806
806
  }
807
- return [
808
- {
809
- name: "unocss:transformers:default",
810
- transform(code, id) {
811
- return applyTransformers(code, id);
812
- },
813
- transformIndexHtml(code) {
814
- return applyTransformers(code, "index.html").then((t) => t?.code);
815
- }
816
- },
817
- {
818
- name: "unocss:transformers:pre",
819
- enforce: "pre",
820
- transform(code, id) {
821
- return applyTransformers(code, id, "pre");
822
- },
823
- transformIndexHtml(code) {
824
- return applyTransformers(code, "index.html", "pre").then((t) => t?.code);
825
- }
807
+ if (code !== original) {
808
+ ctx.affectedModules.add(id);
809
+ return {
810
+ code,
811
+ map: remapping__default(maps, () => null)
812
+ };
813
+ }
814
+ }
815
+
816
+ function createTransformerPlugins(ctx) {
817
+ const enforces = ["default", "pre", "post"];
818
+ return enforces.map((enforce) => ({
819
+ name: `unocss:transformers:${enforce}`,
820
+ enforce: enforce === "default" ? void 0 : enforce,
821
+ transform(code, id) {
822
+ return applyTransformers(ctx, code, id, enforce);
826
823
  },
827
- {
828
- name: "unocss:transformers:post",
829
- enforce: "post",
830
- transform(code, id) {
831
- return applyTransformers(code, id, "post");
832
- },
833
- transformIndexHtml(code) {
834
- applyTransformers(code, "index.html", "post").then((t) => t?.code);
824
+ transformIndexHtml: {
825
+ enforce: enforce === "default" ? void 0 : enforce,
826
+ transform(code) {
827
+ return applyTransformers(ctx, code, "index.html", enforce).then((t) => t?.code);
835
828
  }
836
829
  }
837
- ];
830
+ }));
838
831
  }
839
832
 
840
833
  const _dirname = typeof __dirname !== "undefined" ? __dirname : path.dirname(url.fileURLToPath((typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('index.cjs', document.baseURI).href))));
@@ -973,7 +966,7 @@ function UnocssPlugin(configOrPath, defaults = {}) {
973
966
  const mode = inlineConfig.mode ?? "global";
974
967
  const plugins = [
975
968
  ConfigHMRPlugin(ctx),
976
- ...initTransformerPlugins(ctx),
969
+ ...createTransformerPlugins(ctx),
977
970
  ...createDevtoolsPlugin(ctx)
978
971
  ];
979
972
  if (inlineConfig.inspector !== false)
package/dist/index.mjs CHANGED
@@ -4,12 +4,13 @@ import { createHash } from 'crypto';
4
4
  import { cssIdRE, createGenerator, BetterMap, notNull, toEscapedSelector } from '@unocss/core';
5
5
  import { createFilter } from '@rollup/pluginutils';
6
6
  import MagicString from 'magic-string';
7
+ import remapping from '@ampproject/remapping';
7
8
  import fs from 'fs';
8
9
  import { fileURLToPath } from 'url';
9
10
  import { loadConfig } from '@unocss/config';
10
11
 
11
12
  const defaultExclude = [cssIdRE];
12
- const defaultInclude = [/\.vue$/, /\.vue\?vue/, /\.svelte$/, /\.[jt]sx$/, /\.mdx?$/, /\.astro$/, /\.elm$/];
13
+ const defaultInclude = [/\.vue$/, /\.vue\?vue/, /\.svelte$/, /\.[jt]sx$/, /\.mdx?$/, /\.astro$/, /\.elm$/, /\.html$/];
13
14
 
14
15
  const VIRTUAL_ENTRY_ALIAS = [
15
16
  /^(?:virtual:)?uno(?::(.+))?\.css(\?.*)?$/
@@ -769,62 +770,53 @@ function ConfigHMRPlugin(ctx) {
769
770
  };
770
771
  }
771
772
 
772
- function initTransformerPlugins(ctx) {
773
- async function applyTransformers(code, id, enforce) {
774
- if (code.includes(IGNORE_COMMENT))
775
- return;
776
- const transformers = (ctx.uno.config.transformers || []).filter((i) => i.enforce === enforce);
777
- if (!transformers.length)
778
- return;
779
- const s = new MagicString(code);
780
- for (const t of transformers) {
781
- if (t.idFilter) {
782
- if (!t.idFilter(id))
783
- continue;
784
- } else if (!ctx.filter(code, id)) {
773
+ async function applyTransformers(ctx, original, id, enforce = "default") {
774
+ if (original.includes(IGNORE_COMMENT))
775
+ return;
776
+ const transformers = (ctx.uno.config.transformers || []).filter((i) => (i.enforce || "default") === enforce);
777
+ if (!transformers.length)
778
+ return;
779
+ let code = original;
780
+ let s = new MagicString(code);
781
+ const maps = [];
782
+ for (const t of transformers) {
783
+ if (t.idFilter) {
784
+ if (!t.idFilter(id))
785
785
  continue;
786
- }
787
- await t.transform(s, id, ctx);
786
+ } else if (!ctx.filter(code, id)) {
787
+ continue;
788
788
  }
789
+ await t.transform(s, id, ctx);
789
790
  if (s.hasChanged()) {
790
- ctx.affectedModules.add(id);
791
- return {
792
- code: s.toString(),
793
- map: s.generateMap({ hires: true, source: id })
794
- };
791
+ code = s.toString();
792
+ maps.push(s.generateMap({ hires: true, source: id }));
793
+ s = new MagicString(code);
795
794
  }
796
795
  }
797
- return [
798
- {
799
- name: "unocss:transformers:default",
800
- transform(code, id) {
801
- return applyTransformers(code, id);
802
- },
803
- transformIndexHtml(code) {
804
- return applyTransformers(code, "index.html").then((t) => t?.code);
805
- }
806
- },
807
- {
808
- name: "unocss:transformers:pre",
809
- enforce: "pre",
810
- transform(code, id) {
811
- return applyTransformers(code, id, "pre");
812
- },
813
- transformIndexHtml(code) {
814
- return applyTransformers(code, "index.html", "pre").then((t) => t?.code);
815
- }
796
+ if (code !== original) {
797
+ ctx.affectedModules.add(id);
798
+ return {
799
+ code,
800
+ map: remapping(maps, () => null)
801
+ };
802
+ }
803
+ }
804
+
805
+ function createTransformerPlugins(ctx) {
806
+ const enforces = ["default", "pre", "post"];
807
+ return enforces.map((enforce) => ({
808
+ name: `unocss:transformers:${enforce}`,
809
+ enforce: enforce === "default" ? void 0 : enforce,
810
+ transform(code, id) {
811
+ return applyTransformers(ctx, code, id, enforce);
816
812
  },
817
- {
818
- name: "unocss:transformers:post",
819
- enforce: "post",
820
- transform(code, id) {
821
- return applyTransformers(code, id, "post");
822
- },
823
- transformIndexHtml(code) {
824
- applyTransformers(code, "index.html", "post").then((t) => t?.code);
813
+ transformIndexHtml: {
814
+ enforce: enforce === "default" ? void 0 : enforce,
815
+ transform(code) {
816
+ return applyTransformers(ctx, code, "index.html", enforce).then((t) => t?.code);
825
817
  }
826
818
  }
827
- ];
819
+ }));
828
820
  }
829
821
 
830
822
  const _dirname = typeof __dirname !== "undefined" ? __dirname : dirname(fileURLToPath(import.meta.url));
@@ -963,7 +955,7 @@ function UnocssPlugin(configOrPath, defaults = {}) {
963
955
  const mode = inlineConfig.mode ?? "global";
964
956
  const plugins = [
965
957
  ConfigHMRPlugin(ctx),
966
- ...initTransformerPlugins(ctx),
958
+ ...createTransformerPlugins(ctx),
967
959
  ...createDevtoolsPlugin(ctx)
968
960
  ];
969
961
  if (inlineConfig.inspector !== false)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/vite",
3
- "version": "0.44.1",
3
+ "version": "0.44.4",
4
4
  "description": "The Vite plugin for UnoCSS",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",
@@ -42,16 +42,17 @@
42
42
  "vite": "^2.9.0 || ^3.0.0-0"
43
43
  },
44
44
  "dependencies": {
45
+ "@ampproject/remapping": "^2.2.0",
45
46
  "@rollup/pluginutils": "^4.2.1",
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",
47
+ "@unocss/config": "0.44.4",
48
+ "@unocss/core": "0.44.4",
49
+ "@unocss/inspector": "0.44.4",
50
+ "@unocss/scope": "0.44.4",
51
+ "@unocss/transformer-directives": "0.44.4",
51
52
  "magic-string": "^0.26.2"
52
53
  },
53
54
  "devDependencies": {
54
- "@unocss/shared-integration": "0.44.1",
55
+ "@unocss/shared-integration": "0.44.4",
55
56
  "vite": "^2.9.12"
56
57
  },
57
58
  "scripts": {