This repository has been archived by the owner on Jan 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
130 lines (124 loc) · 3.69 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import alias from '@rollup/plugin-alias';
import commonjs from '@rollup/plugin-commonjs';
import nodejsResolve from '@rollup/plugin-node-resolve';
import arraybufferPlugin from './script/rollup-arraybuffer';
import inlineWebWorkerPlugin from './script/inline-webworker';
import nodePolyfills from 'rollup-plugin-node-polyfills';
import { terser } from 'rollup-plugin-terser';
import strip from '@rollup/plugin-strip';
// import nodeBuiltins from 'rollup-plugin-node-builtins';
// import { getBabelOutputPlugin } from '@rollup/plugin-babel';
import babel from '@rollup/plugin-babel';
import pluginJson from '@rollup/plugin-json';
import replace from '@rollup/plugin-replace';
import { resolve } from 'path';
import * as R from 'ramda';
const PROD = process.env.BUILD_TARGET === 'production';
const DEV = process.env.BUILD_TARGET === 'development';
const globals = {
comlink: 'Comlink',
// buffer: 'Buffer',
};
const pluginsCommon = [
alias({
entries: [
{ find: '@root', replacement: resolve('./src') },
{ find: '@module', replacement: resolve('./src/modules') },
],
}),
replace({ __PROD__: PROD, __DEV__: DEV }),
strip({
exclude: !PROD ? [] : ['@root/logger.js'],
functions: !PROD ? [] : ['log', 'logSAB', 'logSPN', 'logWorklet', 'logVAN'],
}),
pluginJson(),
commonjs({ transformMixedEsModules: true }),
nodejsResolve({ preferBuiltins: false }),
nodePolyfills({ fs: false, crypto: false, sourceMap: false }),
];
const babelCommon = babel({
babelHelpers: 'inline',
include: 'src/**/*.js',
plugins: [
['@babel/plugin-transform-destructuring', { useBuiltIns: true }],
['@babel/plugin-proposal-object-rest-spread', { useBuiltIns: true }],
],
});
export default [
{
input: 'src/workers/sab.worker.js',
// external: ['comlink'],
output: {
file: 'dist/__compiled.sab.worker.js',
format: 'iife',
name: 'sab.worker',
sourcemap: false,
globals,
},
plugins: [
...pluginsCommon,
babelCommon,
...(PROD ? [terser()] : []),
// arraybufferPlugin({ include: ['**/*.wasm', '**/*.wasm.zlib'] })
],
},
{
input: 'src/workers/vanilla.worker.js',
// external: ['comlink'],
output: {
file: 'dist/__compiled.vanilla.worker.js',
format: 'iife',
name: 'vanilla.worker',
sourcemap: false,
globals,
},
plugins: [...pluginsCommon, babelCommon, ...(PROD ? [terser()] : [])],
},
{
input: 'src/workers/worklet.worker.js',
// external: ['comlink'],
output: {
file: 'dist/__compiled.worklet.worker.js',
format: 'iife',
name: 'worklet.worker',
sourcemap: false,
globals,
},
plugins: [...pluginsCommon, babelCommon, ...(PROD ? [terser()] : [])],
},
{
input: 'src/workers/old-spn.worker.js',
output: {
file: 'dist/__compiled.old-spn.worker.js',
format: 'iife',
name: 'old-spn.worker',
sourcemap: false,
globals,
},
plugins: [...pluginsCommon, babelCommon, ...(PROD ? [terser()] : [])],
},
{
input: 'src/index.js',
// external: ['comlink'],
output: {
file: DEV ? 'dist/libcsound.dev.mjs' : 'dist/libcsound.mjs',
format: 'module',
sourcemap: true,
globals,
},
plugins: [
...pluginsCommon,
inlineWebWorkerPlugin({
include: ['**/worklet.worker.js'],
dataUrl: true,
}),
inlineWebWorkerPlugin({
include: ['**/sab.worker.js', '**/vanilla.worker.js', '**/old-spn.worker.js'],
dataUrl: false,
}),
R.assoc('plugins', R.append('add-module-exports', babelCommon.plugins), babelCommon),
arraybufferPlugin({ include: ['**/*.wasm', '**/*.wasm.zlib'] }),
...(PROD ? [terser()] : []),
],
},
];