Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add AOT gzip content-encoding support for main build files. (#565)
* Add AOT gzip content-encoding support. Currently we only do this for main.js and commons.js only. * Remove unwanted await. * Use Promise.all to gzip assets in parallel.
- Loading branch information
Showing
4 changed files
with
583 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import fs from 'fs' | ||
import path from 'path' | ||
import zlib from 'zlib' | ||
|
||
export default async function gzipAssets (dir) { | ||
const nextDir = path.resolve(dir, '.next') | ||
|
||
await Promise.all([ | ||
gzip(path.resolve(nextDir, 'commons.js')), | ||
gzip(path.resolve(nextDir, 'main.js')) | ||
]) | ||
} | ||
|
||
export function gzip (filePath) { | ||
const input = fs.createReadStream(filePath) | ||
const output = fs.createWriteStream(`${filePath}.gz`) | ||
|
||
return new Promise((resolve, reject) => { | ||
const stream = input.pipe(zlib.createGzip()).pipe(output) | ||
stream.on('error', reject) | ||
stream.on('finish', resolve) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.