Skip to content
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

Update on babel 6 can cause 'require' to fail properly loading module #12

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"presets": [
"react",
"es2015"
]
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ open http://localhost:5000
1. Webpack's `require.ensure` defines code splitting points in the app.
2. We polyfill `require.ensure` for node to just do a normal `require`.
3. The server renders the app with `match` and the stateless
`<RoutingContext/>`.
`<RouterContext/>`.
4. When the client JavaScript loads, we use `match` to trigger the split
code to load before rendering. If we didn't do that, then the first
render would be `null` and not reuse the server rendered markup.
Expand Down
5 changes: 2 additions & 3 deletions modules/client.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from 'react'
import { match, Router } from 'react-router'
import { match, Router, browserHistory } from 'react-router'
import { render } from 'react-dom'
import { createHistory } from 'history'
import routes from './routes/RootRoute'

const { pathname, search, hash } = window.location
Expand All @@ -11,7 +10,7 @@ const location = `${pathname}${search}${hash}`
// loading route/component code for the initial location
match({ routes, location }, () => {
render(
<Router routes={routes} history={createHistory()} />,
<Router routes={routes} history={browserHistory} />,
document.getElementById('app')
)
})
Expand Down
2 changes: 1 addition & 1 deletion modules/routes/RootRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default {
component: App,
getChildRoutes(location, cb) {
require.ensure([], (require) => {
cb(null, [ require('./AboutRoute') ])
cb(null, [ require('./AboutRoute').default ])
})
},
indexRoute: {
Expand Down
4 changes: 2 additions & 2 deletions modules/server.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import http from 'http'
import React from 'react'
import { renderToString } from 'react-dom/server'
import { match, RoutingContext } from 'react-router'
import { match, RouterContext } from 'react-router'
import fs from 'fs'
import { createPage, write, writeError, writeNotFound, redirect } from './utils/server-utils'
import routes from './routes/RootRoute'

const PORT = process.env.PORT || 5000

function renderApp(props, res) {
const markup = renderToString(<RoutingContext {...props}/>)
const markup = renderToString(<RouterContext {...props}/>)
const html = createPage(markup)
write(html, 'text/html', res)
}
Expand Down
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@
"description": "",
"main": "client.js",
"dependencies": {
"babel": "^5.8.34",
"babel-core": "^5.8.34",
"babel-loader": "^5.4.0",
"history": "^1.13.1",
"react": "^0.14.2",
"react-dom": "^0.14.2",
"react-router": "^1.0.0",
"react-router": "^2.4.0",
"webpack": "^1.12.6"
},
"scripts": {
"start": "NODE_ENV=production webpack --progress && babel-node modules/server.js"
},
"author": "Ryan Florence",
"license": "ISC"
"license": "ISC",
"devDependencies": {
"babel-cli": "^6.8.0",
"babel-loader": "^6.2.4",
"babel-preset-es2015": "^6.6.0",
"babel-preset-react": "^6.5.0"
}
}