Compare commits

...

1 Commits

Author SHA1 Message Date
Yunus M
4ad19b5259 chore: implement vendor chunk splitting for production builds
Add strategic code splitting to reduce main bundle size from 11MB to 3.7MB
(66% reduction) and improve browser caching efficiency.

Changes:
- Add splitChunks configuration with vendor cache groups:
  * vendors-react: React, Redux, Router (~168KB)
  * vendors-antd: Ant Design core (~1.6MB)
  * vendors-antd-icons: Ant Design icons (~150KB)
  * vendors-charts: Chart libraries (~264KB)
  * vendors-react-query: React Query (~47KB)
  * vendors-signozhq: SigNoz UI components (~338KB)
  * vendors-utilities: lodash-es, dnd-kit, dayjs, axios, i18next (~198KB)
  * vendors-monaco: Monaco editor (~11KB)
  * vendors-common: Other shared dependencies (~1.2MB)
- Enable module concatenation for better tree-shaking
- Update bundlesize.config.json with granular limits per chunk type
- Restrict window.store exposure to development only

Performance Impact:
- Main bundle: 11MB → 3.7MB (66% reduction)
- Total build: 250MB → 97MB (61% reduction)
- Better browser caching (vendor chunks change less frequently)
- Faster subsequent page loads (cached vendor chunks)

Breaking Changes: None
Migration: None required
2026-02-05 10:21:09 +05:30
3 changed files with 127 additions and 4 deletions

View File

@@ -1,8 +1,52 @@
{
"files": [
{
"path": "./build/**.js",
"maxSize": "1.2MB"
"path": "./build/runtime~*.js",
"maxSize": "50KB"
},
{
"path": "./build/vendors-react.*.js",
"maxSize": "300KB"
},
{
"path": "./build/vendors-antd.*.js",
"maxSize": "1MB"
},
{
"path": "./build/vendors-antd-icons.*.js",
"maxSize": "2.5MB"
},
{
"path": "./build/vendors-charts.*.js",
"maxSize": "400KB"
},
{
"path": "./build/vendors-react-query.*.js",
"maxSize": "100KB"
},
{
"path": "./build/vendors-utilities.*.js",
"maxSize": "600KB"
},
{
"path": "./build/vendors-monaco.*.js",
"maxSize": "3MB"
},
{
"path": "./build/vendors-common.*.js",
"maxSize": "800KB"
},
{
"path": "./build/main.*.js",
"maxSize": "500KB"
},
{
"path": "./build/Home.*.js",
"maxSize": "300KB"
},
{
"path": "./build/*.js",
"maxSize": "1MB"
}
]
}

View File

@@ -20,7 +20,7 @@ const store = createStore(
export type AppDispatch = typeof store.dispatch;
if (window !== undefined) {
if (window !== undefined && process.env.NODE_ENV === 'development') {
window.store = store;
}

View File

@@ -171,7 +171,7 @@ const config = {
plugins,
optimization: {
chunkIds: 'named',
concatenateModules: false,
concatenateModules: true, // Enable module concatenation for better tree-shaking and smaller bundles
emitOnErrors: true,
flagIncludedChunks: true,
innerGraph: true, // tells webpack whether to conduct inner graph analysis for unused exports.
@@ -182,6 +182,85 @@ const config = {
runtimeChunk: {
name: (entrypoint) => `runtime~${entrypoint.name}`,
},
splitChunks: {
chunks: 'all',
maxInitialRequests: 30,
minSize: 20000,
cacheGroups: {
// Vendor libraries - React, React-DOM, Redux, Router
vendor: {
test: /[\\/]node_modules[\\/](react|react-dom|react-router|react-router-dom|react-redux|redux|@reduxjs)[\\/]/,
name: 'vendors-react',
priority: 30,
reuseExistingChunk: true,
enforce: true,
},
// Ant Design icons (separate from core - icons are huge)
antdIcons: {
test: /[\\/]node_modules[\\/](@ant-design\/icons)[\\/]/,
name: 'vendors-antd-icons',
priority: 25,
reuseExistingChunk: true,
enforce: true,
},
// Ant Design core (without icons) - matches antd and @ant-design but not @ant-design/icons
antd: {
test: /[\\/]node_modules[\\/](antd|@ant-design(?!\/icons))[\\/]/,
name: 'vendors-antd',
priority: 20,
reuseExistingChunk: true,
enforce: true,
},
// SigNoz UI components
signozhq: {
test: /[\\/]node_modules[\\/](@signozhq)[\\/]/,
name: 'vendors-signozhq',
priority: 19,
reuseExistingChunk: true,
enforce: true,
},
// Chart libraries
charts: {
test: /[\\/]node_modules[\\/](uplot|chart\.js|@visx|@tanstack\/react-table|@tanstack\/react-virtual)[\\/]/,
name: 'vendors-charts',
priority: 18,
reuseExistingChunk: true,
enforce: true,
},
// React Query
reactQuery: {
test: /[\\/]node_modules[\\/](react-query|@tanstack\/react-query)[\\/]/,
name: 'vendors-react-query',
priority: 17,
reuseExistingChunk: true,
enforce: true,
},
// Large utility libraries
utilities: {
test: /[\\/]node_modules[\\/](lodash-es|@dnd-kit|dayjs|axios|i18next)[\\/]/,
name: 'vendors-utilities',
priority: 15,
reuseExistingChunk: true,
enforce: true,
},
// Monaco editor (very large)
monaco: {
test: /[\\/]node_modules[\\/](@monaco-editor|monaco-editor)[\\/]/,
name: 'vendors-monaco',
priority: 16,
reuseExistingChunk: true,
enforce: true,
},
// Other vendor libraries
common: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors-common',
priority: 10,
minChunks: 2,
reuseExistingChunk: true,
},
},
},
minimizer: [
new TerserPlugin({
parallel: true,