Another attempt at chunking

This commit is contained in:
IRBorisov 2023-08-13 23:51:48 +03:00
parent d9fbb57fc6
commit bfb88c5cd7
2 changed files with 24 additions and 1 deletions

View File

@ -6,5 +6,5 @@
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true
},
"include": ["vite.config.ts"]
"include": ["vite.config.ts", "package.json"]
}

View File

@ -1,10 +1,33 @@
import react from '@vitejs/plugin-react';
import { defineConfig } from 'vite';
import { dependencies } from './package.json'
const exclVendors = ['react', 'react-router-dom', 'react-dom']
function renderChunks(deps: Record<string, string>) {
const chunks = {}
Object.keys(deps).forEach((key) => {
if (exclVendors.includes(key)) return
chunks[key] = [key]
})
return chunks
}
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
server: {
port: 3000
},
build: {
chunkSizeWarningLimit: 4000, // KB
sourcemap: false,
rollupOptions: {
output: {
manualChunks: {
...renderChunks(dependencies),
},
},
},
}
})