mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
24 lines
598 B
JavaScript
24 lines
598 B
JavaScript
|
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)
|
||
|
})
|
||
|
}
|