import { defineConfig } from 'vitepress' import menuConfig from './menuConfig' import vueJsx from '@vitejs/plugin-vue-jsx' import { withMermaid } from 'vitepress-plugin-mermaid' import AuthMid from './plugins/casdoor/mid' import SseMid from './plugins/SSE/server' import { watch } from 'fs' const fileAndStyles: Record = {} const BaseUrl = '/fwhwiki/' process.env.BASE_URL = BaseUrl const MalinePrefix = `${BaseUrl}waline` // https://vitepress.dev/reference/site-config export default defineConfig( withMermaid({ base: BaseUrl, lang: 'zh-CN', title: 'FranklinWH Wiki', description: 'FranklinWH Wiki', head: [ ['link', { rel: 'icon', type: 'image/svg+xml', href: BaseUrl + 'favicon.svg' }] ], themeConfig: { logo: { src: '/F_logo.svg', width: 24, height: 24 }, // https://vitepress.dev/reference/default-theme-config ...menuConfig, outline: { level: 'deep', label: '页面导航' }, search: { provider: 'local', options: { translations: { button: { buttonText: '搜索文档', buttonAriaLabel: '搜索文档' }, modal: { noResultsText: '无法找到相关结果', resetButtonTitle: '清除查询条件', footer: { selectText: '选择', navigateText: '切换', closeText: '关闭' } } }, locales: { zh: { translations: { button: { buttonText: '搜索文档', buttonAriaLabel: '搜索文档' }, modal: { noResultsText: '无法找到相关结果', resetButtonTitle: '清除查询条件', footer: { selectText: '选择', navigateText: '切换' } } } } } } } }, markdown: { // markdown-it-anchor 的选项 // https://github.com/valeriangalliat/markdown-it-anchor#usage container: { tipLabel: ':bell: 提示', warningLabel: ':warning: 警告', dangerLabel: ':no_entry: 危险', infoLabel: ':receipt: 信息', detailsLabel: '详细信息' }, lineNumbers: true, // 代码块启用行号 math: true, // 启用数学方程 image: { lazyLoading: true // 为所有图片启用懒加载 } }, // optionally, you can pass MermaidConfig mermaid: { // refer https://mermaid.js.org/config/setup/modules/mermaidAPI.html#mermaidapi-configuration-defaults for options }, // optionally set additional config for plugin itself with MermaidPluginConfig mermaidPlugin: { class: "mermaid my-class", // set additional css classes for parent container }, // vite config vite: { logLevel: 'info', server: { host: '0.0.0.0', port: 8361, allowedHosts: [ 'raspberrypi', // 允许来自 raspberrypi 主机的访问 'raspberrypi.dev', // 允许来自 raspberrypi.dev 主机的访问 'raspberrypi.test', // 允许来自 raspberrypi.dev 主机的访问 'localhost' // 允许 localhost ], // allowedHosts: true, // 允许任何请求 proxy: { [MalinePrefix]: { target: 'http://localhost:8360', // 后端Waline服务地址 changeOrigin: true, rewrite: (path) => path.replace(new RegExp(`^${MalinePrefix}`), ''), // configure: (proxy, options) => { // proxy.on('proxyReq', (proxyReq, req) => { // console.log(`[proxyReq] ${req.method} ${req.url}`) // }) // } } }, watch: { ignored: ['**/node_modules/**', '**/.vitepress/**'] } }, plugins: [ vueJsx(), // dev模式不再需要登录验证插件 // { // name: "middleware", // configureServer(server) { // server.middlewares // .use(SseMid) // .use(AuthMid); // } // } ], ssr: { external: [], noExternal: ['naive-ui', 'date-fns', 'vueuc', 'vitepress', '@excalidraw/excalidraw'] // SSR 时强制编译 }, resolve: { alias: { // 'vitepress': resolve(__dirname, '../../packages/vitepress/src/client'), // 'dayjs/dayjs.min.js': 'dayjs/esm/index.js', // 'dayjs': 'dayjs/esm/index.js', }, }, optimizeDeps: { exclude: ['vitepress'], // 避免预构建 }, // Add this define to fix process.env error in Excalidraw // https://docs.excalidraw.com/docs/@excalidraw/excalidraw/faq#referenceerror-process-is-not-defined define: { 'process.env.IS_PREACT': JSON.stringify('true'), } }, postRender(context) { const styleRegex = /((.|\s)+)<\/css-render-style>/ const vitepressPathRegex = /(.+)<\/vitepress-path>/ const style = styleRegex.exec(context.content)?.[1] const vitepressPath = vitepressPathRegex.exec(context.content)?.[1] if (vitepressPath && style) { fileAndStyles[vitepressPath] = style } context.content = context.content.replace(styleRegex, '') context.content = context.content.replace(vitepressPathRegex, '') }, transformHtml(code, id) { const html = id.split('/').pop() if (!html) return const style = fileAndStyles[`/${html}`] if (style) { return code.replace(/<\/head>/, `${style}`) } } }) )