From eeb5882e96c2f3fd1dd928770c48b2002ff48f31 Mon Sep 17 00:00:00 2001 From: Gowtham Shanmugasundaram Date: Wed, 7 Aug 2024 22:47:45 +0530 Subject: [PATCH] Optimize chunk size by changing devtool Signed-off-by: Gowtham Shanmugasundaram --- webpack.config.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/webpack.config.ts b/webpack.config.ts index 45deee428..26dc4fea6 100644 --- a/webpack.config.ts +++ b/webpack.config.ts @@ -20,6 +20,7 @@ const NODE_ENV = (process.env.NODE_ENV || 'development') as webpack.Configuration['mode']; const PLUGIN = process.env.PLUGIN; const OPENSHIFT_CI = process.env.OPENSHIFT_CI; +const isProduction = NODE_ENV === 'production'; if (PLUGIN === undefined) { process.exit(1); @@ -86,7 +87,7 @@ const config: webpack.Configuration & DevServerConfiguration = { { loader: 'thread-loader', options: { - ...(NODE_ENV === 'development' + ...(!isProduction ? { poolTimeout: Infinity, poolRespawn: false } : OPENSHIFT_CI ? { @@ -153,13 +154,15 @@ const config: webpack.Configuration & DevServerConfiguration = { cwd: process.cwd(), }), ], - devtool: 'eval-cheap-module-source-map', + // 'source-map' is recommended choice for production builds, A full SourceMap is emitted as a separate file. + // 'eval-source-map' is recommended for development but 'eval-cheap-module-source-map' is faster and gives better result. + devtool: isProduction ? 'source-map' : 'eval-cheap-module-source-map', optimization: { chunkIds: 'named', }, }; -if (NODE_ENV === 'production' || process.env.DEV_NO_TYPE_CHECK !== 'true') { +if (isProduction || process.env.DEV_NO_TYPE_CHECK !== 'true') { config.plugins?.push( new ForkTsCheckerWebpackPlugin({ issue: {