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: [
// {
// 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
// },
{
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
// noscript: [
// {
// innerHTML: ``,
// },
// ],
__dangerouslyDisableSanitizers: ['script'], // 允许渲染原始 HTML
},
// 全局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: [
'@nuxtjs/axios',
'@nuxtjs/gtm'
],
gtm: {
id: 'GTM-T4DJXJTT',
layer: 'dataLayer',
pageTracking: true, // 自动发送页面事件
enabled: process.env.NODE_ENV === 'production'
},
// body: {
// innerHTML: ` `
// },
// __dangerouslyDisableSanitizersByTagID: {
// 'bodyAttrs-0': ['innerHTML']
// },
// 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);
}
}
};