请大家帮我看看,这个配置中那些地方是多余的,哪些地方需要补充。共同进步。共勉
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const path = require('path');
const webpack = require('webpack')
const CompressionWebpackPlugin = require('compression-webpack-plugin')
const productionGzipExtensions = ['js', 'css']
const isProduction = process.env.NODE_ENV === 'production'
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
module.exports = {
lintOnSave: false, // 设置是否在开发环境下每次保存代码时都启用eslint验证
runtimeCompiler: true,
filenameHashing: true, // 默认值是true 生成的静态资源在它们的文件名中包含了 hash 以便更好的控制缓存
productionSourceMap: false,// 生产环境是否生成 sourceMap 文件,如果设置为true可以精确定位到代码错误位置
publicPath: './', // 设置打包文件相对路径
// 这是前端解决跨域的代码
devServer: {
port: 8080,
open: true, //配置自动启动浏览器
proxy: {
'/api': {
target: process.env.VUE_APP_URL, //写上接口基地址
changeOrigin: true,
ws: true,
// secure: false, //如果是http接口,需要配置此参数
pathRewrite: {
'^/api': ''
}
}
}
},
configureWebpack: {
// 打包的时候不大包下面的参数
externals: {
vue: 'Vue',
vuex: 'Vuex',
'vue-router': 'VueRouter'
},
//
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
'@i': path.resolve(__dirname, './src/assets'),
}
},
plugins: [
// new BundleAnalyzerPlugin(), // 开启性能面板
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),// 忽略第三方包指定目录,让这些指定目录不要被打包进去 moment这个库中,如果引用了./locale/目录的内容,就忽略掉,不会打包进去
// 压缩js文件
new UglifyJsPlugin({
uglifyOptions: {
compress: {
drop_console: true, // 注释console
drop_debugger: isProduction ? true : false, // 注释debugger
pure_funcs: ["console.log"] //移除console
},
// warnings: false,
mangle: false,
output: {
beautify: true //压缩注释
}
},
sourceMap: false, // 去除打包后生成的.map文件
parallel: true
}),
// 开启gzip压缩
new CompressionWebpackPlugin({
algorithm: 'gzip',
test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
threshold: 10240,
minRatio: 0.8
}),
// 此插件可以通过合并的方式,后处理你的 chunk,以减少请求数
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 5,
minChunkSize: 100
}),
]
},
chainWebpack: config => {
config.optimization.splitChunks({
chunks: 'all', // 表示从哪些chunks里面抽取代码,除了三个可选字符串值 initial、async、all 之外,还可以通过函数来过滤所需的 chunks;
cacheGroups: {
vendors: {
name: 'chunk-vendors', // 抽取出来文件的名字,默认为 true,表示自动生成文件名;
test: /[/]node_modules[/]/, // 表示要过滤 modules,默认为所有的 modules,可匹配模块路径或 chunk 名字,当匹配的是 chunk 名字的时候,其里面的所有 modules 都会选中;
priority: 10, // 表示抽取权重,数字越大表示优先级越高。因为一个 module 可能会满足多个 cacheGroups 的条件,那么抽取到哪个就由权重最高的说了算;
chunks: 'initial'
},
video: {
name: 'chunk-video',
priority: 20,
test: /[/]node_modules[/]_?video(.*)/
},
commons: {
name: 'chunk-commons',
minChunks: 2,
priority: 5,
chunks: 'initial',
reuseExistingChunk: true // 表示是否使用已有的 chunk,如果为 true 则表示如果当前的 chunk 包含的模块已经被抽取出去了,那么将不会重新生成新的。
}
}
})
},
}