Skip to content

Commit

Permalink
misc(build): do not include locales in devtools bundle (#12921)
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjclark authored Aug 17, 2021
1 parent 6e14d3b commit 211fe93
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
25 changes: 18 additions & 7 deletions build/build-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
const fs = require('fs');
const path = require('path');
const assert = require('assert').strict;
const stream = require('stream');
const mkdir = fs.promises.mkdir;
const LighthouseRunner = require('../lighthouse-core/runner.js');
const exorcist = require('exorcist');
Expand Down Expand Up @@ -66,7 +67,23 @@ async function browserifyFile(entryPath, distPath) {
})
// Transform the fs.readFile etc into inline strings.
.transform('@wardpeet/brfs', {
readFileSyncTransform: minifyFileTransform,
/** @param {string} file */
readFileTransform: (file) => {
// Don't include locales in DevTools.
if (isDevtools(entryPath) && locales.includes(file)) {
return new stream.Transform({
transform(chunk, enc, next) {
next();
},
final(next) {
this.push('{}');
next();
},
});
}

return minifyFileTransform(file);
},
global: true,
parserOpts: {ecmaVersion: 12},
})
Expand All @@ -90,12 +107,6 @@ async function browserifyFile(entryPath, distPath) {
bundle.ignore(require.resolve('../report/report-assets.js'));
}

// Don't include locales in DevTools.
if (isDevtools(entryPath)) {
// @ts-expect-error bundle.ignore does accept an array of strings.
bundle.ignore(locales);
}

// Expose the audits, gatherers, and computed artifacts so they can be dynamically loaded.
// Exposed path must be a relative path from lighthouse-core/config/config-helpers.js (where loading occurs).
const corePath = './lighthouse-core/';
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 @@ -40,7 +40,7 @@ function buildReportGenerator() {
browserify(generatorFilename, {standalone: 'ReportGenerator'})
// Transform the fs.readFile etc into inline strings.
.transform('@wardpeet/brfs', {
readFileSyncTransform: minifyFileTransform,
readFileTransform: minifyFileTransform,
global: true,
parserOpts: {ecmaVersion: 12},
})
Expand Down
2 changes: 1 addition & 1 deletion build/build-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async function run() {
const generatorFilename = `${LH_ROOT}/report/report-generator.js`;
const generatorBrowserify = browserify(generatorFilename, {standalone: 'ReportGenerator'})
.transform('@wardpeet/brfs', {
readFileSyncTransform: minifyFileTransform,
readFileTransform: minifyFileTransform,
});

/** @type {Promise<string>} */
Expand Down

0 comments on commit 211fe93

Please sign in to comment.