-
Notifications
You must be signed in to change notification settings - Fork 1
/
rollup.config.js
100 lines (93 loc) · 1.99 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
import resolve from 'rollup-plugin-node-resolve';
import commonJS from 'rollup-plugin-commonjs';
import json from 'rollup-plugin-json';
import builtins from 'rollup-plugin-node-builtins';
import globals from 'rollup-plugin-node-globals';
import replace from 'rollup-plugin-replace';
/**
* Helper function to deep clone an object
*
* @param {object} obj - Object to clone
* @param {boolean} isArray - Whether it's cloning an array
*
* @returns {object} clone
*/
function cloneHelper(obj, isArray) {
let clone = {};
if (isArray) {
clone = [];
}
for (const i in obj) {
if (Array.isArray(obj[i])) {
clone[i] = cloneHelper(obj[i], true);
} else if (obj[i] !== null && typeof obj[i] === 'object') {
clone[i] = cloneHelper(obj[i]);
} else {
clone[i] = obj[i];
}
}
return clone;
}
const noThree = true;
const noThreeReplace = replace({
'three': ``,
include: 'src/**',
exclude: 'src/lib/**',
delimiters: ['import * as THREE from \'', '\'']
});
const configs = [];
const config = {
input: 'src/main.js',
plugins: [
replace({
[`readable-stream`]: `require('stream')`,
include: 'node_modules/simple-peer/index.js',
delimiters: ['require(\'', '\')']
}),
commonJS({
ignoreGlobal: true
}),
json(),
globals(),
builtins(),
resolve({
preferBuiltins: false,
browser: true
})
],
output: [
{
name: 'Simbol',
format: 'iife',
sourcemap: true,
exports: 'named',
dir: 'build',
file: 'simbol.script.js'
},
{
format: 'cjs',
sourcemap: true,
exports: 'named',
dir: 'build',
file: 'simbol.cjs.js'
},
{
format: 'es',
sourcemap: true,
exports: 'named',
dir: 'build',
file: 'simbol.js'
}
]
};
configs.push(config);
if (noThree) {
const noThreeConfig = cloneHelper(config);
noThreeConfig.plugins.unshift(noThreeReplace);
noThreeConfig.output = noThreeConfig.output.map((output) => {
output.file = output.file.replace('.js', '.nothree.js');
return output;
});
configs.push(noThreeConfig);
}
export default configs;