@unocss/nuxt 0.58.0 → 0.58.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.d.mts CHANGED
@@ -28,6 +28,14 @@ interface UnocssNuxtOptions extends UserConfig {
28
28
  * @default false
29
29
  */
30
30
  preflight?: boolean;
31
+ /**
32
+ * Adjust the position of the `uno.css` injection. (Depends on `mode`)
33
+ *
34
+ * @default 'first'
35
+ */
36
+ injectPosition?: 'first' | 'last' | number | {
37
+ after?: string;
38
+ };
31
39
  /**
32
40
  * Installing UnoCSS components
33
41
  * - `<UnoIcon>`
package/dist/index.d.ts CHANGED
@@ -28,6 +28,14 @@ interface UnocssNuxtOptions extends UserConfig {
28
28
  * @default false
29
29
  */
30
30
  preflight?: boolean;
31
+ /**
32
+ * Adjust the position of the `uno.css` injection. (Depends on `mode`)
33
+ *
34
+ * @default 'first'
35
+ */
36
+ injectPosition?: 'first' | 'last' | number | {
37
+ after?: string;
38
+ };
31
39
  /**
32
40
  * Installing UnoCSS components
33
41
  * - `<UnoIcon>`
package/dist/index.mjs CHANGED
@@ -43,6 +43,27 @@ function resolveOptions(options) {
43
43
  options.content.pipeline.exclude.push(/\?macro=true/);
44
44
  }
45
45
  }
46
+ function resolveInjectPosition(css, position) {
47
+ if (typeof position === "number")
48
+ return ~~Math.min(position, css.length + 1);
49
+ if (typeof position === "string") {
50
+ switch (position) {
51
+ case "first":
52
+ return 0;
53
+ case "last":
54
+ return css.length;
55
+ default:
56
+ throw new Error(`invalid literal: ${position}`);
57
+ }
58
+ }
59
+ if (position?.after !== void 0) {
60
+ const index = css.indexOf(position.after);
61
+ if (index === -1)
62
+ throw new Error(`\`after\` position specifies a file which does not exists on CSS stack: ${position.after}`);
63
+ return index + 1;
64
+ }
65
+ throw new Error(`invalid position: ${JSON.stringify(position)}`);
66
+ }
46
67
 
47
68
  const dir = dirname(fileURLToPath(import.meta.url));
48
69
  const index = defineNuxtModule({
@@ -55,6 +76,7 @@ const index = defineNuxtModule({
55
76
  autoImport: true,
56
77
  preflight: false,
57
78
  components: true,
79
+ injectPosition: "first",
58
80
  // presets
59
81
  uno: true,
60
82
  attributify: false,
@@ -64,14 +86,18 @@ const index = defineNuxtModule({
64
86
  },
65
87
  async setup(options, nuxt) {
66
88
  resolveOptions(options);
67
- options.mode ?? (options.mode = "global");
68
- const InjectModes = ["global", "dist-chunk"];
69
89
  if (options.autoImport) {
90
+ options.mode ?? (options.mode = "global");
91
+ const InjectModes = ["global", "dist-chunk"];
92
+ nuxt.options.css = nuxt.options.css ?? [];
93
+ if (InjectModes.includes(options.mode) && !nuxt.options.css.includes("uno.css")) {
94
+ const position = resolveInjectPosition(nuxt.options.css, options.injectPosition);
95
+ nuxt.options.css.splice(position, 0, "uno.css");
96
+ }
70
97
  addPluginTemplate({
71
98
  filename: "unocss.mjs",
72
99
  getContents: () => {
73
100
  const lines = [
74
- InjectModes.includes(options.mode) ? "import 'uno.css'" : "",
75
101
  isNuxt2() ? "export default () => {}" : "import { defineNuxtPlugin } from '#imports'; export default defineNuxtPlugin(() => {})"
76
102
  ];
77
103
  if (options.preflight)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unocss/nuxt",
3
- "version": "0.58.0",
3
+ "version": "0.58.2",
4
4
  "description": "Nuxt module for UnoCSS",
5
5
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
6
6
  "license": "MIT",
@@ -37,23 +37,23 @@
37
37
  "runtime"
38
38
  ],
39
39
  "dependencies": {
40
- "@nuxt/kit": "^3.8.2",
41
- "@unocss/config": "0.58.0",
42
- "@unocss/core": "0.58.0",
43
- "@unocss/preset-attributify": "0.58.0",
44
- "@unocss/preset-icons": "0.58.0",
45
- "@unocss/preset-tagify": "0.58.0",
46
- "@unocss/preset-typography": "0.58.0",
47
- "@unocss/preset-uno": "0.58.0",
48
- "@unocss/preset-web-fonts": "0.58.0",
49
- "@unocss/preset-wind": "0.58.0",
50
- "@unocss/reset": "0.58.0",
51
- "@unocss/vite": "0.58.0",
52
- "@unocss/webpack": "0.58.0",
53
- "unocss": "0.58.0"
40
+ "@nuxt/kit": "^3.9.0",
41
+ "@unocss/core": "0.58.2",
42
+ "@unocss/config": "0.58.2",
43
+ "@unocss/preset-attributify": "0.58.2",
44
+ "@unocss/preset-icons": "0.58.2",
45
+ "@unocss/preset-typography": "0.58.2",
46
+ "@unocss/preset-tagify": "0.58.2",
47
+ "@unocss/preset-uno": "0.58.2",
48
+ "@unocss/preset-web-fonts": "0.58.2",
49
+ "@unocss/preset-wind": "0.58.2",
50
+ "@unocss/reset": "0.58.2",
51
+ "@unocss/vite": "0.58.2",
52
+ "@unocss/webpack": "0.58.2",
53
+ "unocss": "0.58.2"
54
54
  },
55
55
  "devDependencies": {
56
- "@nuxt/schema": "^3.8.2"
56
+ "@nuxt/schema": "^3.9.0"
57
57
  },
58
58
  "scripts": {
59
59
  "build": "unbuild",