admin管理员组文章数量:1287665
How can we pile modern JavaScript into backwards-patible JavaScript bundles that can be used with Internet Explorer 11 (ie11)? Specifically, how can we do this with the latest versions of Webpack 5 and Babel 7?
How can we pile modern JavaScript into backwards-patible JavaScript bundles that can be used with Internet Explorer 11 (ie11)? Specifically, how can we do this with the latest versions of Webpack 5 and Babel 7?
Share Improve this question asked Nov 27, 2020 at 10:08 anthumchrisanthumchris 9,0902 gold badges34 silver badges57 bronze badges 1- I created this self-answered question after spending days trying to get this working. Hope it helps others avoid the pain too. – anthumchris Commented Nov 27, 2020 at 10:13
1 Answer
Reset to default 12Here's the most minimal configuration I could create, with a test file that's included to test with IE 11. Download on GitHub.
package.json
{
"browserslist": [
"ie 11"
],
"scripts": {
"dev": "webpack -w",
"build": "webpack"
},
"devDependencies": {
"@babel/core": "^7.12.9",
"@babel/preset-env": "^7.12.7",
"babel-loader": "^8.2.2",
"core-js": "^3.8.0",
"webpack": "^5.8.0",
"webpack-cli": "^4.2.0"
}
}
webpack.config.js
module.exports = {
entry: './index.js',
module: {
rules: [{
test: /\.m?js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [
['@babel/preset-env', {
useBuiltIns: 'usage',
corejs: 3
}]
]
}
}
}]
}
}
Greeting.js
export default '2020 has been one hell of a year!'
index.js
/*
* Test that uses modern JavaScript and will be piled to work in IE 11
*/
import greeting from './Greeting'
window.addEventListener('load', async () => {
const o = {
greeting: await Promise.resolve(greeting)
}
console.log(
o,
Object.entries(o),
Object.keys(o),
Object.values(o),
)
})
本文标签: javascriptHow to create IE11 Bundles with Webpack 5 and Babel 7Stack Overflow
版权声明:本文标题:javascript - How to create IE11 Bundles with Webpack 5 and Babel 7 - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741315424a2371883.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论