2025-02-14 18:46:25 +08:00
|
|
|
const path = require('path');
|
|
|
|
|
const CompressionPlugin = require('compression-webpack-plugin');
|
|
|
|
|
const SitemapWebpackPlugin = require('sitemap-webpack-plugin').default;
|
|
|
|
|
const sass = require('sass'); // 引入 Dart Sass
|
|
|
|
|
|
2025-03-27 23:08:11 +08:00
|
|
|
module.exports = {
|
2025-02-14 18:46:25 +08:00
|
|
|
// 全局页面头部设置
|
2025-03-27 23:08:11 +08:00
|
|
|
target: 'static', // 使项目成为静态站点
|
2025-02-14 18:46:25 +08:00
|
|
|
head: {
|
|
|
|
|
title: 'raylinx',
|
|
|
|
|
htmlAttrs: {
|
|
|
|
|
lang: 'en'
|
|
|
|
|
},
|
|
|
|
|
script: [
|
2025-03-27 23:08:11 +08:00
|
|
|
// 如果需要内嵌其他脚本,请根据需求开启下面代码
|
2025-02-14 18:46:25 +08:00
|
|
|
{
|
|
|
|
|
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',
|
|
|
|
|
body: true
|
|
|
|
|
}
|
|
|
|
|
],
|
2025-03-27 23:08:11 +08:00
|
|
|
__dangerouslyDisableSanitizers: ['script'], // 允许渲染原始 HTML
|
2025-02-14 18:46:25 +08:00
|
|
|
meta: [
|
|
|
|
|
{ charset: 'utf-8' },
|
|
|
|
|
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
|
|
|
|
|
{ hid: 'description', name: 'description', content: 'My awesome description' },
|
|
|
|
|
{ name: 'format-detection', content: 'telephone=no' }
|
|
|
|
|
],
|
|
|
|
|
link: [
|
|
|
|
|
{ rel: 'icon', type: 'image/x-icon', href: '/favicon.png' }
|
2025-03-27 23:08:11 +08:00
|
|
|
]
|
2025-02-14 18:46:25 +08:00
|
|
|
},
|
|
|
|
|
|
2025-03-27 23:08:11 +08:00
|
|
|
// 全局 CSS
|
2025-02-14 18:46:25 +08:00
|
|
|
css: [
|
|
|
|
|
'element-ui/lib/theme-chalk/index.css',
|
|
|
|
|
'vant/lib/index.css' // 确保 Vant 的样式也被加载
|
|
|
|
|
],
|
|
|
|
|
|
2025-03-27 23:08:11 +08:00
|
|
|
// 插件(注意:含有 fs 操作的插件只在服务器端加载)
|
2025-02-14 18:46:25 +08:00
|
|
|
plugins: [
|
|
|
|
|
'@/plugins/element-ui',
|
2025-03-27 23:08:11 +08:00
|
|
|
'@/plugins/vant',
|
2025-02-14 18:46:25 +08:00
|
|
|
'@/plugins/global-mixin.js'
|
|
|
|
|
// '@/plugins/gtm.client.js'
|
|
|
|
|
],
|
|
|
|
|
|
|
|
|
|
// 自动导入组件
|
|
|
|
|
components: true,
|
|
|
|
|
|
|
|
|
|
// 开发和构建模块
|
|
|
|
|
buildModules: [],
|
|
|
|
|
|
|
|
|
|
// 模块
|
|
|
|
|
modules: [
|
2025-02-28 18:08:01 +08:00
|
|
|
'@nuxtjs/axios',
|
2025-03-27 23:08:11 +08:00
|
|
|
'@nuxtjs/gtm',
|
|
|
|
|
'@nuxt/content'
|
2025-02-14 18:46:25 +08:00
|
|
|
],
|
2025-03-27 23:08:11 +08:00
|
|
|
|
2025-02-28 18:08:01 +08:00
|
|
|
gtm: {
|
|
|
|
|
id: 'GTM-T4DJXJTT',
|
|
|
|
|
layer: 'dataLayer',
|
|
|
|
|
pageTracking: true, // 自动发送页面事件
|
2025-03-27 23:08:11 +08:00
|
|
|
enabled: process.env.NODE_ENV === 'production'
|
2025-02-14 18:46:25 +08:00
|
|
|
},
|
2025-03-27 23:08:11 +08:00
|
|
|
|
2025-02-14 18:46:25 +08:00
|
|
|
axios: {
|
|
|
|
|
baseURL: '/'
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 构建配置
|
|
|
|
|
build: {
|
|
|
|
|
transpile: [/^element-ui/, /^vant/], // 确保 Nuxt 知道需要转译 Vant 和 Element-UI
|
|
|
|
|
loaders: {
|
|
|
|
|
scss: {
|
|
|
|
|
implementation: sass, // 使用 Dart Sass
|
|
|
|
|
sassOptions: {
|
|
|
|
|
// 添加 legacy API 静默处理选项
|
|
|
|
|
silenceDeprecations: ['legacy-js-api']
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
// 扩展 Webpack 配置
|
|
|
|
|
extend(config, ctx) {
|
|
|
|
|
// 生产环境中引入 CompressionWebpackPlugin
|
|
|
|
|
if (!ctx.isDev) {
|
|
|
|
|
config.plugins.push(
|
|
|
|
|
new CompressionPlugin({
|
|
|
|
|
algorithm: 'gzip',
|
|
|
|
|
test: /\.(js|css|html|svg|gif|png|jpeg|txt)$/,
|
|
|
|
|
threshold: 2048,
|
|
|
|
|
filename: '[path][base].gz',
|
|
|
|
|
deleteOriginalAssets: false
|
|
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 引入 SitemapWebpackPlugin 并正确设置
|
|
|
|
|
const routes = ['/', '/aboutUs', '/contactUs'];
|
|
|
|
|
config.plugins.push(
|
|
|
|
|
new SitemapWebpackPlugin({
|
|
|
|
|
base: 'https://www.example.com',
|
2025-03-27 23:08:11 +08:00
|
|
|
paths: routes.map(route => ({
|
|
|
|
|
path: route,
|
2025-02-14 18:46:25 +08:00
|
|
|
lastmod: new Date().toISOString(),
|
|
|
|
|
priority: 0.8,
|
|
|
|
|
changefreq: 'monthly'
|
2025-03-27 23:08:11 +08:00
|
|
|
}))
|
2025-02-14 18:46:25 +08:00
|
|
|
})
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// 设置别名
|
|
|
|
|
config.resolve.alias['@'] = path.resolve(__dirname);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|