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 license from 'rollup-plugin-license';
|
7 | import path from 'path';
|
8 |
|
9 | const VERSION = process.env.VERSION || 'snapshot';
|
10 | const FILE = process.env.FILE;
|
11 | const SOURCEMAPS = process.env.SOURCEMAPS === 'true';
|
12 | const BABEL = process.env.BABEL !== 'false';
|
13 | const NODE_ENV = process.env.NODE_ENV === 'development' ? 'development' : 'production';
|
14 |
|
15 | const input = './src/index.js';
|
16 |
|
17 | const name = 'cytoscape';
|
18 |
|
19 | const envVariables = {
|
20 | 'process.env.VERSION': JSON.stringify(VERSION),
|
21 | 'process.env.NODE_ENV': JSON.stringify(NODE_ENV)
|
22 | };
|
23 |
|
24 | const getBabelOptions = () => ({
|
25 | exclude: '**/node_modules/**'
|
26 | });
|
27 |
|
28 |
|
29 | const isExternal = id => !id.startsWith('\0') && !id.startsWith('.') && !id.startsWith('/');
|
30 |
|
31 | const licenseHeaderOptions = {
|
32 | sourcemap: true,
|
33 | banner: {
|
34 | content: {
|
35 | file: path.join(__dirname, 'LICENSE')
|
36 | }
|
37 | }
|
38 | };
|
39 |
|
40 | const 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 |
|
118 | export default FILE
|
119 | ? configs.filter(config => config.output.file.endsWith(FILE + '.js'))
|
120 | : configs;
|