Advertisement
Guest User

Untitled

a guest
Feb 10th, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 2.48 KB | None | 0 0
  1. diff --git a/examples/hacker-news/client/hmr.js b/examples/hacker-news/client/hmr.js
  2. new file mode 100644
  3. index 00000000..34270ded
  4. --- /dev/null
  5. +++ b/examples/hacker-news/client/hmr.js
  6. @@ -0,0 +1,15 @@
  7. +import getRoutes from './get-routes'
  8. +import getRedux from './get-redux'
  9. +
  10. +const hmrKey = Symbol.for('HMR_KEY')
  11. +
  12. +const entryPoint = async ({ serverImports }, req, res) => {
  13. +  void ([getRedux(serverImports), getRoutes(serverImports)])
  14. +  if(global[hmrKey] == null) {
  15. +    global[hmrKey] = `${Date.now()}${Math.random()}`
  16. +  }
  17. +
  18. +  await res.end(global[hmrKey])
  19. +}
  20. +
  21. +export default entryPoint
  22. diff --git a/examples/hacker-news/client/index.js b/examples/hacker-news/client/index.js
  23. index a3c1355f..c5df1343 100644
  24. --- a/examples/hacker-news/client/index.js
  25. +++ b/examples/hacker-news/client/index.js
  26. @@ -11,6 +11,22 @@ import {
  27.  import getRoutes from './get-routes'
  28.  import getRedux from './get-redux'
  29.  
  30. +const setupHmr = async (origin, rootPath) => {
  31. +  try {
  32. +    const hmrKey = await (await fetch(`${origin}${rootPath}/hmr-key`)).text()
  33. +    if(window.hmrKey == null) {
  34. +      window.hmrKey = hmrKey
  35. +    }
  36. +    if(window.hmrKey !== hmrKey) {
  37. +      throw new Error('Hmr key changed')
  38. +    }
  39. +
  40. +    setTimeout(setupHmr.bind(null, origin, rootPath), 3000)
  41. +  } catch(err) {
  42. +    window.location.reload()
  43. +  }
  44. +}
  45. +
  46.  const entryPoint = ({
  47.    clientImports,
  48.    rootPath,
  49. @@ -46,6 +62,8 @@ const entryPoint = ({
  50.  
  51.      document.getElementsByClassName('app-container')[0]
  52.    )
  53. +
  54. +  setupHmr(origin, rootPath)
  55.  }
  56.  
  57.  export default entryPoint
  58. diff --git a/examples/hacker-news/config.app.js b/examples/hacker-news/config.app.js
  59. index dc42c126..55030a44 100644
  60. --- a/examples/hacker-news/config.app.js
  61. +++ b/examples/hacker-news/config.app.js
  62. @@ -44,6 +44,17 @@ const appConfig = {
  63.        },
  64.        path: '/:markup*',
  65.        method: 'GET'
  66. +    },
  67. +    {
  68. +      controller: {
  69. +        module: 'resolve-runtime/lib/common/handlers/live-require-handler.js',
  70. +        options: {
  71. +          modulePath: './hmr.js',
  72. +          moduleFactoryImport: false
  73. +        }
  74. +      },
  75. +      path: '/hmr-key',
  76. +      method: 'GET'
  77.      }
  78.    ],
  79.    clientEntries: [
  80. @@ -63,7 +74,15 @@ const appConfig = {
  81.          moduleType: 'commonjs',
  82.          target: 'node'
  83.        }
  84. -    ]
  85. +    ],
  86. +    [
  87. +      'client/hmr.js',
  88. +      {
  89. +        outputFile: 'common/local-entry/hmr.js',
  90. +        moduleType: 'commonjs',
  91. +        target: 'node'
  92. +      }
  93. +    ],
  94.    ]
  95.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement