From 81f54040c2cb65537c6c6e1db8358a39a57dea0d Mon Sep 17 00:00:00 2001
From: mayisheng <admin>
Date: Mon, 15 Aug 2022 16:14:01 +0800
Subject: [PATCH] 1
---
vue.config.js | 147 +++++++++++++++++++++++++++++++-----------------
1 files changed, 95 insertions(+), 52 deletions(-)
diff --git a/vue.config.js b/vue.config.js
index b1d1794..6513636 100644
--- a/vue.config.js
+++ b/vue.config.js
@@ -1,61 +1,104 @@
const path = require('path')
const CopywebpackPlugin = require('copy-webpack-plugin')
const dvgisDist = './node_modules/@dvgis'
-
+const webpack = require('webpack')
// 减少chunk-vendors.js文件大小
const CompressionPlugin = require('compression-webpack-plugin')
+const productionGzipExtensions = ['js', 'css']
+
module.exports = {
- publicPath: '/',
- lintOnSave: false,
- // 其他配置
- chainWebpack: (config) => {
- config.plugin('copy').use(CopywebpackPlugin, [
- [
- {
- from: path.join(dvgisDist, 'dc-sdk/dist/resources'),
- to: 'libs/dc-sdk/resources'
+ publicPath: '/',
+ lintOnSave: false,
+ // 其他配置
+ chainWebpack: (config) => {
+ config.plugins.delete('prefetch')
+
+ config.module.rule('images')
+ .test(/\.(png|jpe?g|gif|svg)(\?.*)?$/)
+ .use('image-webpack-loader')
+ .loader('image-webpack-loader')
+ .options({ bypassOnDebug: true })
+
+ config.plugin('copy').use(CopywebpackPlugin, [
+ [
+ {
+ from: path.join(dvgisDist, 'dc-sdk/dist/resources'),
+ to: 'libs/dc-sdk/resources'
+ },
+ {
+ from: './public/img',
+ to: 'img'
+ },
+ {
+ from: './public/examples',
+ to: 'examples'
+ },
+
+ {
+ from: './public/fz',
+ to: 'fz'
+ },
+ {
+ from: './public/favicon.ico',
+ to: 'favicon.ico'
+ }
+ // {
+ // from: './public/mx',
+ // to: 'mx'
+ // },
+ // {
+ // from: './public/wp',
+ // to: 'wp'
+ // },
+ // {
+ // from: './public/qx',
+ // to: 'qx'
+ // }
+ ]
+ ])
+ // config.plugin('webpack-bundle-analyzer')
+ // .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
+ },
+ // 减少chunk-vendors.js文件大小
+ // 报错 TypeError: Cannot read property 'tapPromise' of undefined
+ // 解决 ,把compression-webpack-plugin包退回成 compression-webpack-plugin@5.0.1 即可
+ // 文件由8M 减成2.5M
+ productionSourceMap: false, // 代码压缩加密
+ configureWebpack: {
+ externals: {
+ vue: 'Vue',
+ Vuex: 'Vuex',
+ 'vue-router': 'VueRouter',
+ 'element-ui': 'ELEMENT',
+ echarts: 'echarts'
},
- {
- from: './public/img',
- to: 'img'
- },
- {
- from: './public/examples',
- to: 'examples'
- },
- {
- from: './public/mx',
- to: 'mx'
- },
- {
- from: './public/wp',
- to: 'wp'
- },
- {
- from: './public/favicon.ico',
- to: 'favicon.ico'
- }
- ]
- ])
- },
- // 减少chunk-vendors.js文件大小
- // 报错 TypeError: Cannot read property 'tapPromise' of undefined
- // 解决 ,把compression-webpack-plugin包退回成 compression-webpack-plugin@5.0.1 即可
- // 文件由8M 减成2.5M
- productionSourceMap: false, // 代码压缩加密
- configureWebpack: {
- // webpack plugins
- plugins: [
- // 提供带 Content-Encoding 编码的压缩版的资源
- new CompressionPlugin({
- algorithm: 'gzip',
- test: /\.js$|\.html$|\.css/, // 匹配文件名
- // test: /\.(js|css)$/,
- threshold: 10240, // 对超过10k的数据压缩
- deleteOriginalAssets: false, // 不删除源文件
- minRatio: 0.8 // 压缩比
- })
- ]
- }
+ // webpack plugins
+ plugins: [
+ // Ignore all locale files of moment.js
+ new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
+
+ // 配置compression-webpack-plugin压缩
+ new CompressionPlugin({
+ algorithm: 'gzip',
+ test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
+ threshold: 10240,
+ minRatio: 0.8
+ }),
+ new webpack.optimize.LimitChunkCountPlugin({
+ maxChunks: 5,
+ minChunkSize: 100
+ })
+ // 提供带 Content-Encoding 编码的压缩版的资源
+ // new CompressionPlugin({
+ // algorithm: 'gzip',
+ // test: /\.js$|\.html$|\.css/, // 匹配文件名
+ // // test: /\.(js|css)$/,
+ // threshold: 10240, // 对超过10k的数据压缩
+ // deleteOriginalAssets: false, // 不删除源文件
+ // minRatio: 0.8 // 压缩比
+ // })
+ ]
+ }
+
}
--
Gitblit v1.9.3