Skip to content
This repository has been archived by the owner on Jul 19, 2021. It is now read-only.

How to get React Fast Refresh to work #98

Closed
jizusun opened this issue May 22, 2020 · 3 comments
Closed

How to get React Fast Refresh to work #98

jizusun opened this issue May 22, 2020 · 3 comments

Comments

@jizusun
Copy link

jizusun commented May 22, 2020

Hi all,

The React Fast Refresh is much better than HMR, and here is

/* config-overrides.js */

const { override } = require('customize-cra')
const { addReactRefresh } = require('customize-cra-react-refresh')

module.exports = override(addReactRefresh({ disableRefreshCheck: true }))

I guess I need to use

But I don't know how to write in a rescript way.
Can anyone have a try and help me ?

Thanks so much ❤️

@harrysolovay
Copy link
Owner

If you look at the customize-cra-react-refresh package, you'll see it makes two changes to your config:

  1. the react-refresh/babel Babel plugin is added
  2. the @pmmmwh/react-refresh-webpack-plugin plugin is added

After installing these two dependencies, you should be able to do the following:

const {appendWebpackPlugin} = require(@rescripts/utils);
const ReactRefreshPlugin = require("@pmmmwh/react-refresh-webpack-plugin");

const isDevelopment = process.env.NODE_ENV !== "production";

module.exports = [
  ['use-babel-config', '.babelrc'],
  isDevelopment
    ? [appendWebpackPlugin(new ReactRefreshPlugin(...yourOptions))]
    : config => config
]

Finally, specify the react-refresh babel plugin in your .babelrc.

[
  "plugins": [
    "react-app",
    "react-refresh/babel"
  ]
]

Please try this out and let me know if you need more help

@jizusun
Copy link
Author

jizusun commented May 23, 2020

@harrysolovay It works pretty well on a CRA app!
https://github.com/jizusun/react-typescript-fast-refresh/pull/2/files

Thank you for this great project!

By the way, only a small typo in your answer 😄

- const {appendWebpackPlugin} = require(@rescripts/utils);
+ const {appendWebpackPlugin} = require('@rescripts/utilities')

@jizusun jizusun closed this as completed May 23, 2020
@jizusun jizusun reopened this May 23, 2020
@jizusun
Copy link
Author

jizusun commented May 23, 2020

Hi @harrysolovay Excuse me, but I just found it very strange

Maybe I should dive deep into the code, but do you have any guess about why doesn't it work?
My guess is customize-cra-react-refresh use a pretty old react-refresh-webpack-plugin
And how can I try rescripts + customize-cra-react-refresh?

Thanks so much for your help ❤️

@jizusun jizusun closed this as completed May 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants