@unocss/vite 0.47.5 → 0.47.6

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
@@ -75,7 +75,7 @@ This mode will inject generated CSS to Svelte's `<style>` for isolation.
75
75
 
76
76
  Since `Web Components` uses `Shadow DOM`, there is no way to style content directly from a global stylesheet (unless you use `custom css vars`, those will penetrate the `Shadow DOM`), you need to inline the generated css by the plugin into the `Shadow DOM` style.
77
77
 
78
- To inline the generated css, you only need to configure the plugin mode to `shadow-dom` and include `@unocss-placeholder` magic placeholder on each web component style css block.
78
+ To inline the generated css, you only need to configure the plugin mode to `shadow-dom` and include `@unocss-placeholder` magic placeholder on each web component style css block. If you are defining your Web Components in Vue SFCs and want to define custom styles alongside UnoCSS, you can wrap placeholder in a CSS comment to avoid syntax errors in your IDE.
79
79
 
80
80
  ###### `per-module` (Experimental)
81
81
 
package/dist/index.cjs CHANGED
@@ -411,7 +411,7 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, filter, getConfig
411
411
  msg += "\nIt seems you are building in library mode, it's recommended to set `build.cssCodeSplit` to true.\nSee https://github.com/vitejs/vite/issues/1579";
412
412
  else
413
413
  msg += "\nThis is likely an internal bug of unocss vite plugin";
414
- this.error(new Error(msg));
414
+ this.error(msg);
415
415
  }
416
416
  }
417
417
  }
