vite-plugin-singlefile-compression 1.3.4 → 1.4.1

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
@@ -37,53 +37,66 @@ const router = createRouter({
37
37
 
38
38
  ## Options
39
39
 
40
- See [src/options.ts](src/options.ts)
40
+ Example:
41
+
42
+ ```ts
43
+ singleFileCompression({
44
+ rename: 'example.html'
45
+ }),
46
+ ```
47
+
48
+ More info see [src/options.ts](src/options.ts)
41
49
 
42
50
  ```ts
43
51
  export interface Options {
44
- /**
45
- * https://github.com/terser/html-minifier-terser?tab=readme-ov-file#options-quick-reference
46
- * @default defaultHtmlMinifierTerserOptions
47
- */
48
- htmlMinifierTerser?: htmlMinifierOptions | boolean
49
-
50
- /**
51
- * Try inline html used assets, if inlined or not used in JS.
52
- * @default true
53
- */
54
- tryInlineHtmlAssets?: boolean
55
-
56
- /**
57
- * Remove inlined asset files.
58
- * @default true
59
- */
60
- removeInlinedAssetFiles?: boolean
61
-
62
- /**
63
- * Try inline html icon, if icon is in public dir.
64
- * @default true
65
- */
66
- tryInlineHtmlPublicIcon?: boolean
67
-
68
- /**
69
- * Remove inlined html icon files.
70
- * @default true
71
- */
72
- removeInlinedPublicIconFiles?: boolean
73
-
74
- /**
75
- * Use Base128 to encode gzipped script.
76
- * If false, use Base64.
77
- * https://www.npmjs.com/package/base128-ascii
78
- * @default true
79
- */
80
- useBase128?: boolean
81
-
82
- /**
83
- * Compress format.
84
- * @default "deflate-raw"
85
- */
86
- compressFormat?: compressFormat
52
+ /**
53
+ * Rename index.html
54
+ */
55
+ rename?: string;
56
+
57
+ /**
58
+ * https://github.com/terser/html-minifier-terser?tab=readme-ov-file#options-quick-reference
59
+ * @default defaultHtmlMinifierTerserOptions
60
+ */
61
+ htmlMinifierTerser?: htmlMinifierOptions | boolean;
62
+
63
+ /**
64
+ * Try inline html used assets, if inlined or not used in JS.
65
+ * @default true
66
+ */
67
+ tryInlineHtmlAssets?: boolean;
68
+
69
+ /**
70
+ * Remove inlined asset files.
71
+ * @default true
72
+ */
73
+ removeInlinedAssetFiles?: boolean;
74
+
75
+ /**
76
+ * Try inline html icon, if icon is in public dir.
77
+ * @default true
78
+ */
79
+ tryInlineHtmlPublicIcon?: boolean;
80
+
81
+ /**
82
+ * Remove inlined html icon files.
83
+ * @default true
84
+ */
85
+ removeInlinedPublicIconFiles?: boolean;
86
+
87
+ /**
88
+ * Use Base128 to encode gzipped script.
89
+ * If false, use Base64.
90
+ * https://www.npmjs.com/package/base128-ascii
91
+ * @default true
92
+ */
93
+ useBase128?: boolean;
94
+
95
+ /**
96
+ * Compress format.
97
+ * @default "deflate-raw"
98
+ */
99
+ compressFormat?: compressFormat;
87
100
  }
88
101
  ```
89
102
 
@@ -92,11 +105,11 @@ export interface Options {
92
105
  https://bddjr.github.io/vite-plugin-singlefile-compression/
93
106
 
94
107
  ```
95
- vite v6.0.7 building for production...
108
+ vite v6.0.11 building for production...
96
109
  ✓ 45 modules transformed.
97
110
  rendering chunks (1)...
98
111
 
99
- vite-plugin-singlefile-compression 1.3.4 building...
112
+ vite-plugin-singlefile-compression 1.4.1 building...
100
113
 
101
114
  file:///D:/bddjr/Desktop/code/js/vite-plugin-singlefile-compression/test/dist/index.html
102
115
  101.56 KiB -> 46.32 KiB
@@ -104,7 +117,7 @@ vite-plugin-singlefile-compression 1.3.4 building...
104
117
  Finish.
105
118
 
106
119
  dist/index.html 47.42 kB
107
- ✓ built in 696ms
120
+ ✓ built in 680ms
108
121
  ```
109
122
 
110
123
  ![](effect.jpg)
package/dist/index.js CHANGED
@@ -48,7 +48,16 @@ function setConfig(config) {
48
48
  }
49
49
  }
50
50
  async function generateBundle(bundle, config, options) {
51
- console.log(pc.cyan('\n\nvite-plugin-singlefile-compression ' + version) + pc.green(' building...'));
51
+ console.log(pc.reset('\n\n') + pc.cyan('vite-plugin-singlefile-compression ' + version) + pc.green(' building...'));
52
+ // rename
53
+ if (options.rename
54
+ && options.rename !== "index.html"
55
+ && ("index.html" in bundle)
56
+ && !(options.rename in bundle)) {
57
+ bundle[options.rename] = bundle["index.html"];
58
+ bundle[options.rename].fileName = options.rename;
59
+ delete bundle["index.html"];
60
+ }
52
61
  const distURL = pathToFileURL(config.build.outDir).href + '/';
53
62
  const globalDelete = new Set();
54
63
  const globalDoNotDelete = new Set();
@@ -206,7 +215,7 @@ async function generateBundle(bundle, config, options) {
206
215
  // finish
207
216
  htmlChunk.source = newHtml;
208
217
  console.log("\n"
209
- + " " + pc.underline(pc.cyan(distURL) + pc.greenBright(htmlFileName)) + '\n'
218
+ + " " + pc.underline(pc.cyan(distURL) + pc.greenBright(bundle[htmlFileName].fileName)) + '\n'
210
219
  + " " + pc.gray(KiB(oldSize) + " -> ") + pc.cyanBright(KiB(newHtml.length)) + '\n');
211
220
  // delete assets
212
221
  for (const name of thisDel) {
package/dist/options.d.ts CHANGED
@@ -1,6 +1,10 @@
1
1
  import { Options as htmlMinifierOptions } from 'html-minifier-terser';
2
2
  import { compressFormat } from './compress.js';
3
3
  export interface Options {
4
+ /**
5
+ * Rename index.html
6
+ */
7
+ rename?: string;
4
8
  /**
5
9
  * https://github.com/terser/html-minifier-terser?tab=readme-ov-file#options-quick-reference
6
10
  * @default defaultHtmlMinifierTerserOptions
@@ -41,6 +45,7 @@ export interface Options {
41
45
  }
42
46
  export declare const defaultHtmlMinifierTerserOptions: htmlMinifierOptions;
43
47
  export interface innerOptions {
48
+ rename?: string;
44
49
  htmlMinifierTerser: htmlMinifierOptions | false;
45
50
  tryInlineHtmlAssets: boolean;
46
51
  removeInlinedAssetFiles: boolean;
package/dist/options.js CHANGED
@@ -9,6 +9,7 @@ export const defaultHtmlMinifierTerserOptions = {
9
9
  export function getInnerOptions(opt) {
10
10
  opt ||= {};
11
11
  return {
12
+ rename: opt.rename && opt.rename.replace(/(\.(html?)?)?$/, '.html'),
12
13
  htmlMinifierTerser: opt.htmlMinifierTerser == null || opt.htmlMinifierTerser === true
13
14
  ? defaultHtmlMinifierTerserOptions
14
15
  : opt.htmlMinifierTerser,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-singlefile-compression",
3
- "version": "1.3.4",
3
+ "version": "1.4.1",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
6
6
  "files": [
@@ -41,7 +41,7 @@
41
41
  ],
42
42
  "dependencies": {
43
43
  "@types/html-minifier-terser": "^7.0.2",
44
- "@types/node": "^22.9.3",
44
+ "@types/node": "^22.10.7",
45
45
  "base128-ascii": "^2.1.0",
46
46
  "esbuild": "^0.24.0",
47
47
  "html-minifier-terser": "^7.2.0",
@@ -50,6 +50,6 @@
50
50
  "picocolors": "^1.1.1",
51
51
  "rimraf": "^6.0.1",
52
52
  "typescript": "^5.7.2",
53
- "vite": "^6.0.7"
53
+ "vite": "^6.0.11"
54
54
  }
55
55
  }