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 | });
|
29 |
|
30 |
|
31 | const isExternal = id => !id.startsWith('\0') && !id.startsWith('.') && !id.startsWith('/');
|
32 |
|
33 | const licenseHeaderOptions = {
|
34 | sourcemap: true,
|
35 | banner: {
|
36 | content: {
|
37 | file: path.join(__dirname, 'LICENSE')
|
38 | }
|
39 | }
|
40 | };
|
41 |
|
42 | const 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 |
|
124 | export default FILE
|
125 | ? configs.filter(config => config.output.file.endsWith(FILE + '.js'))
|
126 | : configs;
|