config.mts 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. import { defineConfig } from 'vitepress'
  2. import menuConfig from './menuConfig'
  3. import vueJsx from '@vitejs/plugin-vue-jsx'
  4. import veaury from 'veaury/vite';
  5. import { withMermaid } from 'vitepress-plugin-mermaid'
  6. import AuthMid from './plugins/casdoor/mid'
  7. import SseMid from './plugins/SSE/server'
  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. server: {
  100. host: '0.0.0.0',
  101. port: 8361,
  102. allowedHosts: [
  103. 'raspberrypi', // 允许来自 raspberrypi 主机的访问
  104. 'raspberrypi.dev', // 允许来自 raspberrypi.dev 主机的访问
  105. 'localhost' // 允许 localhost
  106. ],
  107. // allowedHosts: true, // 允许任何请求
  108. proxy: {
  109. [MalinePrefix]: {
  110. target: 'http://localhost:8360', // 后端Waline服务地址
  111. changeOrigin: true,
  112. rewrite: (path) => path.replace(new RegExp(`^${MalinePrefix}`), ''),
  113. // configure: (proxy, options) => {
  114. // proxy.on('proxyReq', (proxyReq, req) => {
  115. // console.log(`[proxyReq] ${req.method} ${req.url}`)
  116. // })
  117. // }
  118. }
  119. }
  120. },
  121. plugins: [
  122. // veaury({
  123. // type: 'vue',
  124. // }),
  125. vueJsx(),
  126. {
  127. name: "middleware",
  128. configureServer(server) {
  129. server.middlewares
  130. .use(SseMid)
  131. .use(AuthMid);
  132. }
  133. }
  134. ],
  135. ssr: {
  136. noExternal: ['naive-ui', 'date-fns', 'vueuc', 'vitepress'] // SSR 时强制编译
  137. },
  138. resolve: {
  139. alias: {
  140. // 'vitepress': resolve(__dirname, '../../packages/vitepress/src/client'),
  141. // 'dayjs/dayjs.min.js': 'dayjs/esm/index.js',
  142. // 'dayjs': 'dayjs/esm/index.js',
  143. },
  144. },
  145. optimizeDeps: {
  146. exclude: ['vitepress'], // 避免预构建
  147. },
  148. // Add this define to fix process.env error in Excalidraw
  149. // https://docs.excalidraw.com/docs/@excalidraw/excalidraw/faq#referenceerror-process-is-not-defined
  150. define: {
  151. 'process.env.IS_PREACT': JSON.stringify('true'),
  152. }
  153. },
  154. postRender(context) {
  155. const styleRegex = /<css-render-style>((.|\s)+)<\/css-render-style>/
  156. const vitepressPathRegex = /<vitepress-path>(.+)<\/vitepress-path>/
  157. const style = styleRegex.exec(context.content)?.[1]
  158. const vitepressPath = vitepressPathRegex.exec(context.content)?.[1]
  159. if (vitepressPath && style) {
  160. fileAndStyles[vitepressPath] = style
  161. }
  162. context.content = context.content.replace(styleRegex, '')
  163. context.content = context.content.replace(vitepressPathRegex, '')
  164. },
  165. transformHtml(code, id) {
  166. const html = id.split('/').pop()
  167. if (!html)
  168. return
  169. const style = fileAndStyles[`/${html}`]
  170. if (style) {
  171. return code.replace(/<\/head>/, `${style}</head>`)
  172. }
  173. }
  174. })
  175. )