Skip to content

Commit

Permalink
misc(build): use rollup to create viewer report generator (#13407)
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjclark authored Nov 22, 2021
1 parent 806c402 commit 4059955
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions build/build-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,37 @@
*/
'use strict';

const browserify = require('browserify');
const rollup = require('rollup');
const rollupPlugins = require('./rollup-plugins.js');
const GhPagesApp = require('./gh-pages-app.js');
const {LH_ROOT} = require('../root.js');
const inlineFs = require('./plugins/browserify-inline-fs.js');

async function buildReportGenerator() {
const bundle = await rollup.rollup({
input: 'report/generator/report-generator.js',
plugins: [
rollupPlugins.shim({
[`${LH_ROOT}/report/generator/flow-report-assets.js`]: 'export default {}',
}),
rollupPlugins.commonjs(),
rollupPlugins.nodeResolve(),
rollupPlugins.inlineFs({verbose: Boolean(process.env.DEBUG)}),
],
});

const result = await bundle.generate({
format: 'umd',
name: 'ReportGenerator',
});
await bundle.close();
return result.output[0].code;
}

/**
* Build viewer, optionally deploying to gh-pages if `--deploy` flag was set.
*/
async function run() {
// JS bundle from browserified ReportGenerator.
const generatorFilename = `${LH_ROOT}/report/generator/report-generator.js`;
const generatorBrowserify = browserify(generatorFilename, {standalone: 'ReportGenerator'})
// Flow report is not used in report viewer, so don't include flow assets.
.ignore(require.resolve('../report/generator/flow-report-assets.js'))
// Transform `fs.readFileSync`, etc into inline strings.
.transform(inlineFs({verbose: Boolean(process.env.DEBUG)}));

/** @type {Promise<string>} */
const generatorJsPromise = new Promise((resolve, reject) => {
generatorBrowserify.bundle((err, src) => {
if (err) return reject(err);
resolve(src.toString());
});
});
const reportGeneratorJs = await buildReportGenerator();

const app = new GhPagesApp({
name: 'viewer',
Expand All @@ -39,7 +45,7 @@ async function run() {
{path: 'styles/*'},
],
javascripts: [
await generatorJsPromise,
reportGeneratorJs,
{path: require.resolve('pako/dist/pako_inflate.js')},
{path: 'src/main.js', rollup: true, rollupPlugins: [
rollupPlugins.shim({
Expand Down

0 comments on commit 4059955

Please sign in to comment.