【发布时间】:2019-08-22 17:38:32
【问题描述】:
我们有一个相当简单的 app/webpack 设置,如下所示:
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'
}
}
}
}
我们最终得到两个块,bundle 和 vendors。奇怪的是whatwg-fetch(和core-js)并没有最终形成一个块。当我创建构建并输出 stats.json 文件并使用 Webpack Analyze 对其进行分析时,我在模块列表 (./node_modules/whatwg-fetch/fetch.js) 中看到了该模块,但它的 块 em> 列是空的。我已经通过搜索捆绑代码验证了它不会在任何一个块/捆绑中结束。
如果我将 polyfill 添加到 entry.bundle 数组的开头,这个问题就得到了解决,但我想知道为什么它不首先包含在包中,因为它是一个正常的应用程序导入?我希望它出现在 vendors 包中,因为它是一个 node_module。
【问题讨论】:
标签: webpack webpack-4 webpack-splitchunks