|
@@ -1,14 +1,14 @@
|
|
-const fs = require('fs');
|
|
|
|
|
|
+const fs = require('fs')
|
|
const path = require('path')
|
|
const path = require('path')
|
|
const webpack = require('webpack')
|
|
const webpack = require('webpack')
|
|
const createThemeColorReplacerPlugin = require('./config/plugin.config')
|
|
const createThemeColorReplacerPlugin = require('./config/plugin.config')
|
|
-// gzip 压锟斤拷
|
|
|
|
-const compressionWebpackPlugin = require('compression-webpack-plugin');
|
|
|
|
-// js,css 压锟斤拷
|
|
|
|
-const TerserPlugin = require('terser-webpack-plugin');
|
|
|
|
-// 锟芥本锟皆讹拷锟斤拷锟斤拷
|
|
|
|
-const WebpackVersionPlugin = require('webpack-version-plugin');
|
|
|
|
-const versionConfig = require(resolve('public/version.json'));
|
|
|
|
|
|
+// gzip 鍘嬬缉
|
|
|
|
+const compressionWebpackPlugin = require('compression-webpack-plugin')
|
|
|
|
+// js,css 鍘嬬缉
|
|
|
|
+const TerserPlugin = require('terser-webpack-plugin')
|
|
|
|
+// 鐗堟湰鑷�姩鐢熸垚
|
|
|
|
+const WebpackVersionPlugin = require('webpack-version-plugin')
|
|
|
|
+const versionConfig = require(resolve('public/version.json'))
|
|
|
|
|
|
function resolve (dir) {
|
|
function resolve (dir) {
|
|
return path.join(__dirname, dir)
|
|
return path.join(__dirname, dir)
|
|
@@ -22,13 +22,13 @@ function isProd () {
|
|
return process.env.NODE_ENV === 'production'
|
|
return process.env.NODE_ENV === 'production'
|
|
}
|
|
}
|
|
|
|
|
|
-// 锟斤拷目锟斤拷锟斤拷锟斤拷锟�
|
|
|
|
-// 默锟斤拷锟斤拷锟斤拷拢锟斤拷锟斤拷羌锟斤拷锟斤拷锟斤拷应锟矫斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷母锟侥柯硷拷锟�
|
|
|
|
-// 锟斤拷锟界:https://www.my-app.com/
|
|
|
|
-// 默锟较o拷'/'
|
|
|
|
-// 锟斤拷锟斤拷锟斤拷锟接︼拷贸锟斤拷锟斤拷锟斤拷锟斤拷锟铰凤拷锟斤拷校锟斤拷锟斤拷锟揭�拷锟斤拷锟街革拷锟斤拷锟铰凤拷锟�
|
|
|
|
-// 锟斤拷锟界:https://www.foobar.com/my-app/
|
|
|
|
-// 锟斤拷要锟斤拷锟斤拷锟斤拷为'/my-app/'
|
|
|
|
|
|
+// 椤圭洰閮ㄧ讲鍩虹�
|
|
|
|
+// 榛樿�鎯呭喌涓嬶紝鎴戜滑鍋囪�浣犵殑搴旂敤灏嗚�閮ㄧ讲鍦ㄥ煙鐨勬牴鐩�綍涓�,
|
|
|
|
+// 渚嬪�锛歨ttps://www.my-app.com/
|
|
|
|
+// 榛樿�锛�'/'
|
|
|
|
+// 濡傛灉鎮ㄧ殑搴旂敤绋嬪簭閮ㄧ讲鍦ㄥ瓙璺�緞涓�紝鍒欓渶瑕佸湪杩欐寚瀹氬瓙璺�緞
|
|
|
|
+// 渚嬪�锛歨ttps://www.foobar.com/my-app/
|
|
|
|
+// 闇€瑕佸皢瀹冩敼涓�'/my-app/'
|
|
const BASE_URL = isProd ? '/' : '/'
|
|
const BASE_URL = isProd ? '/' : '/'
|
|
|
|
|
|
const assetsCDN = {
|
|
const assetsCDN = {
|
|
@@ -51,7 +51,7 @@ const prodExternals = {
|
|
vuex: 'Vuex',
|
|
vuex: 'Vuex',
|
|
axios: 'axios',
|
|
axios: 'axios',
|
|
echarts: 'echarts',
|
|
echarts: 'echarts',
|
|
- // lodash : {
|
|
|
|
|
|
+ // lodash : {
|
|
// commonjs: "lodash",
|
|
// commonjs: "lodash",
|
|
// amd: "lodash",
|
|
// amd: "lodash",
|
|
// root: "_" // indicates global variable
|
|
// root: "_" // indicates global variable
|
|
@@ -61,45 +61,45 @@ const prodExternals = {
|
|
|
|
|
|
// vue.config.js
|
|
// vue.config.js
|
|
const vueConfig = {
|
|
const vueConfig = {
|
|
- runtimeCompiler: true, // 锟斤拷态锟斤拷锟斤拷锟斤拷锟�
|
|
|
|
|
|
+ runtimeCompiler: true, // 鍔ㄦ€佺紪璇戠粍浠�
|
|
publicPath: BASE_URL,
|
|
publicPath: BASE_URL,
|
|
configureWebpack: {
|
|
configureWebpack: {
|
|
optimization: isProd() ? {
|
|
optimization: isProd() ? {
|
|
- minimize: true,
|
|
|
|
- minimizer: [new TerserPlugin({
|
|
|
|
- test: /\.js(\?.*)?$/i, //匹锟斤拷锟斤拷锟窖癸拷锟斤拷锟斤拷募锟�
|
|
|
|
- parallel: true, //使锟矫讹拷锟斤拷滩锟斤拷锟斤拷锟斤拷锟�
|
|
|
|
- terserOptions: { //Terser 压锟斤拷锟斤拷锟斤拷
|
|
|
|
- output:{comments: false},
|
|
|
|
- compress: {//console删锟斤拷
|
|
|
|
- pure_funcs: ["console.log"]
|
|
|
|
- }
|
|
|
|
- },
|
|
|
|
- extractComments: true, //锟斤拷注锟酵帮拷锟诫到锟斤拷锟斤拷锟斤拷锟侥硷拷锟斤拷
|
|
|
|
- })],
|
|
|
|
- }:{},
|
|
|
|
|
|
+ minimize: true,
|
|
|
|
+ minimizer: [new TerserPlugin({
|
|
|
|
+ test: /\.js(\?.*)?$/i, // 鍖归厤鍙備笌鍘嬬缉鐨勬枃浠�
|
|
|
|
+ parallel: true, // 浣跨敤澶氳繘绋嬪苟鍙戣繍琛�
|
|
|
|
+ terserOptions: { // Terser 鍘嬬缉閰嶇疆
|
|
|
|
+ output: { comments: false },
|
|
|
|
+ compress: {// console鍒犻櫎
|
|
|
|
+ pure_funcs: ['console.log']
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ extractComments: true // 灏嗘敞閲婂墺绂诲埌鍗曠嫭鐨勬枃浠朵腑
|
|
|
|
+ })]
|
|
|
|
+ } : {},
|
|
// webpack plugins
|
|
// webpack plugins
|
|
plugins: [
|
|
plugins: [
|
|
// Ignore all locale files of moment.js
|
|
// Ignore all locale files of moment.js
|
|
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
|
|
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
|
|
new compressionWebpackPlugin({
|
|
new compressionWebpackPlugin({
|
|
- //[file] 锟结被锟芥换锟斤拷原始锟斤拷源锟斤拷[path] 锟结被锟芥换锟斤拷原始锟斤拷源锟斤拷路锟斤拷锟斤拷 [query] 锟结被锟芥换锟缴诧拷询锟街凤拷锟斤拷锟斤拷默锟斤拷值锟斤拷 "[path].gz[query]"锟斤拷
|
|
|
|
- filename: '[path].gz[query]', // 锟斤拷示compression-webpack-plugin@3.0.0锟侥伙拷asset锟斤拷为filename
|
|
|
|
- //锟斤拷锟斤拷锟斤拷 function(buf, callback) 锟斤拷锟斤拷锟街凤拷锟斤拷锟斤拷锟斤拷锟斤拷锟街凤拷锟斤拷锟斤拷说锟斤拷锟斤拷 zlib 锟斤拷锟姐法(锟斤拷锟斤拷 zopfli 锟斤拷锟姐法)锟斤拷默锟斤拷值锟斤拷 "gzip"锟斤拷
|
|
|
|
- algorithm: 'gzip',
|
|
|
|
- //锟斤拷锟斤拷匹锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷源锟斤拷锟结被锟斤拷锟斤拷锟斤拷默锟斤拷值锟斤拷全锟斤拷锟斤拷源锟斤拷
|
|
|
|
- test: new RegExp('\\.(' + ['js', 'css'].join('|') + ')$'),
|
|
|
|
- //只锟叫达拷小锟斤拷锟节革拷值锟斤拷锟斤拷源锟结被锟斤拷锟斤拷锟斤拷锟斤拷位锟斤拷 bytes锟斤拷默锟斤拷值锟斤拷 0锟斤拷
|
|
|
|
- threshold: 10240,
|
|
|
|
- //只锟斤拷压锟斤拷锟斤拷小锟斤拷锟斤拷锟街碉拷锟斤拷锟皆达拷呕岜伙拷锟斤拷锟斤拷锟侥�拷锟街碉拷锟�0.8锟斤拷
|
|
|
|
- minRatio: 0.8
|
|
|
|
- }),
|
|
|
|
|
|
+ // [file] 浼氳�鏇挎崲鎴愬師濮嬭祫婧愩€俒path] 浼氳�鏇挎崲鎴愬師濮嬭祫婧愮殑璺�緞锛� [query] 浼氳�鏇挎崲鎴愭煡璇㈠瓧绗︿覆銆傞粯璁ゅ€兼槸 "[path].gz[query]"銆�
|
|
|
|
+ filename: '[path].gz[query]', // 鎻愮ずcompression-webpack-plugin@3.0.0鐨勮瘽asset鏀逛负filename
|
|
|
|
+ // 鍙�互鏄� function(buf, callback) 鎴栬€呭瓧绗︿覆銆傚�浜庡瓧绗︿覆鏉ヨ�渚濈収 zlib 鐨勭畻娉�(鎴栬€� zopfli 鐨勭畻娉�)銆傞粯璁ゅ€兼槸 "gzip"銆�
|
|
|
|
+ algorithm: 'gzip',
|
|
|
|
+ // 鎵€鏈夊尮閰嶈�姝e垯鐨勮祫婧愰兘浼氳�澶勭悊銆傞粯璁ゅ€兼槸鍏ㄩ儴璧勬簮銆�
|
|
|
|
+ test: new RegExp('\\.(' + ['js', 'css'].join('|') + ')$'),
|
|
|
|
+ // 鍙�湁澶у皬澶т簬璇ュ€肩殑璧勬簮浼氳�澶勭悊銆傚崟浣嶆槸 bytes銆傞粯璁ゅ€兼槸 0銆�
|
|
|
|
+ threshold: 10240,
|
|
|
|
+ // 鍙�湁鍘嬬缉鐜囧皬浜庤繖涓�€肩殑璧勬簮鎵嶄細琚��鐞嗐€傞粯璁ゅ€兼槸 0.8銆�
|
|
|
|
+ minRatio: 0.8
|
|
|
|
+ }),
|
|
new WebpackVersionPlugin({
|
|
new WebpackVersionPlugin({
|
|
// You must set the cb option
|
|
// You must set the cb option
|
|
- cb: function(hashMap) {
|
|
|
|
- if(!isProd()){
|
|
|
|
- versionConfig.version = new Date().getTime();
|
|
|
|
- fs.writeFileSync(resolve('./public/version.json'), JSON.stringify(versionConfig, null, 2));
|
|
|
|
|
|
+ cb: function (hashMap) {
|
|
|
|
+ if (!isProd()) {
|
|
|
|
+ versionConfig.version = new Date().getTime()
|
|
|
|
+ fs.writeFileSync(resolve('./public/version.json'), JSON.stringify(versionConfig, null, 2))
|
|
}
|
|
}
|
|
}
|
|
}
|
|
})
|
|
})
|
|
@@ -135,19 +135,19 @@ const vueConfig = {
|
|
return args
|
|
return args
|
|
})
|
|
})
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
config.optimization && config.optimization.splitChunks({
|
|
config.optimization && config.optimization.splitChunks({
|
|
- // 锟斤拷锟斤拷锟斤拷锟�
|
|
|
|
- chunks: 'all', //锟斤拷选一锟斤拷"initial" 锟斤拷始锟斤拷锟斤拷"all"(默锟较撅拷锟斤拷all)锟斤拷"async"锟斤拷锟斤拷态锟斤拷锟截o拷
|
|
|
|
- minSize: 30000, // 锟轿筹拷一锟斤拷锟铰达拷锟斤拷锟斤拷锟叫★拷锟斤拷锟斤拷,只锟斤拷 >= minSize 锟斤拷bundle锟结被锟斤拷殖锟斤拷锟�30000
|
|
|
|
- maxSize: 0, //锟斤拷锟街�帮拷锟斤拷锟斤拷锟街碉拷锟侥�拷锟轿�斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷
|
|
|
|
- minChunks: 1, //锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷为2 锟斤拷么一锟斤拷锟斤拷源锟斤拷锟劫憋拷锟斤拷锟斤拷锟斤拷锟轿才匡拷锟皆憋拷锟斤拷殖锟斤拷锟�
|
|
|
|
- maxAsyncRequests: 5, // 锟斤拷锟斤拷锟斤拷氐锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷
|
|
|
|
- maxInitialRequests: 4, // 一锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷
|
|
|
|
- automaticNameDelimiter: '~', // 锟侥硷拷锟斤拷锟斤拷锟斤拷锟接凤拷
|
|
|
|
- name: true,
|
|
|
|
- cacheGroups: {
|
|
|
|
- // node_modules模锟斤拷锟�
|
|
|
|
|
|
+ // 鎷嗗寘閰嶇疆
|
|
|
|
+ chunks: 'all', // 涓夐€変竴锛�"initial" 鍒濆�鍖栵紝"all"(榛樿�灏辨槸all)锛�"async"锛堝姩鎬佸姞杞斤級
|
|
|
|
+ minSize: 30000, // 褰㈡垚涓€涓�柊浠g爜鍧楁渶灏忕殑浣撶Н,鍙�湁 >= minSize 鐨刡undle浼氳�鎷嗗垎鍑烘潵 30000
|
|
|
|
+ maxSize: 0, // 鎷嗗垎涔嬪墠鏈€澶х殑鏁板€硷紝榛樿�涓�0锛屽嵆涓嶅仛闄愬埗
|
|
|
|
+ minChunks: 1, // 寮曞叆娆℃暟锛屽�鏋滀负2 閭d箞涓€涓�祫婧愭渶灏戣�寮曠敤涓ゆ�鎵嶅彲浠ヨ�鎷嗗垎鍑烘潵
|
|
|
|
+ maxAsyncRequests: 5, // 鎸夐渶鍔犺浇鐨勬渶澶у苟琛岃�姹傛暟
|
|
|
|
+ maxInitialRequests: 4, // 涓€涓�叆鍙f渶澶у苟琛岃�姹傛暟
|
|
|
|
+ automaticNameDelimiter: '~', // 鏂囦欢鍚嶇殑杩炴帴绗�
|
|
|
|
+ name: true,
|
|
|
|
+ cacheGroups: {
|
|
|
|
+ // node_modules妯″潡鍖�
|
|
vendors: {
|
|
vendors: {
|
|
test: /[\\/]node_modules[\\/]/,
|
|
test: /[\\/]node_modules[\\/]/,
|
|
name: 'chunk-vendors',
|
|
name: 'chunk-vendors',
|
|
@@ -156,9 +156,9 @@ const vueConfig = {
|
|
// return `chunk.${packageName.replace('@', '')}`;
|
|
// return `chunk.${packageName.replace('@', '')}`;
|
|
// },
|
|
// },
|
|
chunks: 'all',
|
|
chunks: 'all',
|
|
- priority: -10,
|
|
|
|
|
|
+ priority: -10
|
|
},
|
|
},
|
|
- // UI锟解单锟斤拷锟斤拷锟�
|
|
|
|
|
|
+ // UI搴撳崟鐙�媶鍖�
|
|
antDesign: {
|
|
antDesign: {
|
|
name: 'chunk-antDesign',
|
|
name: 'chunk-antDesign',
|
|
priority: 19, // the weight needs to be larger than libs and app or it will be packaged into libs or app
|
|
priority: 19, // the weight needs to be larger than libs and app or it will be packaged into libs or app
|
|
@@ -169,22 +169,22 @@ const vueConfig = {
|
|
priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
|
|
priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
|
|
test: /[\\/]node_modules[\\/]_?ant-design-vue(.*)/
|
|
test: /[\\/]node_modules[\\/]_?ant-design-vue(.*)/
|
|
},
|
|
},
|
|
- // 锟斤拷锟斤拷模锟斤拷
|
|
|
|
|
|
+ // 鍏变韩妯″潡
|
|
common: {
|
|
common: {
|
|
name: 'chunk-common',
|
|
name: 'chunk-common',
|
|
minChunks: 2,
|
|
minChunks: 2,
|
|
- maxSize: 1024, //锟斤拷锟街�帮拷锟斤拷锟斤拷锟街碉拷锟侥�拷锟轿�斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷
|
|
|
|
|
|
+ maxSize: 1024, // 鎷嗗垎涔嬪墠鏈€澶х殑鏁板€硷紝榛樿�涓�0锛屽嵆涓嶅仛闄愬埗
|
|
priority: -20,
|
|
priority: -20,
|
|
reuseExistingChunk: true
|
|
reuseExistingChunk: true
|
|
}
|
|
}
|
|
- }
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- // 锟斤拷锟斤拷锟斤拷锟斤拷锟叫�
|
|
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ // 鍒嗘瀽鎵撳寘澶у皬
|
|
if (process.env.npm_config_report) {
|
|
if (process.env.npm_config_report) {
|
|
config.plugin('webpack-bundle-analyzer')
|
|
config.plugin('webpack-bundle-analyzer')
|
|
- .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
|
|
|
|
- .end();
|
|
|
|
|
|
+ .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin)
|
|
|
|
+ .end()
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
|
|
@@ -193,7 +193,7 @@ const vueConfig = {
|
|
loaderOptions: {
|
|
loaderOptions: {
|
|
less: {
|
|
less: {
|
|
modifyVars: {
|
|
modifyVars: {
|
|
- // less vars锛宑ustomize ant design theme
|
|
|
|
|
|
+ // less vars閿涘畱ustomize ant design theme
|
|
'primary-color': process.env.VUE_APP_THEME_COLOR,
|
|
'primary-color': process.env.VUE_APP_THEME_COLOR,
|
|
'link-color': process.env.VUE_APP_THEME_COLOR
|
|
'link-color': process.env.VUE_APP_THEME_COLOR
|
|
// 'border-radius-base': '4px'
|
|
// 'border-radius-base': '4px'
|
|
@@ -222,7 +222,7 @@ const vueConfig = {
|
|
}
|
|
}
|
|
},
|
|
},
|
|
watchOptions: {
|
|
watchOptions: {
|
|
- ignored: [/node_modules/, /public/],
|
|
|
|
|
|
+ ignored: [/node_modules/, /public/]
|
|
}
|
|
}
|
|
},
|
|
},
|
|
|
|
|