Skip to content

Commit

Permalink
docs(example): update
Browse files Browse the repository at this point in the history
  • Loading branch information
gregberge committed May 5, 2018
1 parent c5d1e01 commit 65cd498
Show file tree
Hide file tree
Showing 12 changed files with 2,239 additions and 353 deletions.
File renamed without changes.
11 changes: 9 additions & 2 deletions example/App.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import React from 'react'
import loadable from 'loadable-components'
import { hot } from 'react-hot-loader'

const AsyncWhat = loadable(() => import('./What.js'))
const AsyncWhat = loadable(() =>
import(/* webpackChunkName: "What" */ './What.js'),
)

const AsyncBig = loadable(() =>
import(/* webpackChunkName: "Big" */ './Big.js'),
)

const App = () => (
<div>
Hello <AsyncWhat />!
</div>
)

export default App
export default hot(module)(App)
3 changes: 3 additions & 0 deletions example/Big.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const Big = () => 'Big'

export default Big
23 changes: 23 additions & 0 deletions example/Counter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react'

class Counter extends React.Component {
state = { count: 0 }

componentDidMount() {
this.interval = setInterval(
() =>
this.setState(previousState => ({ count: previousState.count + 1 })),
500,
)
}

componentWillUnmount() {
clearInterval(this.interval)
}

render() {
return this.state.count
}
}

export default Counter
3 changes: 0 additions & 3 deletions example/DeepWorld.js

This file was deleted.

10 changes: 7 additions & 3 deletions example/What.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ import loadable from 'loadable-components'

const What = loadable(
async () => {
const { default: DeepWord } = await import('./DeepWorld')
const { default: DeepAmazing } = await import('./DeepAmazing')
const {
default: World,
} = await import(/* webpackChunkName: "World" */ './World')
const {
default: Amazing,
} = await import(/* webpackChunkName: "Amazing" */ './Amazing')
return () => (
<React.Fragment>
<DeepAmazing /> <DeepWord />
<Amazing /> <World />
</React.Fragment>
)
},
Expand Down
10 changes: 10 additions & 0 deletions example/World.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import React from 'react'
import Counter from './Counter'

const World = () => (
<React.Fragment>
<Counter /> World
</React.Fragment>
)

export default World
3 changes: 2 additions & 1 deletion example/nodemon.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"execMap": {
"js": "babel-node"
}
},
"delay": 10000
}
18 changes: 10 additions & 8 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,24 @@
"dev:client": "webpack-dev-server"
},
"dependencies": {
"express": "^4.16.2",
"loadable-components": "latest",
"react": "^16.2.0",
"react-dom": "^16.2.0"
"express": "^4.16.3",
"loadable-components": "/Users/neoziro/projects/loadable-components/loadable-components-v1.4.1-alpha.2.tgz",
"react": "^16.3.2",
"react-dom": "^16.3.2",
"react-hot-loader": "^4.1.2"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-loader": "^7.1.4",
"babel-plugin-dynamic-import-node": "^1.2.0",
"babel-plugin-syntax-dynamic-import": "^6.18.0",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1",
"nodemon": "^1.14.11",
"webpack": "^3.10.0",
"webpack-dev-server": "^2.11.1"
"nodemon": "^1.17.3",
"webpack": "^4.7.0",
"webpack-cli": "^2.1.2",
"webpack-dev-server": "^3.1.4"
}
}
2 changes: 1 addition & 1 deletion example/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ app.get('/', async (req, res) => {
</html>`)
} catch (err) {
res.status(500)
res.send(err)
res.send(err.stack)
}
})

Expand Down
11 changes: 9 additions & 2 deletions example/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const path = require('path')
const webpack = require('webpack')

module.exports = {
mode: 'development',
entry: './client.js',
output: {
path: path.resolve(__dirname, 'public'),
filename: 'bundle.js',
chunkFilename: '[name].bundle.js',
},
module: {
rules: [
Expand All @@ -23,11 +24,12 @@ module.exports = {
targets: {
browsers: ['last 2 chrome versions'],
},
modules: false
modules: false,
},
],
],
plugins: [
'react-hot-loader/babel',
'loadable-components/babel',
['transform-class-properties', { loose: true }],
'transform-object-rest-spread',
Expand All @@ -36,8 +38,13 @@ module.exports = {
},
],
},
plugins: [
new webpack.NamedModulesPlugin(),
new webpack.HotModuleReplacementPlugin(),
],
devtool: 'sourcemap',
devServer: {
hot: true,
proxy: {
contentBase: path.resolve(__dirname, 'public'),
publicPath: '/',
Expand Down
Loading

0 comments on commit 65cd498

Please sign in to comment.