We've got a fairly simple app/webpack setup which goes something like this:
babel.config.js
module.exports = {
plugins: [...],
presets: [
['@babel/preset-env', {
useBuiltIns: 'entry',
corejs: '3'
}]
]
}
index.js
import './polyfill';
import app from './app';
app();
polyfill.js
import 'core-js/stable';
import 'whatwg-fetch';
webpack.config.js
entry: {
bundle: [pathToIndexJs]
}
optimization: {
runtimeChunk: false,
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all'
}
}
}
}
What we end up with is two chunks, bundle
and vendors
. The strange part is that whatwg-fetch
(and core-js
) does not end up in a chunk. When I create a build and output a stats.json file and analyze it using Webpack Analyze, I see the module in the list of modules (./node_modules/whatwg-fetch/fetch.js) but its chunks column is empty. I have verified that it is not ending up in either chunk/bundle by searching the bundle code.
This issue is fixed if I add the polyfill to the beginning of the entry.bundle
array, but I am wondering why is it not being included in the bundle in the first place, since it is a normal app import? I would expect it to appear in the vendors
bundle since it is a node_module.