forked from CirclesUBI/circles-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
63 lines (55 loc) · 1.45 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
import path from 'path';
import babel from '@rollup/plugin-babel';
import builtins from 'rollup-plugin-node-builtins';
import cleanup from 'rollup-plugin-cleanup';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import resolve from '@rollup/plugin-node-resolve';
import terser from '@rollup/plugin-terser';
const FOLDER_DIST = 'lib';
const FOLDER_INPUT = 'src';
const MODULE_NAME = 'CirclesCore';
function rollupPlugins(isUglified = false) {
const plugins = [
json(),
builtins(),
resolve({
extensions: ['.js', '.json'],
preferBuiltins: true,
}),
commonjs(),
babel({
babelHelpers: 'runtime',
skipPreflightCheck: 'true',
}),
cleanup(),
];
return isUglified ? plugins.concat(terser()) : plugins;
}
function buildOptions(customOptions = {}) {
const { file, isUglified } = customOptions;
const defaultOptions = {
input: path.join(FOLDER_INPUT, 'index.js'),
external: ['isomorphic-fetch'],
plugins: isUglified ? rollupPlugins(true) : rollupPlugins(),
output: {
file: file
? path.join(FOLDER_DIST, file)
: path.join(FOLDER_DIST, 'index.js'),
name: MODULE_NAME,
format: 'umd',
sourcemap: isUglified || false,
globals: {
'isomorphic-fetch': 'fetch',
},
},
};
return defaultOptions;
}
export default [
buildOptions(),
buildOptions({
file: 'index.min.js',
isUglified: true,
}),
];