-
Notifications
You must be signed in to change notification settings - Fork 66
/
rollup.worker.js
99 lines (91 loc) · 2.3 KB
/
rollup.worker.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
// Rollup Config for our Web Workers used in the Lib
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import babel from 'rollup-plugin-babel';
import json from 'rollup-plugin-json';
import replace from 'rollup-plugin-replace';
import compiler from '@ampproject/rollup-plugin-closure-compiler';
import bundleSize from 'rollup-plugin-bundle-size';
let sourcemap = true;
if (process.env.PROD) {
sourcemap = false;
}
let filterImports;
if (process.env.TS && !process.env.WASM) {
filterImports = {
'../../../dist/core/getWasmBoyWasmCore.esm': ['default', '*']
};
} else if (process.env.WASM && !process.env.TS) {
filterImports = {
'../../../dist/core/getWasmBoyTsCore.esm': ['default', '*']
};
}
const plugins = [
resolve(),
commonjs(),
json(),
babel({
// so Rollup can convert unsupported es6 code to es5
exclude: ['node_modules/**'],
plugins: [
['@babel/plugin-proposal-class-properties'],
['@babel/plugin-proposal-object-rest-spread'],
[
'babel-plugin-filter-imports',
{
imports: filterImports
}
]
]
})
];
if (process.env.PROD) {
plugins.push(compiler());
}
plugins.push(bundleSize());
// Define our worker input and output
const workerFiles = [
{
input: 'lib/graphics/worker/graphics.worker.js',
output: 'dist/worker/graphics.worker.js'
},
{
input: 'lib/audio/worker/audio.worker.js',
output: 'dist/worker/audio.worker.js'
},
{
input: 'lib/controller/worker/controller.worker.js',
output: 'dist/worker/controller.worker.js'
},
{
input: 'lib/memory/worker/memory.worker.js',
output: 'dist/worker/memory.worker.js'
}
];
if (process.env.TS) {
workerFiles.push({
input: 'lib/wasmboy/worker/wasmboy.worker.js',
output: 'dist/worker/wasmboy.ts.worker.js'
});
}
if (process.env.WASM) {
workerFiles.push({
input: 'lib/wasmboy/worker/wasmboy.worker.js',
output: 'dist/worker/wasmboy.wasm.worker.js'
});
}
const workerBundles = [];
workerFiles.forEach(workerFile => {
workerBundles.push({
input: workerFile.input,
output: {
file: workerFile.output,
format: 'iife',
name: 'WasmBoyWorker',
sourcemap: sourcemap
},
context: 'self',
plugins: plugins
});
});
export default workerBundles;