diff --git a/packages/webpack/src/configs/client.ts b/packages/webpack/src/configs/client.ts index 29ed60a27d..37b06bcc9c 100644 --- a/packages/webpack/src/configs/client.ts +++ b/packages/webpack/src/configs/client.ts @@ -10,11 +10,11 @@ import type { WebpackConfigContext } from '../utils/config' import { applyPresets } from '../utils/config' import { nuxt } from '../presets/nuxt' -export function client (ctx: WebpackConfigContext) { +export async function client (ctx: WebpackConfigContext) { ctx.name = 'client' ctx.isClient = true - applyPresets(ctx, [ + await applyPresets(ctx, [ nuxt, clientPlugins, clientOptimization, diff --git a/packages/webpack/src/configs/server.ts b/packages/webpack/src/configs/server.ts index 6f7dc00f50..09bb782543 100644 --- a/packages/webpack/src/configs/server.ts +++ b/packages/webpack/src/configs/server.ts @@ -9,11 +9,11 @@ import { node } from '../presets/node' const assetPattern = /\.(css|s[ca]ss|png|jpe?g|gif|svg|woff2?|eot|ttf|otf|webp|webm|mp4|ogv)(\?.*)?$/i -export function server (ctx: WebpackConfigContext) { +export async function server (ctx: WebpackConfigContext) { ctx.name = 'server' ctx.isServer = true - applyPresets(ctx, [ + await applyPresets(ctx, [ nuxt, node, serverStandalone, diff --git a/packages/webpack/src/presets/base.ts b/packages/webpack/src/presets/base.ts index 1ce556ac41..ffcfb17930 100644 --- a/packages/webpack/src/presets/base.ts +++ b/packages/webpack/src/presets/base.ts @@ -16,8 +16,8 @@ import WarningIgnorePlugin from '../plugins/warning-ignore' import type { WebpackConfigContext } from '../utils/config' import { applyPresets, fileName } from '../utils/config' -export function base (ctx: WebpackConfigContext) { - applyPresets(ctx, [ +export async function base (ctx: WebpackConfigContext) { + await applyPresets(ctx, [ baseAlias, baseConfig, basePlugins, diff --git a/packages/webpack/src/presets/nuxt.ts b/packages/webpack/src/presets/nuxt.ts index 6b533fe2a9..f1b2e2bb06 100644 --- a/packages/webpack/src/presets/nuxt.ts +++ b/packages/webpack/src/presets/nuxt.ts @@ -8,8 +8,8 @@ import { pug } from './pug' import { style } from './style' import { vue } from './vue' -export function nuxt (ctx: WebpackConfigContext) { - applyPresets(ctx, [ +export async function nuxt (ctx: WebpackConfigContext) { + await applyPresets(ctx, [ base, assets, esbuild, diff --git a/packages/webpack/src/presets/style.ts b/packages/webpack/src/presets/style.ts index 4ef1f3bce0..41f700f3de 100644 --- a/packages/webpack/src/presets/style.ts +++ b/packages/webpack/src/presets/style.ts @@ -4,8 +4,8 @@ import type { WebpackConfigContext } from '../utils/config' import { applyPresets, fileName } from '../utils/config' import { getPostcssConfig } from '../utils/postcss' -export function style (ctx: WebpackConfigContext) { - applyPresets(ctx, [ +export async function style (ctx: WebpackConfigContext) { + await applyPresets(ctx, [ loaders, extractCSS, minimizer diff --git a/packages/webpack/src/utils/config.ts b/packages/webpack/src/utils/config.ts index a9ac4b4acb..3a3e1127a9 100644 --- a/packages/webpack/src/utils/config.ts +++ b/packages/webpack/src/utils/config.ts @@ -36,15 +36,15 @@ export function createWebpackConfigContext (nuxt: Nuxt): WebpackConfigContext { } } -export function applyPresets (ctx: WebpackConfigContext, presets: WebpackConfigPresetItem | WebpackConfigPresetItem[]) { +export async function applyPresets (ctx: WebpackConfigContext, presets: WebpackConfigPresetItem | WebpackConfigPresetItem[]) { if (!Array.isArray(presets)) { presets = [presets] } for (const preset of presets) { if (Array.isArray(preset)) { - preset[0](ctx, preset[1]) + await preset[0](ctx, preset[1]) } else { - preset(ctx) + await preset(ctx) } } } diff --git a/packages/webpack/src/webpack.ts b/packages/webpack/src/webpack.ts index 14ab2d95b3..57f7d6d7b0 100644 --- a/packages/webpack/src/webpack.ts +++ b/packages/webpack/src/webpack.ts @@ -25,12 +25,12 @@ import { applyPresets, createWebpackConfigContext, getWebpackConfig } from './ut export async function bundle (nuxt: Nuxt) { registerVirtualModules() - const webpackConfigs = [client, ...nuxt.options.ssr ? [server] : []].map((preset) => { + const webpackConfigs = await Promise.all([client, ...nuxt.options.ssr ? [server] : []].map(async (preset) => { const ctx = createWebpackConfigContext(nuxt) ctx.userConfig = defu(nuxt.options.webpack[`$${preset.name as 'client' | 'server'}`], ctx.userConfig) - applyPresets(ctx, preset) + await applyPresets(ctx, preset) return getWebpackConfig(ctx) - }) + })) await nuxt.callHook('webpack:config', webpackConfigs)