From 9a3fa512ebcbf9e0b539dd337db967017b626826 Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 5 Sep 2023 19:13:42 +0100 Subject: [PATCH] Enable Fast Refresh for web (#1383) --- package.json | 8 ++++++-- webpack.config.js | 4 ++++ yarn.lock | 18 ++++++++++++++++-- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index f11d482f..929ff8bd 100644 --- a/package.json +++ b/package.json @@ -153,6 +153,7 @@ "@babel/preset-env": "^7.20.0", "@babel/runtime": "^7.20.0", "@did-plc/server": "^0.0.1", + "@pmmmwh/react-refresh-webpack-plugin": "^0.5.11", "@react-native-community/eslint-config": "^3.0.0", "@testing-library/jest-native": "^5.4.1", "@testing-library/react-native": "^11.5.2", @@ -192,6 +193,7 @@ "metro-react-native-babel-preset": "^0.73.7", "prettier": "^2.8.3", "react-native-dotenv": "^3.3.1", + "react-refresh": "^0.14.0", "react-scripts": "^5.0.1", "react-test-renderer": "18.2.0", "ts-node": "^10.9.1", @@ -199,10 +201,12 @@ "url-loader": "^4.1.1", "webpack": "^5.75.0", "webpack-cli": "^5.0.1", - "webpack-dev-server": "^4.11.1" + "webpack-dev-server": "^4.11.1", + "webpack-hot-middleware": "^2.25.4" }, "resolutions": { - "@types/react": "^18" + "@types/react": "^18", + "react-error-overlay": "6.0.9" }, "jest": { "preset": "jest-expo/ios", diff --git a/webpack.config.js b/webpack.config.js index 28e5ca0d..7515db8e 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,5 +1,6 @@ const createExpoWebpackConfigAsync = require('@expo/webpack-config') const {withAlias} = require('@expo/webpack-config/addons') +const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin') const reactNativeWebWebviewConfiguration = { test: /postMock.html$/, @@ -22,5 +23,8 @@ module.exports = async function (env, argv) { ...(config.module.rules || []), reactNativeWebWebviewConfiguration, ] + if (env.mode === 'development') { + config.plugins.push(new ReactRefreshWebpackPlugin()) + } return config } diff --git a/yarn.lock b/yarn.lock index a0704f07..5ef9742d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3563,7 +3563,7 @@ mkdirp "^1.0.4" rimraf "^3.0.2" -"@pmmmwh/react-refresh-webpack-plugin@^0.5.3": +"@pmmmwh/react-refresh-webpack-plugin@^0.5.11", "@pmmmwh/react-refresh-webpack-plugin@^0.5.3": version "0.5.11" resolved "https://registry.yarnpkg.com/@pmmmwh/react-refresh-webpack-plugin/-/react-refresh-webpack-plugin-0.5.11.tgz#7c2268cedaa0644d677e8c4f377bc8fb304f714a" integrity sha512-7j/6vdTym0+qZ6u4XbSAxrWBGYSdCfTzySkj7WAFgDLmSyWlOrWvpyzxlFh5jtw9dn0oL/jtW+06XfFiisN3JQ== @@ -7005,7 +7005,7 @@ ansi-fragments@^0.2.1: slice-ansi "^2.0.0" strip-ansi "^5.0.0" -ansi-html-community@^0.0.8: +ansi-html-community@0.0.8, ansi-html-community@^0.0.8: version "0.0.8" resolved "https://registry.yarnpkg.com/ansi-html-community/-/ansi-html-community-0.0.8.tgz#69fbc4d6ccbe383f9736934ae34c3f8290f1bf41" integrity sha512-1APHAyr3+PCamwNw3bXCPp4HFLONZt/yIH0sZp0/469KWNTEy+qN5jQ3GVX6DMZ1UXAi34yVwtTeaG/HpBuuzw== @@ -17446,6 +17446,11 @@ react-refresh@^0.11.0: resolved "https://registry.yarnpkg.com/react-refresh/-/react-refresh-0.11.0.tgz#77198b944733f0f1f1a90e791de4541f9f074046" integrity sha512-F27qZr8uUqwhWZboondsPx8tnC3Ct3SxZA3V5WyEvujRyyNv0VYPhoBg1gZ8/MV5tubQp76Trw8lTv9hzRBa+A== +react-refresh@^0.14.0: + version "0.14.0" + resolved "https://registry.yarnpkg.com/react-refresh/-/react-refresh-0.14.0.tgz#4e02825378a5f227079554d4284889354e5f553e" + integrity sha512-wViHqhAd8OHeLS/IRMJjTSDHF3U9eWi62F/MledQGPdJGDhodXJ9PBLNGr6WWL7qlH12Mt3TyTpbS+hGXMjCzQ== + react-refresh@^0.4.0: version "0.4.3" resolved "https://registry.yarnpkg.com/react-refresh/-/react-refresh-0.4.3.tgz#966f1750c191672e76e16c2efa569150cc73ab53" @@ -20218,6 +20223,15 @@ webpack-dev-server@^4.11.1, webpack-dev-server@^4.6.0: webpack-dev-middleware "^5.3.1" ws "^8.13.0" +webpack-hot-middleware@^2.25.4: + version "2.25.4" + resolved "https://registry.yarnpkg.com/webpack-hot-middleware/-/webpack-hot-middleware-2.25.4.tgz#d8bc9e9cb664fc3105c8e83d2b9ed436bee4e193" + integrity sha512-IRmTspuHM06aZh98OhBJtqLpeWFM8FXJS5UYpKYxCJzyFoyWj1w6VGFfomZU7OPA55dMLrQK0pRT1eQ3PACr4w== + dependencies: + ansi-html-community "0.0.8" + html-entities "^2.1.0" + strip-ansi "^6.0.0" + webpack-manifest-plugin@^4.0.2, webpack-manifest-plugin@^4.1.1: version "4.1.1" resolved "https://registry.yarnpkg.com/webpack-manifest-plugin/-/webpack-manifest-plugin-4.1.1.tgz#10f8dbf4714ff93a215d5a45bcc416d80506f94f"