我如何使用webpack dev服务器与服务器端呈现?

时间:2016-11-21 18:12:32

标签: reactjs webpack webpack-dev-server

我有一个同构的应用程序,我有一个所有请求的代理,但/ route是express的当前服务器,它不代理这条路径。

问题是我如何使用webpack dev服务器进行服务器端渲染?

devServer: {
    hot: true,
    proxy: {
      '*': 'http://127.0.0.1:' + (process.env.PORT || 3000),
    },
    host: '127.0.0.1'
  },

这是快递

提供的HTML
<!doctype html>
      <html>
        <head>
          <meta charset="utf-8">
          <meta name="viewport" content="width=device-width, initial-scale=1.0">
          <link rel="manifest" href="/static/manifest.webmanifest">
          <meta name="theme-color" content="#033">
          <style>${css.join('')}</style>
        </head>
        <body>
          <div id="app">${body}</div>
          <script async>browser = ${JSON.stringify(parser.getResult())}</script>
          <script async>initialState = ${JSON.stringify(initialState)}</script>
          <script>
            if ('serviceWorker' in navigator) {
             navigator.serviceWorker.register('/serviceWorker.js', {scope: './'})
             .then(function(registration) {
               console.log('SW registrado');
             }).catch(function(err) {
               // Failed registration, service worker won’t be installed
               console.log('Ocurrio un error', err);
             });
            }
          </script>
          <script async src="/static/client.js"></script>
        </body>
      </html>

0 个答案:

没有答案