@@ -889,6 +889,7 @@ function SvelteScopedPlugin({ ready, uno }) {
889
889
  function ShadowDomModuleModePlugin({ uno }) {
890
890
  const partExtractorRegex = /^part-\[(.+)]:/;
891
891
  const nameRegexp = /<([^\s^!>]+)\s*([^>]*)>/;
892
+ const vueSFCStyleRE = new RegExp(`<style.*>[\\s\\S]*${CSS_PLACEHOLDER}[\\s\\S]*<\\/style>`);
892
893
  const checkElement = (useParts, idxResolver, element) => {
893
894
  if (!element)
894
895
  return null;
@@ -921,7 +922,7 @@ function ShadowDomModuleModePlugin({ uno }) {
921
922
  }
922
923
  };
923
924
  };
924
- const transformWebComponent = async (code) => {
925
+ const transformWebComponent = async (code, id) => {
925
926
  if (!code.match(CSS_PLACEHOLDER))
926
927
  return code;
927
928
  let { css, matched } = await uno.generate(code, {
@@ -966,19 +967,21 @@ function ShadowDomModuleModePlugin({ uno }) {
966
967
  }
967
968
  }
968
969
  }
970
+ if (id.includes("?vue&type=style") || id.endsWith(".vue") && vueSFCStyleRE.test(code))
971
+ return code.replace(new RegExp(`(\\/\\*\\s*)?${CSS_PLACEHOLDER}(\\s*\\*\\/)?`), css || "");
969
972
  return code.replace(CSS_PLACEHOLDER, css?.replace(/\\/g, "\\\\") ?? "");
970
973
  };
971
974
  return {
972
975
  name: "unocss:shadow-dom",
973
976
  enforce: "pre",
974
- async transform(code) {
975
- return transformWebComponent(code);
977
+ async transform(code, id) {
978
+ return transformWebComponent(code, id);
976
979
  },
977
980
  handleHotUpdate(ctx) {
978
981
  const read = ctx.read;
979
982
  ctx.read = async () => {
980
983
  const code = await read();
981
- return await transformWebComponent(code);
984
+ return await transformWebComponent(code, ctx.file);
982
985
  };
983
986
  }
984
987
  };
package/dist/index.mjs CHANGED
@@ -400,7 +400,7 @@ function GlobalModeBuildPlugin({ uno, ready, extract, tokens, filter, getConfig
400
400
  msg += "\nIt seems you are building in library mode, it's recommended to set `build.cssCodeSplit` to true.\nSee https://github.com/vitejs/vite/issues/1579";
401
401
  else
402
402
  msg += "\nThis is likely an internal bug of unocss vite plugin";
403
- this.error(new Error(msg));
403
+ this.error(msg);
404
404
  }
405
405
  }
406
406
  }
@@ -878,6 +878,7 @@ function SvelteScopedPlugin({ ready, uno }) {
878
878
  function ShadowDomModuleModePlugin({ uno }) {
879
879
  const partExtractorRegex = /^part-\[(.+)]:/;
880
880
  const nameRegexp = /<([^\s^!>]+)\s*([^>]*)>/;
881
+ const vueSFCStyleRE = new RegExp(`<style.*>[\\s\\S]*${CSS_PLACEHOLDER}[\\s\\S]*<\\/style>`);
881
882
  const checkElement = (useParts, idxResolver, element) => {
882
883
  if (!element)
883
884
  return null;
@@ -910,7 +911,7 @@ function ShadowDomModuleModePlugin({ uno }) {
910
911
  }
911
912
  };
912
913
  };
913
- const transformWebComponent = async (code) => {
914
+ const transformWebComponent = async (code, id) => {
914
915
  if (!code.match(CSS_PLACEHOLDER))
915
916
  return code;
916
917
  let { css, matched } = await uno.generate(code, {
@@ -955,19 +956,21 @@ function ShadowDomModuleModePlugin({ uno }) {
955
956
  }
956
957
  }
957
958
  }
959
+ if (id.includes("?vue&type=style") || id.endsWith(".vue") && vueSFCStyleRE.test(code))
960
+ return code.replace(new RegExp(`(\\/\\*\\s*)?${CSS_PLACEHOLDER}(\\s*\\*\\/)?`), css || "");
958
961
  return code.replace(CSS_PLACEHOLDER, css?.replace(/\\/g, "\\\\") ?? "");
959
962
  };
960
963
  return {
961
964
  name: "unocss:shadow-dom",
962
965
  enforce: "pre",
963
- async transform(code) {
964
- return transformWebComponent(code);
966
+ async transform(code, id) {
967
+ return transformWebComponent(code, id);
965
968
  },
966
969
  handleHotUpdate(ctx) {
967
970
  const read = ctx.read;
968
971
  ctx.read = async () => {
969
972
  const code = await read();
970
- return await transformWebComponent(code);
973
+ return await transformWebComponent(code, ctx.file);
971
974
  };
972
975
  }
973
976
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/vite",
3
- "version": "0.47.5",
3
+ "version": "0.47.6",
4
4
  "description": "The Vite plugin for UnoCSS",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",
@@ -39,21 +39,21 @@
39
39
  "dist"
40
40
  ],
41
41
  "peerDependencies": {
42
- "vite": "^2.9.0 || ^3.0.0-0"
42
+ "vite": "^2.9.0 || ^3.0.0-0 || ^4.0.0"
43
43
  },
44
44
  "dependencies": {
45
45
  "@ampproject/remapping": "^2.2.0",
46
46
  "@rollup/pluginutils": "^5.0.2",
47
- "@unocss/config": "0.47.5",
48
- "@unocss/core": "0.47.5",
49
- "@unocss/inspector": "0.47.5",
50
- "@unocss/scope": "0.47.5",
51
- "@unocss/transformer-directives": "0.47.5",
52
- "magic-string": "^0.26.7"
47
+ "@unocss/config": "0.47.6",
48
+ "@unocss/core": "0.47.6",
49
+ "@unocss/inspector": "0.47.6",
50
+ "@unocss/scope": "0.47.6",
51
+ "@unocss/transformer-directives": "0.47.6",
52
+ "magic-string": "^0.27.0"
53
53
  },
54
54
  "devDependencies": {
55
- "@unocss/shared-integration": "0.47.5",
56
- "vite": "^3.2.4"
55
+ "@unocss/shared-integration": "0.47.6",
56
+ "vite": "^4.0.0"
57
57
  },
58
58
  "scripts": {
59
59
  "build": "unbuild",