UNPKG

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