From e891ea0cca70ba3899b3d9579819c3730cfca065 Mon Sep 17 00:00:00 2001 From: Ahad Birang Date: Sun, 13 Mar 2022 22:13:41 +0330 Subject: [PATCH] feat(webpack): add `webpack:devMiddleware` and `webpack:hotMiddleware` hooks (#3606) --- packages/schema/src/types/hooks.ts | 2 ++ packages/webpack/src/webpack.ts | 3 +++ 2 files changed, 5 insertions(+) diff --git a/packages/schema/src/types/hooks.ts b/packages/schema/src/types/hooks.ts index a2336996aa..f0d8dd70ad 100644 --- a/packages/schema/src/types/hooks.ts +++ b/packages/schema/src/types/hooks.ts @@ -143,6 +143,8 @@ export interface NuxtHooks { // @nuxt/webpack 'webpack:config': (webpackConfigs: Configuration[]) => HookResult + 'webpack:devMiddleware': (middleware: (req: IncomingMessage, res: ServerResponse, next: (err?: any) => any) => any) => HookResult + 'webpack:hotMiddleware': (middleware: (req: IncomingMessage, res: ServerResponse, next: (err?: any) => any) => any) => HookResult 'build:compile': (options: { name: string, compiler: Compiler }) => HookResult 'build:compiled': (options: { name: string, compiler: Compiler, stats: Stats }) => HookResult 'build:resources': (mfs?: Compiler['outputFileSystem']) => HookResult diff --git a/packages/webpack/src/webpack.ts b/packages/webpack/src/webpack.ts index 154e9bd15c..01de8b5259 100644 --- a/packages/webpack/src/webpack.ts +++ b/packages/webpack/src/webpack.ts @@ -89,6 +89,9 @@ async function createDevMiddleware (compiler: Compiler) { ...hotMiddlewareOptions })) + await nuxt.callHook('webpack:devMiddleware', devMiddleware) + await nuxt.callHook('webpack:hotMiddleware', hotMiddleware) + // Register devMiddleware on server await nuxt.callHook('server:devMiddleware', async (req, res, next) => { for (const mw of [devMiddleware, hotMiddleware]) {