vite-plugin-singlefile-compression 2.0.10 → 2.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/compress.d.ts +3 -3
- package/dist/compress.js +27 -12
- package/dist/getTemplate.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ Using [DecompressionStream](https://developer.mozilla.org/docs/Web/API/Decompres
|
|
|
9
9
|
## Setup
|
|
10
10
|
|
|
11
11
|
```
|
|
12
|
-
npm i vite-plugin-singlefile-compression
|
|
12
|
+
npm i vite-plugin-singlefile-compression -D
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
Then modify `vite.config.ts`, see [test/vite.config.ts](test/vite.config.ts)
|
package/dist/compress.d.ts
CHANGED
|
@@ -4,9 +4,9 @@ declare const compressors: {
|
|
|
4
4
|
deflate(buf: zlib.InputType): Buffer;
|
|
5
5
|
gzip(buf: zlib.InputType): Buffer;
|
|
6
6
|
brotli: typeof zlib.brotliCompressSync;
|
|
7
|
-
zstd:
|
|
7
|
+
zstd: (buf: zlib.InputType) => NonSharedBuffer;
|
|
8
8
|
};
|
|
9
|
-
export type compressor = ((buf: zlib.InputType) => Buffer);
|
|
9
|
+
export type compressor = ((buf: zlib.InputType) => (Buffer | Uint8Array));
|
|
10
10
|
export type compressFormat = keyof typeof compressors;
|
|
11
|
-
export declare function compress(format: compressFormat, buf: zlib.InputType, useBase128: boolean, compressor: compressor):
|
|
11
|
+
export declare function compress(format: compressFormat, buf: zlib.InputType, useBase128: boolean, compressor: compressor | undefined): any;
|
|
12
12
|
export {};
|
package/dist/compress.js
CHANGED
|
@@ -1,20 +1,29 @@
|
|
|
1
1
|
import base128 from "base128-ascii";
|
|
2
2
|
import zlib from 'zlib';
|
|
3
|
-
const zlibDefaultOptions = {
|
|
4
|
-
level: zlib.constants.Z_BEST_COMPRESSION,
|
|
5
|
-
};
|
|
6
3
|
const compressors = {
|
|
7
4
|
"deflate-raw"(buf) {
|
|
8
|
-
return zlib.deflateRawSync(buf,
|
|
5
|
+
return zlib.deflateRawSync(buf, {
|
|
6
|
+
level: zlib.constants.Z_BEST_COMPRESSION,
|
|
7
|
+
});
|
|
9
8
|
},
|
|
10
9
|
deflate(buf) {
|
|
11
|
-
return zlib.deflateSync(buf,
|
|
10
|
+
return zlib.deflateSync(buf, {
|
|
11
|
+
level: zlib.constants.Z_BEST_COMPRESSION,
|
|
12
|
+
});
|
|
12
13
|
},
|
|
13
14
|
gzip(buf) {
|
|
14
|
-
return zlib.gzipSync(buf,
|
|
15
|
+
return zlib.gzipSync(buf, {
|
|
16
|
+
level: zlib.constants.Z_BEST_COMPRESSION,
|
|
17
|
+
});
|
|
15
18
|
},
|
|
16
19
|
brotli: zlib.brotliCompressSync,
|
|
17
|
-
zstd: zlib.zstdCompressSync
|
|
20
|
+
zstd: zlib.zstdCompressSync && function (buf) {
|
|
21
|
+
return zlib.zstdCompressSync(buf, {
|
|
22
|
+
params: {
|
|
23
|
+
[zlib.constants.ZSTD_c_compressionLevel]: 22
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
},
|
|
18
27
|
};
|
|
19
28
|
function switchCompressor(format) {
|
|
20
29
|
if (Object.prototype.hasOwnProperty.call(compressors, format)) {
|
|
@@ -25,15 +34,21 @@ function switchCompressor(format) {
|
|
|
25
34
|
}
|
|
26
35
|
let funcName = format + 'CompressSync';
|
|
27
36
|
if (Object.prototype.hasOwnProperty.call(zlib, funcName)) {
|
|
28
|
-
const f = zlib[
|
|
37
|
+
const f = zlib[funcName];
|
|
29
38
|
if (typeof f == 'function')
|
|
30
39
|
return f;
|
|
31
40
|
}
|
|
32
41
|
throw Error(`Could not get compressor: Unknown compress format '${format}', please set your compressor function.`);
|
|
33
42
|
}
|
|
34
43
|
export function compress(format, buf, useBase128, compressor) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
44
|
+
if (typeof compressor != 'function')
|
|
45
|
+
compressor = switchCompressor(format);
|
|
46
|
+
const outBuf = compressor(buf);
|
|
47
|
+
if (useBase128)
|
|
48
|
+
return base128.encode(outBuf).toJSTemplateLiterals();
|
|
49
|
+
if (outBuf instanceof Buffer)
|
|
50
|
+
return outBuf.toString('base64');
|
|
51
|
+
if (typeof outBuf.toBase64 == 'function') // Uint8Array Node25
|
|
52
|
+
return outBuf.toBase64();
|
|
53
|
+
return Buffer.from(outBuf).toString('base64');
|
|
39
54
|
}
|
package/dist/getTemplate.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { compressFormat, compressor } from './compress.js';
|
|
2
2
|
export declare const template: {
|
|
3
|
-
base(script: string, format: compressFormat, useBase128: boolean, compressor: compressor): string;
|
|
3
|
+
base(script: string, format: compressFormat, useBase128: boolean, compressor: compressor | undefined): string;
|
|
4
4
|
assets(assetsJSON: string): string;
|
|
5
5
|
css(cssSource: string): string;
|
|
6
6
|
icon(dataURL: string): string;
|
package/package.json
CHANGED