This repository has been archived by the owner on Apr 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathrollup.config.js
78 lines (70 loc) · 1.62 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import babel from 'rollup-plugin-babel';
import nodeResolve from 'rollup-plugin-node-resolve';
import { uglify } from 'rollup-plugin-uglify';
import bundleSize from 'rollup-plugin-bundle-size';
import commonjs from 'rollup-plugin-commonjs';
import typescript from 'rollup-plugin-typescript2';
import pkg from './package.json';
const IS_PROD = process.env.NODE_ENV === 'production';
const INPUT_FILE = './src/index.ts';
const INPUT_FILE_BROWSER = './src/browser.ts';
const OUTPUT_FILE_BROWSER = './dist/browser.min.js';
const getPlugins = (tsDeclaration = false) => [
typescript(
tsDeclaration
? {
useTsconfigDeclarationDir: true,
tsconfigOverride: {
compilerOptions: {
declaration: true,
declarationDir: 'dist/types'
},
exclude: ['test/*']
}
}
: {}
),
babel(),
nodeResolve({ mainFields: ['module', 'jsnext'] }),
commonjs({ include: 'node_modules/**' }),
bundleSize()
];
const cjs = {
plugins: getPlugins(true),
input: INPUT_FILE,
output: {
exports: 'named',
file: pkg.main,
format: 'cjs'
}
};
const es = {
plugins: getPlugins(),
input: INPUT_FILE,
output: [
{
file: pkg.module,
format: 'es'
}
]
};
const umd = {
plugins: getPlugins(),
input: INPUT_FILE,
output: [
{
name: pkg.umdName,
file: pkg.browser,
format: 'umd'
}
]
};
const browser = {
plugins: [...getPlugins(), uglify()],
input: INPUT_FILE_BROWSER,
output: {
file: OUTPUT_FILE_BROWSER,
format: 'iife'
}
};
export default IS_PROD ? [cjs, es, umd, browser] : cjs;