-
Notifications
You must be signed in to change notification settings - Fork 15
Real world example with react, babel and code splitting by routes #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
andresgutgon
wants to merge
7
commits into
okonet:master
Choose a base branch
from
andresgutgon:feature/real-world-example-with-react-and-code-splitting
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d9cdfbb
Install with yarn
andresgutgon 7cfb4a8
Crazy world: react, babel, mobx, lodash
andresgutgon 0ec7a08
ID with route prefix
andresgutgon de683a8
Understanding manifest extraction
andresgutgon 49d91b2
Fixed public path
andresgutgon 033202d
Understanding a bit more tree shaking
andresgutgon 672dc8e
WIP route code splitting
andresgutgon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
{ | ||
"presets": [ | ||
["env", { | ||
"targets": { | ||
"browsers": [ | ||
">1%", | ||
"last 4 versions", | ||
"Firefox ESR", | ||
"not ie < 10" | ||
] | ||
} | ||
}], | ||
["es2015", { "modules": false }], | ||
"react" | ||
], | ||
"plugins": [ | ||
"transform-decorators-legacy", | ||
"transform-class-properties", | ||
["transform-object-rest-spread", { useBuiltIns: true }], | ||
["transform-react-jsx", { useBuiltIns: true }], | ||
["transform-runtime", { | ||
"helpers": false, | ||
"polyfill": false, | ||
"regenerator": true, | ||
"moduleName": "babel-runtime" | ||
}], | ||
"transform-es2015-parameters", | ||
["transform-regenerator", {"async": false}] | ||
], | ||
"env": { | ||
"development": { | ||
"presets": ["react-hmre"], | ||
"plugins": [ | ||
"transform-react-jsx-source", | ||
"transform-react-jsx-self" | ||
] | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
# Logs | ||
logs | ||
*.log | ||
.DS_Store | ||
|
||
# Runtime data | ||
pids | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
## TODO | ||
- [ ] Continue with router code splitting. Not clear how to do it right :/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,52 @@ | ||
{ | ||
"name": "webpack-long-term-cache-demo", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"description": "A demo project which leverages long-term caching for webpack assets", | ||
"main": "", | ||
"scripts": { | ||
"start": "webpack", | ||
"start": "NODE_ENV=production node server.js", | ||
"build": "npm run clean && NODE_ENV=production webpack --config webpack/production.js", | ||
"clean": "./node_modules/rimraf/bin.js build/*", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [ | ||
"webpack", | ||
"cache", | ||
"long-term", | ||
"demo", | ||
"sample" | ||
"sample", | ||
"react", | ||
"babel" | ||
], | ||
"author": "@okonetchnikov", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"chunk-manifest-webpack-plugin": "0.0.1", | ||
"node-libs-browser": "^0.5.2", | ||
"webpack": "^1.10.1", | ||
"webpack-manifest-plugin": "^0.3.0", | ||
"babel-core": "6.22.1", | ||
"babel-loader": "6.2.10", | ||
"babel-plugin-transform-decorators-legacy": "1.3.4", | ||
"babel-plugin-transform-react-jsx-self": "6.22.0", | ||
"babel-plugin-transform-react-jsx-source": "6.22.0", | ||
"babel-plugin-transform-runtime": "6.22.0", | ||
"babel-polyfill": "6.22.0", | ||
"babel-preset-env": "1.1.8", | ||
"babel-preset-es2015": "6.22.0", | ||
"babel-preset-react": "6.22.0", | ||
"babel-preset-react-hmre": "1.1.1", | ||
"babel-preset-stage-0": "6.22.0", | ||
"html-webpack-plugin": "2.26.0", | ||
"inline-manifest-webpack-plugin": "^3.0.1", | ||
"rimraf": "2.5.4", | ||
"webpack": "2.2.1", | ||
"webpack-dev-server": "2.2.1", | ||
"webpack-md5-hash": "0.0.5" | ||
}, | ||
"dependencies": { | ||
"lodash": "4.17.4", | ||
"mobx": "2.7.0", | ||
"mobx-react": "4.1.0", | ||
"mobx-react-devtools": "4.2.11", | ||
"react": "15.4.2", | ||
"react-dom": "15.4.2", | ||
"react-router": "3.0.2" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Look all those big guys ☝️ |
||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const webpack = require('webpack') | ||
const WebpackDevServer = require('webpack-dev-server') | ||
|
||
const config = require('./webpack/production') | ||
|
||
const server = new WebpackDevServer(webpack(config), { | ||
contentBase: './src', | ||
publicPath: config.output.publicPath, | ||
hot: true, | ||
historyApiFallback: true, | ||
stats: { | ||
chunks: false, | ||
colors: true, | ||
}, | ||
}) | ||
|
||
server.listen(8000, 'localhost', function (err, result) { | ||
if (err) console.log(err) | ||
|
||
console.log('Listening at localhost:8000') | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import React from 'react' | ||
import { observer } from 'mobx-react' | ||
import { Router, browserHistory } from 'react-router' | ||
import rootRoute from './root' | ||
|
||
@observer | ||
export default class Routes extends React.Component { | ||
rootRoute () { | ||
return { | ||
childRoutes: [ | ||
rootRoute | ||
] | ||
} | ||
} | ||
|
||
render () { | ||
return ( | ||
<Router | ||
history={browserHistory} | ||
routes={this.rootRoute()} | ||
/> | ||
) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import React from 'react' | ||
import { observer } from 'mobx-react' | ||
import { Link } from 'react-router' | ||
|
||
@observer | ||
export default class RootContainer extends React.Component { | ||
render () { | ||
return ( | ||
<div> | ||
<h1>Long term webpack caching</h1> | ||
<ul> | ||
<li><Link to='/'>HOME</Link></li> | ||
<li><Link to='route-a'>Route A</Link></li> | ||
<li><Link to='route-b'>Route B</Link></li> | ||
</ul> | ||
{this.props.children} | ||
</div> | ||
); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import component from './component' | ||
import indexComponent from './indexComponent' | ||
|
||
import routeA from '../routeA' | ||
import routeB from '../routeB' | ||
|
||
export default { | ||
path: '/', | ||
component, | ||
indexRoute: { | ||
component: indexComponent | ||
}, | ||
childRoutes: [ | ||
routeA, | ||
routeB | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from 'react' | ||
|
||
export default class IndexRootComponent extends React.Component { | ||
render () { | ||
return ( | ||
<h3>Index root component</h3> | ||
) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from 'react' | ||
import { observer } from 'mobx-react' | ||
|
||
@observer | ||
export default class ChildComponent extends React.Component { | ||
render () { | ||
return ( | ||
<div> | ||
Here we're with params ID: <strong>route-A-ID-{this.props.params.id}</strong> | ||
</div> | ||
) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import component from './component' | ||
|
||
export default { | ||
path: 'child/:id', | ||
sectionLevel: 2, | ||
component | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react' | ||
import { observer } from 'mobx-react' | ||
import { Link } from 'react-router' | ||
|
||
@observer | ||
export default class Container extends React.Component { | ||
render () { | ||
return ( | ||
<div> | ||
<p>You're on <strong>Route A</strong></p> | ||
<ul> | ||
<li><Link to='/route-a/child/1'>Route A child with ID 1</Link></li> | ||
<li><Link to='/route-a/child/2'>Route A child with ID 2</Link></li> | ||
</ul> | ||
{this.props.children} | ||
</div> | ||
); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
//import Authorize from 'components/Authorize' | ||
//import component from './component' | ||
//import indexComponent from './indexComponent' | ||
//import childComponent from './childComponent' | ||
|
||
/** | ||
* indexRoute: { | ||
* component: Authorize({ isAdmin: true, admin: indexComponent }) | ||
* }, | ||
*/ | ||
export default { | ||
path: 'route-a', | ||
getComponent(nextState, cb) { | ||
require.ensure([], (require) => { | ||
cb(null, require('./component')) | ||
}) | ||
}, | ||
getIndexRoute(partialNextState, cb) { | ||
// do something async here | ||
cb(null, require('./indexComponent')) | ||
}, | ||
getChildRoutes(location, cb) { | ||
require.ensure([], (require) => { | ||
cb(null, [ | ||
require('./childComponent'), | ||
]) | ||
}) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from 'react' | ||
import { observer } from 'mobx-react' | ||
|
||
@observer | ||
export default class IndexComponent extends React.Component { | ||
render () { | ||
return ( | ||
<div> | ||
Just an index component | ||
</div> | ||
) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from 'react' | ||
import { observer } from 'mobx-react' | ||
|
||
@observer | ||
export default class ChildComponent extends React.Component { | ||
render () { | ||
return ( | ||
<div> | ||
Here we're with params ID: <strong>route-B-ID-{this.props.params.id}</strong> | ||
</div> | ||
) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import component from './component' | ||
|
||
export default { | ||
path: 'child/:id', | ||
sectionLevel: 2, | ||
component | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react' | ||
import { observer } from 'mobx-react' | ||
import { Link } from 'react-router' | ||
|
||
@observer | ||
export default class Container extends React.Component { | ||
render () { | ||
return ( | ||
<div> | ||
<p>You're on <strong>Route A</strong></p> | ||
<ul> | ||
<li><Link to='/route-b/child/1'>Route B child with ID 1</Link></li> | ||
<li><Link to='/route-b/child/2'>Route B child with ID 2</Link></li> | ||
</ul> | ||
{this.props.children} | ||
</div> | ||
); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import Authorize from 'components/Authorize' | ||
import component from './component' | ||
import indexComponent from './indexComponent' | ||
import childComponent from './childComponent' | ||
|
||
export default { | ||
path: 'route-b', | ||
component: component, | ||
indexRoute: { | ||
component: Authorize({ isAdmin: true, admin: indexComponent }) | ||
}, | ||
childRoutes: [ | ||
childComponent | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from 'react' | ||
import { observer } from 'mobx-react' | ||
import _map from 'lodash/map'; | ||
|
||
|
||
@observer | ||
export default class IndexComponent extends React.Component { | ||
render () { | ||
const mapAdd = _map([1, 2, 3], (item) => item + 1); | ||
console.log('chunk', mapAdd); | ||
return ( | ||
<div> | ||
Just an index component | ||
</div> | ||
) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from 'react' | ||
import { observer } from 'mobx-react' | ||
import NotFound from 'components/NotFound' | ||
|
||
export default (options) => { | ||
return observer(class Proxy extends React.Component { | ||
render () { | ||
const AdminComponent = options.admin || NotFound | ||
const BasicComponent = options.basic || NotFound | ||
console.log('admin', options.isAdmin); | ||
|
||
if (options.isAdmin) { | ||
return <AdminComponent {...this.props} /> | ||
} else { | ||
return <BasicComponent {...this.props} /> | ||
} | ||
} | ||
}) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I want to experiment with route authorization and code splitting at the same time |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignore this. I just wanted to make clear that those changes is breaking everything 😸