chore: update webpack

pull/4499/head
tangjinzhou 2021-08-09 21:49:57 +08:00
parent 553554d72f
commit 02b934c33d
6 changed files with 56 additions and 37 deletions

2
.gitignore vendored
View File

@ -73,3 +73,5 @@ site/dev.js
# IDE 语法提示临时文件 # IDE 语法提示临时文件
vetur/ vetur/
report.html

View File

@ -8,16 +8,17 @@ import { withInstall } from '../_util/type';
import type { ValidateMessages } from '../form/interface'; import type { ValidateMessages } from '../form/interface';
import type { TransferLocale } from '../transfer'; import type { TransferLocale } from '../transfer';
import type { PickerLocale as DatePickerLocale } from '../date-picker/generatePicker'; import type { PickerLocale as DatePickerLocale } from '../date-picker/generatePicker';
import { PaginationLocale } from '../pagination/Pagination';
interface TransferLocaleForEmpty { interface TransferLocaleForEmpty {
description: string; description: string;
} }
export interface Locale { export interface Locale {
locale: string; locale: string;
Pagination?: Object; Pagination?: PaginationLocale;
Table?: Object; Table?: Record<string, any>;
Popconfirm?: Object; Popconfirm?: Record<string, any>;
Upload?: Object; Upload?: Record<string, any>;
Form?: { Form?: {
optional?: string; optional?: string;
defaultValidateMessages: ValidateMessages; defaultValidateMessages: ValidateMessages;
@ -72,9 +73,9 @@ const LocaleProvider = defineComponent({
() => props.locale, () => props.locale,
val => { val => {
state.antLocale = { state.antLocale = {
...val, ...props.locale,
exist: true, exist: true,
}; } as any;
changeConfirmLocale(val && val.Modal); changeConfirmLocale(val && val.Modal);
}, },
{ immediate: true }, { immediate: true },

View File

@ -51,6 +51,7 @@ export const paginationConfig = () => ({
export type PaginationProps = Partial<ExtractPropTypes<ReturnType<typeof paginationProps>>>; export type PaginationProps = Partial<ExtractPropTypes<ReturnType<typeof paginationProps>>>;
export type PaginationConfig = Partial<ExtractPropTypes<ReturnType<typeof paginationConfig>>>; export type PaginationConfig = Partial<ExtractPropTypes<ReturnType<typeof paginationConfig>>>;
export type PaginationLocale = any;
export default defineComponent({ export default defineComponent({
name: 'APagination', name: 'APagination',
inheritAttrs: false, inheritAttrs: false,

View File

@ -212,7 +212,7 @@ export default defineComponent({
if (!!filterOption === false) { if (!!filterOption === false) {
return true; return true;
} }
return filterOption(targetMeasureText, option); return (filterOption as Function)(targetMeasureText, option);
}); });
return list; return list;
}; };

View File

@ -195,7 +195,7 @@
"vue-style-loader": "^4.1.2", "vue-style-loader": "^4.1.2",
"vuex": "^4.0.0-beta.2", "vuex": "^4.0.0-beta.2",
"webpack": "^5.0.0", "webpack": "^5.0.0",
"webpack-bundle-analyzer": "^4.0.0", "webpack-bundle-analyzer": "^4.4.2",
"webpack-cli": "^4.6.0", "webpack-cli": "^4.6.0",
"webpack-dev-server": "^3.1.14", "webpack-dev-server": "^3.1.14",
"webpack-merge": "^5.0.0", "webpack-merge": "^5.0.0",

View File

@ -1,4 +1,5 @@
// This config is for building dist files // This config is for building dist files
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const getWebpackConfig = require('./antd-tools/getWebpackConfig'); const getWebpackConfig = require('./antd-tools/getWebpackConfig');
const IgnoreEmitPlugin = require('ignore-emit-webpack-plugin'); const IgnoreEmitPlugin = require('ignore-emit-webpack-plugin');
const darkVars = require('./scripts/dark-vars'); const darkVars = require('./scripts/dark-vars');
@ -21,22 +22,13 @@ function externalDayjs(config) {
}; };
} }
const webpackConfig = getWebpackConfig(false); function processWebpackThemeConfig(themeConfig, theme, vars) {
if (process.env.RUN_ENV === 'PRODUCTION') { themeConfig.forEach(config => {
webpackConfig.forEach(config => {
externalDayjs(config);
addLocales(config);
});
}
const webpackDarkConfig = getWebpackConfig(false);
webpackDarkConfig.forEach(config => {
externalDayjs(config); externalDayjs(config);
// rename default entry to ${theme} entry // rename default entry to ${theme} entry
Object.keys(config.entry).forEach(entryName => { Object.keys(config.entry).forEach(entryName => {
config.entry[entryName.replace('antd', `antd.dark`)] = config.entry[entryName]; config.entry[entryName.replace('antd', `antd.${theme}`)] = config.entry[entryName];
delete config.entry[entryName]; delete config.entry[entryName];
}); });
@ -46,16 +38,39 @@ webpackDarkConfig.forEach(config => {
if (rule.test instanceof RegExp && rule.test.test('.less')) { if (rule.test instanceof RegExp && rule.test.test('.less')) {
const lessRule = rule.use[rule.use.length - 1]; const lessRule = rule.use[rule.use.length - 1];
if (lessRule.options.lessOptions) { if (lessRule.options.lessOptions) {
lessRule.options.lessOptions.modifyVars = darkVars; lessRule.options.lessOptions.modifyVars = vars;
} else { } else {
lessRule.options.modifyVars = darkVars; lessRule.options.modifyVars = vars;
} }
} }
}); });
const themeReg = new RegExp(`dark(.min)?\\.js(\\.map)?`); const themeReg = new RegExp(`${theme}(.min)?\\.js(\\.map)?$`);
// ignore emit ${theme} entry js & js.map file // ignore emit ${theme} entry js & js.map file
config.plugins.push(new IgnoreEmitPlugin(themeReg)); config.plugins.push(new IgnoreEmitPlugin(themeReg));
}); });
}
const webpackConfig = getWebpackConfig(false);
const webpackDarkConfig = getWebpackConfig(false);
if (process.env.RUN_ENV === 'PRODUCTION') {
webpackConfig.forEach(config => {
externalDayjs(config);
addLocales(config);
// Reduce non-minified dist files size
config.optimization.usedExports = true;
config.plugins.push(
new BundleAnalyzerPlugin({
analyzerMode: 'static',
openAnalyzer: false,
reportFilename: '../report.html',
}),
);
});
processWebpackThemeConfig(webpackDarkConfig, 'dark', darkVars);
}
module.exports = webpackConfig.concat(webpackDarkConfig); module.exports = webpackConfig.concat(webpackDarkConfig);