1 | import nodeResolve from 'rollup-plugin-node-resolve';
|
2 | import commonjs from 'rollup-plugin-commonjs';
|
3 | import babel from 'rollup-plugin-babel';
|
4 | import replace from 'rollup-plugin-replace';
|
5 | import { terser } from "rollup-plugin-terser";
|
6 | import { sizeSnapshot } from 'rollup-plugin-size-snapshot';
|
7 | import license from 'rollup-plugin-license';
|
8 | import path from 'path';
|
9 |
|
10 | const VERSION = process.env.VERSION || 'snapshot';
|
11 | const FILE = process.env.FILE;
|
12 | const SOURCEMAPS = process.env.SOURCEMAPS === 'true';
|
13 | const BABEL = process.env.BABEL !== 'false';
|
14 | const NODE_ENV = process.env.NODE_ENV === 'development' ? 'development' : 'production';
|
15 | const matchSnapshot = process.env.SNAPSHOT === 'match';
|
16 |
|
17 | const input = './src/index.js';
|
18 |
|
19 | const name = 'cytoscape';
|
20 |
|
21 | const envVariables = {
|
22 | 'process.env.VERSION': JSON.stringify(VERSION),
|
23 | 'process.env.NODE_ENV': JSON.stringify(NODE_ENV)
|
24 | };
|
25 |
|
26 | const getBabelOptions = () => ({
|
27 | exclude: '**/node_modules/**',
|
28 | externalHelpers: true
|
29 | });
|
30 |
|
31 |
|
32 | const isExternal = id => !id.startsWith('\0') && !id.startsWith('.') && !id.startsWith('/');
|
33 |
|
34 | const licenseHeaderOptions = {
|
35 | sourcemap: true,
|
36 | banner: {
|
37 | content: {
|
38 | file: path.join(__dirname, 'LICENSE')
|
39 | }
|
40 | }
|
41 | };
|
42 |
|
43 | const 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 |
|
125 | export default FILE
|
126 | ? configs.filter(config => config.output.file.endsWith(FILE + '.js'))
|
127 | : configs;
|