Skip to content

advancedChunks weird splitting #250

Closed
Closed
@Micnubinub

Description

@Micnubinub

Describe the bug

I think there is something wrong with advancedChunks. I have so many small mapbox chunks, then 1 big 1 over the size limit?

Image

Reproduction

not sure if reproducable without whole codebase

Steps to reproduce

vite build with this config:

import { resolve } from 'node:path';
import tailwindcss from '@tailwindcss/vite';
import react from '@vitejs/plugin-react-oxc';
import { visualizer } from 'rollup-plugin-visualizer';
import { defineConfig, loadEnv } from 'vite';
const CORE = /sentry|zustand|vite|mui|src/app/;

export default defineConfig(({ mode }) => {
process.env = { ...process.env, ...loadEnv(mode, process.cwd()) };
return {

	define: {
		global: 'globalThis',
		_global: '{}'
	},
	resolve: {
		alias: [{ find: '@', replacement: resolve(__dirname, './src/') }]
	},
	server: {
		port: 9100,
		open: true
	},
	base: './',
	build: {
		assetsDir: '.',
		commonjsOptions: {
			transformMixedEsModules: true
		},
		reportCompressedSize: false,
		cssCodeSplit: true,
		emptyOutDir: true,
		rollupOptions: {
			treeshake: true,
			output: {
				assetFileNames: (assetInfo) => {
					if (assetInfo.names.some((name) => name.includes('favicon')))
						return '[name].[ext]';
					return '[name]-[hash].[ext]';
				},
				advancedChunks: {
					maxSize: 1_000,
					minSize: 500,
					groups: [
						{
							maxSize,
							name: 'mapbox',
							test: (id) =>
								id.toLowerCase().includes('mapbox') && !CORE.test(id)
						},
						{
							name: 'pdf',
							test: (id) => id.toLowerCase().includes('pdf') && !CORE.test(id)
						},
						{
							name: 'konva',
							test: (id) =>
								id.toLowerCase().includes('konva') && !CORE.test(id)
						}
					]
				}
			},
			cache: false
		},
		minify: true,
		outDir: '../dist/web/',
		sourcemap: true
	},
	plugins: [
		tailwindcss({
			minify: true
		}),
		react(),
		process.env.GITHUB_ACTIONS
			? undefined
			: visualizer({
					open: false, // TODO check sizes
					filename: 'tmpStats.html'
				})
	]
};

});

System Info

System:
    OS: macOS 15.5
    CPU: (10) arm64 Apple M1 Pro
    Memory: 1.79 GB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 24.2.0 - /opt/homebrew/bin/node
    Yarn: 1.22.22 - /opt/homebrew/bin/yarn
    npm: 8.19.2 - /usr/local/bin/npm
    bun: 1.2.15 - /opt/homebrew/bin/bun

Used Package Manager

bun

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions