nuxt.config.ts 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /** @format */
  2. import process from 'node:process'
  3. import { sitemapConfig } from './utils/sitemap.config'
  4. const isDev = process.env.NODE_ENV === 'development'
  5. export default defineNuxtConfig({
  6. ssr: true,
  7. app: {
  8. pageTransition: { name: 'page', mode: 'out-in', onBeforeEnter: () => { window.scrollTo(0, 0) } },
  9. // layoutTransition: { name: 'layout', mode: 'out-in', onBeforeEnter() { window.scrollTo(0, 0) } },
  10. head: {
  11. htmlAttrs: {
  12. lang: 'en',
  13. },
  14. },
  15. },
  16. modules: [
  17. '@unocss/nuxt',
  18. '@vueuse/nuxt',
  19. '@nuxt/image',
  20. '@nuxtjs/i18n',
  21. '@nuxtjs/html-validator',
  22. '@element-plus/nuxt',
  23. '@pinia/nuxt',
  24. '@pinia-plugin-persistedstate/nuxt',
  25. 'nuxt-svgo',
  26. '@nuxtjs/sitemap',
  27. ],
  28. css: [
  29. 'element-plus/dist/index.css',
  30. 'element-plus/theme-chalk/display.css',
  31. '@/assets/style/reset.css',
  32. '@/assets/style/public.css',
  33. '@/assets/style/variables.css',
  34. '@/assets/style/common.less',
  35. ],
  36. experimental: {
  37. inlineSSRStyles: false,
  38. viewTransition: true,
  39. renderJsonPayloads: true,
  40. },
  41. routeRules: {
  42. '/**': isDev
  43. ? {}
  44. : {
  45. cache: { swr: true, maxAge: 120, staleMaxAge: 60, headersOnly: true },
  46. },
  47. },
  48. runtimeConfig: {
  49. public: {
  50. apiBase: process.env.MY_ENV_BASE,
  51. scrollToTop: true,
  52. },
  53. },
  54. devtools: {
  55. enabled: true,
  56. },
  57. // image: {
  58. // provider: 'proxy',
  59. // providers: {
  60. // proxy: {
  61. // provider: 'ipx',
  62. // options: {
  63. // baseURL: `${apiBaseUrl}/ipx`,
  64. // },
  65. // },
  66. // },
  67. // },
  68. nitro: {
  69. routeRules: {
  70. '/**': { isr: false },
  71. },
  72. devProxy: {
  73. '/jeecgboot': {
  74. target: process.env.MY_ENV_DEV_URL,
  75. changeOrigin: true,
  76. },
  77. },
  78. },
  79. i18n: {
  80. detectBrowserLanguage: {
  81. useCookie: true,
  82. fallbackLocale: 'en',
  83. },
  84. strategy: 'no_prefix',
  85. locales: [
  86. {
  87. code: 'en',
  88. name: 'English',
  89. file: 'en.json',
  90. },
  91. {
  92. code: 'zh-CN',
  93. name: '简体中文',
  94. file: 'zh-CN.json',
  95. },
  96. ],
  97. lazy: true,
  98. langDir: 'internationalization',
  99. defaultLocale: 'en',
  100. },
  101. htmlValidator: {
  102. usePrettier: false,
  103. logLevel: 'verbose',
  104. failOnError: false,
  105. /** A list of routes to ignore (that is, not check validity for). */
  106. ignore: [/\.(xml|rss|json)$/],
  107. options: {
  108. extends: [
  109. 'html-validate:document',
  110. 'html-validate:recommended',
  111. 'html-validate:standard',
  112. ],
  113. rules: {
  114. 'svg-focusable': 'off',
  115. 'no-unknown-elements': 'error',
  116. // Conflicts or not needed as we use prettier formatting
  117. 'void-style': 'off',
  118. 'no-trailing-whitespace': 'off',
  119. // Conflict with Nuxt defaults
  120. 'require-sri': 'off',
  121. 'attribute-boolean-style': 'off',
  122. 'doctype-style': 'off',
  123. // Unreasonable rule
  124. 'no-inline-style': 'off',
  125. },
  126. },
  127. },
  128. sitemap: {
  129. urls: async () => {
  130. // 只生成静态路由
  131. const staticRoutes = sitemapConfig.staticRoutes.map(route => ({
  132. ...route,
  133. loc: `${sitemapConfig.hostname}${route.loc}`,
  134. lastmod: new Date().toISOString(),
  135. }))
  136. // 生成动态路由
  137. const dynamicRoutes = await sitemapConfig.generateDynamicRoutes()
  138. const dynamics = dynamicRoutes.map(route => ({
  139. ...route,
  140. loc: route.loc,
  141. lastmod: new Date().toISOString(),
  142. }))
  143. // 合并路由
  144. const routes = [...staticRoutes, ...dynamics]
  145. return routes
  146. },
  147. defaults: {
  148. changefreq: 'daily',
  149. priority: 0.5,
  150. lastmod: new Date().toISOString(),
  151. },
  152. exclude: [
  153. '/404',
  154. ],
  155. // exclude all app sources
  156. excludeAppSources: true,
  157. debug: true,
  158. },
  159. })