|
@@ -3,8 +3,8 @@ const path = require('path')
|
|
|
function resolve(dir) {
|
|
|
return path.join(__dirname, dir)
|
|
|
}
|
|
|
-const WebpackBundleAnalyzer = require('webpack-bundle-analyzer');
|
|
|
-const CompressionWebpackPlugin = require('compression-webpack-plugin')
|
|
|
+const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
|
|
|
+const DEV = process.env.NODE_ENV == 'production';
|
|
|
module.exports = {
|
|
|
// 选项...
|
|
|
publicPath: './',
|
|
@@ -23,11 +23,19 @@ module.exports = {
|
|
|
disableHostCheck: true,
|
|
|
},
|
|
|
chainWebpack: (config) => {
|
|
|
- // 配置可视化打包结构构成
|
|
|
- if (process.env.use_analyzer) {
|
|
|
- config.plugin('webpack-bundle-analyzer').use(WebpackBundleAnalyzer.BundleAnalyzerPlugin);
|
|
|
- }
|
|
|
-
|
|
|
+ // 移除 prefetch 插件
|
|
|
+ config.plugins.delete('prefetch')
|
|
|
+ // 移除 preload 插件
|
|
|
+ config.plugins.delete('preload');
|
|
|
+ // ============压缩图片 start============
|
|
|
+ config.module
|
|
|
+ .rule('images')
|
|
|
+ .use('image-webpack-loader')
|
|
|
+ .loader('image-webpack-loader')
|
|
|
+ .options({bypassOnDebug: true})
|
|
|
+ .end()
|
|
|
+ // ============压缩图片 end============
|
|
|
+
|
|
|
//配置 svg-sprite-loader
|
|
|
// 第一步:让其他svg loader不要对src/icons进行操作
|
|
|
config.module
|
|
@@ -49,20 +57,81 @@ module.exports = {
|
|
|
.end()
|
|
|
},
|
|
|
configureWebpack: config => {
|
|
|
- let plugins = [
|
|
|
- new CompressionWebpackPlugin({
|
|
|
- filename: '[path].gz[query]',
|
|
|
- algorithm: 'gzip',
|
|
|
- test: new RegExp(
|
|
|
- '\\.(' + ['js', 'css'].join('|') +
|
|
|
- ')$',
|
|
|
- ),
|
|
|
- threshold: 10240,
|
|
|
- minRatio: 0.8,
|
|
|
- }),
|
|
|
- ]
|
|
|
- if (process.env.NODE_ENV !== 'development') {
|
|
|
- config.plugins = [...config.plugins, ...plugins]
|
|
|
+ config.plugins.push(
|
|
|
+ new UglifyJsPlugin({
|
|
|
+ uglifyOptions: {
|
|
|
+ //生产环境自动删除console
|
|
|
+ compress: {
|
|
|
+ drop_debugger: true,
|
|
|
+ drop_console: true,
|
|
|
+ pure_funcs: ['console.log']
|
|
|
+ }
|
|
|
+ },
|
|
|
+ sourceMap: false,
|
|
|
+ parallel: true
|
|
|
+ })
|
|
|
+ )
|
|
|
+ config.optimization.splitChunks = {
|
|
|
+ cacheGroups: {
|
|
|
+ vendors: {
|
|
|
+ chunks: 'all',
|
|
|
+ name: "chunk-vendors",
|
|
|
+ test: /[\\/]node_modules[\\/]/,
|
|
|
+ chunks: "initial",
|
|
|
+ priority: 2,
|
|
|
+ reuseExistingChunk: true,
|
|
|
+ enforce: true
|
|
|
+ },
|
|
|
+ elementUI: {
|
|
|
+ chunks: 'all',
|
|
|
+ name: "stabled-elementui",
|
|
|
+ test: /[\\/]node_modules[\\/]element-ui[\\/]/,
|
|
|
+ priority: 3,
|
|
|
+ reuseExistingChunk: true,
|
|
|
+ enforce: true
|
|
|
+ },
|
|
|
+ echarts: {
|
|
|
+ chunks: 'all',
|
|
|
+ name: "stabled-echarts",
|
|
|
+ test: /[\\/]node_modules[\\/]echarts[\\/]/,
|
|
|
+ priority: 4,
|
|
|
+ reuseExistingChunk: true,
|
|
|
+ enforce: true
|
|
|
+ },
|
|
|
+ vue: {
|
|
|
+ name: 'stabled-vue',
|
|
|
+ test: /[\\/]node_modules[\\/]vue[\\/]/,
|
|
|
+ chunks: "all",
|
|
|
+ priority: 5,
|
|
|
+ reuseExistingChunk: true,
|
|
|
+ enforce: true
|
|
|
+ },
|
|
|
+ vuex: {
|
|
|
+ name: 'stabled-vue',
|
|
|
+ test: /[\\/]node_modules[\\/]vuex[\\/]/,
|
|
|
+ chunks: "all",
|
|
|
+ priority: 6,
|
|
|
+ reuseExistingChunk: true,
|
|
|
+ enforce: true
|
|
|
+ },
|
|
|
+ 'vue-router': {
|
|
|
+ name: 'stabled-vue',
|
|
|
+ test: /[\\/]node_modules[\\/]vue-router[\\/]/,
|
|
|
+ chunks: "all",
|
|
|
+ priority: 7,
|
|
|
+ reuseExistingChunk: true,
|
|
|
+ enforce: true
|
|
|
+ },
|
|
|
+ zrender: {
|
|
|
+ name: "stabled-zrender",
|
|
|
+ test: /[\\/]node_modules[\\/]zrender[\\/]/,
|
|
|
+ chunks: "all",
|
|
|
+ priority: 8,
|
|
|
+ reuseExistingChunk: true,
|
|
|
+ enforce: true
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
},
|
|
|
+
|
|
|
}
|