@sveltejs/adapter-static
Advanced tools
Comparing version
# @sveltejs/adapter-static | ||
## 1.0.0-next.39 | ||
### Patch Changes | ||
- Move `compress` logic to `Builder` API ([#5822](https://github.com/sveltejs/kit/pull/5822)) | ||
## 1.0.0-next.38 | ||
@@ -4,0 +10,0 @@ |
51
index.js
@@ -1,10 +0,3 @@ | ||
import { createReadStream, createWriteStream, statSync } from 'fs'; | ||
import { pipeline } from 'stream'; | ||
import glob from 'tiny-glob'; | ||
import { promisify } from 'util'; | ||
import zlib from 'zlib'; | ||
import { platforms } from './platforms.js'; | ||
const pipe = promisify(pipeline); | ||
/** @type {import('.').default} */ | ||
@@ -52,9 +45,9 @@ export default function (options) { | ||
builder.log.minor('Compressing assets and pages'); | ||
await compress(assets); | ||
await builder.compress(assets); | ||
} else { | ||
builder.log.minor('Compressing assets'); | ||
await compress(assets); | ||
await builder.compress(assets); | ||
builder.log.minor('Compressing pages'); | ||
await compress(pages); | ||
await builder.compress(pages); | ||
} | ||
@@ -73,39 +66,1 @@ } | ||
} | ||
/** | ||
* @param {string} directory | ||
*/ | ||
async function compress(directory) { | ||
const files = await glob('**/*.{html,js,json,css,svg,xml,wasm}', { | ||
cwd: directory, | ||
dot: true, | ||
absolute: true, | ||
filesOnly: true | ||
}); | ||
await Promise.all( | ||
files.map((file) => Promise.all([compress_file(file, 'gz'), compress_file(file, 'br')])) | ||
); | ||
} | ||
/** | ||
* @param {string} file | ||
* @param {'gz' | 'br'} format | ||
*/ | ||
async function compress_file(file, format = 'gz') { | ||
const compress = | ||
format == 'br' | ||
? zlib.createBrotliCompress({ | ||
params: { | ||
[zlib.constants.BROTLI_PARAM_MODE]: zlib.constants.BROTLI_MODE_TEXT, | ||
[zlib.constants.BROTLI_PARAM_QUALITY]: zlib.constants.BROTLI_MAX_QUALITY, | ||
[zlib.constants.BROTLI_PARAM_SIZE_HINT]: statSync(file).size | ||
} | ||
}) | ||
: zlib.createGzip({ level: zlib.constants.Z_BEST_COMPRESSION }); | ||
const source = createReadStream(file); | ||
const destination = createWriteStream(`${file}.${format}`); | ||
await pipe(source, compress, destination); | ||
} |
{ | ||
"name": "@sveltejs/adapter-static", | ||
"version": "1.0.0-next.38", | ||
"version": "1.0.0-next.39", | ||
"repository": { | ||
@@ -21,7 +21,4 @@ "type": "git", | ||
"types": "index.d.ts", | ||
"dependencies": { | ||
"tiny-glob": "^0.2.9" | ||
}, | ||
"devDependencies": { | ||
"@sveltejs/kit": "1.0.0-next.380", | ||
"@sveltejs/kit": "1.0.0-next.405", | ||
"@types/node": "^16.11.36", | ||
@@ -38,5 +35,5 @@ "playwright-chromium": "^1.23.4", | ||
"check": "tsc", | ||
"format": "npm run check-format -- --write", | ||
"format": "npm run lint -- --write", | ||
"test": "uvu test test.js" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
0
-100%6
-14.29%26913
-4.1%335
-10.43%- Removed
- Removed
- Removed
- Removed