Polyfills are required in order for a Svelte app to run in IE11. Here are the steps required:
Add the following in
public/index.html
before thescript
tag forbundle.js
:<script defer src="https://polyfill.io/v3/polyfill.min.js"></script>
Add the following in
rollup.config.js
just before the lineproduction && terser()
:babel({
extensions: ['.js', '.mjs', '.html', '.svelte'],
exclude: ['node_modules/@babel/**', 'node_modules/core-js/**'],
presets: [
[
'@babel/preset-env',
{
targets: {
ie: '11'
},
useBuiltIns: 'usage',
corejs: 3
}
]
],
plugins: [
'@babel/plugin-syntax-dynamic-import',
[
'@babel/plugin-transform-runtime',
{
useESModules: true
}
]
],
runtimeHelpers: true
}),Enter
npm install -D
for each of these packages:- @babel/plugin-syntax-dynamic-import
- @babel/plugin-transform-runtime
- @babel/runtime
- @rollup/plugin-babel
- corejs
- whatwg-fetch
In each source file where the Fetch API is being used, add the following:
import 'whatwg-fetch';
Remove all use of CSS variables.
Test all uses of CSS flexbox and grid layout. There are some bugs in the IE11 implementation of these.
Unfortunately all the polyfills make the generated bundle.js
file much bigger. For one app the size changed from 52K to 410K.