window is not defined in server side render window.webpackJsonp

大城市里の小女人 提交于 2019-12-24 06:47:50

问题


I'm attempting to upgrade a Rails/Webpacker/ReactOnRails application to webpack 4. I have included a call to environment.splitChunks. That is placing this code:

window.webpackJsonp=window.webpackJsonp||[]).push([[11],.......

in my bundle. Since this is my server side bundle, window does not exist. Is there a way to completely exclude this bundle from having webpackJsonp added?

I have tried these two configurations:

environment.splitChunks();

and

environment.splitChunks(config =>
  Object.assign({}, config, {
    optimization: {
      splitChunks: {
        chunks(chunk) {
          return chunk.name !== 'server-bundle';
        }
      }
    }
  })
);

Both end up with the same result. If I don't include splitChunks, my code works fine.

I also just tried:

environment.splitChunks(config =>
  Object.assign({}, config, {
    optimization: {
      splitChunks: {
        cacheGroups: {
          server: {
            test: /server-bundle/,
            minChunks: 99999 // Do not ever chunk this file
          }
        }
      }
    }
  })
);

and

environment.splitChunks(config =>
  Object.assign({}, config, {
    optimization: {
      splitChunks: {
        cacheGroups: {
          server: {
            test: /server-bundle/,
            minChunks: 99999 // Do not ever chunk this file
          }
        },
        chunks(chunk) {
          return chunk.name !== 'server-bundle';
        }
      }
    }
  })
);

I thought one of those would put it in its own group that didn't get chunked, but no dice.

来源:https://stackoverflow.com/questions/56696118/window-is-not-defined-in-server-side-render-window-webpackjsonp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!