-
Notifications
You must be signed in to change notification settings - Fork 66
/
rollup.debugger.js
135 lines (126 loc) · 3.35 KB
/
rollup.debugger.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
// Bundle for the debugger app
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import babel from 'rollup-plugin-babel';
import compiler from '@ampproject/rollup-plugin-closure-compiler';
import { terser } from 'rollup-plugin-terser';
import url from 'rollup-plugin-url';
import json from 'rollup-plugin-json';
import serve from 'rollup-plugin-serve';
import replace from 'rollup-plugin-replace';
import bundleSize from 'rollup-plugin-bundle-size';
import postcss from 'rollup-plugin-postcss';
import postcssImport from 'postcss-import';
import copy from 'rollup-plugin-copy-glob';
import del from 'rollup-plugin-delete';
import hash from 'rollup-plugin-hash';
import pkg from './package.json';
const fs = require('fs');
const writeIndexHtmlToBuild = bundleName => {
let indexHtml = fs.readFileSync('demo/debugger/index.html', 'utf8');
indexHtml = indexHtml.replace('<%BUNDLE%>', bundleName.replace('build/', ''));
fs.writeFileSync('build/index.html', indexHtml, 'utf8');
};
const babelPluginConfig = {
// https://github.com/webpack/webpack/issues/2031#issuecomment-219040479
exclude: [/node_modules\/(?!(shared-gb)\/).*/],
plugins: [
['@babel/plugin-proposal-class-properties'],
['@babel/plugin-proposal-object-rest-spread'],
['@babel/plugin-transform-react-jsx', { pragma: 'h' }],
['@babel/plugin-proposal-export-default-from']
]
};
let plugins = [
postcss({
extensions: ['.css'],
plugins: [postcssImport()]
}),
resolve({
preferBuiltins: false
}),
babel(babelPluginConfig),
commonjs(),
json(),
url({
limit: 0, // Always emit file
include: ['**/*.gb', '**/*.gbc', '**/*.png', '**/*.jpg'],
emitFiles: true
})
];
let sourcemap = false;
if (process.env.DEBUGGER && process.env.SERVE) {
plugins = [
...plugins,
replace({
delimiters: ['', ''],
values: {
'/*ROLLUP_REPLACE_DEBUGGER_DEV': '',
'ROLLUP_REPLACE_DEBUGGER_DEV*/': ''
}
}),
serve({
contentBase: ['dist/', 'build/', 'demo/debugger/'],
port: 8080
})
];
writeIndexHtmlToBuild('index.iife.js');
sourcemap = 'inline';
} else {
// Using whitespace only closure as,
// It will mangle preact nodeNames, which is used
// For restoring debugger layout
plugins = [
...plugins,
// TODO: Compiler gives Out of memory errors in node :(
/*
compiler({
compilation_level: 'WHITESPACE_ONLY'
}),
*/
terser({
mangle: false
}),
copy([
{
files: 'demo/debugger/assets/**/*',
dest: 'build/assets'
},
{
files: 'demo/debugger/manifest.json',
dest: 'build/'
}
]),
del({
targets: ['build/bundle.*.js']
}),
hash({
dest: 'build/bundle.[hash].js',
callback: bundleName => {
writeIndexHtmlToBuild(bundleName);
}
})
];
}
plugins = [...plugins, bundleSize()];
// Had to hack around crypto for phosphor
// https://github.com/phosphorjs/phosphor/issues/353
const debuggerBundles = [
{
input: 'demo/debugger/index.js',
output: {
name: 'WasmBoyBenchmark',
file: 'build/index.iife.js',
format: 'iife',
globals: {
crypto: 'crypto'
},
sourcemap: sourcemap
},
external: ['crypto'],
context: 'window',
plugins: plugins,
sourcemap: true
}
];
export default debuggerBundles;