-
Notifications
You must be signed in to change notification settings - Fork 30
/
rollup.config.js
58 lines (52 loc) · 1.3 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
import alias from '@rollup/plugin-alias'
import babel from '@rollup/plugin-babel'
import cleanup from 'rollup-plugin-cleanup'
import dts from 'rollup-plugin-dts'
import { terser } from 'rollup-plugin-terser'
function rollupPlugins({ isBrowser = false } = {}) {
const plugins = [
babel({
babelHelpers: 'bundled',
exclude: 'node_modules/**',
}),
cleanup(),
]
return isBrowser ? [alias({
entries: [
{ find: 'ws', replacement: 'src/external/ws.js' },
{ find: 'dgram', replacement: 'src/external/dgram.js' },
],
}), ...plugins, terser()] : plugins
}
function buildOptions(customOptions = {}) {
const { file, isBrowser } = customOptions
const defaultOptions = {
input: 'src/osc.js',
external: isBrowser ? [] : ['ws', 'dgram'],
plugins: rollupPlugins({ isBrowser }),
output: {
globals: isBrowser ? {} : {
ws: 'ws',
dgram: 'dgram',
},
file: file || 'lib/osc.js',
name: 'OSC',
format: 'umd',
sourcemap: isBrowser || false,
},
}
return defaultOptions
}
export default [
buildOptions(),
buildOptions({
file: 'lib/osc.min.js',
isBrowser: true,
}),
{
input: './src/osc.js',
output: [{ file: 'lib/osc.d.ts', format: 'es' }],
plugins: [dts()],
external: ['http', 'https'],
},
]