vite-plugin-singlefile-compression 2.0.8 → 2.0.10
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 +11 -4
- package/dist/compress.js +11 -8
- package/dist/getTemplate.js +1 -1
- package/dist/getVersion.js +1 -1
- package/dist/index.js +15 -13
- package/dist/options.d.ts +7 -0
- package/dist/options.js +2 -1
- package/dist/template/importmeta.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
|
|
@@ -103,6 +104,12 @@ export interface Options {
|
|
|
103
104
|
* Custom compressor.
|
|
104
105
|
*/
|
|
105
106
|
compressor?: compressor
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Use import.meta polyfill.
|
|
110
|
+
* @default true
|
|
111
|
+
*/
|
|
112
|
+
useImportMetaPolyfill?: boolean
|
|
106
113
|
}
|
|
107
114
|
```
|
|
108
115
|
|
|
@@ -115,15 +122,15 @@ vite v7.3.1 building client environment for production...
|
|
|
115
122
|
✓ 46 modules transformed.
|
|
116
123
|
rendering chunks (1)...
|
|
117
124
|
|
|
118
|
-
vite-plugin-singlefile-compression 2.0.
|
|
125
|
+
vite-plugin-singlefile-compression 2.0.10 building...
|
|
119
126
|
|
|
120
127
|
file:///D:/code/js/vite-plugin-singlefile-compression/test/dist/index.html
|
|
121
|
-
107.
|
|
128
|
+
107.149 kB -> 48.323 kB
|
|
122
129
|
|
|
123
130
|
Finish.
|
|
124
131
|
|
|
125
|
-
dist/index.html 48.
|
|
126
|
-
✓ built in
|
|
132
|
+
dist/index.html 48.32 kB
|
|
133
|
+
✓ built in 829ms
|
|
127
134
|
```
|
|
128
135
|
|
|
129
136
|

|
package/dist/compress.js
CHANGED
|
@@ -17,16 +17,19 @@ const compressors = {
|
|
|
17
17
|
zstd: zlib.zstdCompressSync,
|
|
18
18
|
};
|
|
19
19
|
function switchCompressor(format) {
|
|
20
|
-
if (
|
|
20
|
+
if (Object.prototype.hasOwnProperty.call(compressors, format)) {
|
|
21
|
+
const f = compressors[format];
|
|
22
|
+
if (f)
|
|
23
|
+
return f;
|
|
24
|
+
throw Error(`Could not get compressor: Please upgrade node.js or set your compressor function.`);
|
|
25
|
+
}
|
|
26
|
+
let funcName = format + 'CompressSync';
|
|
27
|
+
if (Object.prototype.hasOwnProperty.call(zlib, funcName)) {
|
|
21
28
|
const f = zlib[format + 'CompressSync'];
|
|
22
|
-
if (
|
|
23
|
-
|
|
24
|
-
return f;
|
|
29
|
+
if (typeof f == 'function')
|
|
30
|
+
return f;
|
|
25
31
|
}
|
|
26
|
-
|
|
27
|
-
if (!f)
|
|
28
|
-
throw Error(`Could not get compressor: Please upgrade node.js or set your compressor function.`);
|
|
29
|
-
return f;
|
|
32
|
+
throw Error(`Could not get compressor: Unknown compress format '${format}', please set your compressor function.`);
|
|
30
33
|
}
|
|
31
34
|
export function compress(format, buf, useBase128, compressor) {
|
|
32
35
|
const outBuf = compressor ? compressor(buf) : switchCompressor(format)(buf);
|
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) {
|
|
@@ -202,7 +203,8 @@ async function generateBundle(bundle, config, options) {
|
|
|
202
203
|
}
|
|
203
204
|
}
|
|
204
205
|
inlineHtmlAssets();
|
|
205
|
-
|
|
206
|
+
if (options.useImportMetaPolyfill)
|
|
207
|
+
newJSCode.push(template.importmeta(scriptName));
|
|
206
208
|
// 此 polyfill 仅在以下选项的值为 true 时需要。
|
|
207
209
|
// config.build.rollupOptions.output.inlineDynamicImports
|
|
208
210
|
if (code.includes("__VITE_PRELOAD__"))
|
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;
|
|
@@ -47,6 +48,11 @@ export interface Options {
|
|
|
47
48
|
* Custom compressor.
|
|
48
49
|
*/
|
|
49
50
|
compressor?: compressor;
|
|
51
|
+
/**
|
|
52
|
+
* Use import.meta polyfill.
|
|
53
|
+
* @default true
|
|
54
|
+
*/
|
|
55
|
+
useImportMetaPolyfill?: boolean;
|
|
50
56
|
}
|
|
51
57
|
export declare const defaultHtmlMinifierTerserOptions: htmlMinifierOptions;
|
|
52
58
|
export interface innerOptions {
|
|
@@ -59,5 +65,6 @@ export interface innerOptions {
|
|
|
59
65
|
useBase128: boolean;
|
|
60
66
|
compressFormat: compressFormat;
|
|
61
67
|
compressor?: compressor;
|
|
68
|
+
useImportMetaPolyfill: boolean;
|
|
62
69
|
}
|
|
63
70
|
export declare function getInnerOptions(opt?: Options): innerOptions;
|
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
|
|
@@ -20,5 +20,6 @@ export function getInnerOptions(opt) {
|
|
|
20
20
|
useBase128: opt.useBase128 ?? true,
|
|
21
21
|
compressFormat: opt.compressFormat || "deflate-raw",
|
|
22
22
|
compressor: typeof opt.compressor == 'function' ? opt.compressor : undefined,
|
|
23
|
+
useImportMetaPolyfill: opt.useImportMetaPolyfill ?? true,
|
|
23
24
|
};
|
|
24
25
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{import.meta.url=new URL("<path>",location).href;
|
|
1
|
+
{let e=import.meta,r=e.resolve,l=e.url=new URL("<path>",location).href;e.resolve=function(t){return/^\.{0,2}\//.test(t)?new URL(t,l).href:r.apply(this,arguments)}}
|
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.10",
|
|
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
|
+
}
|