forked from vueComponent/ant-design-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.build.conf.js
75 lines (69 loc) · 1.98 KB
/
webpack.build.conf.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// This config is for building dist files
// const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const { EsbuildPlugin } = require('esbuild-loader');
const DuplicatePackageCheckerPlugin = require('duplicate-package-checker-webpack-plugin');
const getWebpackConfig = require('./antd-tools/getWebpackConfig');
function addLocales(webpackConfig) {
let packageName = 'antd-with-locales';
if (webpackConfig.entry['antd.min']) {
packageName += '.min';
}
webpackConfig.entry[packageName] = './index-with-locales.js';
webpackConfig.output.filename = '[name].js';
}
function externalDayjs(config) {
config.externals.push({
dayjs: {
root: 'dayjs',
commonjs2: 'dayjs',
commonjs: 'dayjs',
amd: 'dayjs',
module: 'dayjs',
},
});
config.externals.push(function ({ _context, request }, callback) {
if (/^dayjs\/plugin\//.test(request)) {
const name = request.replace(/\//g, '_');
return callback(null, {
root: name,
commonjs2: name,
commonjs: name,
amd: name,
module: name,
});
}
callback();
});
}
const webpackConfig = getWebpackConfig(false);
if (process.env.RUN_ENV === 'PRODUCTION') {
webpackConfig.forEach(config => {
addLocales(config);
externalDayjs(config);
// Reduce non-minified dist files size
config.optimization.usedExports = true;
// use esbuild
if (process.env.ESBUILD || process.env.CSB_REPO) {
config.optimization.minimizer[0] = new EsbuildPlugin({
target: 'es2015',
css: true,
});
}
// config.plugins.push(
// new BundleAnalyzerPlugin({
// analyzerMode: 'static',
// openAnalyzer: false,
// reportFilename: '../report.html',
// }),
// );
if (!process.env.NO_DUP_CHECK) {
config.plugins.push(
new DuplicatePackageCheckerPlugin({
verbose: true,
emitError: true,
}),
);
}
});
}
module.exports = [...webpackConfig];