forked from focus-trap/tabbable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
118 lines (108 loc) · 2.15 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/* eslint-env node */
import babel from '@rollup/plugin-babel';
import resolve from '@rollup/plugin-node-resolve';
import sourceMaps from 'rollup-plugin-sourcemaps';
import { terser } from 'rollup-plugin-terser';
// REQUIRED: process.env.BUILD_ENV: "esm" | "cjs" | "umd"
const terserOptions = {
output: { comments: false },
compress: {
keep_infinity: true,
pure_getters: true,
passes: 10,
},
ecma: 5,
toplevel: false,
warnings: true,
};
const commonPlugins = [
babel({ exclude: /node_modules/, babelHelpers: 'bundled' }),
resolve({
mainFields: ['module', 'main', 'browser'],
}),
sourceMaps(),
];
const input = 'src/index.js';
const cjs = [
{
input,
output: {
file: 'dist/index.js',
format: 'cjs',
esModule: false,
sourcemap: true,
},
},
{
input,
output: {
file: 'dist/index.min.js',
format: 'cjs',
esModule: false,
sourcemap: true,
},
plugins: [...commonPlugins, terser({ ...terserOptions, toplevel: true })],
},
];
const esm = [
{
input,
output: {
file: 'dist/index.esm.js',
format: 'esm',
esModule: true,
sourcemap: true,
},
},
{
input,
output: {
file: 'dist/index.esm.min.js',
format: 'esm',
esModule: true,
sourcemap: true,
},
plugins: [...commonPlugins, terser(terserOptions)],
},
];
const umd = [
{
input,
output: {
file: 'dist/index.umd.js',
format: 'umd',
esModule: true,
sourcemap: true,
name: 'tabbable',
},
},
{
input,
output: {
file: 'dist/index.umd.min.js',
format: 'umd',
esModule: true,
sourcemap: true,
name: 'tabbable',
},
plugins: [...commonPlugins, terser(terserOptions)],
},
];
let config = {};
console.log(process.env.BUILD_ENV);
switch (process.env.BUILD_ENV) {
case 'cjs':
config = cjs;
break;
case 'esm':
config = esm;
break;
case 'umd':
config = umd;
break;
default:
throw Error(
'You must define process.env.BUILD_ENV before building with rollup. Check rollup.config.js for valid options.'
);
}
export default config;