Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/examples/hacker-news/client/hmr.js b/examples/hacker-news/client/hmr.js
- new file mode 100644
- index 00000000..34270ded
- --- /dev/null
- +++ b/examples/hacker-news/client/hmr.js
- @@ -0,0 +1,15 @@
- +import getRoutes from './get-routes'
- +import getRedux from './get-redux'
- +
- +const hmrKey = Symbol.for('HMR_KEY')
- +
- +const entryPoint = async ({ serverImports }, req, res) => {
- + void ([getRedux(serverImports), getRoutes(serverImports)])
- + if(global[hmrKey] == null) {
- + global[hmrKey] = `${Date.now()}${Math.random()}`
- + }
- +
- + await res.end(global[hmrKey])
- +}
- +
- +export default entryPoint
- diff --git a/examples/hacker-news/client/index.js b/examples/hacker-news/client/index.js
- index a3c1355f..c5df1343 100644
- --- a/examples/hacker-news/client/index.js
- +++ b/examples/hacker-news/client/index.js
- @@ -11,6 +11,22 @@ import {
- import getRoutes from './get-routes'
- import getRedux from './get-redux'
- +const setupHmr = async (origin, rootPath) => {
- + try {
- + const hmrKey = await (await fetch(`${origin}${rootPath}/hmr-key`)).text()
- + if(window.hmrKey == null) {
- + window.hmrKey = hmrKey
- + }
- + if(window.hmrKey !== hmrKey) {
- + throw new Error('Hmr key changed')
- + }
- +
- + setTimeout(setupHmr.bind(null, origin, rootPath), 3000)
- + } catch(err) {
- + window.location.reload()
- + }
- +}
- +
- const entryPoint = ({
- clientImports,
- rootPath,
- @@ -46,6 +62,8 @@ const entryPoint = ({
- document.getElementsByClassName('app-container')[0]
- )
- +
- + setupHmr(origin, rootPath)
- }
- export default entryPoint
- diff --git a/examples/hacker-news/config.app.js b/examples/hacker-news/config.app.js
- index dc42c126..55030a44 100644
- --- a/examples/hacker-news/config.app.js
- +++ b/examples/hacker-news/config.app.js
- @@ -44,6 +44,17 @@ const appConfig = {
- },
- path: '/:markup*',
- method: 'GET'
- + },
- + {
- + controller: {
- + module: 'resolve-runtime/lib/common/handlers/live-require-handler.js',
- + options: {
- + modulePath: './hmr.js',
- + moduleFactoryImport: false
- + }
- + },
- + path: '/hmr-key',
- + method: 'GET'
- }
- ],
- clientEntries: [
- @@ -63,7 +74,15 @@ const appConfig = {
- moduleType: 'commonjs',
- target: 'node'
- }
- - ]
- + ],
- + [
- + 'client/hmr.js',
- + {
- + outputFile: 'common/local-entry/hmr.js',
- + moduleType: 'commonjs',
- + target: 'node'
- + }
- + ],
- ]
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement