From 1f103989344230e6789cf562dce74aebb98777eb Mon Sep 17 00:00:00 2001 From: Matt Lewis Date: Wed, 6 Sep 2023 19:24:27 +0100 Subject: [PATCH] fix(webpack): enable in memory caching when building for node in watch mode (#18348) (cherry picked from commit f30174b677e760b44daac9988ce2a3c68acade35) --- packages/webpack/src/utils/with-nx.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/webpack/src/utils/with-nx.ts b/packages/webpack/src/utils/with-nx.ts index d0c518877d087..7261e10d1e40d 100644 --- a/packages/webpack/src/utils/with-nx.ts +++ b/packages/webpack/src/utils/with-nx.ts @@ -191,6 +191,12 @@ export function withNx(pluginOptions?: WithNxOptions): NxWebpackPlugin { process.env.NODE_ENV === 'production' ? (process.env.NODE_ENV as 'development' | 'production') : ('none' as const), + // When target is Node, the Webpack mode will be set to 'none' which disables in memory caching and causes a full rebuild on every change. + // So to mitigate this we enable in memory caching when target is Node and in watch mode. + cache: + options.target === ('node' as const) && options.watch + ? { type: 'memory' as const } + : undefined, devtool: options.sourceMap === 'hidden' ? 'hidden-source-map'