fixed dayjs to moment bug with webpack plugin
This commit is contained in:
@@ -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: {
|
||||
|
||||
Reference in New Issue
Block a user