83 lines
2.4 KiB
JavaScript
83 lines
2.4 KiB
JavaScript
const CompressionPlugin = require("compression-webpack-plugin")
|
||
const path = require("path");
|
||
function resolve (dir) {
|
||
return path.join(__dirname, dir)
|
||
}
|
||
// vue.config.js
|
||
module.exports = {
|
||
// baseUrl: "./",
|
||
publicPath: './' ,
|
||
outputDir: "dist",
|
||
assetsDir: "assets",
|
||
indexPath: "index.html",
|
||
filenameHashing: true,
|
||
pages: undefined,
|
||
lintOnSave: true,
|
||
runtimeCompiler: false,
|
||
// productionSourceMap: true,//生成map文件
|
||
productionSourceMap: false,//去掉生成map文件
|
||
crossorigin: undefined,
|
||
integrity: false,
|
||
// autoOpenBrowser: true,
|
||
|
||
configureWebpack: config => {
|
||
//生产环境取消 console.log
|
||
if (process.env.NODE_ENV === 'production') {
|
||
config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true
|
||
}
|
||
},
|
||
chainWebpack: (config) => { //引入
|
||
config.resolve.alias
|
||
.set('@$', resolve('src'))
|
||
.set('@api', resolve('src/api'))
|
||
.set('@assets', resolve('src/assets'))
|
||
.set('@comp', resolve('src/components'))
|
||
.set('@views', resolve('src/pages'))
|
||
.set('@public', resolve('public'))
|
||
//生产环境,开启js\css压缩
|
||
if (process.env.NODE_ENV === 'production') {
|
||
config.plugin('compressionPlugin').use(new CompressionPlugin({
|
||
test: /\.js$|\.html$|\.json$|\.css$|\.ttf$|\.less$/, // 匹配文件名
|
||
threshold: 10240, // 对超过10k的数据压缩
|
||
deleteOriginalAssets: false // 不删除源文件
|
||
}))
|
||
}
|
||
//针对svg文件添加svg-sprite-loader规则
|
||
// 配置svg
|
||
config.module
|
||
.rule('svg')
|
||
.exclude.add(resolve('src/assets/icons'))
|
||
.end()
|
||
config.module
|
||
.rule('icons')
|
||
.test(/\.svg$/)
|
||
.include.add(resolve('src/assets/icons'))
|
||
.end()
|
||
.use('svg-sprite-loader')
|
||
.loader('svg-sprite-loader')
|
||
.options({
|
||
symbolId: 'icon-[name]'
|
||
})
|
||
.end()
|
||
},
|
||
transpileDependencies: [ //babel会忽略node_modules中的文件。如果需要Babel转译,单独列出来。
|
||
'@jiaminghi',
|
||
],
|
||
css: {
|
||
loaderOptions: {
|
||
less: {
|
||
lessOptions: {
|
||
javascriptEnabled: true,
|
||
// 兼容 less-loader 3.x
|
||
math: "always",
|
||
}
|
||
}
|
||
}
|
||
},
|
||
devServer: {
|
||
disableHostCheck: true, // 使用Nginx + hosts 来访问域名代理访问本地项目
|
||
port: 3000
|
||
},
|
||
lintOnSave: process.env.NODE_ENV !== 'production'
|
||
}
|