2025-02-14 18:46:25 +08:00
import { Script } from 'vm' ;
const path = require ( 'path' ) ;
const CompressionPlugin = require ( 'compression-webpack-plugin' ) ;
const SitemapWebpackPlugin = require ( 'sitemap-webpack-plugin' ) . default ;
const sass = require ( 'sass' ) ; // 引入 Dart Sass
export default {
// 全局页面头部设置
head : {
title : 'raylinx' ,
htmlAttrs : {
lang : 'en'
} ,
script : [
2025-02-28 18:08:01 +08:00
// {
// innerHTML: `(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src='https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','GTM-T4DJXJTT');`,
// type: 'text/javascript',
// body: false
// },
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
}
] ,
// __dangerouslyDisableSanitizers: ['script'],
// __dangerouslyDisableSanitizersByTagID: {
// 'script-0': ['innerHTML'],
// 'script-1': ['innerHTML']
// },
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' }
] ,
// 谷歌tag manger
2025-02-28 18:08:01 +08:00
// noscript: [
// {
// innerHTML: `<iframe src="https://www.googletagmanager.com/ns.html?id=GTM-T4DJXJTT" height="0" width="0" style="display: none; visibility: hidden;"></iframe>`,
// },
// ],
_ _dangerouslyDisableSanitizers : [ 'script' ] , // 允许渲染原始 HTML
2025-02-14 18:46:25 +08:00
} ,
// 全局CSS
css : [
'element-ui/lib/theme-chalk/index.css' ,
'vant/lib/index.css' // 确保 Vant 的样式也被加载
] ,
// 在渲染页面前运行的插件
plugins : [
'@/plugins/element-ui' ,
'@/plugins/vant' , // 新添加的 Vant 插件
'@/plugins/global-mixin.js'
// '@/plugins/gtm.client.js'
] ,
// 自动导入组件
components : true ,
// 开发和构建模块
buildModules : [ ] ,
// 模块
modules : [
2025-02-28 18:08:01 +08:00
'@nuxtjs/axios' ,
'@nuxtjs/gtm'
2025-02-14 18:46:25 +08:00
] ,
2025-02-28 18:08:01 +08:00
gtm : {
id : 'GTM-T4DJXJTT' ,
layer : 'dataLayer' ,
pageTracking : true , // 自动发送页面事件
enabled : process . env . NODE _ENV === 'production'
2025-02-14 18:46:25 +08:00
} ,
2025-02-28 18:08:01 +08:00
// body: {
// innerHTML: `<!-- Google Tag Manager (noscript) --><noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-T4DJXJTT" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript> <!-- End Google Tag Manager (noscript) -->`
// },
// __dangerouslyDisableSanitizersByTagID: {
// 'bodyAttrs-0': ['innerHTML']
// },
2025-02-14 18:46:25 +08:00
// Axios 模块配置
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 SitemapWebpackPlugin = require ( 'sitemap-webpack-plugin' ) . default ;
const routes = [ '/' , '/aboutUs' , '/contactUs' ] ;
config . plugins . push (
new SitemapWebpackPlugin ( {
base : 'https://www.example.com' ,
paths : routes . map ( path => ( {
path ,
lastmod : new Date ( ) . toISOString ( ) ,
priority : 0.8 ,
changefreq : 'monthly'
} ) ) ,
} )
) ;
// 设置别名
config . resolve . alias [ '@' ] = path . resolve ( _ _dirname ) ;
}
}
} ;