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

report(viewer): minify inlined report-generator bundle #9596

Merged
merged 4 commits into from
Oct 11, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion build/build-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async function browserifyFile(entryPath, distPath) {

bundle
// Transform the fs.readFile etc into inline strings.
.transform('brfs', {global: true, parserOpts: {ecmaVersion: 10}})
.transform('@wardpeet/brfs', {global: true, parserOpts: {ecmaVersion: 10}})
// Strip everything out of package.json includes except for the version.
.transform('package-json-versionify');

Expand Down
2 changes: 1 addition & 1 deletion build/build-lightrider-bundles.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function buildEntryPoint() {
function buildReportGenerator() {
browserify(generatorFilename, {standalone: 'ReportGenerator'})
// Transform the fs.readFile etc into inline strings.
.transform('brfs', {global: true, parserOpts: {ecmaVersion: 10}})
.transform('@wardpeet/brfs', {global: true, parserOpts: {ecmaVersion: 10}})
.bundle((err, src) => {
if (err) throw err;
fs.writeFileSync(bundleOutFile, src.toString());
Expand Down
25 changes: 24 additions & 1 deletion build/build-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const path = require('path');
const {promisify} = require('util');
const readFileAsync = promisify(fs.readFile);
const writeFileAsync = promisify(fs.writeFile);
const stream = require('stream');

const browserify = require('browserify');
const cpy = require('cpy');
Expand Down Expand Up @@ -106,7 +107,29 @@ async function compileJs() {
// JS bundle from browserified ReportGenerator.
const generatorFilename = `${sourceDir}/../lighthouse-core/report/report-generator.js`;
const generatorBrowserify = browserify(generatorFilename, {standalone: 'ReportGenerator'})
.transform('brfs');
.transform('@wardpeet/brfs', {
/**
* @param {string} file
*/
readFileSyncTransform: file => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably pull this out into a top-level named function

return new stream.Transform({
transform(chunk, enc, next) {
if (file.endsWith('.js')) {
const result = terser.minify(chunk.toString());
if (result.error) {
throw result.error;
}

this.push(result.code);
} else {
this.push(chunk);
}

next();
},
});
},
});

/** @type {Promise<string>} */
const generatorJsPromise = new Promise((resolve, reject) => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@
"@types/update-notifier": "^1.0.2",
"@types/ws": "^4.0.1",
"@types/yargs": "^8.0.2",
"@wardpeet/brfs": "^2.1.0-0",
"angular": "^1.7.4",
"archiver": "^3.0.0",
"babel-core": "^6.26.0",
"babel-plugin-syntax-async-generators": "^6.13.0",
"babel-plugin-syntax-object-rest-spread": "^6.13.0",
"brfs": "^2.0.2",
"browserify": "^16.2.3",
"bundlesize": "^0.17.2",
"chalk": "^2.4.1",
Expand Down
20 changes: 10 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,16 @@
resolved "https://registry.yarnpkg.com/@types/yargs/-/yargs-8.0.2.tgz#0f9c7b236e2d78cd8f4b6502de15d0728aa29385"
integrity sha512-Upj9YsBZRgjEVPvsaeGru48d2JiyzBNZkmkebHyoaQ+UM9wqj/rp5mkilRjSq/Ga45yfd/zwrNuML9f2gGfVpw==

"@wardpeet/brfs@^2.1.0-0":
version "2.1.0-0"
resolved "https://registry.yarnpkg.com/@wardpeet/brfs/-/brfs-2.1.0-0.tgz#04e77dc088ca5bbc5b07051860faa45569e799f3"
integrity sha512-ra9bDHPwsI+HBKQJk9CLMYaFDHLA7QGEH0teWlIcZ6/CHtFvjRb2YjwLBXc8jgtw+3LvCEuqme/BQaDfo74fUA==
dependencies:
quote-stream "^1.0.1"
resolve "^1.1.5"
static-module "^3.0.2"
through2 "^2.0.0"

JSONStream@^1.0.3, JSONStream@^1.0.4:
version "1.3.5"
resolved "https://registry.yarnpkg.com/JSONStream/-/JSONStream-1.3.5.tgz#3208c1f08d3a4d99261ab64f92302bc15e111ca0"
Expand Down Expand Up @@ -1372,16 +1382,6 @@ braces@^2.3.1:
split-string "^3.0.2"
to-regex "^3.0.1"

brfs@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/brfs/-/brfs-2.0.2.tgz#44237878fa82aa479ce4f5fe2c1796ec69f07845"
integrity sha512-IrFjVtwu4eTJZyu8w/V2gxU7iLTtcHih67sgEdzrhjLBMHp2uYefUBfdM4k2UvcuWMgV7PQDZHSLeNWnLFKWVQ==
dependencies:
quote-stream "^1.0.1"
resolve "^1.1.5"
static-module "^3.0.2"
through2 "^2.0.0"

brorand@^1.0.1:
version "1.1.0"
resolved "https://registry.yarnpkg.com/brorand/-/brorand-1.1.0.tgz#12c25efe40a45e3c323eb8675a0a0ce57b22371f"
Expand Down