Hanye官网
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

nuxt.config.ts 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. import i18nConfig from "./i18n.config";
  2. import type { Strategies } from "@nuxtjs/i18n";
  3. import { resolve } from "path";
  4. import { readFileSync } from "fs";
  5. import { fileURLToPath } from "url";
  6. import { dirname, join } from "path";
  7. // 尝试导入预生成的路由配置,如果文件不存在则使用默认路由
  8. let prerenderRoutes = [
  9. "/",
  10. "/products",
  11. "/faq",
  12. "/contact",
  13. "/about",
  14. "/en",
  15. "/ja",
  16. "/en/products",
  17. "/ja/products",
  18. "/en/faq",
  19. "/ja/faq",
  20. "/en/contact",
  21. "/ja/contact",
  22. "/en/about",
  23. "/ja/about",
  24. ];
  25. try {
  26. const __dirname = dirname(fileURLToPath(import.meta.url));
  27. const routesPath = join(__dirname, "prerenderRoutes.json");
  28. prerenderRoutes = JSON.parse(readFileSync(routesPath, "utf-8"));
  29. console.log(`已加载预渲染路由,共 ${prerenderRoutes.length} 条`);
  30. } catch (err) {
  31. console.warn("未找到预渲染路由配置文件,使用默认路由");
  32. }
  33. // https://nuxt.com/docs/api/configuration/nuxt-config
  34. export default defineNuxtConfig({
  35. devtools: { enabled: true },
  36. // 添加CSS
  37. css: [
  38. "~/assets/css/tailwind.css",
  39. "~/assets/css/styles.css",
  40. "~/assets/icomoon/style.css",
  41. ],
  42. // 模块
  43. modules: ["@nuxtjs/i18n", "@nuxt/content"],
  44. // content模块配置
  45. content: {
  46. // 配置 Markdown
  47. build: {
  48. markdown: {
  49. // 配置高亮
  50. highlight: {
  51. theme: "github-light",
  52. },
  53. },
  54. },
  55. },
  56. // i18n 配置 (从外部文件加载)
  57. i18n: {
  58. ...i18nConfig,
  59. defaultLocale: i18nConfig.defaultLocale as "zh" | "en" | "ja" | undefined,
  60. strategy: i18nConfig.strategy as Strategies, // 显式类型转换 strategy
  61. },
  62. // Typescript 配置
  63. typescript: {
  64. strict: true,
  65. shim: false,
  66. },
  67. // PostCSS配置 (统一到这里)
  68. postcss: {
  69. plugins: {
  70. tailwindcss: {},
  71. autoprefixer: {},
  72. },
  73. },
  74. // 编译配置
  75. build: {
  76. transpile: ["@nuxtjs/i18n"],
  77. },
  78. // 静态站点生成配置
  79. nitro: {
  80. prerender: {
  81. crawlLinks: false, // 不自动抓取链接
  82. routes: [...prerenderRoutes],
  83. ignore: ["/api/**", "/admin/**"],
  84. failOnError: false, // 遇到错误继续生成其他页面
  85. },
  86. // 添加图片本地化配置
  87. publicAssets: [
  88. {
  89. dir: "public",
  90. baseURL: "/",
  91. },
  92. ],
  93. },
  94. // 禁用 payload 提取,优化静态生成
  95. experimental: {
  96. payloadExtraction: false,
  97. renderJsonPayloads: false,
  98. },
  99. // 页面过渡效果配置
  100. app: {
  101. head: {
  102. charset: "utf-8",
  103. viewport: "width=device-width, initial-scale=1",
  104. link: [
  105. {
  106. rel: "preload",
  107. href: "/_nuxt/sqlite3-WT1HU0S9.wasm",
  108. as: "fetch",
  109. },
  110. {
  111. rel: "preload",
  112. href: "/_nuxt/sqlite3.WT1HU0S9.wasm",
  113. as: "fetch",
  114. },
  115. ],
  116. },
  117. pageTransition: {
  118. name: "page",
  119. mode: "out-in",
  120. },
  121. },
  122. // 路由配置
  123. router: {
  124. options: {
  125. linkActiveClass: "active",
  126. },
  127. },
  128. devServer: {
  129. host: "0.0.0.0",
  130. },
  131. compatibilityDate: "2025-05-07",
  132. });