@unocss/nuxt 0.60.3 → 0.61.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.d.mts CHANGED
@@ -34,6 +34,12 @@ interface UnocssNuxtOptions extends UserConfig {
34
34
  * @default true
35
35
  */
36
36
  disableNuxtInlineStyle?: boolean;
37
+ /**
38
+ * Automatically merge UnoCSS configs from Nuxt layers.
39
+ *
40
+ * @default false
41
+ */
42
+ nuxtLayers?: boolean;
37
43
  /**
38
44
  * Adjust the position of the `uno.css` injection. (Depends on `mode`)
39
45
  *
package/dist/index.d.ts CHANGED
@@ -34,6 +34,12 @@ interface UnocssNuxtOptions extends UserConfig {
34
34
  * @default true
35
35
  */
36
36
  disableNuxtInlineStyle?: boolean;
37
+ /**
38
+ * Automatically merge UnoCSS configs from Nuxt layers.
39
+ *
40
+ * @default false
41
+ */
42
+ nuxtLayers?: boolean;
37
43
  /**
38
44
  * Adjust the position of the `uno.css` injection. (Depends on `mode`)
39
45
  *
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { dirname, resolve } from 'node:path';
2
2
  import { fileURLToPath } from 'node:url';
3
3
  import process from 'node:process';
4
- import { defineNuxtModule, addPluginTemplate, isNuxt2, addComponentsDir, isNuxt3, extendWebpackConfig } from '@nuxt/kit';
4
+ import { defineNuxtModule, addPluginTemplate, isNuxt2, addComponentsDir, addTemplate, findPath, extendWebpackConfig, isNuxt3 } from '@nuxt/kit';
5
5
  import WebpackPlugin from '@unocss/webpack';
6
6
  import VitePlugin from '@unocss/vite';
7
7
  import { loadConfig } from '@unocss/config';
@@ -56,6 +56,7 @@ const index = defineNuxtModule({
56
56
  preflight: false,
57
57
  components: true,
58
58
  disableNuxtInlineStyle: true,
59
+ nuxtLayers: false,
59
60
  // presets
60
61
  uno: true,
61
62
  attributify: false,
@@ -94,22 +95,44 @@ const index = defineNuxtModule({
94
95
  watch: false
95
96
  });
96
97
  }
97
- const { config: unoConfig } = await loadConfig(process.cwd(), {
98
- configFile: options.configFile
99
- }, [], options);
100
- await nuxt.callHook("unocss:config", unoConfig);
101
- if (isNuxt3() && nuxt.options.builder === "@nuxt/vite-builder" && nuxt.options.postcss.plugins.cssnano && unoConfig.transformers?.some((t) => t.name === "@unocss/transformer-directives" && t.enforce !== "pre")) {
102
- const preset = nuxt.options.postcss.plugins.cssnano.preset;
103
- nuxt.options.postcss.plugins.cssnano = {
104
- preset: [preset?.[0] || "default", Object.assign(
105
- { mergeRules: false, normalizeWhitespace: false, discardComments: false },
106
- preset?.[1]
107
- )]
108
- };
98
+ if (options.nuxtLayers) {
99
+ addTemplate({
100
+ filename: "uno.config.mjs",
101
+ async getContents() {
102
+ const configPaths = (await Promise.all(nuxt.options._layers.map(
103
+ (layer) => findPath(options.configFile || ["uno.config", "unocss.config"], { cwd: layer.config.srcDir })
104
+ ))).filter(Boolean).reverse();
105
+ return `import { mergeConfigs } from '@unocss/core'
106
+ ${configPaths.map((path, index) => `import cfg${index} from '${path}'`.trimStart()).join("\n").trimEnd()}
107
+
108
+ export default mergeConfigs([${configPaths.map((_, index) => `cfg${index}`).join(", ")}])
109
+ `;
110
+ },
111
+ write: true
112
+ });
113
+ }
114
+ async function loadUnoConfig() {
115
+ const { config: unoConfig } = await loadConfig(process.cwd(), {
116
+ configFile: options.nuxtLayers ? resolve(nuxt.options.buildDir, "uno.config.mjs") : options.configFile
117
+ }, [], options);
118
+ await nuxt.callHook("unocss:config", unoConfig);
119
+ if (isNuxt3() && nuxt.options.builder === "@nuxt/vite-builder" && nuxt.options.postcss.plugins.cssnano && unoConfig.transformers?.some((t) => t.name === "@unocss/transformer-directives" && t.enforce !== "pre")) {
120
+ const preset = nuxt.options.postcss.plugins.cssnano.preset;
121
+ nuxt.options.postcss.plugins.cssnano = {
122
+ preset: [preset?.[0] || "default", Object.assign(
123
+ { mergeRules: false, normalizeWhitespace: false, discardComments: false },
124
+ preset?.[1]
125
+ )]
126
+ };
127
+ }
128
+ return unoConfig;
109
129
  }
110
- nuxt.hook("vite:extend", ({ config }) => {
130
+ nuxt.hook("vite:extend", async ({ config }) => {
131
+ const unoConfig = await loadUnoConfig();
111
132
  config.plugins = config.plugins || [];
112
- config.plugins.unshift(...VitePlugin({ mode: options.mode }, unoConfig));
133
+ config.plugins.unshift(...VitePlugin({
134
+ mode: options.mode
135
+ }, unoConfig));
113
136
  });
114
137
  if (nuxt.options.dev) {
115
138
  nuxt.hook("devtools:customTabs", (tabs) => {
@@ -133,7 +156,8 @@ const index = defineNuxtModule({
133
156
  config.plugins = [plugin];
134
157
  });
135
158
  }
136
- extendWebpackConfig((config) => {
159
+ extendWebpackConfig(async (config) => {
160
+ const unoConfig = await loadUnoConfig();
137
161
  config.plugins = config.plugins || [];
138
162
  config.plugins.unshift(WebpackPlugin({}, unoConfig));
139
163
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unocss/nuxt",
3
3
  "type": "module",
4
- "version": "0.60.3",
4
+ "version": "0.61.0",
5
5
  "description": "Nuxt module for UnoCSS",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -38,23 +38,23 @@
38
38
  "runtime"
39
39
  ],
40
40
  "dependencies": {
41
- "@nuxt/kit": "^3.11.2",
42
- "@unocss/config": "0.60.3",
43
- "@unocss/core": "0.60.3",
44
- "@unocss/preset-attributify": "0.60.3",
45
- "@unocss/preset-tagify": "0.60.3",
46
- "@unocss/preset-icons": "0.60.3",
47
- "@unocss/preset-typography": "0.60.3",
48
- "@unocss/preset-uno": "0.60.3",
49
- "@unocss/preset-web-fonts": "0.60.3",
50
- "@unocss/preset-wind": "0.60.3",
51
- "@unocss/reset": "0.60.3",
52
- "@unocss/vite": "0.60.3",
53
- "@unocss/webpack": "0.60.3",
54
- "unocss": "0.60.3"
41
+ "@nuxt/kit": "^3.12.1",
42
+ "@unocss/config": "0.61.0",
43
+ "@unocss/core": "0.61.0",
44
+ "@unocss/preset-icons": "0.61.0",
45
+ "@unocss/preset-attributify": "0.61.0",
46
+ "@unocss/preset-tagify": "0.61.0",
47
+ "@unocss/preset-typography": "0.61.0",
48
+ "@unocss/preset-uno": "0.61.0",
49
+ "@unocss/preset-web-fonts": "0.61.0",
50
+ "@unocss/preset-wind": "0.61.0",
51
+ "@unocss/reset": "0.61.0",
52
+ "@unocss/vite": "0.61.0",
53
+ "@unocss/webpack": "0.61.0",
54
+ "unocss": "0.61.0"
55
55
  },
56
56
  "devDependencies": {
57
- "@nuxt/schema": "^3.11.2"
57
+ "@nuxt/schema": "^3.12.1"
58
58
  },
59
59
  "scripts": {
60
60
  "build": "unbuild",