-
Notifications
You must be signed in to change notification settings - Fork 187
/
build.js
111 lines (107 loc) · 3.1 KB
/
build.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
/* eslint-disable node/no-unpublished-require */
const rollup = require('rollup');
const sourcemap = require('rollup-plugin-sourcemaps');
const { terser } = require('rollup-plugin-terser');
const strip = require('@rollup/plugin-strip');
const path = require('path');
const fs = require('fs-extra');
const symlinkOrCopy = require('symlink-or-copy').sync;
const benchmark = require('./rollup-plugin');
/**
* @param {string} dist
* @param {string} out
*/
async function build(dist, out) {
// create a bundle
const bundle = await rollup.rollup({
input: [
path.resolve(__dirname, '../benchmarks/krausest/browser.js'),
path.resolve(__dirname, '../benchmarks/krausest/ssr.js'),
],
plugins: [
benchmark(dist),
sourcemap(),
strip({
functions: ['assert', 'deprecate'],
}),
// terser({
// compress: {
// // eslint-disable-next-line @typescript-eslint/naming-convention
// negate_iife: false,
// sequences: 0,
// },
// output: {
// semicolons: false,
// },
// }),
],
onwarn(warning) {
let { code } = warning;
if (
// Suppress known error message caused by TypeScript compiled code with Rollup
// https://github.com/rollup/rollup/wiki/Troubleshooting#this-is-undefined
code === 'THIS_IS_UNDEFINED' ||
// Suppress errors regarding un-used exports. These may be left behind
// after DEBUG stripping and Rollup removed them anyway.
code === 'UNUSED_EXTERNAL_IMPORT' ||
code === 'CIRCULAR_DEPENDENCY'
) {
return;
}
console.log(`Rollup warning: ${warning.message}`);
},
});
// or write the bundle to disk
await bundle.write({
format: 'es',
dir: path.resolve(out, 'krausest'),
entryFileNames: '[name].mjs',
chunkFileNames: '[name].mjs',
sourcemap: true,
plugins: [
{
generateBundle() {
this.emitFile({
type: 'asset',
fileName: 'index.html',
source: `
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>krausest benchmark</title>
</head>
<script type="module">
import run from './browser.mjs';
run();
</script>
<body>
</body>
</html>
`,
});
},
},
],
});
}
module.exports = async function buildAll() {
const experimentDist = path.resolve(__dirname, '../../dist');
const experimentBuild = path.resolve(experimentDist, '@glimmer');
if (!fs.existsSync(experimentBuild)) {
return;
}
await build(experimentDist, path.resolve(experimentDist, 'benchmarks/experiment'));
const controlDist = path.resolve(__dirname, '../../control-dist');
const controlBuild = path.resolve(controlDist, '@glimmer');
if (fs.existsSync(controlBuild)) {
if (!fs.existsSync(path.join(controlDist, 'node_modules'))) {
fs.mkdirsSync(path.join(controlDist, 'node_modules'));
symlinkOrCopy(
path.join(controlDist, '@glimmer'),
path.join(controlDist, 'node_modules/@glimmer')
);
}
await build(controlDist, path.resolve(experimentDist, 'benchmarks/control'));
}
};