Files
ebiz-sunful-eco-h5-weixin/vue.config.js
陈昱达 abda23b641 feat(build): 添加生产环境构建命令并优化相关配置
- 在 package.json 中添加 build:prd命令用于生产环境构建
- 新增 .env.prd 文件配置生产环境变量
- 在 vue.config.js 中添加 CompressionPlugin 插件配置,启用 gzip 压缩
- 优化 home.vue 中的空白 p 标签,使用   替代空内容
2025-07-09 20:24:02 +08:00

93 lines
2.4 KiB
JavaScript

const autoprefixer = require('autoprefixer')
const pxtoviewport = require('postcss-px-to-viewport')
const { codeInspectorPlugin } = require('code-inspector-plugin')
const CompressionPlugin = require('compression-webpack-plugin')
const path = require('path')
function resolve(dir) {
return path.join(__dirname, dir)
}
module.exports = {
publicPath: '.',
lintOnSave: false, //是否开启代码检查
outputDir: 'dist', //打包输出目录
productionSourceMap: false,
devServer: {
https: false,
proxy: {
'/api': {
target: 'http://127.0.0.1:7100',
changeOrigin: true,
rewrite: path => path.replace(/^\/api/, '')
}
}
},
css: {
sourceMap: true, // 查看css属于哪个css文件
loaderOptions: {
postcss: {
plugins: [
autoprefixer(),
pxtoviewport({
viewportWidth: 375,
// 该项仅在使用 Circle 组件时需要
// 原因参见 https://github.com/youzan/vant/issues/1948
selectorBlackList: ['van-circle__layer']
})
]
}
}
},
chainWebpack: config => {
// 移除 prefetch 插件
config.resolve.alias.set('@utils', resolve('./src/assets/js/utils'))
// config.plugins.delete('prefetch')
/* 配置svg图标自动加载 begin */
config.module
.rule('svg')
.exclude.add(resolve('src/icons'))
.end()
config.module
.rule('icons')
.test(/\.svg$/)
.include.add(resolve('src/icons'))
.end()
.use('svg-sprite-loader')
.loader('svg-sprite-loader')
.options({
symbolId: 'icon-[name]'
})
config.plugin('code-inspector-plugin').use(
codeInspectorPlugin({
bundler: 'webpack'
})
)
},
configureWebpack: config => {
;(config.devtool = 'source-map'), // 调试js
(config.performance = {
hints: 'error',
//入口起点的最大体积 700kb
maxEntrypointSize: 7168000,
//生成文件的最大体积 700kb
maxAssetSize: 7168000,
//只给出 js 文件的性能提示
assetFilter: function(assetFilename) {
return assetFilename.endsWith('.js')
}
})
config.plugins.push(
new CompressionPlugin({
filename: '[path][base].gz',
algorithm: 'gzip',
test: /\.(js|css|html|svg)$/,
threshold: 10240,
minRatio: 0.8,
deleteOriginalAssets: false,
})
)
}
}