This repository has been archived by the owner on Dec 19, 2023. It is now read-only.
forked from cytoscape/cytoscape.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
rollup.config.js
126 lines (113 loc) · 3.12 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
119
120
121
122
123
124
125
126
import nodeResolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import babel from '@rollup/plugin-babel';
import replace from '@rollup/plugin-replace';
import { terser } from "rollup-plugin-terser";
import { sizeSnapshot } from 'rollup-plugin-size-snapshot';
import license from 'rollup-plugin-license';
import path from 'path';
const VERSION = process.env.VERSION || 'snapshot'; // default snapshot
const FILE = process.env.FILE;
const SOURCEMAPS = process.env.SOURCEMAPS === 'true'; // default false
const BABEL = process.env.BABEL !== 'false'; // default true
const NODE_ENV = process.env.NODE_ENV === 'development' ? 'development' : 'production'; // default prod
const matchSnapshot = process.env.SNAPSHOT === 'match';
const input = './src/index.js';
const name = 'cytoscape';
const envVariables = {
'process.env.VERSION': JSON.stringify(VERSION),
'process.env.NODE_ENV': JSON.stringify(NODE_ENV)
};
const getBabelOptions = () => ({
exclude: '**/node_modules/**'
});
// Ignore all node_modules dependencies
const isExternal = id => !id.startsWith('\0') && !id.startsWith('.') && !id.startsWith('/');
const licenseHeaderOptions = {
sourcemap: true,
banner: {
content: {
file: path.join(__dirname, 'LICENSE')
}
}
};
const configs = [
{
input,
output: {
file: 'build/cytoscape.umd.js',
format: 'umd',
name,
sourcemap: SOURCEMAPS ? 'inline' : false
},
plugins: [
nodeResolve(),
commonjs({ include: '**/node_modules/**' }),
BABEL ? babel(getBabelOptions()) : {},
replace(envVariables),
license(licenseHeaderOptions),
!FILE ? sizeSnapshot({ matchSnapshot }) : {}
]
},
{
input,
output: {
file: 'build/cytoscape.min.js',
format: 'umd',
name
},
plugins: [
nodeResolve(),
commonjs({ include: '**/node_modules/**' }),
BABEL ? babel(getBabelOptions()) : {},
replace(envVariables),
terser({
sourcemap: false
}),
license(licenseHeaderOptions)
]
},
{
input,
output: {
file: 'build/cytoscape.esm.min.js',
format: 'es'
},
plugins: [
nodeResolve(),
commonjs({ include: '**/node_modules/**' }),
BABEL ? babel(getBabelOptions()) : {},
replace(envVariables),
license(licenseHeaderOptions),
terser(),
!FILE ? sizeSnapshot({ matchSnapshot }) : {}
]
},
{
input,
output: { file: 'build/cytoscape.cjs.js', format: 'cjs' },
external: isExternal,
plugins: [
nodeResolve(),
BABEL ? babel(getBabelOptions()) : {},
replace(envVariables),
license(licenseHeaderOptions),
!FILE ? sizeSnapshot({ matchSnapshot }) : {}
]
},
{
input,
output: { file: 'build/cytoscape.esm.js', format: 'es' },
external: isExternal,
plugins: [
nodeResolve(),
BABEL ? babel(getBabelOptions()) : {},
replace(envVariables),
license(licenseHeaderOptions),
!FILE ? sizeSnapshot({ matchSnapshot }) : {}
]
}
];
export default FILE
? configs.filter(config => config.output.file.endsWith(FILE + '.js'))
: configs;