Skip to content

Instantly share code, notes, and snippets.

@anthumchris
Last active May 3, 2023 11:16
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anthumchris/249d741b64081f88db7938f502855447 to your computer and use it in GitHub Desktop.
Save anthumchris/249d741b64081f88db7938f502855447 to your computer and use it in GitHub Desktop.
Use Webpack 5 and Babel 7 to create JavaScript bundle for Internet Explorer 11 (IE11, IE 11)
export default 'Hello!'
/*
* Test file for IE 11 that uses modern JavaScript
*/
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),
)
})
{
"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"
}
}
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
}]
]
}
}
}]
}
}
@anthumchris
Copy link
Author

Hope this helps everyone compile modern JavaScript into bundles that work with IE 11. This is the most minimal configuration I used to achieve this in late 2020. To use:

$ npm install
$ npm run build

@61315
Copy link

61315 commented Nov 10, 2021

It actually helped my video.js project to work in IE 11, cheers:heart:

@grdhog
Copy link

grdhog commented May 3, 2023

Still useful 2023. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment