@unocss/astro 0.51.12 → 0.52.0

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,28 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
8
8
 
9
9
  const VitePlugin__default = /*#__PURE__*/_interopDefaultLegacy(VitePlugin);
10
10
 
11
+ const UNO_INJECT_ID = "uno-astro";
12
+ const UNO_QUERY_KEY = "uno-with-astro-key";
13
+ function AstroVitePlugin(options) {
14
+ const { injects } = options;
15
+ return {
16
+ name: "unocss:astro",
17
+ apply: "serve",
18
+ enforce: "pre",
19
+ resolveId(id, importer) {
20
+ if (id === UNO_INJECT_ID)
21
+ return id;
22
+ if (importer?.endsWith(UNO_INJECT_ID))
23
+ return `${id}${id.includes("?") ? "&" : "?"}${UNO_QUERY_KEY}`;
24
+ },
25
+ load(id, options2) {
26
+ if (id.endsWith(UNO_INJECT_ID))
27
+ return injects.join("\n");
28
+ if (!options2?.ssr && id.includes(UNO_QUERY_KEY) && id.includes(".css"))
29
+ return "";
30
+ }
31
+ };
32
+ }
11
33
  function UnoCSSAstroIntegration(options = {}, defaults) {
12
34
  const {
13
35
  injectEntry = true,
@@ -17,13 +39,11 @@ function UnoCSSAstroIntegration(options = {}, defaults) {
17
39
  return {
18
40
  name: "unocss",
19
41
  hooks: {
20
- "astro:config:setup": async ({ config, injectScript }) => {
21
- var _a, _b;
42
+ "astro:config:setup": async ({ config, updateConfig, injectScript }) => {
43
+ var _a;
22
44
  options.extraContent || (options.extraContent = {});
23
45
  (_a = options.extraContent).filesystem || (_a.filesystem = []);
24
46
  options.extraContent.filesystem.push(node_path.resolve(node_url.fileURLToPath(config.srcDir), "components/**/*").replace(/\\/g, "/"));
25
- (_b = config.vite).plugins || (_b.plugins = []);
26
- config.vite.plugins.push(...VitePlugin__default(options, defaults));
27
47
  const injects = [];
28
48
  if (injectReset) {
29
49
  const resetPath = typeof injectReset === "string" ? injectReset : "@unocss/reset/tailwind.css";
@@ -34,8 +54,15 @@ function UnoCSSAstroIntegration(options = {}, defaults) {
34
54
  }
35
55
  if (injectExtra.length > 0)
36
56
  injects.push(...injectExtra);
57
+ updateConfig({
58
+ vite: {
59
+ plugins: [AstroVitePlugin({
60
+ injects
61
+ }), ...VitePlugin__default(options, defaults)]
62
+ }
63
+ });
37
64
  if (injects?.length)
38
- injectScript("page-ssr", injects.join("\n"));
65
+ injectScript("page-ssr", `import ${JSON.stringify(UNO_INJECT_ID)}`);
39
66
  }
40
67
  }
41
68
  };
package/dist/index.mjs CHANGED
@@ -2,6 +2,28 @@ import { resolve } from 'node:path';
2
2
  import { fileURLToPath } from 'node:url';
3
3
  import VitePlugin from '@unocss/vite';
4
4
 
5
+ const UNO_INJECT_ID = "uno-astro";
6
+ const UNO_QUERY_KEY = "uno-with-astro-key";
7
+ function AstroVitePlugin(options) {
8
+ const { injects } = options;
9
+ return {
10
+ name: "unocss:astro",
11
+ apply: "serve",
12
+ enforce: "pre",
13
+ resolveId(id, importer) {
14
+ if (id === UNO_INJECT_ID)
15
+ return id;
16
+ if (importer?.endsWith(UNO_INJECT_ID))
17
+ return `${id}${id.includes("?") ? "&" : "?"}${UNO_QUERY_KEY}`;
18
+ },
19
+ load(id, options2) {
20
+ if (id.endsWith(UNO_INJECT_ID))
21
+ return injects.join("\n");
22
+ if (!options2?.ssr && id.includes(UNO_QUERY_KEY) && id.includes(".css"))
23
+ return "";
24
+ }
25
+ };
26
+ }
5
27
  function UnoCSSAstroIntegration(options = {}, defaults) {
6
28
  const {
7
29
  injectEntry = true,
@@ -11,13 +33,11 @@ function UnoCSSAstroIntegration(options = {}, defaults) {
11
33
  return {
12
34
  name: "unocss",
13
35
  hooks: {
14
- "astro:config:setup": async ({ config, injectScript }) => {
15
- var _a, _b;
36
+ "astro:config:setup": async ({ config, updateConfig, injectScript }) => {
37
+ var _a;
16
38
  options.extraContent || (options.extraContent = {});
17
39
  (_a = options.extraContent).filesystem || (_a.filesystem = []);
18
40
  options.extraContent.filesystem.push(resolve(fileURLToPath(config.srcDir), "components/**/*").replace(/\\/g, "/"));
19
- (_b = config.vite).plugins || (_b.plugins = []);
20
- config.vite.plugins.push(...VitePlugin(options, defaults));
21
41
  const injects = [];
22
42
  if (injectReset) {
23
43
  const resetPath = typeof injectReset === "string" ? injectReset : "@unocss/reset/tailwind.css";
@@ -28,8 +48,15 @@ function UnoCSSAstroIntegration(options = {}, defaults) {
28
48
  }
29
49
  if (injectExtra.length > 0)
30
50
  injects.push(...injectExtra);
51
+ updateConfig({
52
+ vite: {
53
+ plugins: [AstroVitePlugin({
54
+ injects
55
+ }), ...VitePlugin(options, defaults)]
56
+ }
57
+ });
31
58
  if (injects?.length)
32
- injectScript("page-ssr", injects.join("\n"));
59
+ injectScript("page-ssr", `import ${JSON.stringify(UNO_INJECT_ID)}`);
33
60
  }
34
61
  }
35
62
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/astro",
3
- "version": "0.51.12",
3
+ "version": "0.52.0",
4
4
  "description": "UnoCSS integration for Astro",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",
@@ -37,9 +37,9 @@
37
37
  "dist"
38
38
  ],
39
39
  "dependencies": {
40
- "@unocss/core": "0.51.12",
41
- "@unocss/reset": "0.51.12",
42
- "@unocss/vite": "0.51.12"
40
+ "@unocss/core": "0.52.0",
41
+ "@unocss/reset": "0.52.0",
42
+ "@unocss/vite": "0.52.0"
43
43
  },
44
44
  "devDependencies": {
45
45
  "astro": "^2.4.1"