config.mts 5.8 KB

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