Skip to content

Commit

Permalink
feat(hmr): handle fast reloading
Browse files Browse the repository at this point in the history
  • Loading branch information
keellyp committed Sep 27, 2024
1 parent 8ed4f91 commit 3c01e92
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 11 deletions.
13 changes: 10 additions & 3 deletions .babelrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
module.exports = () => {
module.exports = (api) => {
// This caches the Babel config
api.cache.using(() => process.env.NODE_ENV)
return {
presets: ['@babel/preset-env', '@babel/preset-react'],
presets: [
'@babel/preset-env',
// Enable development transform of React with new automatic runtime
['@babel/preset-react', { development: !api.env('production'), runtime: 'automatic' }],
],
plugins: [
'@babel/plugin-syntax-dynamic-import',
['babel-plugin-styled-components', { displayName: true }],
Expand All @@ -13,6 +19,7 @@ module.exports = () => {
css: true,
},
],
],
...(!api.env('production') && ['react-refresh/babel']),
].filter(Boolean),
}
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"@graphql-codegen/typescript-operations": "4.2.3",
"@graphql-codegen/typescript-react-apollo": "4.3.2",
"@parcel/watcher": "^2.3.0",
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.15",
"@svgr/webpack": "8.1.0",
"@testing-library/dom": "^10.0.0",
"@testing-library/jest-dom": "6.4.8",
Expand Down Expand Up @@ -89,6 +90,7 @@
"postcss-preset-env": "^9.5.13",
"prettier": "^3.3.3",
"prettier-plugin-tailwindcss": "^0.6.6",
"react-refresh": "^0.14.2",
"style-loader": "^4.0.0",
"tailwind-merge": "^2.5.2",
"tailwindcss": "^3.4.11",
Expand Down
7 changes: 2 additions & 5 deletions webpack.dev.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const path = require('path')

const webpack = require('webpack')
const { merge } = require('webpack-merge')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin')
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin')

const common = require('./webpack.common.js')

