97 lines
2.6 KiB
JavaScript
97 lines
2.6 KiB
JavaScript
const autoprefixer = require('autoprefixer')
|
|
const pxtoviewport = require('postcss-px-to-viewport')
|
|
const path = require('path')
|
|
|
|
const CompressionPlugin = require('compression-webpack-plugin')
|
|
function resolve(dir) {
|
|
return path.join(__dirname, dir)
|
|
}
|
|
module.exports = {
|
|
publicPath: '.',
|
|
lintOnSave: false, //是否开启代码检查
|
|
outputDir: 'dist', //打包输出目录
|
|
productionSourceMap: false,
|
|
devServer: {
|
|
https: false,
|
|
},
|
|
proxy: {
|
|
'/api': {
|
|
target: process.env.VUE_APP_ADMIN,
|
|
changeOrigin: true,
|
|
pathRewrite: {
|
|
'^/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'))
|
|
// 设置 HTML 标题
|
|
config.plugin('html').tap((args) => {
|
|
args[0].title = '幸福人寿'
|
|
return args
|
|
})
|
|
|
|
// 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]',
|
|
})
|
|
//设置路径别名
|
|
},
|
|
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,
|
|
})
|
|
)
|
|
// 添加 hash 到输出文件名
|
|
config.output = {
|
|
...config.output,
|
|
filename: 'js/[name].[hash:8].js',
|
|
chunkFilename: 'js/[name].[hash:8].js',
|
|
}
|
|
},
|
|
}
|