Skip to content
This repository has been archived by the owner on Jan 26, 2019. It is now read-only.

enable webpack hmr #312

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions packages/react-scripts/template/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,25 @@ import App from './App';
import './index.css';
import registerServiceWorker from './registerServiceWorker';

ReactDOM.render(
<App />,
document.getElementById('root') as HTMLElement
);
function registerHMR() {
type ModuleHMR = typeof module & {
hot?: {
accept(dependencies: string | string[], callback: (updatedDependencies: any[]) => void): void
}
};

if ((module as ModuleHMR).hot) {
(module as ModuleHMR).hot!.accept('./App', render);
}
}

function render() {
ReactDOM.render(
<App />,
document.getElementById('root') as HTMLElement
);
}

registerServiceWorker();
registerHMR();
render();