vite-plugin-singlefile-compression 2.2.3 → 2.3.0
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 +6 -6
- package/dist/index.d.ts +1 -1
- package/dist/index.js +9 -10
- package/package.json +22 -15
package/README.md
CHANGED
|
@@ -142,7 +142,7 @@ type: `boolean`
|
|
|
142
142
|
|
|
143
143
|
Use import.meta polyfill.
|
|
144
144
|
|
|
145
|
-
default: `
|
|
145
|
+
default: `false`
|
|
146
146
|
|
|
147
147
|
type: `boolean`
|
|
148
148
|
|
|
@@ -152,21 +152,21 @@ type: `boolean`
|
|
|
152
152
|
Preview: https://bddjr.github.io/vite-plugin-singlefile-compression/
|
|
153
153
|
|
|
154
154
|
```
|
|
155
|
-
vite v8.0.
|
|
155
|
+
vite v8.0.8 building client environment for production...
|
|
156
156
|
✓ 42 modules transformed.
|
|
157
157
|
rendering chunks (1)...
|
|
158
158
|
|
|
159
|
-
vite-plugin-singlefile-compression 2.
|
|
159
|
+
vite-plugin-singlefile-compression 2.3.0 deflate-raw base128-ascii
|
|
160
160
|
|
|
161
161
|
file:///D:/code/js/vite-plugin-singlefile-compression/test/dist/index.html
|
|
162
|
-
122.
|
|
162
|
+
122.767 kB -> 50.111 kB
|
|
163
163
|
|
|
164
164
|
Finish.
|
|
165
165
|
|
|
166
166
|
computing gzip size...
|
|
167
|
-
dist/index.html 50.
|
|
167
|
+
dist/index.html 50.11 kB │ gzip: 43.67 kB
|
|
168
168
|
|
|
169
|
-
✓ built in
|
|
169
|
+
✓ built in 313ms
|
|
170
170
|
```
|
|
171
171
|
|
|
172
172
|
## Clone
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -7,9 +7,9 @@ import { pathToFileURL } from "url";
|
|
|
7
7
|
import base128 from "base128-ascii";
|
|
8
8
|
import zlib from "zlib";
|
|
9
9
|
import svgToTinyDataUri from "mini-svg-data-uri";
|
|
10
|
-
import
|
|
10
|
+
import { lookup } from "mrmime";
|
|
11
11
|
//#region package.json
|
|
12
|
-
var version = "2.
|
|
12
|
+
var version = "2.3.0";
|
|
13
13
|
//#endregion
|
|
14
14
|
//#region src/compress.ts
|
|
15
15
|
const compressors = {
|
|
@@ -68,14 +68,14 @@ async function compress(format, buf, useBase128, compressor) {
|
|
|
68
68
|
const files = {
|
|
69
69
|
"assets": ["{let e=", ";for(let l in e)for(let r of document.querySelectorAll(`[src=\"data:${l}\"]`))r.src=e[l]}"],
|
|
70
70
|
"base128": [
|
|
71
|
-
"for(var e,
|
|
72
|
-
",
|
|
73
|
-
"))
|
|
71
|
+
"for(var e,n=",
|
|
72
|
+
",t=n.length,r=new Uint8Array(t/8*7),o=0,d=0,p=t=>(e=n.charCodeAt(o++))>127?e=0:e,_=Response,a=document.createElement(\"script\");o<t;)r[d++]=p()<<1|p()>>6,r[d++]=e<<2|p()>>5,r[d++]=e<<3|p()>>4,r[d++]=e<<4|p()>>3,r[d++]=e<<5|p()>>2,r[d++]=e<<6|p()>>1,r[d++]=e<<7|p();new _(new _(r).body.pipeThrough(new DecompressionStream(",
|
|
73
|
+
"))).text().then(e=>{a.type=\"module\",a.innerHTML=e,document.head.appendChild(a)})"
|
|
74
74
|
],
|
|
75
75
|
"base64": [
|
|
76
76
|
"fetch(\"data:;base64,",
|
|
77
77
|
"\").then(e=>new Response(e.body.pipeThrough(new DecompressionStream(",
|
|
78
|
-
"))
|
|
78
|
+
"))).text()).then(e=>{var t=document.createElement(\"script\");t.type=\"module\",t.innerHTML=e,document.head.appendChild(t)})"
|
|
79
79
|
],
|
|
80
80
|
"css": "document.head.appendChild(document.createElement(\"style\")).innerHTML=",
|
|
81
81
|
"icon": "document.querySelector(\"link[rel=icon]\").href=",
|
|
@@ -107,7 +107,7 @@ const template = {
|
|
|
107
107
|
//#endregion
|
|
108
108
|
//#region src/dataurl.ts
|
|
109
109
|
function bufferToDataURL(name, b) {
|
|
110
|
-
return /\.svg$/i.test(name) ? svgToTinyDataUri(b.toString()) : `data:${
|
|
110
|
+
return /\.svg$/i.test(name) ? svgToTinyDataUri(b.toString()) : `data:${lookup(name)};base64,${b.toString("base64")}`;
|
|
111
111
|
}
|
|
112
112
|
//#endregion
|
|
113
113
|
//#region src/kB.ts
|
|
@@ -138,7 +138,7 @@ function getInnerOptions(opt) {
|
|
|
138
138
|
removeInlinedAssetFiles: opt.removeInlinedAssetFiles ?? true,
|
|
139
139
|
tryInlineHtmlPublicIcon: opt.tryInlineHtmlPublicIcon ?? true,
|
|
140
140
|
removeInlinedPublicIconFiles: opt.removeInlinedPublicIconFiles ?? true,
|
|
141
|
-
useImportMetaPolyfill: opt.useImportMetaPolyfill ??
|
|
141
|
+
useImportMetaPolyfill: opt.useImportMetaPolyfill ?? false
|
|
142
142
|
};
|
|
143
143
|
}
|
|
144
144
|
//#endregion
|
|
@@ -307,9 +307,8 @@ async function generateBundle(bundle, config, options) {
|
|
|
307
307
|
else newJSCode.push("var __VITE_PRELOAD__");
|
|
308
308
|
newJSCode.push(code);
|
|
309
309
|
} else inlineHtmlAssets();
|
|
310
|
-
let outputScript = newJSCode.join(";");
|
|
310
|
+
let outputScript = newJSCode.join(";").replaceAll("<\/script", "<\\/script");
|
|
311
311
|
if (options.enableCompress) outputScript = await template.base(outputScript, options.compressFormat, options.useBase128, options.compressor);
|
|
312
|
-
else outputScript = outputScript.replaceAll("<\/script", "<\\/script");
|
|
313
312
|
htmlChunk.source = htmlChunk.source.replace(fakeScript, () => outputScript);
|
|
314
313
|
console.log(" " + pc.gray(kB(oldSize) + " -> ") + pc.cyanBright(kB(Buffer.byteLength(htmlChunk.source))) + "\n");
|
|
315
314
|
for (const name of thisDel) globalDelete.add(name);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-plugin-singlefile-compression",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
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.",
|
|
@@ -78,24 +78,31 @@
|
|
|
78
78
|
"vite-plugin-compression2",
|
|
79
79
|
"html-minifier-terser"
|
|
80
80
|
],
|
|
81
|
+
"peerDependencies": {
|
|
82
|
+
"@types/node": "*",
|
|
83
|
+
"vite": ">=3.0.0"
|
|
84
|
+
},
|
|
85
|
+
"peerDependenciesMeta": {
|
|
86
|
+
"@types/node": {
|
|
87
|
+
"optional": true
|
|
88
|
+
}
|
|
89
|
+
},
|
|
81
90
|
"dependencies": {
|
|
82
91
|
"@types/html-minifier-terser": ">=7.0.2",
|
|
83
|
-
"
|
|
84
|
-
"base128-ascii": ">=2.1.11",
|
|
92
|
+
"base128-ascii": "^2.1.12",
|
|
85
93
|
"html-minifier-terser": ">=7.2.0",
|
|
86
|
-
"jsdom": ">=
|
|
87
|
-
"mime": ">=4.1.0",
|
|
94
|
+
"jsdom": ">=29.0.2",
|
|
88
95
|
"mini-svg-data-uri": ">=1.4.4",
|
|
89
|
-
"
|
|
90
|
-
"
|
|
96
|
+
"mrmime": ">=2.0.1",
|
|
97
|
+
"picocolors": ">=1.1.1"
|
|
91
98
|
},
|
|
92
99
|
"devDependencies": {
|
|
93
|
-
"@types/jsdom": ">=28.0.
|
|
94
|
-
"@types/node": "^22.19.
|
|
95
|
-
"rolldown": ">=1.0.0-rc.
|
|
96
|
-
"rolldown-plugin-dts": "
|
|
97
|
-
"terser": "
|
|
98
|
-
"typescript": ">=
|
|
99
|
-
"vite": ">=8.0.
|
|
100
|
+
"@types/jsdom": ">=28.0.1",
|
|
101
|
+
"@types/node": "^22.19.17",
|
|
102
|
+
"rolldown": ">=1.0.0-rc.15",
|
|
103
|
+
"rolldown-plugin-dts": ">=0.22.5",
|
|
104
|
+
"terser": ">=5.46.1",
|
|
105
|
+
"typescript": ">=6.0.2",
|
|
106
|
+
"vite": ">=8.0.8"
|
|
100
107
|
}
|
|
101
|
-
}
|
|
108
|
+
}
|