UNPKG

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