From f4da983c9d22acf3cf48bb9f32552c9c06edb9fa Mon Sep 17 00:00:00 2001 From: "Morten N.O. Henriksen" Date: Wed, 4 Nov 2020 01:52:02 +0100 Subject: [PATCH] Support Webpack 4+5 IgnorePlugin signature Reference: * https://webpack.js.org/plugins/ignore-plugin/#example-of-ignoring-moment-locales --- packages/react-scripts/config/webpack.config.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/react-scripts/config/webpack.config.js b/packages/react-scripts/config/webpack.config.js index 8efff0b96c7..06ba8c3e6fa 100644 --- a/packages/react-scripts/config/webpack.config.js +++ b/packages/react-scripts/config/webpack.config.js @@ -705,7 +705,12 @@ module.exports = function (webpackEnv) { // solution that requires the user to opt into importing specific locales. // https://github.com/jmblog/how-to-optimize-momentjs-with-webpack // You can remove this if you don't use Moment.js: - new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/), + webpack.version.startsWith('5.') + ? new webpack.IgnorePlugin({ + resourceRegExp: /^\.\/locale$/, + contextRegExp: /moment$/, + }) + : new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/), // Generate a service worker script that will precache, and keep up to date, // the HTML & assets that are part of the webpack build. isEnvProduction &&