-
Notifications
You must be signed in to change notification settings - Fork 46
/
rollup.config.js
69 lines (65 loc) · 1.86 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
import path from 'path';
import json from 'rollup-plugin-json';
import flow from 'rollup-plugin-flow';
import babel from 'rollup-plugin-babel';
import commonjs from 'rollup-plugin-commonjs';
import resolve from 'rollup-plugin-node-resolve';
import shim from 'rollup-plugin-shim';
import { uglify } from 'rollup-plugin-uglify';
const env = process.env.NODE_ENV;
const isCLI = process.argv[process.argv.length - 1] === 'bin/blinktrade';
const format = (env === 'development' || env === 'production') ? 'umd' : env;
const config = {
input: isCLI ? 'bin/blinktrade.js' : 'src/index.js',
output: {
name: 'blinktrade',
format,
},
plugins: [
json({ preferConst: true }),
flow({ all: true }),
resolve({
jsnext: true,
browser: format === 'umd',
preferBuiltins: false,
}),
commonjs({
include: 'node_modules/**',
}),
babel({
babelrc: false,
presets: [['@babel/preset-env', { modules: false }]],
plugins: ['@babel/plugin-proposal-object-rest-spread'],
}),
],
};
if (format === 'umd') {
config.plugins.push(uglify({
mangle: env === 'production',
output: {
beautify: env !== 'production',
},
compress: {
pure_getters: true,
unsafe: true,
unsafe_comps: true,
warnings: false,
},
}));
// Remove modules that can't be bundled on the browser
config.plugins.unshift(shim({
ws: 'export default {}',
ip: 'export default {}',
dgram: 'export default {}',
os: 'export default {}',
'macaddress-secure': 'export default {}',
[path.join(__dirname, 'src/util/macaddress')]: 'export function getMac() {}',
[path.join(__dirname, 'src/util/stun')]: `
export function getStun() {}
export function closeStun() {}
`,
}));
} else {
config.external = ['ws', 'commander', 'inquirer', 'dotenv', '../lib/blinktrade'];
}
export default config;