Expand Down Expand Up @@ -85,18 +85,15 @@ module.exports = (env) =>
template: path.join(__dirname, 'src', 'index.html'),
favicon: './src/public/images/favicon-local.svg',
}),
new webpack.HotModuleReplacementPlugin(),
new ReactRefreshWebpackPlugin(),
],
devServer: {
historyApiFallback: true,
open: true,
hot: true,
port: process.env.PORT || 8080,
static: {
directory: path.resolve(__dirname, './dist'),
},
client: {
overlay: true,
webSocketURL: {
port: 443,
},
Expand Down
46 changes: 43 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2963,6 +2963,19 @@
resolved "https://registry.yarnpkg.com/@pkgjs/parseargs/-/parseargs-0.11.0.tgz#a77ea742fab25775145434eb1d2328cf5013ac33"
integrity sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==

"@pmmmwh/react-refresh-webpack-plugin@^0.5.15":
version "0.5.15"
resolved "https://registry.yarnpkg.com/@pmmmwh/react-refresh-webpack-plugin/-/react-refresh-webpack-plugin-0.5.15.tgz#f126be97c30b83ed777e2aeabd518bc592e6e7c4"
integrity sha512-LFWllMA55pzB9D34w/wXUCf8+c+IYKuJDgxiZ3qMhl64KRMBHYM1I3VdGaD2BV5FNPV2/S2596bppxHbv2ZydQ==
dependencies:
ansi-html "^0.0.9"
core-js-pure "^3.23.3"
error-stack-parser "^2.0.6"
html-entities "^2.1.0"
loader-utils "^2.0.4"
schema-utils "^4.2.0"
source-map "^0.7.3"

"@polka/url@^1.0.0-next.24":
version "1.0.0-next.27"
resolved "https://registry.yarnpkg.com/@polka/url/-/url-1.0.0-next.27.tgz#527e8df13dea13ab68d347d20ba9432cadb867a8"
Expand Down Expand Up @@ -4229,6 +4242,11 @@ ansi-html-community@^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==

ansi-html@^0.0.9:
version "0.0.9"
resolved "https://registry.yarnpkg.com/ansi-html/-/ansi-html-0.0.9.tgz#6512d02342ae2cc68131952644a129cb734cd3f0"
integrity sha512-ozbS3LuenHVxNRh/wdnN16QapUHzauqSomAl1jwwJRRsGwFwtj644lIhxfWu0Fy0acCij2+AEgHvjscq3dlVXg==

ansi-regex@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-5.0.1.tgz#082cb2c89c9fe8659a311a53bd6a4dc5301db304"
Expand Down Expand Up @@ -5325,6 +5343,11 @@ core-js-compat@^3.31.0, core-js-compat@^3.33.1, core-js-compat@^3.37.1, core-js-
dependencies:
browserslist "^4.23.3"

core-js-pure@^3.23.3:
version "3.38.1"
resolved "https://registry.yarnpkg.com/core-js-pure/-/core-js-pure-3.38.1.tgz#e8534062a54b7221344884ba9b52474be495ada3"
integrity sha512-BY8Etc1FZqdw1glX0XNOq2FDwfrg/VGqoZOZCdaL+UmdaqDwQwYXkMJT4t6In+zfEfOJDcM9T0KdbBeJg8KKCQ==

[email protected]:
version "1.0.2"
resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7"
Expand Down Expand Up @@ -6218,6 +6241,13 @@ error-ex@^1.3.1:
dependencies:
is-arrayish "^0.2.1"

error-stack-parser@^2.0.6:
version "2.1.4"
resolved "https://registry.yarnpkg.com/error-stack-parser/-/error-stack-parser-2.1.4.tgz#229cb01cdbfa84440bfa91876285b94680188286"
integrity sha512-Sk5V6wVazPhq5MhpO+AUxJn5x7XSXGl1R93Vn7i+zS15KDVxQijejNCrz8340/2bgLBjR9GtEG8ZVKONDjcqGQ==
dependencies:
stackframe "^1.3.4"

es-abstract@^1.22.1, es-abstract@^1.22.3, es-abstract@^1.23.0, es-abstract@^1.23.1, es-abstract@^1.23.2, es-abstract@^1.23.3:
version "1.23.3"
resolved "https://registry.yarnpkg.com/es-abstract/-/es-abstract-1.23.3.tgz#8f0c5a35cd215312573c5a27c87dfd6c881a0aa0"
Expand Down Expand Up @@ -7394,7 +7424,7 @@ html-encoding-sniffer@^3.0.0:
dependencies:
whatwg-encoding "^2.0.0"

html-entities@^2.4.0:
html-entities@^2.1.0, html-entities@^2.4.0:
version "2.5.2"
resolved "https://registry.yarnpkg.com/html-entities/-/html-entities-2.5.2.tgz#201a3cf95d3a15be7099521620d19dfb4f65359f"
integrity sha512-K//PSRMQk4FZ78Kyau+mZurHn3FH0Vwr+H36eE0rPbeYkRRi9YxceYPhuN60UwWorxyKHhqoAJl2OFKa4BVtaA==
Expand Down Expand Up @@ -8790,7 +8820,7 @@ loader-runner@^4.2.0:
resolved "https://registry.yarnpkg.com/loader-runner/-/loader-runner-4.3.0.tgz#c1b4a163b99f614830353b16755e7149ac2314e1"
integrity sha512-3R/1M+yS3j5ou80Me59j7F9IMs4PXs3VqRrm0TU3AbKPxlmpoY1TNscJV/oGJXo8qCatFGTfDbY6W6ipGOYXfg==

loader-utils@^2.0.0:
loader-utils@^2.0.0, loader-utils@^2.0.4:
version "2.0.4"
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-2.0.4.tgz#8b5cb38b5c34a9a018ee1fc0e6a066d1dfcc528c"
integrity sha512-xXqpXoINfFhgua9xiqD8fPFHgkoq1mmmpE92WlDbm9rNRd/EbRb+Gqf908T2DMfuHjjJlksiK2RbHVOdD/MqSw==
Expand Down Expand Up @@ -10429,6 +10459,11 @@ react-is@^18.0.0, react-is@^18.2.0, react-is@^18.3.1:
resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.3.1.tgz#e83557dc12eae63a99e003a46388b1dcbb44db7e"
integrity sha512-/LLMVyas0ljjAtoYiPqYiL8VWXzUUdThrmU5+n20DZv+a+ClRoevUzw5JxU+Ieh5/c87ytoTBV9G1FiKfNJdmg==

react-refresh@^0.14.2:
version "0.14.2"
resolved "https://registry.yarnpkg.com/react-refresh/-/react-refresh-0.14.2.tgz#3833da01ce32da470f1f936b9d477da5c7028bf9"
integrity sha512-jCvmsr+1IUSMUyzOkRcvnVbX3ZYC6g9TDrDbFuFmRDq7PD4yaGbLKNQL6k2jnArV8hjYxh7hVhAZB6s9HDGpZA==

[email protected]:
version "6.15.0"
resolved "https://registry.yarnpkg.com/react-router-dom/-/react-router-dom-6.15.0.tgz#6da7db61e56797266fbbef0d5e324d6ac443ee40"
Expand Down Expand Up @@ -11147,7 +11182,7 @@ source-map@^0.6.0, source-map@^0.6.1, source-map@~0.6.0, source-map@~0.6.1:
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==

source-map@^0.7.4:
source-map@^0.7.3, source-map@^0.7.4:
version "0.7.4"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.7.4.tgz#a9bbe705c9d8846f4e08ff6765acf0f1b0898656"
integrity sha512-l3BikUxvPOcn5E74dZiq5BGsTb5yEwhaTSzccU6t4sDOH8NWJCstKO5QT2CvtFoK6F0saL7p9xHAqHOlCPJygA==
Expand Down Expand Up @@ -11209,6 +11244,11 @@ stack-utils@^2.0.3:
dependencies:
escape-string-regexp "^2.0.0"

stackframe@^1.3.4:
version "1.3.4"
resolved "https://registry.yarnpkg.com/stackframe/-/stackframe-1.3.4.tgz#b881a004c8c149a5e8efef37d51b16e412943310"
integrity sha512-oeVtt7eWQS+Na6F//S4kJ2K2VbRlS9D43mAlMyVpVWovy9o+jfgH8O9agzANzaiLjclA0oYzUXEM4PurhSUChw==

[email protected]:
version "2.0.1"
resolved "https://registry.yarnpkg.com/statuses/-/statuses-2.0.1.tgz#55cb000ccf1d48728bd23c685a063998cf1a1b63"
Expand Down

0 comments on commit 3c01e92

Please sign in to comment.