From 303110d3d4d2c28bacc6b0233f5184ee8521cb5f Mon Sep 17 00:00:00 2001 From: Yash Raj Chhabra Date: Thu, 18 Sep 2025 12:21:48 +0530 Subject: [PATCH] chore: faster builds for storybook --- webpack.common.js | 42 +++++++++++++++++++++++++++++++++++++++--- webpack.dev.js | 23 ++++++++++++++++++----- 2 files changed, 57 insertions(+), 8 deletions(-) diff --git a/webpack.common.js b/webpack.common.js index b2a92eade..1716bb713 100644 --- a/webpack.common.js +++ b/webpack.common.js @@ -8,11 +8,26 @@ module.exports = (_, { mode }) => ({ octuple: [path.resolve(__dirname, 'src/octuple.ts')], locale: [path.resolve(__dirname, 'src/locale.ts')], }, + cache: { + type: 'filesystem', + cacheDirectory: path.resolve(__dirname, '.webpack-cache'), + buildDependencies: { + config: [__filename], + }, + }, module: { rules: [ { test: /\.tsx?$/, - use: 'ts-loader', + use: [ + { + loader: 'ts-loader', + options: { + transpileOnly: mode === 'development', + experimentalWatchApi: true, + }, + }, + ], exclude: /node_modules/, include: path.resolve(__dirname, 'src'), }, @@ -45,13 +60,30 @@ module.exports = (_, { mode }) => ({ ], }, optimization: { + moduleIds: 'deterministic', + splitChunks: mode === 'development' ? false : { + chunks: 'all', + cacheGroups: { + vendor: { + test: /[\\/]node_modules[\\/]/, + name: 'vendors', + chunks: 'all', + }, + }, + }, minimizer: [ new TerserPlugin({ + parallel: true, terserOptions: { keep_fnames: true, + compress: { + drop_console: mode === 'production', + }, }, }), - new CssMinimizerPlugin(), + new CssMinimizerPlugin({ + parallel: true, + }), ], }, plugins: [ @@ -61,8 +93,12 @@ module.exports = (_, { mode }) => ({ ], resolve: { extensions: ['.ts', '.tsx', '.js', '.json', '.css', '.scss'], + symlinks: false, + alias: { + '@': path.resolve(__dirname, 'src'), + }, }, - devtool: 'source-map', + devtool: mode === 'development' ? 'eval-cheap-module-source-map' : 'source-map', output: { path: path.join(__dirname, 'lib'), library: 'Octuple', diff --git a/webpack.dev.js b/webpack.dev.js index f40d49ce7..dd2c9219b 100644 --- a/webpack.dev.js +++ b/webpack.dev.js @@ -9,16 +9,29 @@ module.exports = (_, argv) => { const commonConfig = WebpackCommonConfig(_, argv); return { ...commonConfig, + mode: 'development', + stats: { + preset: 'minimal', + moduleTrace: false, + errorDetails: false, + }, plugins: [ ...commonConfig.plugins, new webpack.DefinePlugin({ VERSION: JSON.stringify(require('./package.json').version), }), - new BundleAnalyzerPlugin({ - options: { - generateStatsFile: true, - }, - }), + ...(process.env.ANALYZE ? [ + new BundleAnalyzerPlugin({ + analyzerMode: 'server', + openAnalyzer: true, + }), + ] : []), ], + optimization: { + ...commonConfig.optimization, + removeAvailableModules: false, + removeEmptyChunks: false, + splitChunks: false, + }, }; };