forked from torch2424/wasmboy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.iframe.js
109 lines (94 loc) · 2.48 KB
/
rollup.iframe.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
// Bundle for the iframe embed app
import svelte from 'rollup-plugin-svelte';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import livereload from 'rollup-plugin-livereload';
import { terser } from 'rollup-plugin-terser';
import bundleSize from 'rollup-plugin-bundle-size';
import copy from 'rollup-plugin-copy-glob';
import json from 'rollup-plugin-json';
const production = !process.env.SERVE;
const hashGenerator = require('hash-generator');
const bundleHash = hashGenerator(10);
const fs = require('fs');
let jsBundle = 'bundle.js';
let cssBundle = 'bundle.css';
if (production) {
jsBundle = `bundle.${bundleHash}.js`;
cssBundle = `bundle.${bundleHash}.css`;
}
const serve = () => {
let started = false;
return {
generateBundle() {
if (!started) {
started = true;
require('child_process').spawn('npm', ['run', 'iframe:serve'], {
stdio: ['ignore', 'inherit', 'inherit'],
shell: true
});
setTimeout(() => {
console.log(`
-------
Click this URL for all embed query params pre-filled:
http://localhost:8080/?rom-name=Tobu%20Tobu%20Girl&play-poster=https://gbhh.avivace.com/database/entries/tobutobugirl/screenshot1.bmp&rom-url=https://gbhh.avivace.com/database/entries/tobutobugirl/tobu.gb
-------
`);
}, 500);
}
}
};
};
const writeIndexToBuild = () => {
return {
generateBundle() {
let indexHtml = fs.readFileSync('demo/iframe/index.html', 'utf8');
indexHtml = indexHtml.replace('%CSS_BUNDLE%', cssBundle);
indexHtml = indexHtml.replace('%JS_BUNDLE%', jsBundle);
fs.writeFileSync('build/iframe/index.html', indexHtml, 'utf8');
}
};
};
const plugins = [
svelte({
dev: !production,
css: css => {
css.write(`build/iframe/${cssBundle}`);
}
}),
resolve({
browser: true,
dedupe: ['svelte']
}),
commonjs(),
json(),
!production && serve(),
!production && livereload('build/iframe'),
production && terser(),
bundleSize(),
production &&
copy([
{
files: 'demo/iframe/assets/**/*',
dest: 'build/iframe/assets/'
}
]),
writeIndexToBuild()
];
const iframeBundles = [
{
input: 'demo/iframe/index.js',
output: {
sourcemap: true,
format: 'iife',
name: 'WasmBoyIframe',
file: `build/iframe/${jsBundle}`
},
plugins,
watch: {
chokidar: false,
clearScreen: false
}
}
];
export default iframeBundles;