-
Notifications
You must be signed in to change notification settings - Fork 11
/
rollup.config.ts
70 lines (63 loc) · 1.43 KB
/
rollup.config.ts
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
import resolve from 'rollup-plugin-node-resolve';
import replace from 'rollup-plugin-replace';
import { eslint } from 'rollup-plugin-eslint';
import typescript from 'rollup-plugin-typescript';
import commonjs from 'rollup-plugin-commonjs';
import uglify from 'rollup-plugin-uglify-es';
const banner = require('./config/banner');
const pack = require('./package.json');
function toUpper (_, c) {
return c ? c.toUpperCase() : '';
}
function classify (str) {
return str.replace(/(?:^|[-_\/])(\w)/g, toUpper);
}
const moduleName = classify(pack.name);
const plugins = [
resolve(),
replace({
'process.env.NODE_ENV': JSON.stringify(
process.env.NODE_ENV || 'production'
),
'__NAME__': pack.name,
'__VERSION__': pack.version,
}),
eslint({
throwOnError: true,
}),
typescript(),
commonjs(),
];
function makeEntry(options) {
return {
input: 'src/index.ts',
plugins: options.plugins || plugins,
output: {
file: `dist/${pack.name}${options.extension}`,
format: options.format,
banner,
name: options.name || undefined,
},
};
}
export default [
makeEntry({
extension: '.common.js',
format: 'cjs',
}),
makeEntry({
extension: '.esm.js',
format: 'es',
}),
makeEntry({
extension: '.min.js',
format: 'umd',
plugins: [...plugins, uglify()],
name: moduleName,
}),
makeEntry({
extension: '.js',
format: 'umd',
name: moduleName,
}),
];