This repository has been archived by the owner on Feb 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
create-rollup-config.js
64 lines (62 loc) · 1.86 KB
/
create-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
import typescript from '@rollup/plugin-typescript';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import { terser } from 'rollup-plugin-terser';
import visualizer from 'rollup-plugin-visualizer';
import replace from 'rollup-plugin-replace';
import json from '@rollup/plugin-json';
import compiler from '@ampproject/rollup-plugin-closure-compiler';
const isProduction = process.env.NODE_ENV === 'production';
export function createRollupConfig(globalName, pkg, external = []) {
return [
{
input: 'src/index.ts',
output: [
{
file: pkg.web,
name: globalName,
format: 'umd',
sourcemap: true,
},
],
plugins: [
typescript({ target: isProduction ? 'es5' : 'es2020' }),
replace({
'process.env.NODE_ENV': JSON.stringify(isProduction ? 'production' : 'development'),
}),
resolve({ browser: true }), // so Rollup can find `ms`
commonjs({ extensions: ['.js', '.ts'] }), // the ".ts" extension is required
json(),
isProduction && terser(),
isProduction && compiler(),
],
external,
},
{
input: 'src/index.ts',
output: [
{
file: pkg.main,
format: 'cjs',
sourcemap: true,
},
{
file: pkg.module,
format: 'es',
sourcemap: true,
},
],
external: ['crypto', ...external, ...Object.keys(pkg.dependencies)],
plugins: [
typescript(),
replace({
'process.env.NODE_ENV': JSON.stringify(isProduction ? 'production' : 'development'),
}),
resolve(), // so Rollup can find `ms`
commonjs({ extensions: ['.js', '.ts'] }), // the ".ts" extension is required
json(),
isProduction && visualizer(),
],
},
];
}