I am trying to use SplitChunks on a Webpack 4 application, but I am seeing "window is not defined". I am trying to opt my SSR bundle out of being chunked or affected by chunking in any way, but it isn't working:
const { environment } = require('@rails/webpacker');
const notServerRendering = (name) => name !== 'server-bundle';
environment.splitChunks((config) =>
Object.assign({}, config, {
optimization: {
splitChunks: {
chunks (chunk) {
console.log(chunk.name);
console.log(notServerRendering(chunk.name));
return notServerRendering(chunk.name);
},
minSize: 0
}
}
})
);
module.exports = environment;
The problem is, the first line of my server bundle is:
(window["webpackJsonp"] = window["webpackJsonp"] || []).push([["server-bundle"],{
This is causing my SSR execution to blow up.
Based on https://webpack.js.org/configuration/output/#outputjsonpfunction which I just found, I think I need to somehow change the output target to node
from web
for my server bundle. I'm not sure how to do that yet.