| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- import { defineConfig } from 'vite'
- import vue from '@vitejs/plugin-vue'
- import { viteSingleFile } from 'vite-plugin-singlefile'
- import fs from 'fs'
- import path from 'path'
- // 人设图谱数据路径由 Python 通过环境变量传入
- const personaDataPath = process.env.GRAPH_DATA_PATH
- if (!personaDataPath) {
- console.error('错误: 请设置 GRAPH_DATA_PATH 环境变量')
- process.exit(1)
- }
- console.log('人设图谱数据文件:', personaDataPath)
- // 读取人设图谱 JSON 数据
- const personaGraphData = JSON.parse(fs.readFileSync(personaDataPath, 'utf-8'))
- console.log('人设节点数:', Object.keys(personaGraphData.nodes || {}).length)
- // 帖子图谱数据路径(可选,目录)
- const postGraphDir = process.env.POST_GRAPH_DIR
- let postGraphList = []
- if (postGraphDir && fs.existsSync(postGraphDir)) {
- console.log('帖子图谱目录:', postGraphDir)
- const files = fs.readdirSync(postGraphDir).filter(f => f.endsWith('_帖子图谱.json'))
- console.log('帖子图谱文件数:', files.length)
- // 读取所有帖子图谱
- for (const file of files) {
- const filePath = path.join(postGraphDir, file)
- const postData = JSON.parse(fs.readFileSync(filePath, 'utf-8'))
- postGraphList.push(postData)
- }
- // 按创建时间降序排序
- postGraphList.sort((a, b) => {
- const dateA = a.meta?.postDetail?.create_time || 0
- const dateB = b.meta?.postDetail?.create_time || 0
- return dateB - dateA
- })
- } else {
- console.log('未设置帖子图谱目录或目录不存在')
- }
- export default defineConfig({
- plugins: [vue(), viteSingleFile()],
- define: {
- // 将数据注入为全局常量
- __GRAPH_DATA__: JSON.stringify(personaGraphData),
- __POST_GRAPH_LIST__: JSON.stringify(postGraphList)
- },
- build: {
- target: 'esnext',
- outDir: 'dist',
- assetsInlineLimit: 100000000,
- chunkSizeWarningLimit: 100000000,
- cssCodeSplit: false,
- rollupOptions: {
- output: {
- inlineDynamicImports: true
- }
- }
- }
- })
|