2018-03-18 11:59:38 +00:00
|
|
|
// This config is for building dist files
|
2021-09-25 08:51:32 +00:00
|
|
|
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
|
2020-03-15 05:12:47 +00:00
|
|
|
const getWebpackConfig = require('./antd-tools/getWebpackConfig');
|
2021-01-14 09:33:17 +00:00
|
|
|
const IgnoreEmitPlugin = require('ignore-emit-webpack-plugin');
|
|
|
|
const darkVars = require('./scripts/dark-vars');
|
2018-03-18 11:59:38 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
function addLocales(webpackConfig) {
|
|
|
|
let packageName = 'antd-with-locales';
|
2018-03-18 11:59:38 +00:00
|
|
|
if (webpackConfig.entry['antd.min']) {
|
2019-01-12 03:33:27 +00:00
|
|
|
packageName += '.min';
|
2018-03-18 11:59:38 +00:00
|
|
|
}
|
2019-01-12 03:33:27 +00:00
|
|
|
webpackConfig.entry[packageName] = './index-with-locales.js';
|
|
|
|
webpackConfig.output.filename = '[name].js';
|
2018-03-18 11:59:38 +00:00
|
|
|
}
|
|
|
|
|
2021-09-25 08:51:32 +00:00
|
|
|
function externalDayjs(config) {
|
|
|
|
config.externals.dayjs = {
|
|
|
|
root: 'dayjs',
|
|
|
|
commonjs2: 'dayjs',
|
|
|
|
commonjs: 'dayjs',
|
|
|
|
amd: 'dayjs',
|
2019-01-12 03:33:27 +00:00
|
|
|
};
|
2018-03-18 11:59:38 +00:00
|
|
|
}
|
|
|
|
|
2021-09-25 08:51:32 +00:00
|
|
|
function processWebpackThemeConfig(themeConfig, theme, vars) {
|
|
|
|
themeConfig.forEach(config => {
|
|
|
|
externalDayjs(config);
|
|
|
|
|
|
|
|
// rename default entry to ${theme} entry
|
|
|
|
Object.keys(config.entry).forEach(entryName => {
|
|
|
|
config.entry[entryName.replace('antd', `antd.${theme}`)] = config.entry[entryName];
|
|
|
|
delete config.entry[entryName];
|
|
|
|
});
|
|
|
|
|
|
|
|
// apply ${theme} less variables
|
|
|
|
config.module.rules.forEach(rule => {
|
|
|
|
// filter less rule
|
|
|
|
if (rule.test instanceof RegExp && rule.test.test('.less')) {
|
|
|
|
const lessRule = rule.use[rule.use.length - 1];
|
|
|
|
if (lessRule.options.lessOptions) {
|
|
|
|
lessRule.options.lessOptions.modifyVars = vars;
|
|
|
|
} else {
|
|
|
|
lessRule.options.modifyVars = vars;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const themeReg = new RegExp(`${theme}(.min)?\\.js(\\.map)?$`);
|
|
|
|
// ignore emit ${theme} entry js & js.map file
|
|
|
|
config.plugins.push(new IgnoreEmitPlugin(themeReg));
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2018-03-18 11:59:38 +00:00
|
|
|
}
|
|
|
|
|
2021-09-25 08:51:32 +00:00
|
|
|
const webpackConfig = getWebpackConfig(false);
|
2021-01-14 09:33:17 +00:00
|
|
|
const webpackDarkConfig = getWebpackConfig(false);
|
|
|
|
|
2021-09-25 08:51:32 +00:00
|
|
|
if (process.env.RUN_ENV === 'PRODUCTION') {
|
|
|
|
webpackConfig.forEach(config => {
|
|
|
|
externalDayjs(config);
|
|
|
|
addLocales(config);
|
|
|
|
// Reduce non-minified dist files size
|
|
|
|
config.optimization.usedExports = true;
|
2021-01-14 09:33:17 +00:00
|
|
|
|
2021-09-25 08:51:32 +00:00
|
|
|
config.plugins.push(
|
|
|
|
new BundleAnalyzerPlugin({
|
|
|
|
analyzerMode: 'static',
|
|
|
|
openAnalyzer: false,
|
|
|
|
reportFilename: '../report.html',
|
|
|
|
}),
|
|
|
|
);
|
2021-01-14 09:33:17 +00:00
|
|
|
});
|
|
|
|
|
2021-09-25 08:51:32 +00:00
|
|
|
processWebpackThemeConfig(webpackDarkConfig, 'dark', darkVars);
|
|
|
|
}
|
2021-01-14 09:33:17 +00:00
|
|
|
|
|
|
|
module.exports = webpackConfig.concat(webpackDarkConfig);
|