nuxt.config.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. apiBaseUrl: process.env.MY_ENV_DEV_URL,
  52. apiBaseSiteUrl: process.env.NUXT_PUBLIC_SITE_URL,
  53. scrollToTop: true,
  54. },
  55. },
  56. devtools: {
  57. enabled: true,
  58. },
  59. // image: {
  60. // provider: 'proxy',
  61. // providers: {
  62. // proxy: {
  63. // provider: 'ipx',
  64. // options: {
  65. // baseURL: `${apiBaseUrl}/ipx`,
  66. // },
  67. // },
  68. // },
  69. // },
  70. nitro: {
  71. routeRules: {
  72. '/**': { isr: false },
  73. },
  74. devProxy: {
  75. '/jeecgboot': {
  76. target: process.env.MY_ENV_DEV_URL,
  77. changeOrigin: true,
  78. },
  79. },
  80. },
  81. i18n: {
  82. detectBrowserLanguage: {
  83. useCookie: true,
  84. fallbackLocale: 'en',
  85. },
  86. strategy: 'no_prefix',
  87. locales: [
  88. {
  89. code: 'en',
  90. name: 'English',
  91. file: 'en.json',
  92. },
  93. {
  94. code: 'zh-CN',
  95. name: '简体中文',
  96. file: 'zh-CN.json',
  97. },
  98. ],
  99. lazy: true,
  100. langDir: 'internationalization',
  101. defaultLocale: 'en',
  102. },
  103. htmlValidator: {
  104. usePrettier: false,
  105. logLevel: 'verbose',
  106. failOnError: false,
  107. /** A list of routes to ignore (that is, not check validity for). */
  108. ignore: [/\.(xml|rss|json)$/],
  109. options: {
  110. extends: [
  111. 'html-validate:document',
  112. 'html-validate:recommended',
  113. 'html-validate:standard',
  114. ],
  115. rules: {
  116. 'svg-focusable': 'off',
  117. 'no-unknown-elements': 'error',
  118. // Conflicts or not needed as we use prettier formatting
  119. 'void-style': 'off',
  120. 'no-trailing-whitespace': 'off',
  121. // Conflict with Nuxt defaults
  122. 'require-sri': 'off',
  123. 'attribute-boolean-style': 'off',
  124. 'doctype-style': 'off',
  125. // Unreasonable rule
  126. 'no-inline-style': 'off',
  127. },
  128. },
  129. },
  130. sitemap: {
  131. urls: async () => {
  132. // 只生成静态路由
  133. const staticRoutes = sitemapConfig.staticRoutes.map(route => ({
  134. ...route,
  135. loc: `${sitemapConfig.hostname}${route.loc}`,
  136. lastmod: new Date().toISOString(),
  137. }))
  138. // 生成动态路由
  139. const dynamicRoutes = await sitemapConfig.generateDynamicRoutes()
  140. const dynamics = dynamicRoutes.map(route => ({
  141. ...route,
  142. loc: route.loc,
  143. lastmod: new Date().toISOString(),
  144. }))
  145. // 合并路由
  146. const routes = [...staticRoutes, ...dynamics]
  147. return routes
  148. },
  149. defaults: {
  150. changefreq: 'daily',
  151. priority: 0.5,
  152. lastmod: new Date().toISOString(),
  153. },
  154. exclude: [
  155. '/404',
  156. ],
  157. // exclude all app sources
  158. excludeAppSources: true,
  159. debug: true,
  160. },
  161. })