UNPKG

2.87 kBJavaScriptView Raw
1import nodeResolve from '@rollup/plugin-node-resolve';
2import commonjs from '@rollup/plugin-commonjs';
3import babel from '@rollup/plugin-babel';
4import replace from '@rollup/plugin-replace';
5import { terser } from "rollup-plugin-terser";
6import license from 'rollup-plugin-license';
7import path from 'path';
8
9const VERSION = process.env.VERSION || 'snapshot'; // default snapshot
10const FILE = process.env.FILE;
11const SOURCEMAPS = process.env.SOURCEMAPS === 'true'; // default false
12const BABEL = process.env.BABEL !== 'false'; // default true
13const NODE_ENV = process.env.NODE_ENV === 'development' ? 'development' : 'production'; // default prod
14
15const input = './src/index.js';
16
17const name = 'cytoscape';
18
19const envVariables = {
20 'process.env.VERSION': JSON.stringify(VERSION),
21 'process.env.NODE_ENV': JSON.stringify(NODE_ENV)
22};
23
24const getBabelOptions = () => ({
25 exclude: '**/node_modules/**'
26});
27
28// Ignore all node_modules dependencies
29const isExternal = id => !id.startsWith('\0') && !id.startsWith('.') && !id.startsWith('/');
30
31const licenseHeaderOptions = {
32 sourcemap: true,
33 banner: {
34 content: {
35 file: path.join(__dirname, 'LICENSE')
36 }
37 }
38};
39
40const configs = [
41 {
42 input,
43 output: {
44 file: 'build/cytoscape.umd.js',
45 format: 'umd',
46 name,
47 sourcemap: SOURCEMAPS ? 'inline' : false
48 },
49 plugins: [
50 nodeResolve(),
51 commonjs({ include: '**/node_modules/**' }),
52 BABEL ? babel(getBabelOptions()) : {},
53 replace(envVariables),
54 license(licenseHeaderOptions)
55 ]
56 },
57
58 {
59 input,
60 output: {
61 file: 'build/cytoscape.min.js',
62 format: 'umd',
63 name
64 },
65 plugins: [
66 nodeResolve(),
67 commonjs({ include: '**/node_modules/**' }),
68 BABEL ? babel(getBabelOptions()) : {},
69 replace(envVariables),
70 terser({
71 sourcemap: false
72 }),
73 license(licenseHeaderOptions)
74 ]
75 },
76
77 {
78 input,
79 output: {
80 file: 'build/cytoscape.esm.min.js',
81 format: 'es'
82 },
83 plugins: [
84 nodeResolve(),
85 commonjs({ include: '**/node_modules/**' }),
86 BABEL ? babel(getBabelOptions()) : {},
87 replace(envVariables),
88 license(licenseHeaderOptions),
89 terser()
90 ]
91 },
92
93 {
94 input,
95 output: { file: 'build/cytoscape.cjs.js', format: 'cjs' },
96 external: isExternal,
97 plugins: [
98 nodeResolve(),
99 BABEL ? babel(getBabelOptions()) : {},
100 replace(envVariables),
101 license(licenseHeaderOptions)
102 ]
103 },
104
105 {
106 input,
107 output: { file: 'build/cytoscape.esm.js', format: 'es' },
108 external: isExternal,
109 plugins: [
110 nodeResolve(),
111 BABEL ? babel(getBabelOptions()) : {},
112 replace(envVariables),
113 license(licenseHeaderOptions)
114 ]
115 }
116];
117
118export default FILE
119 ? configs.filter(config => config.output.file.endsWith(FILE + '.js'))
120 : configs;