gpt4 book ai didi

IE11 中的 Webpack 隐式 vendor/ list block - Promise 未定义

转载 作者:行者123 更新时间:2023-12-02 15:18:32 24 4
gpt4 key购买 nike

简短版本

当我在 IE11 中运行应用程序时,我收到一条错误消息,指出 list .js 文件中的 Promise is undefined

如何添加 babel-polyfill 或类似内容,使其在执行 list 之前运行?

长版

我正在尝试将 CommonsChunkPlugin 添加到我的 webpack 配置中,以便将第三方(npm 包)脚本拆分到单独的包中。根据 Webpack 2 文档,我设置了“combined implicit common vendor chunks and manifest file ”,它在现代浏览器中运行良好。

我编写了一个函数来确保 block 以正确的顺序包含在我的索引文件中(见下文)。

关于我的两个显式入口点的一些背景:

  • legacy_libs - 使用 script-loader 放置到全局命名空间中的旧库。我希望随着时间的推移逐步淘汰这些
  • main - 我的主应用入口点

另外两个( vendor 和 list )是隐式的,并使用 CommonsChunkPlugin 创建。

当我使用 IE11 运行此程序时,出现错误:Promise is undefined。这似乎是因为 webpack list 本身正在调用 new Promise()

在我的主入口点中,我有 import 'babel-polyfill';。在添加 vendor 和 list 分块之前,这使我能够克服 IE 缺乏 Promise 的问题。但既然我先加载了 manifest.js,我不知道如何以正确的顺序包含它。

我的配置如下:

module.exports = {
entry: {
legacy_libs: './app/libs.js',
main: './app/main.js'
},
...
plugins: [
// Extract third party libraries into a separate vendor bundle.
// Also extract webpack manifest into its own bundle (to prevent vendor hash changing when app source changes)
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: function (module) {
return module.context && module.context.indexOf('node_modules') !== -1;
}
}),
new webpack.optimize.CommonsChunkPlugin({
name: 'manifest'
}),

// Generate index.html file.
// Include script bundles in the right order based on chunk name prefixes.
new HtmlWebpackPlugin({
template: 'app/index.ejs',
chunksSortMode: function (a, b) {
const chunkOrder = ['manifest', 'vendor', 'legacy_libs', 'main'];
const aChunk = chunkOrder.findIndex(chunk => a.names[0].startsWith(chunk));
const bChunk = chunkOrder.findIndex(chunk => b.names[0].startsWith(chunk));
const aValue = (aChunk > -1) ? aChunk : chunkOrder.length;
const bValue = (bChunk > -1) ? bChunk : chunkOrder.length;
return aValue - bValue;
}
})
}

最佳答案

这似乎是 webpack 2.6.0 引入的问题,已经发布了一个错误:https://github.com/webpack/webpack/issues/4916

所以要么等到 bug 修复发布,要么恢复到 2.5.1!

关于IE11 中的 Webpack 隐式 vendor/ list block - Promise 未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44160986/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com