This repository has been archived by the owner on Jan 8, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrollup.config.js
58 lines (51 loc) · 1.61 KB
/
rollup.config.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
import babel from 'rollup-plugin-babel';
import cleanup from 'rollup-plugin-cleanup';
import commonjs from 'rollup-plugin-commonjs';
import path from 'path';
import resolve from 'rollup-plugin-node-resolve';
import sourceMaps from 'rollup-plugin-sourcemaps';
import { terser } from 'rollup-plugin-terser';
import pkg from './package.json';
const FORMATS = ['umd', 'cjs', 'esm'];
const name = pkg.name;
const basePath = path.resolve(__dirname);
const distPath = path.resolve(basePath, 'dist');
const inputPath = path.resolve(basePath, pkg.index);
const bannerText = `/*! ${name} v${pkg.version} | Copyright (c) 2016-2019 Jacob Müller */`;
const banner = text => ({
name: 'banner',
renderChunk: code => ({ code: `${text}\n${code}`, map: null })
});
const getFileName = (baseName, format, minify) =>
[baseName, format !== 'umd' ? format : null, minify ? 'min' : null, 'js']
.filter(Boolean)
.join('.');
const createConfig = (format, minify = false) => ({
input: inputPath,
output: {
format,
file: path.resolve(distPath, getFileName(name, format, minify)),
sourcemap: true
},
plugins: [
resolve(),
format === 'umd' ? commonjs() : null,
babel({ exclude: 'node_modules/**' }),
sourceMaps(),
cleanup({ comments: 'none' }),
minify
? terser({
sourcemap: true,
compress: { passes: 10 },
ecma: 5,
toplevel: format === 'cjs',
warnings: true
})
: null,
banner(bannerText)
].filter(Boolean)
});
export default [
...FORMATS.map(format => createConfig(format)),
...FORMATS.map(format => createConfig(format, true))
];