-
-
Save yelban/553796807adef9c03697c0f4eb57c6c1 to your computer and use it in GitHub Desktop.
Svelte 3, Babel 7, Polyfill IE 11
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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