fixed dayjs to moment bug with webpack plugin

This commit is contained in:
swtmply
2023-04-18 01:49:42 +08:00
parent 4e90534e69
commit a2eaa3b376
4 changed files with 12195 additions and 12368 deletions

View File

@@ -2,6 +2,32 @@
const TerserPlugin = require("terser-webpack-plugin");
const SentryWebpackPlugin = require("@sentry/webpack-plugin");
const generateRegExp = /generate\/dayjs/;
const updateResource = (resource) => {
resource.request = resource.request.replace("dayjs", "moment");
};
const plugin = "AntdMomentWebpackPlugin";
class AntdMomentWebpackPlugin {
constructor(options) {
this.options = options || {};
}
apply(compiler) {
compiler.hooks.normalModuleFactory.tap(plugin, (factory) => {
factory.hooks.beforeResolve.tap(plugin, (result) => {
if (generateRegExp.test(result.request)) {
updateResource(result);
}
});
factory.hooks.afterResolve.tap(plugin, (result) => {
const createData = result.createData;
if (generateRegExp.test(createData.resource)) {
updateResource(result);
}
});
});
}
}
module.exports = {
plugins: [
{
@@ -21,6 +47,7 @@ module.exports = {
},
],
webpack: {
plugins: [new AntdMomentWebpackPlugin()],
configure: (webpackConfig) => ({
...webpackConfig,
optimization: {

View File

@@ -13,7 +13,7 @@
"@sentry/tracing": "^7.40.0",
"@splitsoftware/splitio-react": "^1.8.1",
"@tanem/react-nprogress": "^5.0.8",
"antd": "5.1.5",
"antd": "^5.4.2",
"apollo-link-logger": "^2.0.0",
"axios": "^1.3.4",
"dinero.js": "^1.9.1",
@@ -114,6 +114,7 @@
"react-error-overlay": "6.0.9"
},
"devDependencies": {
"@ant-design/moment-webpack-plugin": "^0.0.3",
"@sentry/webpack-plugin": "^1.20.0",
"@testing-library/cypress": "^9.0.0",
"cypress": "^12.3.0",

File diff suppressed because it is too large Load Diff

6373
yarn.lock

File diff suppressed because it is too large Load Diff