-
Notifications
You must be signed in to change notification settings - Fork 66
/
rollup.getcore.js
147 lines (126 loc) · 3.36 KB
/
rollup.getcore.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// Rollup Config to bundle our "Get Core" exports
// Convinient JS Exports to instantiate and import the
// WasmBoy Core
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import babel from 'rollup-plugin-babel';
import typescript from 'rollup-plugin-typescript';
import url from 'rollup-plugin-url';
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';
import pkg from './package.json';
// Our base plugins needed by every bundle type
let plugins = [
resolve(), // so Rollup can find node modules
commonjs(),
json(),
url({
limit: 1000000 * 1024, // Always inline
include: ['**/*.wasm'],
// Don't emit files, this will replace the worker build output
emitFiles: false
})
];
if (!process.env.ES_NEXT) {
plugins = [
...plugins,
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']]
})
];
}
if (process.env.GET_CORE_CLOSURE) {
let closureCompilerOptions = {};
if (process.env.CLOSURE_DEBUG) {
closureCompilerOptions = {
...closureCompilerOptions,
debug: true
};
}
plugins = [...plugins, compiler(closureCompilerOptions)];
}
plugins = [...plugins, bundleSize()];
// Array of bundles to make
const bundleMap = [];
const addDotIdentifiers = output => {
if (process.env.ES_NEXT) {
output += '.esnext';
}
if (process.env.GET_CORE_CLOSURE) {
output += '.closure';
if (process.env.CLOSURE_DEBUG) {
output += '.closuredebug';
}
}
return output;
};
if (process.env.WASM) {
let bundleMapObject = {
name: 'WasmBoyWasmCore',
input: 'core/portable/getWasmCore.js',
output: 'dist/core/getWasmBoyWasmCore'
};
bundleMapObject.output = addDotIdentifiers(bundleMapObject.output);
bundleMap.push(bundleMapObject);
}
if (process.env.TS) {
let bundleMapObject = {
name: 'WasmBoyTsCore',
input: 'core/portable/getTsCore.js',
output: 'dist/core/getWasmBoyTsCore'
};
bundleMapObject.output = addDotIdentifiers(bundleMapObject.output);
bundleMap.push(bundleMapObject);
}
const getCoreBundles = [];
bundleMap.forEach(bundleObject => {
getCoreBundles.push({
input: bundleObject.input,
output: {
name: bundleObject.name,
file: `${bundleObject.output}.umd.js`,
format: 'umd',
sourcemap: true
},
context: 'window',
plugins: plugins
});
getCoreBundles.push({
input: bundleObject.input,
output: {
name: bundleObject.name,
file: `${bundleObject.output}.iife.js`,
format: 'iife',
sourcemap: true
},
context: 'window',
plugins: plugins
});
getCoreBundles.push({
input: bundleObject.input,
output: {
name: bundleObject.name,
file: `${bundleObject.output}.esm.js`,
format: 'es',
sourcemap: true
},
context: 'window',
plugins: plugins
});
getCoreBundles.push({
input: bundleObject.input,
output: {
name: bundleObject.name,
file: `${bundleObject.output}.cjs.js`,
format: 'cjs',
sourcemap: true
},
context: 'global',
plugins: plugins
});
});
export default getCoreBundles;