RWKV-Runner/frontend/vite.config.ts

64 lines
1.5 KiB
TypeScript
Raw Permalink Normal View History

2023-11-07 19:27:21 +08:00
// @ts-ignore
import { dependencies } from './package.json';
import { defineConfig } from 'vite';
2023-05-06 23:39:23 +08:00
import react from '@vitejs/plugin-react';
2023-11-07 19:27:21 +08:00
import { visualizer } from 'rollup-plugin-visualizer';
import topLevelAwait from 'vite-plugin-top-level-await';
2023-11-07 19:27:21 +08:00
// dependencies that exist anywhere
const vendor = [
'react', 'react-dom', 'react-router', 'react-router-dom',
'@fluentui/react-icons',
'mobx', 'mobx-react-lite',
'i18next', 'react-i18next',
'usehooks-ts', 'react-toastify',
'classnames'
];
const embedded = [
// split @fluentui/react-components by components
'@fluentui/react-components',
// dependencies that exist in single component
'react-beautiful-dnd',
2023-11-28 15:34:06 +08:00
'react-draggable',
2023-11-07 19:27:21 +08:00
'@magenta/music', 'html-midi-player',
'react-markdown', 'rehype-highlight', 'rehype-raw', 'remark-breaks', 'remark-gfm'
];
function renderChunks(deps: Record<string, string>) {
let chunks = {};
Object.keys(deps).forEach((key) => {
if ([...vendor, ...embedded].includes(key)) return;
chunks[key] = [key];
});
return chunks;
}
2023-05-03 23:38:54 +08:00
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
react(),
2023-05-06 23:39:23 +08:00
visualizer({
template: 'treemap',
gzipSize: true,
brotliSize: true
}),
topLevelAwait({
promiseExportName: '__tla',
promiseImportName: i => `__tla_${i}`
})
],
2023-11-07 19:27:21 +08:00
build: {
chunkSizeWarningLimit: 3000,
rollupOptions: {
output: {
manualChunks: {
vendor,
...renderChunks(dependencies)
}
}
}
}
2023-05-06 23:39:23 +08:00
});