1
0
Fork 0

esm bundle only targets browsers with module support

This commit is contained in:
Hakim El Hattab 2020-05-04 11:13:11 +02:00
parent 2ca01bb4a5
commit 9242b25bc9
2 changed files with 51 additions and 22 deletions

2
dist/reveal.esm.js vendored

File diff suppressed because one or more lines are too long

View File

@ -35,9 +35,7 @@ const banner = `/*!
// Prevents warnings from opening too many test pages // Prevents warnings from opening too many test pages
process.setMaxListeners(20); process.setMaxListeners(20);
const rollupConfig = { const babelConfig = {
plugins: [
babel({
exclude: 'node_modules/**', exclude: 'node_modules/**',
compact: false, compact: false,
presets: [[ presets: [[
@ -48,26 +46,39 @@ const rollupConfig = {
modules: false modules: false
} }
]] ]]
}), };
const rollupConfig = {
plugins: [
babel( babelConfig ),
resolve(), resolve(),
commonjs(), commonjs(),
terser() terser()
] ]
}; };
gulp.task('js', () => { // Our ES module bundle only needs to support modern
// browser features
const babelConfigESM = JSON.parse( JSON.stringify( babelConfig ) );
babelConfigESM.presets[0][1].targets = { esmodules: true };
const rollupConfigESM = {
plugins: [
babel( babelConfigESM ),
resolve(),
commonjs(),
terser()
]
};
// Creates a bundle with broad browser support, exposed
// as UMD
gulp.task('js-es5', () => {
return rollup({ return rollup({
input: 'js/index.js', input: 'js/index.js',
...rollupConfig ...rollupConfig
}).then( bundle => { }).then( bundle => {
bundle.write({ return bundle.write({
file: './dist/reveal.esm.js',
format: 'es',
banner: banner,
sourcemap: true
});
bundle.write({
name: 'Reveal', name: 'Reveal',
file: './dist/reveal.js', file: './dist/reveal.js',
format: 'umd', format: 'umd',
@ -77,6 +88,24 @@ gulp.task('js', () => {
}); });
}) })
// Creates an ES module bundle
gulp.task('js-es6', () => {
return rollup({
input: 'js/index.js',
...rollupConfigESM
}).then( bundle => {
return bundle.write({
file: './dist/reveal.esm.js',
format: 'es',
banner: banner,
sourcemap: true
});
});
})
gulp.task('js', gulp.parallel('js-es5', 'js-es6'));
// Creates a UMD and ES module bundle for each of our
// built-in plugins
gulp.task('plugins', () => { gulp.task('plugins', () => {
return Promise.all([ return Promise.all([
{ name: 'RevealHighlight', input: './plugin/highlight/plugin.js', output: './dist/plugin/highlight' }, { name: 'RevealHighlight', input: './plugin/highlight/plugin.js', output: './dist/plugin/highlight' },