-
Notifications
You must be signed in to change notification settings - Fork 492
Enabling 'react-hot' on typescript project #3
Comments
I have had |
I tried with react-hot-loader@3 (current beta version), but in typescript I don't find
Any idea where i can get the definition for |
This typing looks like it includes the neccessary definitions to enable |
I just had a quick play, and made the changes to get hot-reloading working, you can see the repo and commit here. You will need to replace I'm going to close this issue, as I think the above should be enough to get this working for you. But, want to keep |
It nearly works. As long as I don't need to use the Unfortunately many libraries (written in typescript) require I guess there is currently no fix for this... |
@Aranir just got back to work, and found the way it was handled here, hope this helps: export interface WebpackNodeModule extends NodeModule {
hot: {
accept: (name: string, handler: () => void) => void
};
} import { WebpackNodeModule } from './typePatches/webpackNodeModule';
if ((module as WebpackNodeModule).hot) {
// do stuff
} it's not ideal, and is quite hacky, but would allow you to carry on using the |
yarn add |
I followed @gaearon recomendations in and code from And I succeed with https://github.com/wmonk/create-react-app-typescript hot loader This is what I did, hope it helps. https://gist.github.com/kerwynrg/0ecf4d53345585e77b3fa694bad60d4d |
@kerwynrg Thanks for sharing this. I still can't get it working though, my app just reloads and I don't get anything in the console from HMR. Would you mind sharing what your root/index component looks like? Did you have to add a .babelrc or anything else not covered in the gist? Thanks again for sharing, would really like to get this working! |
@SeanRoberts I updated the gist with mi Root and configureStore for dev environment, It includes some redux-saga code but if you don't use it, you can omit it. Sometimes it inject code on demand, some other times app reloads to load, I don't remember what are the scenarios when this happens. |
Thanks @kerwynrg, this looks a lot like what I have so I think something else in my stack (possibly another rewire package) might be causing the issue. |
@SeanRoberts What package are you using? |
@kerwynrg I'm using the following:
I've also got the following in tsconfig:
Did you manually add babel-loader? Or anything in a babelrc file? Really appreciate the help with this, it'd be great to get a definitive recipe together for getting hot reloading with react-scripts-ts! |
I don't have a .babelrc. This is my tsconfig.json {
"compilerOptions": {
"baseUrl": "./",
"outDir": "build/dist",
"module": "commonjs",
"target": "es6",
"lib": ["es6", "dom"],
"sourceMap": true,
"allowJs": true,
"jsx": "react",
"moduleResolution": "node",
"rootDir": "src",
"noImplicitReturns": true,
"noImplicitThis": true,
"noImplicitAny": true,
"strictNullChecks": true,
"noUnusedLocals": true
},
"files": ["src/index.tsx"],
"exclude": [
"node_modules",
"build",
"scripts",
"acceptance-tests",
"webpack",
"jest",
"src/setupTests.ts",
"stories",
".storybook",
"*.stories.tsx",
"*.test.tsx"
],
"types": ["typePatches"]
} @SeanRoberts I see module and target are different. |
Finally, I also made it work. pfeeew 😤 This is everything I did during the process, some of it might be unnecessary. package.json
tsconfig.json
tsconfig.prod.json
src\index.tsx (practically default)
src\App.tsx
config-overrides.js
|
Thank you for the template, it is very helpful.
There is just one thing I can't figure out yet, how can I simply add the 'hot-reloading' to the project?
I ejected it, added the
react-hot-loader
package with yarn and modified the loaders:But it seems still to reload the whole page if I change a component.
Any help would be appreciated.
The text was updated successfully, but these errors were encountered: