RWKV-Runner/frontend/vite.config.ts

67 lines
1.6 KiB
TypeScript
Raw 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',
2023-12-22 14:44:27 +08:00
'classnames', 'lodash-es'
2023-11-07 19:27:21 +08:00
];
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-12-08 11:22:31 +08:00
},
entryFileNames: `assets/[name].js`,
chunkFileNames: `assets/[name].js`,
assetFileNames: `assets/[name].[ext]`
2023-11-07 19:27:21 +08:00
}
}
}
2023-05-06 23:39:23 +08:00
});