Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc(build): use rollup to create extension bundle #13408

Merged
merged 1 commit into from
Nov 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 22 additions & 17 deletions build/build-extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ const fs = require('fs');
const mkdir = fs.promises.mkdir;
const archiver = require('archiver');
const cpy = require('cpy');
const browserify = require('browserify');
const path = require('path');
const rollup = require('rollup');
const rollupPlugins = require('./rollup-plugins.js');
const {LH_ROOT} = require('../root.js');

const argv = process.argv.slice(2);
Expand All @@ -26,25 +26,30 @@ const packagePath = `${distDir}/../extension-${browserBrand}-package`;
const manifestVersion = require(`${sourceDir}/manifest.json`).version;

/**
* Browserify and minify entry point.
* Bundle and minify entry point.
*/
async function buildEntryPoint() {
const inFile = `${sourceDir}/scripts/${sourceName}`;
const outFile = `${distDir}/scripts/${distName}`;
const bundleStream = browserify(inFile).bundle();

await mkdir(path.dirname(outFile), {recursive: true});
await new Promise((resolve, reject) => {
const writeStream = fs.createWriteStream(outFile);
writeStream.on('finish', resolve);
writeStream.on('error', reject);

bundleStream.pipe(writeStream);
const bundle = await rollup.rollup({
input: `${sourceDir}/scripts/${sourceName}`,
plugins: [
rollupPlugins.shim({
[`${LH_ROOT}/report/generator/flow-report-assets.js`]: 'export default {}',
}),
rollupPlugins.replace({
'___BROWSER_BRAND___': browserBrand,
}),
rollupPlugins.commonjs(),
rollupPlugins.nodeResolve(),
rollupPlugins.inlineFs({verbose: false}),
rollupPlugins.terser(),
],
});

let outCode = fs.readFileSync(outFile, 'utf-8');
outCode = outCode.replace('___BROWSER_BRAND___', browserBrand);
fs.writeFileSync(outFile, outCode);
await bundle.write({
file: `${distDir}/scripts/${distName}`,
format: 'iife',
});
await bundle.close();
}

/**
Expand Down