-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
104 lines (90 loc) · 1.94 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
94
95
96
97
98
99
100
101
102
103
104
import typescript from '@rollup/plugin-typescript';
import resolve from '@rollup/plugin-node-resolve';
import alias from '@rollup/plugin-alias';
import {terser} from "rollup-plugin-terser";
import ttypescript from 'ttypescript';
const production = process.env.NODE_ENV === 'production';
function config(patch = {}) {
let {alias: aliases, ...other} = patch;
let optinalPlugins = [];
if (production) {
optinalPlugins.push(terser({
compress: {
ecma: 2018,
// inline: 3, // max
passes: 2,
unsafe_methods: true, // f: function(){} -> f(){}
warnings: true,
},
mangle: {
properties: {
regex: /^_\w/,
},
}
}));
}
return merge({
output: {
compact: false,
strict: false,
exports: 'named', // doesn't works with typescript and commonjs plugins
interop: false,
esModule: false,
externalLiveBindings: false,
},
watch: {
exclude: 'node_modules/**',
clearScreen: false,
},
plugins: [
alias({entries: aliases}),
resolve(),
typescript({
typescript: ttypescript,
}),
...optinalPlugins,
],
}, other);
}
export default [config({
external: ['ws'],
input: 'src/api.ts',
output: {
format: 'cjs',
file: 'dist/chat-api-node.js',
},
}), config({
input: 'src/api.ts',
output: {
format: 'cjs',
file: 'dist/chat-api-browser.js',
},
alias: [
{find: 'ws', replacement: __dirname + '/src/ws-browser.ts'}
],
})];
function merge(base, ...others) {
for (let other of others) {
for (let key in other) {
if (!other.hasOwnProperty(key)) {
continue;
}
let val = other[key];
if (typeof val === 'object') {
if (val instanceof Array) {
if (!base.hasOwnProperty(key) || typeof base[key] !== 'object' || !(base[key] instanceof Array)) {
base[key] = [];
}
} else {
if (!base.hasOwnProperty(key) || typeof base[key] !== 'object') {
base[key] = {};
}
}
merge(base[key], val);
} else {
base[key] = val;
}
}
}
return base;
}