@nuxt/kit-nightly 4.2.0-29344233.e79f117e → 4.2.0-29344661.0b65203b

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
@@ -158,7 +158,23 @@ interface ExtendConfigOptions {
158
158
  }
159
159
  interface ExtendWebpackConfigOptions extends ExtendConfigOptions {
160
160
  }
161
- interface ExtendViteConfigOptions extends ExtendConfigOptions {
161
+ interface ExtendViteConfigOptions extends Omit<ExtendConfigOptions, 'server' | 'client'> {
162
+ /**
163
+ * Extend server Vite configuration
164
+ * @default true
165
+ * @deprecated calling \`extendViteConfig\` with only server/client environment is deprecated.
166
+ * Nuxt 5+ uses the Vite Environment API which shares a configuration between environments.
167
+ * You can likely use a Vite plugin to achieve the same result.
168
+ */
169
+ server?: boolean;
170
+ /**
171
+ * Extend client Vite configuration
172
+ * @default true
173
+ * @deprecated calling \`extendViteConfig\` with only server/client environment is deprecated.
174
+ * Nuxt 5+ uses the Vite Environment API which shares a configuration between environments.
175
+ * You can likely use a Vite plugin to achieve the same result.
176
+ */
177
+ client?: boolean;
162
178
  }
163
179
  /**
164
180
  * Extend webpack config
@@ -189,7 +205,7 @@ declare function addRspackPlugin(pluginOrGetter: RspackPluginInstance | RspackPl
189
205
  /**
190
206
  * Append Vite plugin to the config.
191
207
  */
192
- declare function addVitePlugin(pluginOrGetter: Plugin | Plugin[] | (() => Plugin | Plugin[]), options?: ExtendViteConfigOptions): void;
208
+ declare function addVitePlugin(pluginOrGetter: Plugin | Plugin[] | (() => Plugin | Plugin[]), options?: ExtendConfigOptions): void;
193
209
  interface AddBuildPluginFactory {
194
210
  vite?: () => Plugin | Plugin[];
195
211
  webpack?: () => WebpackPluginInstance | WebpackPluginInstance[];
package/dist/index.d.ts CHANGED
@@ -158,7 +158,23 @@ interface ExtendConfigOptions {
158
158
  }
159
159
  interface ExtendWebpackConfigOptions extends ExtendConfigOptions {
160
160
  }
161
- interface ExtendViteConfigOptions extends ExtendConfigOptions {
161
+ interface ExtendViteConfigOptions extends Omit<ExtendConfigOptions, 'server' | 'client'> {
162
+ /**
163
+ * Extend server Vite configuration
164
+ * @default true
165
+ * @deprecated calling \`extendViteConfig\` with only server/client environment is deprecated.
166
+ * Nuxt 5+ uses the Vite Environment API which shares a configuration between environments.
167
+ * You can likely use a Vite plugin to achieve the same result.
168
+ */
169
+ server?: boolean;
170
+ /**
171
+ * Extend client Vite configuration
172
+ * @default true
173
+ * @deprecated calling \`extendViteConfig\` with only server/client environment is deprecated.
174
+ * Nuxt 5+ uses the Vite Environment API which shares a configuration between environments.
175
+ * You can likely use a Vite plugin to achieve the same result.
176
+ */
177
+ client?: boolean;
162
178
  }
163
179
  /**
164
180
  * Extend webpack config
@@ -189,7 +205,7 @@ declare function addRspackPlugin(pluginOrGetter: RspackPluginInstance | RspackPl
189
205
  /**
190
206
  * Append Vite plugin to the config.
191
207
  */
192
- declare function addVitePlugin(pluginOrGetter: Plugin | Plugin[] | (() => Plugin | Plugin[]), options?: ExtendViteConfigOptions): void;
208
+ declare function addVitePlugin(pluginOrGetter: Plugin | Plugin[] | (() => Plugin | Plugin[]), options?: ExtendConfigOptions): void;
193
209
  interface AddBuildPluginFactory {
194
210
  vite?: () => Plugin | Plugin[];
195
211
  webpack?: () => WebpackPluginInstance | WebpackPluginInstance[];
package/dist/index.mjs CHANGED
@@ -1162,17 +1162,13 @@ function extendViteConfig(fn, options = {}) {
1162
1162
  if (options.build === false && nuxt.options.build) {
1163
1163
  return;
1164
1164
  }
1165
- if (options.server !== false && options.client !== false) {
1166
- return nuxt.hook("vite:extend", ({ config }) => fn(config));
1165
+ if (options.server === false || options.client === false) {
1166
+ const caller = getUserCaller();
1167
+ const explanation = caller ? ` (used at \`${resolveAlias(caller.source)}:${caller.line}:${caller.column}\`)` : "";
1168
+ const warning = `[@nuxt/kit] calling \`extendViteConfig\` with only server/client environment is deprecated${explanation}. Nuxt 5+ will use the Vite Environment API which shares a configuration between environments. You can likely use a Vite plugin to achieve the same result.`;
1169
+ warn(warning);
1167
1170
  }
1168
- nuxt.hook("vite:extendConfig", (config, { isClient, isServer }) => {
1169
- if (options.server !== false && isServer) {
1170
- return fn(config);
1171
- }
1172
- if (options.client !== false && isClient) {
1173
- return fn(config);
1174
- }
1175
- });
1171
+ return nuxt.hook("vite:extend", ({ config }) => fn(config));
1176
1172
  }
1177
1173
  function addWebpackPlugin(pluginOrGetter, options) {
1178
1174
  extendWebpackConfig((config) => {
@@ -1190,13 +1186,52 @@ function addRspackPlugin(pluginOrGetter, options) {
1190
1186
  config.plugins[method](...toArray(plugin));
1191
1187
  }, options);
1192
1188
  }
1193
- function addVitePlugin(pluginOrGetter, options) {
1194
- extendViteConfig((config) => {
1195
- const method = options?.prepend ? "unshift" : "push";
1196
- const plugin = typeof pluginOrGetter === "function" ? pluginOrGetter() : pluginOrGetter;
1189
+ function addVitePlugin(pluginOrGetter, options = {}) {
1190
+ const nuxt = useNuxt();
1191
+ if (options.dev === false && nuxt.options.dev) {
1192
+ return;
1193
+ }
1194
+ if (options.build === false && nuxt.options.build) {
1195
+ return;
1196
+ }
1197
+ let needsEnvInjection = false;
1198
+ nuxt.hook("vite:extend", ({ config }) => {
1197
1199
  config.plugins ||= [];
1198
- config.plugins[method](...toArray(plugin));
1199
- }, options);
1200
+ const plugin = toArray(typeof pluginOrGetter === "function" ? pluginOrGetter() : pluginOrGetter);
1201
+ if (options.server !== false && options.client !== false) {
1202
+ const method = options?.prepend ? "unshift" : "push";
1203
+ config.plugins[method](...plugin);
1204
+ return;
1205
+ }
1206
+ if (!config.environments?.ssr || !config.environments.client) {
1207
+ needsEnvInjection = true;
1208
+ return;
1209
+ }
1210
+ const environmentName = options.server === false ? "client" : "ssr";
1211
+ const pluginName = plugin.map((p) => p.name).join("|");
1212
+ config.plugins.push({
1213
+ name: `${pluginName}:wrapper`,
1214
+ enforce: options?.prepend ? "pre" : "post",
1215
+ applyToEnvironment(environment) {
1216
+ if (environment.name === environmentName) {
1217
+ return plugin;
1218
+ }
1219
+ }
1220
+ });
1221
+ });
1222
+ nuxt.hook("vite:extendConfig", (config, env) => {
1223
+ if (!needsEnvInjection) {
1224
+ return;
1225
+ }
1226
+ const plugin = toArray(typeof pluginOrGetter === "function" ? pluginOrGetter() : pluginOrGetter);
1227
+ const method = options?.prepend ? "unshift" : "push";
1228
+ if (env.isClient && options.server === false) {
1229
+ config.plugins[method](...plugin);
1230
+ }
1231
+ if (env.isServer && options.client === false) {
1232
+ config.plugins[method](...plugin);
1233
+ }
1234
+ });
1200
1235
  }
1201
1236
  function addBuildPlugin(pluginFactory, options) {
1202
1237
  if (pluginFactory.vite) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/kit-nightly",
3
- "version": "4.2.0-29344233.e79f117e",
3
+ "version": "4.2.0-29344661.0b65203b",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/nuxt/nuxt.git",
@@ -45,7 +45,7 @@
45
45
  "untyped": "^2.0.0"
46
46
  },
47
47
  "devDependencies": {
48
- "@nuxt/schema": "npm:@nuxt/schema-nightly@4.2.0-29344233.e79f117e",
48
+ "@nuxt/schema": "npm:@nuxt/schema-nightly@4.2.0-29344661.0b65203b",
49
49
  "@rspack/core": "1.5.8",
50
50
  "@types/semver": "7.7.1",
51
51
  "hookable": "5.5.3",