forked from denehyg/reveal.js-menu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
99 lines (90 loc) · 2.27 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
const pkg = require('./package.json');
const { rollup } = require('rollup');
const { terser } = require('rollup-plugin-terser');
const babel = require('@rollup/plugin-babel').default;
const commonjs = require('@rollup/plugin-commonjs');
const resolve = require('@rollup/plugin-node-resolve').default;
const gulp = require('gulp');
const banner = `/*!
* reveal.js-menu ${pkg.version}
* ${pkg.homepage}
* MIT licensed
*
* Copyright (C) 2016 Greg Denehy
*/\n`;
const babelConfig = {
babelHelpers: 'bundled',
ignore: ['node_modules'],
compact: false,
extensions: ['.js', '.html'],
plugins: ['transform-html-import-to-string'],
presets: [
[
'@babel/preset-env',
{
corejs: 3,
useBuiltIns: 'usage',
modules: false
}
]
]
};
// Our ES module bundle only targets newer browsers with
// module support. Browsers are targeted explicitly instead
// of using the "esmodule: true" target since that leads to
// polyfilling older browsers and a larger bundle.
const babelConfigESM = JSON.parse(JSON.stringify(babelConfig));
babelConfigESM.presets[0][1].targets = {
browsers: [
'last 2 Chrome versions',
'not Chrome < 60',
'last 2 Safari versions',
'not Safari < 10.1',
'last 2 iOS versions',
'not iOS < 10.3',
'last 2 Firefox versions',
'not Firefox < 60',
'last 2 Edge versions',
'not Edge < 16'
]
};
let cache = {};
// Creates a UMD and ES module bundle for each plugin
gulp.task('build', () => {
return Promise.all(
[
{
name: 'RevealMenu',
input: './plugin.js',
output: './menu'
}
].map(plugin => {
return rollup({
cache: cache[plugin.input],
input: plugin.input,
plugins: [
resolve(),
commonjs(),
babel({
...babelConfig,
ignore: [/node_modules\/.*/]
}),
terser()
]
}).then(bundle => {
cache[plugin.input] = bundle.cache;
bundle.write({
file: plugin.output + '.esm.js',
name: plugin.name,
format: 'es'
});
bundle.write({
file: plugin.output + '.js',
name: plugin.name,
format: 'umd'
});
});
})
);
});
gulp.task('default', gulp.series('build'));