Skip to content

Instantly share code, notes, and snippets.

@bgrand-ch
Created June 17, 2020 12:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save bgrand-ch/2f5d9bdb3070b695f483a944689a07f7 to your computer and use it in GitHub Desktop.
Save bgrand-ch/2f5d9bdb3070b695f483a944689a07f7 to your computer and use it in GitHub Desktop.
Svelte 3, Babel 7, Polyfill IE 11
// https://www.learningsomethingnew.com/how-to-make-your-svelte-3-cordova-app-work-on-old-phones-using-babel-7-and-rollup
// https://blog.az.sg/posts/svelte-and-ie11/
module.exports = function (api) {
api.cache(true);
const presets = [
[
'@babel/preset-env', {
useBuiltIns: 'usage',
corejs: 3,
targets: {
browsers: 'last 2 versions'
}
}
]
];
return {
presets
}
}
{
"name": "babel-ie11",
"version": "0.0.1",
"scripts": {
"build": "npm install && rollup -c",
"dev": "npm install && rollup -c -w",
"start": "sirv public --single"
},
"devDependencies": {
"@babel/core": "^7.10.2",
"@babel/preset-env": "^7.10.2",
"@rollup/plugin-babel": "^5.0.3",
"@rollup/plugin-commonjs": "^13.0.0",
"@rollup/plugin-node-resolve": "^8.0.1",
"core-js": "^3.6.5",
"rollup": "^2.16.1",
"rollup-plugin-livereload": "^1.3.0",
"rollup-plugin-svelte": "^5.2.2",
"rollup-plugin-terser": "^6.1.0",
"svelte": "^3.23.2"
},
"dependencies": {
"sirv-cli": "^1.0.0"
}
}
import svelte from 'rollup-plugin-svelte';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import livereload from 'rollup-plugin-livereload';
import { terser } from 'rollup-plugin-terser';
import babel from '@rollup/plugin-babel';
const production = !process.env.ROLLUP_WATCH;
export default {
input: 'src/main.js',
output: {
sourcemap: true,
format: 'iife',
name: 'app',
file: 'public/build/bundle.js'
},
plugins: [
svelte({
dev: !production,
css: css => {
css.write('public/build/bundle.css');
}
}),
resolve({
browser: true,
dedupe: ['svelte']
}),
commonjs(),
!production && serve(),
!production && livereload('public'),
production && babel({
babelHelpers: 'bundled',
extensions: [
'.js',
'.mjs',
'.html',
'.svelte'
],
exclude: [
/\/core-js\//
]
}),
production && terser()
],
watch: {
clearScreen: false
}
};
function serve() {
let started = false;
return {
writeBundle() {
if (!started) {
started = true;
require('child_process').spawn('npm', ['run', 'start', '--', '--dev'], {
stdio: ['ignore', 'inherit', 'inherit'],
shell: true
});
}
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment