-
Notifications
You must be signed in to change notification settings - Fork 2
/
rollup.scripts.js
61 lines (54 loc) · 1.26 KB
/
rollup.scripts.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
import babel from 'rollup-plugin-babel';
import license from 'rollup-plugin-license';
import { terser } from 'rollup-plugin-terser';
import prettier from 'rollup-plugin-prettier';
const createBanner = ({ id, version, license, homepage }) => ({banner:`/*!
* ${ id } ${ version }
* Licensed under ${ license }, https://opensource.org/licenses/${ license }/
* Please visit ${ homepage } for details.
*/
/* eslint-disable */
`});
const createBuild = (options) => {
const { format, id, name, minify = false, transpile = false } = options;
// get filename
const filename = ['dist/', name];
if (format === 'es') {
filename.push('.esm');
}
if (minify) {
filename.push('.min');
}
filename.push('.js');
// collect plugins
const plugins = [];
if (transpile) {
plugins.push(babel({
exclude: ['node_modules/**']
}))
}
if (minify) {
plugins.push(terser())
}
else {
plugins.push(prettier({
singleQuote: true,
parser: 'babel'
}))
}
plugins.push(license(createBanner(options)))
// return Rollup config
return {
input: 'src/js/index.js',
treeshake: false,
output: [
{
format,
name: id,
file: filename.join('')
}
],
plugins
}
};
export default (metadata, configs) => configs.map(config => createBuild({ ...metadata, ...config }));