Files
ragflow/web/vite.config.ts
chanx 2a4627d9a0 Fix: Issues and style fixes related to the 'Memory' page (#12469)
### What problem does this PR solve?

Fix:  Some bugs
- Issues and style fixes related to the 'Memory' page
- Data source icon replacement
- Build optimization

### Type of change

- [x] Bug Fix (non-breaking change which fixes an issue)
2026-01-07 10:03:54 +08:00

174 lines
4.3 KiB
TypeScript

import { inspectorServer } from '@react-dev-inspector/vite-plugin';
import react from '@vitejs/plugin-react';
import path from 'path';
import { defineConfig, loadEnv } from 'vite';
import { createHtmlPlugin } from 'vite-plugin-html';
import { viteStaticCopy } from 'vite-plugin-static-copy';
import { appName } from './src/conf.json';
// https://vitejs.dev/config/
export default defineConfig(({ mode, command }) => {
const env = loadEnv(mode, process.cwd(), '');
return {
plugins: [
react(),
viteStaticCopy({
targets: [
{
src: 'src/conf.json',
dest: './',
},
{
src: 'node_modules/monaco-editor/min/vs/',
dest: './',
},
],
}),
createHtmlPlugin({
inject: {
data: {
title: appName,
},
},
}),
inspectorServer(),
],
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
'@parent': path.resolve(__dirname, '../'),
},
},
css: {
modules: {
localsConvention: 'camelCase',
},
postcss: './postcss.config.js',
preprocessorOptions: {
less: {
javascriptEnabled: true,
additionalData: `
@import "@/less/variable.less";
@import "@/less/mixins.less";
`,
modifyVars: {
hack: `true; @import "@/less/index.less";`,
},
},
},
},
server: {
port: 9222,
strictPort: false,
hmr: {
overlay: false,
},
proxy: {
'/api/v1/admin': {
target: 'http://127.0.0.1:9381/',
changeOrigin: true,
ws: true,
},
'^/(api|v1)': {
target: 'http://127.0.0.1:9380/',
changeOrigin: true,
ws: true,
},
},
},
assetsInclude: ['**/*.md'],
base: env.VITE_BASE_URL,
publicDir: 'public',
cacheDir: './node_modules/.vite-cache',
optimizeDeps: {
include: [
'react',
'react-dom',
'react-router',
'antd',
'axios',
'lodash',
'dayjs',
],
exclude: [],
force: false,
},
build: {
outDir: 'dist',
assetsDir: 'assets',
assetsInlineLimit: 4096,
experimentalMinChunkSize: 30 * 1024,
chunkSizeWarningLimit: 1000,
rollupOptions: {
output: {
manualChunks(id) {
// if (id.includes('src/components')) {
// return 'components';
// }
if (id.includes('node_modules')) {
if (id.includes('node_modules/d3')) {
return 'd3';
}
if (id.includes('node_modules/ajv')) {
return 'ajv';
}
if (id.includes('node_modules/@antv')) {
return 'antv';
}
const name = id
.toString()
.split('node_modules/')[1]
.split('/')[0]
.toString();
if (['lodash', 'dayjs', 'date-fns', 'axios'].includes(name)) {
return 'utils';
}
if (['@xmldom', 'xmlbuilder '].includes(name)) {
return 'xml-js';
}
return name;
}
},
chunkFileNames: 'chunk/js/[name]-[hash].js',
entryFileNames: 'entry/js/[name]-[hash].js',
assetFileNames: 'assets/[ext]/[name]-[hash].[ext]',
},
plugins: [],
treeshake: true,
},
minify: 'terser',
terserOptions: {
compress: {
drop_console: true, // delete console
drop_debugger: true, // delete debugger
pure_funcs: ['console.log'],
},
mangle: {
// properties: {
// regex: /^_/,
// },
properties: false,
},
format: {
comments: false, // Delete comments
},
},
sourcemap: true,
cssCodeSplit: true,
target: 'es2015',
},
esbuild: {
tsconfigRaw: {
compilerOptions: {
strict: false,
noImplicitAny: false,
skipLibCheck: true,
},
},
},
entries: ['./src/main.tsx'],
};
});