vite-plugin-singlefile-compression 1.2.0 → 1.2.2

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 CHANGED
@@ -101,15 +101,15 @@ vite v6.0.6 building for production...
101
101
  ✓ 45 modules transformed.
102
102
  rendering chunks (1)...
103
103
 
104
- vite-plugin-singlefile-compression 1.2.0 building...
104
+ vite-plugin-singlefile-compression 1.2.2 building...
105
105
 
106
106
  file:///D:/bddjr/Desktop/code/js/vite-plugin-singlefile-compression/test/dist/index.html
107
- 101.02 KiB -> 46.81 KiB
107
+ 101.02 KiB -> 46.54 KiB
108
108
 
109
109
  Finish.
110
110
 
111
- dist/index.html 47.93 kB
112
- ✓ built in 687ms
111
+ dist/index.html 47.65 kB
112
+ ✓ built in 694ms
113
113
  ```
114
114
 
115
115
  ## Clone
package/dist/index.js CHANGED
@@ -21,21 +21,11 @@ export function singleFileCompression(opt) {
21
21
  htmlMinifierTerser: opt.htmlMinifierTerser == null || opt.htmlMinifierTerser === true
22
22
  ? defaultHtmlMinifierTerserOptions
23
23
  : opt.htmlMinifierTerser,
24
- tryInlineHtmlAssets: opt.tryInlineHtmlAssets == null
25
- ? true
26
- : opt.tryInlineHtmlAssets,
27
- removeInlinedAssetFiles: opt.removeInlinedAssetFiles == null
28
- ? true
29
- : opt.removeInlinedAssetFiles,
30
- tryInlineHtmlPublicIcon: opt.tryInlineHtmlPublicIcon == null
31
- ? true
32
- : opt.tryInlineHtmlPublicIcon,
33
- removeInlinedPublicIconFiles: opt.removeInlinedPublicIconFiles == null
34
- ? true
35
- : opt.removeInlinedPublicIconFiles,
36
- useBase128: opt.useBase128 == null
37
- ? true
38
- : opt.useBase128,
24
+ tryInlineHtmlAssets: opt.tryInlineHtmlAssets ?? true,
25
+ removeInlinedAssetFiles: opt.removeInlinedAssetFiles ?? true,
26
+ tryInlineHtmlPublicIcon: opt.tryInlineHtmlPublicIcon ?? true,
27
+ removeInlinedPublicIconFiles: opt.removeInlinedPublicIconFiles ?? true,
28
+ useBase128: opt.useBase128 ?? true,
39
29
  };
40
30
  let conf;
41
31
  return {
@@ -56,15 +46,16 @@ function bufferToDataURL(name, b) {
56
46
  ? svgToTinyDataUri(b.toString())
57
47
  : `data:${mime.getType(name)};base64,${b.toString('base64')}`;
58
48
  }
59
- function gzipToBase64(buf) {
49
+ function gzip(buf) {
60
50
  return zlib.gzipSync(buf, {
61
51
  level: zlib.constants.Z_BEST_COMPRESSION,
62
- }).toString('base64');
52
+ });
53
+ }
54
+ function gzipToBase64(buf) {
55
+ return gzip(buf).toString('base64');
63
56
  }
64
57
  function gzipToBase128(buf) {
65
- return base128.encodeToTemplateLiterals(Uint8Array.from(zlib.gzipSync(buf, {
66
- level: zlib.constants.Z_BEST_COMPRESSION,
67
- })));
58
+ return base128.encode(Uint8Array.from(gzip(buf))).toJSTemplateLiterals();
68
59
  }
69
60
  function KiB(size) {
70
61
  return `${Math.ceil(size / 10.24) / 100} KiB`;
@@ -1 +1 @@
1
- function l(o){let n=new TextEncoder().encode(o),t=new Uint8Array(Math.ceil((n.length-1)/8)*7);for(let r=1,i=0;r<n.length;){let e=BigInt(n[r++]||0)<<49n;e|=BigInt(n[r++]||0)<<42n,e|=BigInt(n[r++]||0)<<35n,e|=BigInt(n[r++]||0)<<28n,e|=BigInt(n[r++]||0)<<21n,e|=BigInt(n[r++]||0)<<14n,e|=BigInt(n[r++]||0)<<7n,e|=BigInt(n[r++]||0),t[i++]=Number(e>>48n),t[i++]=Number(e>>40n&255n),t[i++]=Number(e>>32n&255n),t[i++]=Number(e>>24n&255n),t[i++]=Number(e>>16n&255n),t[i++]=Number(e>>8n&255n),t[i++]=Number(e&255n)}let c=n[0]-48;return c?t.slice(0,c-7):t}new Response(new ReadableStream({start(o){o.enqueue(l("<script>")),o.close()}}).pipeThrough(new DecompressionStream("gzip")),{headers:{"Content-Type":"text/javascript"}}).blob().then(o=>import(o=URL.createObjectURL(o)).finally(()=>URL.revokeObjectURL(o)))
1
+ function c(e){let l=0,o=0,n,r=new Uint8Array(Math.floor(e.length/8*7));function t(){return n=e.charCodeAt(l++)||0}for(;l<e.length;)r[o++]=t()<<1|t()>>6,r[o++]=n<<2|t()>>5,r[o++]=n<<3|t()>>4,r[o++]=n<<4|t()>>3,r[o++]=n<<5|t()>>2,r[o++]=n<<6|t()>>1,r[o++]=n<<7|t();return r}new Response(new ReadableStream({start(e){e.enqueue(c("<script>")),e.close()}}).pipeThrough(new DecompressionStream("gzip")),{headers:{"Content-Type":"text/javascript"}}).blob().then(e=>import(e=URL.createObjectURL(e)).finally(()=>URL.revokeObjectURL(e)))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-singlefile-compression",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
6
6
  "files": [
@@ -42,7 +42,7 @@
42
42
  "dependencies": {
43
43
  "@types/html-minifier-terser": "^7.0.2",
44
44
  "@types/node": "^22.9.3",
45
- "base128-ascii": "^0.0.1",
45
+ "base128-ascii": "^2.0.0",
46
46
  "esbuild": "^0.24.0",
47
47
  "html-minifier-terser": "^7.2.0",
48
48
  "mime": "^4.0.4",