@unocss/vite 0.56.5 → 0.57.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/dist/client.cjs CHANGED
@@ -1,7 +1,8 @@
1
1
  'use strict';
2
2
 
3
- function post(data) {
3
+ function post(data, config) {
4
4
  return fetch("__POST_PATH__", {
5
+ ...config,
5
6
  method: "POST",
6
7
  headers: {
7
8
  "Content-Type": "application/json"
@@ -26,7 +27,10 @@ function schedule() {
26
27
  clearTimeout(_timer);
27
28
  _timer = setTimeout(() => {
28
29
  if (pendingClasses.size) {
29
- post({ type: "add-classes", data: Array.from(pendingClasses) });
30
+ post(
31
+ { type: "add-classes", data: Array.from(pendingClasses) },
32
+ { mode: "__POST_FETCH_MODE__" }
33
+ );
30
34
  include(visitedClasses, pendingClasses);
31
35
  pendingClasses.clear();
32
36
  }
package/dist/client.mjs CHANGED
@@ -1,5 +1,6 @@
1
- function post(data) {
1
+ function post(data, config) {
2
2
  return fetch("__POST_PATH__", {
3
+ ...config,
3
4
  method: "POST",
4
5
  headers: {
5
6
  "Content-Type": "application/json"
@@ -24,7 +25,10 @@ function schedule() {
24
25
  clearTimeout(_timer);
25
26
  _timer = setTimeout(() => {
26
27
  if (pendingClasses.size) {
27
- post({ type: "add-classes", data: Array.from(pendingClasses) });
28
+ post(
29
+ { type: "add-classes", data: Array.from(pendingClasses) },
30
+ { mode: "__POST_FETCH_MODE__" }
31
+ );
28
32
  include(visitedClasses, pendingClasses);
29
33
  pendingClasses.clear();
30
34
  }
package/dist/index.cjs CHANGED
@@ -688,9 +688,10 @@ function GlobalModeDevPlugin({ uno, tokens, tasks, flushTasks, affectedModules,
688
688
  enforce: "pre",
689
689
  async configureServer(_server) {
690
690
  servers.push(_server);
691
- _server.ws.on(WS_EVENT_PREFIX, async ([layer, hash]) => {
691
+ _server.ws.on(WS_EVENT_PREFIX, async ([layer]) => {
692
+ const preHash = lastServedHash.get(layer);
692
693
  await generateCSS(layer);
693
- if (lastServedHash.get(layer) !== hash)
694
+ if (lastServedHash.get(layer) !== preHash)
694
695
  sendUpdate(entries);
695
696
  });
696
697
  },
@@ -749,7 +750,7 @@ try {
749
750
  if (!hash)
750
751
  console.warn('[unocss-hmr]', 'failed to get unocss hash, hmr might not work')
751
752
  else
752
- await import.meta.hot.send('${WS_EVENT_PREFIX}', ['${layer}', hash]);
753
+ await import.meta.hot.send('${WS_EVENT_PREFIX}', ['${layer}']);
753
754
  } catch (e) {
754
755
  console.warn('[unocss-hmr]', e)
755
756
  }
@@ -1082,7 +1083,7 @@ function getBodyJson(req) {
1082
1083
  });
1083
1084
  });
1084
1085
  }
1085
- function createDevtoolsPlugin(ctx) {
1086
+ function createDevtoolsPlugin(ctx, pluginConfig) {
1086
1087
  let config;
1087
1088
  let server;
1088
1089
  let clientCode = "";
@@ -1171,7 +1172,7 @@ function createDevtoolsPlugin(ctx) {
1171
1172
  await fs__default$1.promises.readFile(node_path.resolve(_dirname, "client.mjs"), "utf-8"),
1172
1173
  `import('${MOCK_CLASSES_MODULE_ID}')`,
1173
1174
  `import('${DEVTOOLS_CSS_PATH}')`
1174
- ].join("\n").replace("__POST_PATH__", `${config.server?.origin ?? ""}${postPath}`);
1175
+ ].join("\n").replace("__POST_PATH__", `${config.server?.origin ?? ""}${postPath}`).replace("__POST_FETCH_MODE__", pluginConfig.fetchMode ?? "cors");
1175
1176
  }
1176
1177
  return config.command === "build" ? "" : clientCode;
1177
1178
  } else if (id === MOCK_CLASSES_PATH) {
@@ -1198,7 +1199,7 @@ function UnocssPlugin(configOrPath, defaults = {}) {
1198
1199
  const plugins = [
1199
1200
  ConfigHMRPlugin(ctx),
1200
1201
  ...createTransformerPlugins(ctx),
1201
- ...createDevtoolsPlugin(ctx),
1202
+ ...createDevtoolsPlugin(ctx, inlineConfig),
1202
1203
  {
1203
1204
  name: "unocss:api",
1204
1205
  api: {
package/dist/index.d.cts CHANGED
@@ -45,6 +45,15 @@ interface VitePluginConfig<Theme extends object = object> extends UserConfig<The
45
45
  * @default true
46
46
  */
47
47
  hmrTopLevelAwait?: boolean;
48
+ /**
49
+ * Fetch mode in devtools.
50
+ *
51
+ * Some server does not configure its CORS and you may want to set this to 'no-cors'.
52
+ * See https://github.com/unocss/unocss/issues/2822.
53
+ *
54
+ * @default 'cors'
55
+ */
56
+ fetchMode?: 'cors' | 'navigate' | 'no-cors' | 'same-origin';
48
57
  }
49
58
 
50
59
  declare function ChunkModeBuildPlugin({ uno, filter }: UnocssPluginContext): Plugin;
package/dist/index.d.mts CHANGED
@@ -45,6 +45,15 @@ interface VitePluginConfig<Theme extends object = object> extends UserConfig<The
45
45
  * @default true
46
46
  */
47
47
  hmrTopLevelAwait?: boolean;
48
+ /**
49
+ * Fetch mode in devtools.
50
+ *
51
+ * Some server does not configure its CORS and you may want to set this to 'no-cors'.
52
+ * See https://github.com/unocss/unocss/issues/2822.
53
+ *
54
+ * @default 'cors'
55
+ */
56
+ fetchMode?: 'cors' | 'navigate' | 'no-cors' | 'same-origin';
48
57
  }
49
58
 
50
59
  declare function ChunkModeBuildPlugin({ uno, filter }: UnocssPluginContext): Plugin;
package/dist/index.d.ts CHANGED
@@ -45,6 +45,15 @@ interface VitePluginConfig<Theme extends object = object> extends UserConfig<The
45
45
  * @default true
46
46
  */
47
47
  hmrTopLevelAwait?: boolean;
48
+ /**
49
+ * Fetch mode in devtools.
50
+ *
51
+ * Some server does not configure its CORS and you may want to set this to 'no-cors'.
52
+ * See https://github.com/unocss/unocss/issues/2822.
53
+ *
54
+ * @default 'cors'
55
+ */
56
+ fetchMode?: 'cors' | 'navigate' | 'no-cors' | 'same-origin';
48
57
  }
49
58
 
50
59
  declare function ChunkModeBuildPlugin({ uno, filter }: UnocssPluginContext): Plugin;
package/dist/index.mjs CHANGED
@@ -673,9 +673,10 @@ function GlobalModeDevPlugin({ uno, tokens, tasks, flushTasks, affectedModules,
673
673
  enforce: "pre",
674
674
  async configureServer(_server) {
675
675
  servers.push(_server);
676
- _server.ws.on(WS_EVENT_PREFIX, async ([layer, hash]) => {
676
+ _server.ws.on(WS_EVENT_PREFIX, async ([layer]) => {
677
+ const preHash = lastServedHash.get(layer);
677
678
  await generateCSS(layer);
678
- if (lastServedHash.get(layer) !== hash)
679
+ if (lastServedHash.get(layer) !== preHash)
679
680
  sendUpdate(entries);
680
681
  });
681
682
  },
@@ -734,7 +735,7 @@ try {
734
735
  if (!hash)
735
736
  console.warn('[unocss-hmr]', 'failed to get unocss hash, hmr might not work')
736
737
  else
737
- await import.meta.hot.send('${WS_EVENT_PREFIX}', ['${layer}', hash]);
738
+ await import.meta.hot.send('${WS_EVENT_PREFIX}', ['${layer}']);
738
739
  } catch (e) {
739
740
  console.warn('[unocss-hmr]', e)
740
741
  }
@@ -1067,7 +1068,7 @@ function getBodyJson(req) {
1067
1068
  });
1068
1069
  });
1069
1070
  }
1070
- function createDevtoolsPlugin(ctx) {
1071
+ function createDevtoolsPlugin(ctx, pluginConfig) {
1071
1072
  let config;
1072
1073
  let server;
1073
1074
  let clientCode = "";
@@ -1156,7 +1157,7 @@ function createDevtoolsPlugin(ctx) {
1156
1157
  await fs$1.promises.readFile(resolve(_dirname, "client.mjs"), "utf-8"),
1157
1158
  `import('${MOCK_CLASSES_MODULE_ID}')`,
1158
1159
  `import('${DEVTOOLS_CSS_PATH}')`
1159
- ].join("\n").replace("__POST_PATH__", `${config.server?.origin ?? ""}${postPath}`);
1160
+ ].join("\n").replace("__POST_PATH__", `${config.server?.origin ?? ""}${postPath}`).replace("__POST_FETCH_MODE__", pluginConfig.fetchMode ?? "cors");
1160
1161
  }
1161
1162
  return config.command === "build" ? "" : clientCode;
1162
1163
  } else if (id === MOCK_CLASSES_PATH) {
@@ -1183,7 +1184,7 @@ function UnocssPlugin(configOrPath, defaults = {}) {
1183
1184
  const plugins = [
1184
1185
  ConfigHMRPlugin(ctx),
1185
1186
  ...createTransformerPlugins(ctx),
1186
- ...createDevtoolsPlugin(ctx),
1187
+ ...createDevtoolsPlugin(ctx, inlineConfig),
1187
1188
  {
1188
1189
  name: "unocss:api",
1189
1190
  api: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/vite",
3
- "version": "0.56.5",
3
+ "version": "0.57.1",
4
4
  "description": "The Vite plugin for UnoCSS",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",
@@ -43,19 +43,19 @@
43
43
  },
44
44
  "dependencies": {
45
45
  "@ampproject/remapping": "^2.2.1",
46
- "@rollup/pluginutils": "^5.0.4",
46
+ "@rollup/pluginutils": "^5.0.5",
47
47
  "chokidar": "^3.5.3",
48
48
  "fast-glob": "^3.3.1",
49
- "magic-string": "^0.30.3",
50
- "@unocss/config": "0.56.5",
51
- "@unocss/core": "0.56.5",
52
- "@unocss/inspector": "0.56.5",
53
- "@unocss/scope": "0.56.5",
54
- "@unocss/transformer-directives": "0.56.5"
49
+ "magic-string": "^0.30.5",
50
+ "@unocss/config": "0.57.1",
51
+ "@unocss/core": "0.57.1",
52
+ "@unocss/inspector": "0.57.1",
53
+ "@unocss/scope": "0.57.1",
54
+ "@unocss/transformer-directives": "0.57.1"
55
55
  },
56
56
  "devDependencies": {
57
- "vite": "^4.4.9",
58
- "@unocss/shared-integration": "0.56.5"
57
+ "vite": "^4.5.0",
58
+ "@unocss/shared-integration": "0.57.1"
59
59
  },
60
60
  "scripts": {
61
61
  "build": "unbuild",