|
|
@ -1,8 +1,11 @@ |
|
|
|
let path = require('path') |
|
|
|
let path = require('path') |
|
|
|
|
|
|
|
const webpack = require('webpack') |
|
|
|
const ThemeColorReplacer = require('webpack-theme-color-replacer') |
|
|
|
const ThemeColorReplacer = require('webpack-theme-color-replacer') |
|
|
|
const {getThemeColors, modifyVars} = require('./src/utils/themeUtil') |
|
|
|
const {getThemeColors, modifyVars} = require('./src/utils/themeUtil') |
|
|
|
const {resolveCss} = require('./src/utils/theme-color-replacer-extend') |
|
|
|
const {resolveCss} = require('./src/utils/theme-color-replacer-extend') |
|
|
|
|
|
|
|
const CompressionWebpackPlugin = require('compression-webpack-plugin') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const productionGzipExtensions = ['js', 'css'] |
|
|
|
const isProd = process.env.NODE_ENV === 'production' |
|
|
|
const isProd = process.env.NODE_ENV === 'production' |
|
|
|
|
|
|
|
|
|
|
|
const assetsCDN = { |
|
|
|
const assetsCDN = { |
|
|
@ -14,7 +17,8 @@ const assetsCDN = { |
|
|
|
axios: 'axios', |
|
|
|
axios: 'axios', |
|
|
|
nprogress: 'NProgress', |
|
|
|
nprogress: 'NProgress', |
|
|
|
clipboard: 'ClipboardJS', |
|
|
|
clipboard: 'ClipboardJS', |
|
|
|
'@antv/data-set': 'DataSet' |
|
|
|
'@antv/data-set': 'DataSet', |
|
|
|
|
|
|
|
'js-cookie': 'Cookies' |
|
|
|
}, |
|
|
|
}, |
|
|
|
css: [ |
|
|
|
css: [ |
|
|
|
], |
|
|
|
], |
|
|
@ -25,7 +29,8 @@ const assetsCDN = { |
|
|
|
'//cdn.jsdelivr.net/npm/axios@0.19.2/dist/axios.min.js', |
|
|
|
'//cdn.jsdelivr.net/npm/axios@0.19.2/dist/axios.min.js', |
|
|
|
'//cdn.jsdelivr.net/npm/nprogress@0.2.0/nprogress.min.js', |
|
|
|
'//cdn.jsdelivr.net/npm/nprogress@0.2.0/nprogress.min.js', |
|
|
|
'//cdn.jsdelivr.net/npm/clipboard@2.0.6/dist/clipboard.min.js', |
|
|
|
'//cdn.jsdelivr.net/npm/clipboard@2.0.6/dist/clipboard.min.js', |
|
|
|
'//cdn.jsdelivr.net/npm/@antv/data-set@0.11.4/build/data-set.min.js' |
|
|
|
'//cdn.jsdelivr.net/npm/@antv/data-set@0.11.4/build/data-set.min.js', |
|
|
|
|
|
|
|
'//cdn.jsdelivr.net/npm/js-cookie@2.2.1/src/js.cookie.min.js' |
|
|
|
] |
|
|
|
] |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -49,6 +54,9 @@ module.exports = { |
|
|
|
}, |
|
|
|
}, |
|
|
|
configureWebpack: config => { |
|
|
|
configureWebpack: config => { |
|
|
|
config.entry.app = ["babel-polyfill", "whatwg-fetch", "./src/main.js"]; |
|
|
|
config.entry.app = ["babel-polyfill", "whatwg-fetch", "./src/main.js"]; |
|
|
|
|
|
|
|
config.performance = { |
|
|
|
|
|
|
|
hints: false |
|
|
|
|
|
|
|
} |
|
|
|
config.plugins.push( |
|
|
|
config.plugins.push( |
|
|
|
new ThemeColorReplacer({ |
|
|
|
new ThemeColorReplacer({ |
|
|
|
fileName: 'css/theme-colors-[contenthash:8].css', |
|
|
|
fileName: 'css/theme-colors-[contenthash:8].css', |
|
|
@ -57,7 +65,22 @@ module.exports = { |
|
|
|
resolveCss |
|
|
|
resolveCss |
|
|
|
}) |
|
|
|
}) |
|
|
|
) |
|
|
|
) |
|
|
|
config.externals = isProd ? assetsCDN.externals : {} |
|
|
|
// Ignore all locale files of moment.js
|
|
|
|
|
|
|
|
config.plugins.push(new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/)) |
|
|
|
|
|
|
|
// 生产环境下将资源压缩成gzip格式
|
|
|
|
|
|
|
|
if (isProd) { |
|
|
|
|
|
|
|
// add `CompressionWebpack` plugin to webpack plugins
|
|
|
|
|
|
|
|
config.plugins.push(new CompressionWebpackPlugin({ |
|
|
|
|
|
|
|
algorithm: 'gzip', |
|
|
|
|
|
|
|
test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'), |
|
|
|
|
|
|
|
threshold: 10240, |
|
|
|
|
|
|
|
minRatio: 0.8 |
|
|
|
|
|
|
|
})) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// if prod, add externals
|
|
|
|
|
|
|
|
if (isProd) { |
|
|
|
|
|
|
|
config.externals = assetsCDN.externals |
|
|
|
|
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
chainWebpack: config => { |
|
|
|
chainWebpack: config => { |
|
|
|
// 生产环境下关闭css压缩的 colormin 项,因为此项优化与主题色替换功能冲突
|
|
|
|
// 生产环境下关闭css压缩的 colormin 项,因为此项优化与主题色替换功能冲突
|
|
|
@ -68,11 +91,7 @@ module.exports = { |
|
|
|
return args |
|
|
|
return args |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
config.plugin('html') |
|
|
|
// 生产环境下使用CDN
|
|
|
|
.tap(args => { |
|
|
|
|
|
|
|
args[0].title = 'Vue Antd Admin' |
|
|
|
|
|
|
|
return args |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
if (isProd) { |
|
|
|
if (isProd) { |
|
|
|
config.plugin('html') |
|
|
|
config.plugin('html') |
|
|
|
.tap(args => { |
|
|
|
.tap(args => { |
|
|
|