Skip to content

Commit

Permalink
Brotli compress dist-extensions
Browse files Browse the repository at this point in the history
Saves about 7MB.
  • Loading branch information
GarboMuffin committed Dec 22, 2024
1 parent 5526428 commit ef23830
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
23 changes: 20 additions & 3 deletions scripts/prepare-extensions.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
const pathUtil = require('path');
const fs = require('fs');
const zlib = require('zlib');
const Builder = require('@turbowarp/extensions/builder');

const outputDirectory = pathUtil.join(__dirname, '../dist-extensions/');
const mode = 'desktop';
const builder = new Builder(mode);
const build = builder.build();
build.export(outputDirectory);
console.log(`Built extensions (mode: ${mode})`);

const outputDirectory = pathUtil.join(__dirname, '../dist-extensions/');
fs.rmSync(outputDirectory, {
recursive: true,
force: true,
});
for (const [relativePath, file] of Object.entries(build.files)) {
console.log(`Compressing ${relativePath}`);
const directoryName = pathUtil.dirname(relativePath);
fs.mkdirSync(pathUtil.join(outputDirectory, directoryName), {
recursive: true,
});
const contents = file.read();
const compressed = zlib.brotliCompressSync(contents);
fs.writeFileSync(pathUtil.join(outputDirectory, `${relativePath}.br`), compressed);
}

console.log(`Built ${mode} copy of extensions.turbowarp.org to ${outputDirectory}`);
console.log(`Exported to ${outputDirectory}`);
1 change: 1 addition & 0 deletions src-main/protocols.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const FILE_SCHEMES = {
'tw-extensions': {
root: path.resolve(__dirname, '../dist-extensions'),
supportFetch: true,
brotli: true,
embeddable: true,
stream: true,
directoryIndex: 'index.html',
Expand Down

0 comments on commit ef23830

Please sign in to comment.