Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

Commit eeaf4e6

Browse files
Update ReactSpa to React Hot Loader 3. Remove babel dependency.
1 parent ef9dbfe commit eeaf4e6

File tree

6 files changed

+30
-25
lines changed

6 files changed

+30
-25
lines changed

templates/ReactSpa/.babelrc

-3
This file was deleted.

templates/ReactSpa/ClientApp/boot.tsx

+23-7
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,28 @@ import './css/site.css';
22
import 'bootstrap';
33
import * as React from 'react';
44
import * as ReactDOM from 'react-dom';
5+
import { AppContainer } from 'react-hot-loader';
56
import { BrowserRouter } from 'react-router-dom';
6-
import routes from './routes';
7+
import * as RoutesModule from './routes';
8+
let routes = RoutesModule.routes;
79

8-
// This code starts up the React app when it runs in a browser. It sets up the routing configuration
9-
// and injects the app into a DOM element.
10-
ReactDOM.render(
11-
<BrowserRouter children={ routes } />,
12-
document.getElementById('react-app')
13-
);
10+
function renderApp() {
11+
// This code starts up the React app when it runs in a browser. It sets up the routing
12+
// configuration and injects the app into a DOM element.
13+
ReactDOM.render(
14+
<AppContainer>
15+
<BrowserRouter children={ routes } />
16+
</AppContainer>,
17+
document.getElementById('react-app')
18+
);
19+
}
20+
21+
renderApp();
22+
23+
// Allow Hot Module Replacement
24+
if (module.hot) {
25+
module.hot.accept('./routes', () => {
26+
routes = require<typeof RoutesModule>('./routes').routes;
27+
renderApp();
28+
});
29+
}

templates/ReactSpa/ClientApp/routes.tsx

+1-7
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,8 @@ import { Home } from './components/Home';
55
import { FetchData } from './components/FetchData';
66
import { Counter } from './components/Counter';
77

8-
export default <Layout>
8+
export const routes = <Layout>
99
<Route exact path='/' component={ Home } />
1010
<Route path='/counter' component={ Counter } />
1111
<Route path='/fetchdata' component={ FetchData } />
1212
</Layout>;
13-
14-
// Allow Hot Module Reloading
15-
declare var module: any;
16-
if (module.hot) {
17-
module.hot.accept();
18-
}

templates/ReactSpa/package.json

+3-5
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,10 @@
66
"@types/react": "^0.14.38",
77
"@types/react-dom": "^0.14.17",
88
"@types/react-router": "^2.0.38",
9+
"@types/webpack-env": "^1.13.0",
910
"aspnet-webpack": "^1.0.27",
10-
"aspnet-webpack-react": "^1.0.4",
11+
"aspnet-webpack-react": "^2.0.0",
1112
"awesome-typescript-loader": "^3.0.0",
12-
"babel-core": "^6.17.0",
13-
"babel-loader": "^6.2.5",
14-
"babel-preset-es2015": "^6.16.0",
15-
"babel-preset-react": "^6.16.0",
1613
"bootstrap": "^3.3.6",
1714
"css-loader": "^0.25.0",
1815
"event-source-polyfill": "^0.0.7",
@@ -23,6 +20,7 @@
2320
"json-loader": "^0.5.4",
2421
"react": "~15.4.0",
2522
"react-dom": "~15.4.0",
23+
"react-hot-loader": "3.0.0-beta.7",
2624
"react-router-dom": "^4.0.0",
2725
"style-loader": "^0.13.1",
2826
"typescript": "^2.2.1",

templates/ReactSpa/tsconfig.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
"compilerOptions": {
33
"baseUrl": ".",
44
"moduleResolution": "node",
5-
"target": "es6",
6-
"jsx": "preserve",
5+
"target": "es5",
6+
"jsx": "react",
77
"sourceMap": true,
88
"skipDefaultLibCheck": true,
9+
"types": [ "webpack-env" ],
910
"paths": {
1011
// Fix "Duplicate identifier" errors caused by multiple dependencies fetching their own copies of type definitions.
1112
// We tell TypeScript which type definitions module to treat as the canonical one (instead of combining all of them).

templates/ReactSpa/webpack.config.js

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ module.exports = (env) => {
1717
},
1818
module: {
1919
rules: [
20-
{ test: /\.ts(x?)$/, include: /ClientApp/, use: { loader: 'babel-loader', options: { cacheDirectory: true } } },
2120
{ test: /\.tsx?$/, include: /ClientApp/, use: 'awesome-typescript-loader?silent=true' },
2221
{ test: /\.css$/, use: isDevBuild ? ['style-loader', 'css-loader'] : ExtractTextPlugin.extract({ use: 'css-loader?minimize' }) },
2322
{ test: /\.(png|jpg|jpeg|gif|svg)$/, use: 'url-loader?limit=25000' }

0 commit comments

Comments
 (0)