nuxt.config.ts 4.0 KB

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