vite.config.js 1013 B

12345678910111213141516171819202122232425262728293031323334353637
  1. import { defineConfig } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import { viteSingleFile } from 'vite-plugin-singlefile'
  4. import fs from 'fs'
  5. // 数据路径由 Python 通过环境变量传入
  6. const dataPath = process.env.GRAPH_DATA_PATH
  7. if (!dataPath) {
  8. console.error('错误: 请设置 GRAPH_DATA_PATH 环境变量')
  9. process.exit(1)
  10. }
  11. console.log('数据文件:', dataPath)
  12. // 读取 JSON 数据
  13. const graphData = JSON.parse(fs.readFileSync(dataPath, 'utf-8'))
  14. console.log('节点数:', Object.keys(graphData.nodes || {}).length)
  15. console.log('边数:', (graphData.edges || []).length)
  16. export default defineConfig({
  17. plugins: [vue(), viteSingleFile()],
  18. define: {
  19. // 将数据注入为全局常量
  20. __GRAPH_DATA__: JSON.stringify(graphData)
  21. },
  22. build: {
  23. target: 'esnext',
  24. outDir: 'dist',
  25. assetsInlineLimit: 100000000,
  26. chunkSizeWarningLimit: 100000000,
  27. cssCodeSplit: false,
  28. rollupOptions: {
  29. output: {
  30. inlineDynamicImports: true
  31. }
  32. }
  33. }
  34. })