config.mts 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. import { defineConfig } from 'vitepress'
  2. import path from 'path'
  3. import menuConfig from './menuConfig'
  4. import vueJsx from '@vitejs/plugin-vue-jsx'
  5. import { withMermaid } from 'vitepress-plugin-mermaid'
  6. import AuthMid from './plugins/casdoor/mid'
  7. import SseMid from './plugins/SSE/server'
  8. import { watch } from 'fs'
  9. const fileAndStyles: Record<string, string> = {}
  10. const BaseUrl = '/fwhwiki/'
  11. process.env.BASE_URL = BaseUrl
  12. const MalinePrefix = `${BaseUrl}waline`
  13. // https://vitepress.dev/reference/site-config
  14. export default defineConfig(
  15. withMermaid({
  16. base: BaseUrl,
  17. lang: 'zh-CN',
  18. title: 'FranklinWH Wiki',
  19. description: 'FranklinWH Wiki',
  20. head: [
  21. ['link', { rel: 'icon', type: 'image/svg+xml', href: BaseUrl + 'favicon.svg' }]
  22. ],
  23. themeConfig: {
  24. logo: {
  25. src: '/F_logo.svg',
  26. width: 24,
  27. height: 24
  28. },
  29. // https://vitepress.dev/reference/default-theme-config
  30. ...menuConfig,
  31. outline: {
  32. level: 'deep',
  33. label: '页面导航'
  34. },
  35. search: {
  36. provider: 'local',
  37. options: {
  38. translations: {
  39. button: {
  40. buttonText: '搜索文档',
  41. buttonAriaLabel: '搜索文档'
  42. },
  43. modal: {
  44. noResultsText: '无法找到相关结果',
  45. resetButtonTitle: '清除查询条件',
  46. footer: {
  47. selectText: '选择',
  48. navigateText: '切换',
  49. closeText: '关闭'
  50. }
  51. }
  52. },
  53. locales: {
  54. zh: {
  55. translations: {
  56. button: {
  57. buttonText: '搜索文档',
  58. buttonAriaLabel: '搜索文档'
  59. },
  60. modal: {
  61. noResultsText: '无法找到相关结果',
  62. resetButtonTitle: '清除查询条件',
  63. footer: {
  64. selectText: '选择',
  65. navigateText: '切换'
  66. }
  67. }
  68. }
  69. }
  70. }
  71. }
  72. }
  73. },
  74. markdown: {
  75. // markdown-it-anchor 的选项
  76. // https://github.com/valeriangalliat/markdown-it-anchor#usage
  77. container: {
  78. tipLabel: ':bell: 提示',
  79. warningLabel: ':warning: 警告',
  80. dangerLabel: ':no_entry: 危险',
  81. infoLabel: ':receipt: 信息',
  82. detailsLabel: '详细信息'
  83. },
  84. lineNumbers: true, // 代码块启用行号
  85. math: true, // 启用数学方程
  86. image: {
  87. lazyLoading: true // 为所有图片启用懒加载
  88. }
  89. },
  90. // optionally, you can pass MermaidConfig
  91. mermaid: {
  92. // refer https://mermaid.js.org/config/setup/modules/mermaidAPI.html#mermaidapi-configuration-defaults for options
  93. },
  94. // optionally set additional config for plugin itself with MermaidPluginConfig
  95. mermaidPlugin: {
  96. class: "mermaid my-class", // set additional css classes for parent container
  97. },
  98. // vite config
  99. vite: {
  100. logLevel: 'info',
  101. server: {
  102. host: '0.0.0.0',
  103. port: 8361,
  104. allowedHosts: [
  105. 'raspberrypi', // 允许来自 raspberrypi 主机的访问
  106. 'raspberrypi.dev', // 允许来自 raspberrypi.dev 主机的访问
  107. 'raspberrypi.test', // 允许来自 raspberrypi.dev 主机的访问
  108. 'localhost' // 允许 localhost
  109. ],
  110. // allowedHosts: true, // 允许任何请求
  111. proxy: {
  112. [MalinePrefix]: {
  113. target: 'http://localhost:8360', // 后端Waline服务地址
  114. changeOrigin: true,
  115. rewrite: (path) => path.replace(new RegExp(`^${MalinePrefix}`), ''),
  116. // configure: (proxy, options) => {
  117. // proxy.on('proxyReq', (proxyReq, req) => {
  118. // console.log(`[proxyReq] ${req.method} ${req.url}`)
  119. // })
  120. // }
  121. }
  122. },
  123. watch: {
  124. ignored: ['**/node_modules/**', '**/.vitepress/**']
  125. }
  126. },
  127. plugins: [
  128. vueJsx(),
  129. // dev模式不再需要登录验证插件
  130. // {
  131. // name: "middleware",
  132. // configureServer(server) {
  133. // server.middlewares
  134. // .use(SseMid)
  135. // .use(AuthMid);
  136. // }
  137. // }
  138. ],
  139. ssr: {
  140. external: [],
  141. noExternal: ['naive-ui', 'date-fns', 'vueuc', 'vitepress', '@excalidraw/excalidraw'] // SSR 时强制编译
  142. },
  143. resolve: {
  144. alias: {
  145. // 'vitepress': resolve(__dirname, '../../packages/vitepress/src/client'),
  146. // 'dayjs/dayjs.min.js': 'dayjs/esm/index.js',
  147. // 'dayjs': 'dayjs/esm/index.js',
  148. '@': path.resolve(__dirname, './'),
  149. '@theme': path.resolve(__dirname, './theme'),
  150. '@docs': path.resolve(__dirname, '../'),
  151. },
  152. },
  153. optimizeDeps: {
  154. exclude: ['vitepress'], // 避免预构建
  155. },
  156. // Add this define to fix process.env error in Excalidraw
  157. // https://docs.excalidraw.com/docs/@excalidraw/excalidraw/faq#referenceerror-process-is-not-defined
  158. define: {
  159. 'process.env.IS_PREACT': JSON.stringify('true'),
  160. }
  161. },
  162. postRender(context) {
  163. const styleRegex = /<css-render-style>((.|\s)+)<\/css-render-style>/
  164. const vitepressPathRegex = /<vitepress-path>(.+)<\/vitepress-path>/
  165. const style = styleRegex.exec(context.content)?.[1]
  166. const vitepressPath = vitepressPathRegex.exec(context.content)?.[1]
  167. if (vitepressPath && style) {
  168. fileAndStyles[vitepressPath] = style
  169. }
  170. context.content = context.content.replace(styleRegex, '')
  171. context.content = context.content.replace(vitepressPathRegex, '')
  172. },
  173. transformHtml(code, id) {
  174. const html = id.split('/').pop()
  175. if (!html)
  176. return
  177. const style = fileAndStyles[`/${html}`]
  178. if (style) {
  179. return code.replace(/<\/head>/, `${style}</head>`)
  180. }
  181. }
  182. })
  183. )