| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180 |
- import { defineConfig } from 'vitepress'
- import menuConfig from './menuConfig'
- import vueJsx from '@vitejs/plugin-vue-jsx'
- import veaury from 'veaury/vite';
- import { withMermaid } from 'vitepress-plugin-mermaid'
- import AuthMid from './plugins/casdoor/mid'
- import SseMid from './plugins/SSE/server'
- const fileAndStyles: Record<string, string> = {}
- 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: {
- server: {
- host: '0.0.0.0',
- port: 8361,
- allowedHosts: [
- 'raspberrypi', // 允许来自 raspberrypi 主机的访问
- 'raspberrypi.dev', // 允许来自 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}`)
- // })
- // }
- }
- }
- },
- plugins: [
- // veaury({
- // type: 'vue',
- // }),
- vueJsx(),
- {
- name: "middleware",
- configureServer(server) {
- server.middlewares
- .use(SseMid)
- .use(AuthMid);
- }
- }
- ],
- ssr: {
- noExternal: ['naive-ui', 'date-fns', 'vueuc', 'vitepress'] // 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 = /<css-render-style>((.|\s)+)<\/css-render-style>/
- const vitepressPathRegex = /<vitepress-path>(.+)<\/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}</head>`)
- }
- }
- })
- )
|