Hanye官网
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

nuxt.config.ts 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. highlight: {
  50. theme: "github-light",
  51. },
  52. },
  53. },
  54. },
  55. // i18n 配置 (从外部文件加载)
  56. i18n: {
  57. ...i18nConfig,
  58. defaultLocale: i18nConfig.defaultLocale as "zh" | "en" | "ja" | undefined,
  59. strategy: i18nConfig.strategy as Strategies, // 显式类型转换 strategy
  60. },
  61. // Typescript 配置
  62. typescript: {
  63. strict: true,
  64. shim: false,
  65. },
  66. // PostCSS配置 (统一到这里)
  67. postcss: {
  68. plugins: {
  69. tailwindcss: {},
  70. autoprefixer: {},
  71. },
  72. },
  73. // 编译配置
  74. build: {
  75. transpile: ["@nuxtjs/i18n"],
  76. },
  77. // 静态站点生成配置
  78. nitro: {
  79. prerender: {
  80. crawlLinks: false, // 不自动抓取链接
  81. routes: prerenderRoutes,
  82. ignore: ["/api/**", "/admin/**"],
  83. failOnError: false, // 遇到错误继续生成其他页面
  84. },
  85. // 添加图片本地化配置
  86. publicAssets: [
  87. {
  88. dir: "public",
  89. baseURL: "/",
  90. },
  91. ],
  92. },
  93. // 禁用 payload 提取,优化静态生成
  94. experimental: {
  95. payloadExtraction: false,
  96. renderJsonPayloads: false,
  97. },
  98. devServer: {
  99. host: "0.0.0.0",
  100. },
  101. compatibilityDate: "2025-05-07",
  102. });