Skip to content

Commit 68e6405

Browse files
committed
feat: added manual chunking of vendor JS to reduce size
1 parent 4ee7597 commit 68e6405

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

vite.config.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { defineConfig, PluginOption, loadEnv } from 'vite'
1+
import { defineConfig, PluginOption, loadEnv, splitVendorChunkPlugin } from 'vite'
22
import react from '@vitejs/plugin-react'
33
import svgr from 'vite-plugin-svgr'
44
import fs from 'node:fs/promises'
@@ -8,7 +8,6 @@ import { createRequire } from 'node:module'
88
import requireTransform from 'vite-plugin-require-transform'
99
import { NodeGlobalsPolyfillPlugin } from '@esbuild-plugins/node-globals-polyfill'
1010
import { VitePWA } from 'vite-plugin-pwa'
11-
import replace from '@rollup/plugin-replace'
1211

1312
const WRONG_CODE = `import { bpfrpt_proptype_WindowScroller } from "../WindowScroller.js";`
1413

@@ -44,14 +43,36 @@ export default defineConfig(({ mode }) => {
4443
port: 3000,
4544
},
4645
build: {
47-
sourcemap: true,
46+
sourcemap: true,
47+
rollupOptions: {
48+
output: {
49+
manualChunks(id: string) {
50+
// separating the common lib chunk
51+
if (id.includes('devtron-fe-common-lib')) {
52+
return 'devtron-fe-common-lib';
53+
}
54+
if (id.includes('@devtron')) {
55+
return '@devtron';
56+
}
57+
// creating a chunk to react routes deps. Reducing the vendor chunk size
58+
if (
59+
id.includes('react-router-dom') ||
60+
id.includes('@react') ||
61+
id.includes('react-router')
62+
) {
63+
return '@react-router';
64+
}
65+
},
66+
},
67+
},
4868
},
4969
plugins: [
5070
// @TODO: Check if we can remove the config object inside the react plugin
5171
react({
5272
// Use React plugin in all *.jsx and *.tsx files
5373
include: '**/*.{jsx,tsx}',
5474
}),
75+
splitVendorChunkPlugin(),
5576
svgr({
5677
svgrOptions: {},
5778
}),

0 commit comments

Comments
 (0)