forked from elemaudio/elementary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
63 lines (56 loc) · 1.64 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
import cjs from '@rollup/plugin-commonjs';
import replace from '@rollup/plugin-replace';
import typescript from '@rollup/plugin-typescript';
import pkg from './package.json';
import { createFilter } from 'rollup-pluginutils';
import { minify } from 'terser';
/**
* A quick plugin which loads the desired file, minifies it with terser, and then
* returns the string itself.
*
* This is helpful so that I can load the wasm module and worklet processor into
* the main bundle, inject them into a Blob and use the Blob URI to open the
* worklet. Otherwise I would need a distinct bundle in some known spot on disk,
* which makes the whole thingy difficult.
*/
function minString(opts = {}) {
if (!opts.include) {
throw Error('include option should be specified');
}
const filter = createFilter(opts.include, opts.exclude);
return {
name: 'minString',
async transform(code, id) {
if (filter(id)) {
return {
code: `export default ${JSON.stringify((await minify(code)).code)};`,
map: { mappings: "" }
};
}
}
};
}
export default {
input: 'index.ts',
output: {
dir: './dist/',
},
external: ['@elemaudio/core'],
plugins: [
replace({
preventAssignment: true,
values: {
'process.env.NODE_ENV': JSON.stringify('production'),
'__PKG_VERSION__': JSON.stringify(pkg.version),
},
}),
// This plugin must come before the module resolution plugins, otherwise
// rollup will inject some resolvey thingies that I don't actually want in my
// raw strings
minString({
include: './raw/**/*.js',
}),
cjs(),
typescript(),
],
};