vite-plugin-singlefile-compression 2.0.9 → 2.0.11
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 +3 -2
- package/dist/compress.d.ts +3 -3
- package/dist/compress.js +38 -20
- package/dist/getTemplate.d.ts +1 -1
- package/dist/getTemplate.js +1 -1
- package/dist/getVersion.js +1 -1
- package/dist/index.js +13 -12
- package/dist/options.d.ts +1 -0
- package/dist/options.js +1 -1
- package/package.json +10 -8
package/README.md
CHANGED
|
@@ -95,6 +95,7 @@ export interface Options {
|
|
|
95
95
|
/**
|
|
96
96
|
* Compress format.
|
|
97
97
|
* https://developer.mozilla.org/en-US/docs/Web/API/DecompressionStream/DecompressionStream
|
|
98
|
+
* @type "deflate-raw" | "deflate" | "gzip" | "brotli" | "zstd"
|
|
98
99
|
* @default "deflate-raw"
|
|
99
100
|
*/
|
|
100
101
|
compressFormat?: compressFormat
|
|
@@ -121,7 +122,7 @@ vite v7.3.1 building client environment for production...
|
|
|
121
122
|
✓ 46 modules transformed.
|
|
122
123
|
rendering chunks (1)...
|
|
123
124
|
|
|
124
|
-
vite-plugin-singlefile-compression 2.0.
|
|
125
|
+
vite-plugin-singlefile-compression 2.0.10 building...
|
|
125
126
|
|
|
126
127
|
file:///D:/code/js/vite-plugin-singlefile-compression/test/dist/index.html
|
|
127
128
|
107.149 kB -> 48.323 kB
|
|
@@ -129,7 +130,7 @@ vite-plugin-singlefile-compression 2.0.9 building...
|
|
|
129
130
|
Finish.
|
|
130
131
|
|
|
131
132
|
dist/index.html 48.32 kB
|
|
132
|
-
✓ built in
|
|
133
|
+
✓ built in 829ms
|
|
133
134
|
```
|
|
134
135
|
|
|
135
136
|

|
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,36 +1,54 @@
|
|
|
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
|
-
if (
|
|
21
|
-
const f =
|
|
22
|
-
if (
|
|
23
|
-
|
|
24
|
-
return f;
|
|
25
|
-
}
|
|
26
|
-
const f = compressors[format];
|
|
27
|
-
if (!f)
|
|
29
|
+
if (Object.prototype.hasOwnProperty.call(compressors, format)) {
|
|
30
|
+
const f = compressors[format];
|
|
31
|
+
if (f)
|
|
32
|
+
return f;
|
|
28
33
|
throw Error(`Could not get compressor: Please upgrade node.js or set your compressor function.`);
|
|
29
|
-
|
|
34
|
+
}
|
|
35
|
+
let funcName = format + 'CompressSync';
|
|
36
|
+
if (Object.prototype.hasOwnProperty.call(zlib, funcName)) {
|
|
37
|
+
const f = zlib[funcName];
|
|
38
|
+
if (typeof f == 'function')
|
|
39
|
+
return f;
|
|
40
|
+
}
|
|
41
|
+
throw Error(`Could not get compressor: Unknown compress format '${format}', please set your compressor function.`);
|
|
30
42
|
}
|
|
31
43
|
export function compress(format, buf, useBase128, compressor) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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');
|
|
36
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/dist/getTemplate.js
CHANGED
|
@@ -2,7 +2,7 @@ import fs from 'fs';
|
|
|
2
2
|
import { fileURLToPath } from 'url';
|
|
3
3
|
import { compress } from './compress.js';
|
|
4
4
|
function r(name) {
|
|
5
|
-
return fs.readFileSync(fileURLToPath(
|
|
5
|
+
return fs.readFileSync(fileURLToPath(new URL(`./template/${name}.js`, import.meta.url))).toString();
|
|
6
6
|
}
|
|
7
7
|
function rt(name, template) {
|
|
8
8
|
const s = r(name).split(template);
|
package/dist/getVersion.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
2
|
import { fileURLToPath } from 'url';
|
|
3
|
-
export const
|
|
3
|
+
export const version = JSON.parse(fs.readFileSync(fileURLToPath(new URL("../package.json", import.meta.url))).toString()).version;
|
package/dist/index.js
CHANGED
|
@@ -21,18 +21,19 @@ export function singleFileCompression(opt) {
|
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
23
|
export default singleFileCompression;
|
|
24
|
-
function setConfig(config) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
24
|
+
function setConfig(config, env) {
|
|
25
|
+
config.base ??= './';
|
|
26
|
+
const build = (config.build ??= {});
|
|
27
|
+
build.cssCodeSplit ??= false;
|
|
28
|
+
build.assetsInlineLimit ??= () => true;
|
|
29
|
+
build.chunkSizeWarningLimit ??= Number.MAX_SAFE_INTEGER;
|
|
30
|
+
build.modulePreload ??= { polyfill: false };
|
|
31
|
+
build.reportCompressedSize ??= false;
|
|
32
|
+
const rollupOptions = (this.meta.rolldownVersion
|
|
33
|
+
? (build.rolldownOptions ?? build.rollupOptions ?? (build.rolldownOptions = {}))
|
|
34
|
+
: (build.rollupOptions ??= {}));
|
|
35
|
+
for (const output of [rollupOptions.output ??= {}].flat(1)) {
|
|
36
|
+
output.inlineDynamicImports ??= true;
|
|
36
37
|
}
|
|
37
38
|
}
|
|
38
39
|
async function generateBundle(bundle, config, options) {
|
package/dist/options.d.ts
CHANGED
|
@@ -40,6 +40,7 @@ export interface Options {
|
|
|
40
40
|
/**
|
|
41
41
|
* Compress format.
|
|
42
42
|
* https://developer.mozilla.org/en-US/docs/Web/API/DecompressionStream/DecompressionStream
|
|
43
|
+
* @type "deflate-raw" | "deflate" | "gzip" | "brotli" | "zstd"
|
|
43
44
|
* @default "deflate-raw"
|
|
44
45
|
*/
|
|
45
46
|
compressFormat?: compressFormat;
|
package/dist/options.js
CHANGED
|
@@ -7,7 +7,7 @@ export const defaultHtmlMinifierTerserOptions = {
|
|
|
7
7
|
minifyJS: false,
|
|
8
8
|
};
|
|
9
9
|
export function getInnerOptions(opt) {
|
|
10
|
-
opt
|
|
10
|
+
opt ||= {};
|
|
11
11
|
return {
|
|
12
12
|
rename: opt.rename && opt.rename.replace(/(\.(html?)?)?$/, '.html'),
|
|
13
13
|
htmlMinifierTerser: opt.htmlMinifierTerser == null || opt.htmlMinifierTerser === true
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-singlefile-compression",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.11",
|
|
4
4
|
"author": "bddjr",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Compress all assets and embeds them into dist/index.html, making it convenient to share as a single HTML file.",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
],
|
|
14
14
|
"type": "module",
|
|
15
15
|
"scripts": {
|
|
16
|
-
"build": "rimraf dist && tsc && node build.js && cd test && node --run build",
|
|
16
|
+
"build": "rimraf dist && tsc && node build.js && es-check es2021 --checkFeatures --module dist/**/*.js && cd test && node --run build",
|
|
17
17
|
"prepublishOnly": "node --run build"
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
@@ -43,20 +43,22 @@
|
|
|
43
43
|
"class"
|
|
44
44
|
],
|
|
45
45
|
"dependencies": {
|
|
46
|
+
"@types/html-minifier-terser": ">=7.0.2",
|
|
46
47
|
"base128-ascii": ">=2.1.0",
|
|
47
48
|
"html-minifier-terser": ">=7.2.0",
|
|
48
49
|
"jsdom": ">=26.0.0",
|
|
49
50
|
"mime": ">=4.0.4",
|
|
50
51
|
"mini-svg-data-uri": ">=1.4.4",
|
|
51
|
-
"picocolors": ">=1.1.1"
|
|
52
|
-
"@types/html-minifier-terser": ">=7.0.2"
|
|
52
|
+
"picocolors": ">=1.1.1"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
|
-
"vite": ">=6.2.5",
|
|
56
|
-
"rimraf": ">=6.0.1",
|
|
57
55
|
"@types/jsdom": ">=21.1.7",
|
|
58
56
|
"@types/node": ">=22.10.7",
|
|
57
|
+
"es-check": "^9.5.3",
|
|
59
58
|
"esbuild": ">=0.25.0",
|
|
60
|
-
"
|
|
59
|
+
"rimraf": ">=6.0.1",
|
|
60
|
+
"rollup": ">=4.55.1",
|
|
61
|
+
"typescript": ">=5.7.2",
|
|
62
|
+
"vite": ">=6.2.5"
|
|
61
63
|
}
|
|
62
|
-
}
|
|
64
|
+
}
|