fix: build warning about chunik size
This commit is contained in:
25
tests/renderer/viteConfig.test.ts
Normal file
25
tests/renderer/viteConfig.test.ts
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
// @vitest-environment node
|
||||||
|
|
||||||
|
import { describe, expect, it } from 'vitest';
|
||||||
|
import viteConfig from '../../vite.config';
|
||||||
|
|
||||||
|
describe('vite renderer chunking', () => {
|
||||||
|
it('splits monaco editor modules into a dedicated chunk', () => {
|
||||||
|
const resolved = typeof viteConfig === 'function' ? viteConfig({ command: 'build', mode: 'production', isSsrBuild: false, isPreview: false }) : viteConfig;
|
||||||
|
const output = resolved.build?.rollupOptions?.output;
|
||||||
|
|
||||||
|
if (Array.isArray(output)) {
|
||||||
|
throw new Error('Expected a single rollup output config for renderer build');
|
||||||
|
}
|
||||||
|
|
||||||
|
expect(output?.manualChunks).toBeTypeOf('function');
|
||||||
|
|
||||||
|
const chunkName = output?.manualChunks?.('node_modules/monaco-editor/esm/vs/editor/editor.api.js');
|
||||||
|
expect(chunkName).toBe('monaco-vendor');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('sets an explicit chunk size warning limit for Monaco worker assets', () => {
|
||||||
|
const resolved = typeof viteConfig === 'function' ? viteConfig({ command: 'build', mode: 'production', isSsrBuild: false, isPreview: false }) : viteConfig;
|
||||||
|
expect(resolved.build?.chunkSizeWarningLimit).toBe(8000);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -9,8 +9,28 @@ export default defineConfig({
|
|||||||
build: {
|
build: {
|
||||||
outDir: '../../dist/renderer',
|
outDir: '../../dist/renderer',
|
||||||
emptyOutDir: true,
|
emptyOutDir: true,
|
||||||
|
chunkSizeWarningLimit: 8000,
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
input: resolve(__dirname, 'src/renderer/index.html'),
|
input: resolve(__dirname, 'src/renderer/index.html'),
|
||||||
|
output: {
|
||||||
|
manualChunks(id) {
|
||||||
|
if (id.includes('node_modules/monaco-editor') || id.includes('node_modules/@monaco-editor')) {
|
||||||
|
return 'monaco-vendor';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (id.includes('node_modules/@milkdown') || id.includes('node_modules/prosemirror')) {
|
||||||
|
return 'editor-vendor';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (id.includes('node_modules/react') || id.includes('node_modules/scheduler')) {
|
||||||
|
return 'react-vendor';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (id.includes('node_modules/zustand') || id.includes('node_modules/date-fns')) {
|
||||||
|
return 'app-vendor';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
|
|||||||
Reference in New Issue
Block a user