-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathrollup.config.js
93 lines (81 loc) · 2.67 KB
/
rollup.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/* eslint-env node */
import commonjs from '@rollup/plugin-commonjs';
import packageJson from './package.json';
import replace from '@rollup/plugin-replace';
import resolve from '@rollup/plugin-node-resolve';
import serve from 'rollup-plugin-serve';
import svgr from '@svgr/rollup';
import { terser } from 'rollup-plugin-terser';
import typescript from '@rollup/plugin-typescript';
// == constants ====================================================================================
const copyright = '(c) 2017-2021 0b5vr';
const licenseName = 'MIT License';
const licenseUri = 'https://github.com/0b5vr/automaton/blob/master/LICENSE';
const globalName = 'AUTOMATON_WITH_GUI';
const filename = 'dist/automaton-with-gui';
// == envs =========================================================================================
const DEV = process.env.NODE_ENV === 'development';
const WATCH = process.env.ROLLUP_WATCH === 'true';
// == banner =======================================================================================
const bannerTextDev = `/*!
* ${ packageJson.name } v${ packageJson.version }
* ${ packageJson.description }
*
* Copyright ${ copyright }
* ${ packageJson.name } is distributed under ${ licenseName }
* ${ licenseUri }
*/`;
const bannerTextProd = `/*! ${ copyright } - ${ licenseUri } */`;
// == serve ========================================================================================
const serveOptions = {
contentBase: '../..',
};
// == config =======================================================================================
function createOutputOptions( { esm } ) {
let file = filename;
file += esm ? '.module' : '';
file += DEV ? '' : '.min';
file += '.js';
return {
file,
format: esm ? 'esm' : 'umd',
name: esm ? undefined : globalName,
banner: DEV ? bannerTextDev : bannerTextProd,
sourcemap: DEV ? 'inline' : false,
plugins: [
...( DEV ? [] : [
terser(),
] ),
...( WATCH ? [
serve( serveOptions )
] : [] ),
],
};
}
function createConfig( output ) {
return {
input: 'src/index.ts',
output,
plugins: [
typescript(),
replace( {
'process.env.VERSION': `'${ packageJson.version }'`,
'process.env.NODE_ENV': `'${ process.env.NODE_ENV }'`,
} ),
resolve(),
commonjs(),
svgr(),
],
};
};
// == output =======================================================================================
const buildConfig = [
createConfig( [
createOutputOptions( {} ),
createOutputOptions( { esm: true } ),
] ),
];
const watchConfig = createConfig( [
createOutputOptions( {} ),
] );
export default WATCH ? watchConfig : buildConfig;