// @ts-nocheck import compression from 'vite-plugin-compression'; // https://nuxt.com/docs/api/configuration/nuxt-config export default defineNuxtConfig({ ssr: true, // ogImage: { enabled: false }, compatibilityDate: '2024-11-01', css: ['~/assets/css/main.css'], devtools: { enabled: true }, modules: [ '@nuxtjs/tailwindcss', '@nuxt/content', '@nuxtjs/i18n', '@nuxtjs/seo', '@nuxt/image', 'vite-plugin-compression', ], nitro: { compressPublicAssets: true, // 启动压缩 // 确保站点地图被正确预渲染 prerender: { routes: ['/sitemap.xml', '/sitemap_index.xml', '/__sitemap__/zh.xml', '/__sitemap__/en.xml', '/__sitemap__/zh-TW.xml'], failOnError: false }, // 添加路由重写规则,使sitemap.xml直接使用预生成的站点地图 routeRules: { '/sitemap.xml': { static: true }, '/sitemap_index.xml': { static: true } } }, // 图片配置 image: { presets: { default: { modifiers: { quality: 80, format: 'webp', }, }, }, }, // 站点配置 - 关键部分,用于站点地图生成 site: { url: 'https://pinnovatecloud.com' }, // 运行时配置 runtimeConfig: { public: { siteUrl: 'https://pinnovatecloud.com' } }, seo: { sitemap: { sitemapName: 'sitemap.xml', autoLastmod: true, xsl: true, // 确保在构建时生成站点地图 cacheTtl: 1, strictNuxtContentPaths: true, // 多语言支持 i18n: { locales: ['zh', 'en', 'zh-TW'], defaultLocale: 'zh' }, // 解决文件vs目录问题 runtimeCacheStorage: { driver: 'memory', }, // 确保生成静态文件而不是目录 trailingSlash: false, // 防止重复路径 skipUnresolvedRoutes: true, excludeURLs: [ /\/zh-TW\/zh-TW/, /\/en\/en/, /\/zh\/zh/ ] } }, render: { compressor: { threshold: 0, gzip: true, brotli: true, }, }, postcss: { plugins: { cssnano: {}, }, }, app: { head: { script: [ { src: 'https://www.googletagmanager.com/gtag/js?id=G-KNJFL438C1', async: true, }, { innerHTML: ` window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-KNJFL438C1'); `, type: 'text/javascript', }, { innerHTML: `(function(d,w,c){if(w[c])return;var s=d.createElement('script');w[c]=function(){(w[c].z=w[c].z||[]).push(arguments);};s.async=true;s.src='https://static.ahc.ink/hecong.js';if(d.head)d.head.appendChild(s);})(document,window,'_AIHECONG');_AIHECONG('ini',{channelId:'9BgJ9p'});`, type: 'text/javascript', }, ], link: [ { rel: 'icon', type: 'image/x-icon', href: 'favicon.ico' }, { rel: 'stylesheet', href: 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css', }, { rel: 'preconnect', href: 'https://fonts.googleapis.com' }, { rel: 'preconnect', href: 'https://fonts.gstatic.com', crossorigin: '', }, { rel: 'stylesheet', href: 'https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;600;700&display=swap', }, ], }, }, i18n: { strategy: 'prefix_and_default', defaultLocale: 'zh', lazy: true, langDir: 'locales', locales: [ { code: 'zh', name: '简体中文', file: 'zh.json' }, { code: 'zh-TW', name: '繁體中文', file: 'zh-TW.json' }, { code: 'en', name: 'English', file: 'en.json' }, ], detectBrowserLanguage: { useCookie: true, cookieKey: 'i18n_redirected', alwaysRedirect: true, fallbackLocale: 'zh', }, pages: { index: { zh: '/', en: '/en', 'zh-TW': '/zh-TW', }, about: { zh: '/about', en: '/en/about', 'zh-TW': '/zh-TW/about', }, contact: { zh: '/contact', en: '/en/contact', 'zh-TW': '/zh-TW/contact', }, solutions: { zh: '/solutions', en: '/en/solutions', 'zh-TW': '/zh-TW/solutions', }, products: { zh: '/products', en: '/en/products', 'zh-TW': '/zh-TW/products', }, cases: { zh: '/cases', en: '/en/cases', 'zh-TW': '/zh-TW/cases', }, tag: { zh: '/tag', en: '/en/tag', 'zh-TW': '/zh-TW/tag', } } }, target: 'static', // 添加清理选项,避免目录不为空错误 build: { emptyOutDir: true, }, // Vite配置 vite: { plugins: [ compression({ algorithm: 'gzip', // 支持 gzip、brotliCompress 等 ext: '.gz', // 默认 .gz threshold: 1024, // 超过 1kb 才压缩 deleteOriginFile: false, // 是否删除原始文件 }), ], // 构建优化配置 build: { minify: 'terser', terserOptions: { compress: { drop_console: true, // 生产环境移除console }, }, }, }, });