Last active
June 9, 2020 16:40
-
-
Save trungtin/0991b9ed687dc9fc5caa58f533eddc9a to your computer and use it in GitHub Desktop.
Patch react-scripts for hot reloading
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
yarn add -D patch-package @pmmmwh/react-refresh-webpack-plugin react-refresh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/node_modules/react-scripts/config/webpack.config.js b/node_modules/react-scripts/config/webpack.config.js | |
index 25840d9..51f2e69 100644 | |
--- a/node_modules/react-scripts/config/webpack.config.js | |
+++ b/node_modules/react-scripts/config/webpack.config.js | |
@@ -32,6 +32,7 @@ const getClientEnvironment = require('./env'); | |
const ModuleNotFoundPlugin = require('react-dev-utils/ModuleNotFoundPlugin'); | |
const ForkTsCheckerWebpackPlugin = require('react-dev-utils/ForkTsCheckerWebpackPlugin'); | |
const typescriptFormatter = require('react-dev-utils/typescriptFormatter'); | |
+const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin'); | |
// @remove-on-eject-begin | |
const getCacheIdentifier = require('react-dev-utils/getCacheIdentifier'); | |
// @remove-on-eject-end | |
@@ -420,7 +421,8 @@ module.exports = function(webpackEnv) { | |
}, | |
}, | |
], | |
- ], | |
+ isEnvDevelopment && require.resolve('react-refresh/babel') | |
+ ].filter(Boolean), | |
// This is a feature of `babel-loader` for webpack (not Babel itself). | |
// It enables caching results in ./node_modules/.cache/babel-loader/ | |
// directory for faster rebuilds. | |
@@ -699,6 +701,7 @@ module.exports = function(webpackEnv) { | |
// The formatter is invoked directly in WebpackDevServerUtils during development | |
formatter: isEnvProduction ? typescriptFormatter : undefined, | |
}), | |
+ isEnvDevelopment && new ReactRefreshWebpackPlugin(), | |
].filter(Boolean), | |
// Some libraries import Node modules but don't use them in the browser. | |
// Tell webpack to provide empty mocks for them so importing them works. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment