Skip to content

Commit

Permalink
32. Code Split
Browse files Browse the repository at this point in the history
  • Loading branch information
tylermcginnis committed Mar 16, 2019
1 parent 18977db commit 97f21e5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
22 changes: 13 additions & 9 deletions app/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import React from 'react'
import ReactDOM from 'react-dom'
import './index.css'
import Popular from './components/Popular'
import Battle from './components/Battle'
import Results from './components/Results'
import { ThemeProvider } from './contexts/theme'
import Nav from './components/Nav'
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom'
import Loading from './components/Loading'

const Popular = React.lazy(() => import('./components/Popular'))
const Battle = React.lazy(() => import('./components/Battle'))
const Results = React.lazy(() => import('./components/Results'))

class App extends React.Component {
state = {
Expand All @@ -25,12 +27,14 @@ class App extends React.Component {
<div className='container'>
<Nav />

<Switch>
<Route exact path='/' component={Popular} />
<Route exact path='/battle' component={Battle} />
<Route path='/battle/results' component={Results} />
<Route render={() => <h1>404</h1>} />
</Switch>
<React.Suspense fallback={<Loading />} >
<Switch>
<Route exact path='/' component={Popular} />
<Route exact path='/battle' component={Battle} />
<Route path='/battle/results' component={Results} />
<Route render={() => <h1>404</h1>} />
</Switch>
</React.Suspense>
</div>
</div>
</ThemeProvider>
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
"description": "",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server"
"start": "webpack-dev-server",
"build": "webpack"
},
"babel": {
"presets": [
"@babel/preset-env",
"@babel/preset-react"
],
"plugins": [
"@babel/plugin-proposal-class-properties"
"@babel/plugin-proposal-class-properties",
"syntax-dynamic-import"
]
},
"keywords": [],
Expand All @@ -32,6 +34,7 @@
"@babel/preset-env": "^7.3.4",
"@babel/preset-react": "^7.0.0",
"babel-loader": "^8.0.5",
"babel-plugin-syntax-dynamic-import": "^6.18.0",
"css-loader": "^2.1.1",
"html-webpack-plugin": "^3.2.0",
"style-loader": "^0.23.1",
Expand Down

0 comments on commit 97f21e5

Please sign in to comment.