vite-plugin-singlefile-compression 1.2.4 → 1.2.5

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.
Files changed (3) hide show
  1. package/README.md +52 -46
  2. package/dist/index.js +15 -7
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -4,7 +4,7 @@ Compress all assets and embeds them into `dist/index.html`, making it convenient
4
4
 
5
5
  The recipient can open it directly in the browser without manually unzipping the file.
6
6
 
7
- Adapted from [vite-plugin-singlefile](https://www.npmjs.com/package/vite-plugin-singlefile)
7
+ Using [DecompressionStream](https://developer.mozilla.org/docs/Web/API/DecompressionStream) + [base128-ascii](https://www.npmjs.com/package/base128-ascii).
8
8
 
9
9
  ## Setup
10
10
 
@@ -12,13 +12,12 @@ Adapted from [vite-plugin-singlefile](https://www.npmjs.com/package/vite-plugin-
12
12
  npm i vite-plugin-singlefile-compression
13
13
  ```
14
14
 
15
- Then modify [vite.config.ts](test/vite.config.ts#L14)
15
+ Then modify `vite.config.ts`, see [test/vite.config.ts](test/vite.config.ts)
16
16
 
17
17
  ```ts
18
18
  // Import singleFileCompression
19
19
  import singleFileCompression from 'vite-plugin-singlefile-compression'
20
20
 
21
- // https://vite.dev/config/
22
21
  export default defineConfig({
23
22
  plugins: [
24
23
  vue(),
@@ -26,26 +25,31 @@ export default defineConfig({
26
25
  // Add singleFileCompression
27
26
  singleFileCompression(),
28
27
  ],
28
+
29
+ // Not required options:
29
30
  esbuild: {
30
- // Remove license comments
31
+ // Remove license comments, make file smaller.
31
32
  legalComments: "none"
32
33
  },
33
34
  build: {
34
35
  terserOptions: {
35
36
  format: {
36
- // Remove license comments
37
+ // Remove license comments, make file smaller.
37
38
  comments: false
38
39
  }
39
40
  },
41
+ // Not use old syntax, make file smaller.
40
42
  target: 'esnext',
43
+ // Disable reporting compressed chunk sizes, slightly improve build speed.
41
44
  reportCompressedSize: false
42
45
  },
43
46
  ```
44
47
 
45
- Then modify [src/router/index.ts](test/src/router/index.ts#L5) , change `createWebHistory` to `createWebHashHistory`
48
+ Then modify [src/router/index.ts](test/src/router/index.ts#L5)
46
49
 
47
50
  ```ts
48
51
  const router = createRouter({
52
+ // Use Hash History
49
53
  history: createWebHashHistory(),
50
54
  ```
51
55
 
@@ -53,43 +57,43 @@ const router = createRouter({
53
57
 
54
58
  ```ts
55
59
  export interface Options {
56
- /**
57
- * https://github.com/terser/html-minifier-terser?tab=readme-ov-file#options-quick-reference
58
- * @default defaultHtmlMinifierTerserOptions
59
- */
60
- htmlMinifierTerser?: htmlMinifierOptions | boolean;
61
-
62
- /**
63
- * Try inline html used assets, if inlined or not used in JS.
64
- * @default true
65
- */
66
- tryInlineHtmlAssets?: boolean;
67
-
68
- /**
69
- * Remove inlined asset files.
70
- * @default true
71
- */
72
- removeInlinedAssetFiles?: boolean;
73
-
74
- /**
75
- * Try inline html icon, if icon is in public dir.
76
- * @default true
77
- */
78
- tryInlineHtmlPublicIcon?: boolean;
79
-
80
- /**
81
- * Remove inlined html icon files.
82
- * @default true
83
- */
84
- removeInlinedPublicIconFiles?: boolean;
85
-
86
- /**
87
- * Use Base128 to encode gzipped script.
88
- * If false, use Base64.
89
- * https://www.npmjs.com/package/base128-ascii
90
- * @default true
91
- */
92
- useBase128?: boolean
60
+ /**
61
+ * https://github.com/terser/html-minifier-terser?tab=readme-ov-file#options-quick-reference
62
+ * @default defaultHtmlMinifierTerserOptions
63
+ */
64
+ htmlMinifierTerser?: htmlMinifierOptions | boolean;
65
+
66
+ /**
67
+ * Try inline html used assets, if inlined or not used in JS.
68
+ * @default true
69
+ */
70
+ tryInlineHtmlAssets?: boolean;
71
+
72
+ /**
73
+ * Remove inlined asset files.
74
+ * @default true
75
+ */
76
+ removeInlinedAssetFiles?: boolean;
77
+
78
+ /**
79
+ * Try inline html icon, if icon is in public dir.
80
+ * @default true
81
+ */
82
+ tryInlineHtmlPublicIcon?: boolean;
83
+
84
+ /**
85
+ * Remove inlined html icon files.
86
+ * @default true
87
+ */
88
+ removeInlinedPublicIconFiles?: boolean;
89
+
90
+ /**
91
+ * Use Base128 to encode gzipped script.
92
+ * If false, use Base64.
93
+ * https://www.npmjs.com/package/base128-ascii
94
+ * @default true
95
+ */
96
+ useBase128?: boolean;
93
97
  }
94
98
  ```
95
99
 
@@ -98,11 +102,11 @@ export interface Options {
98
102
  https://bddjr.github.io/vite-plugin-singlefile-compression/
99
103
 
100
104
  ```
101
- vite v6.0.6 building for production...
105
+ vite v6.0.7 building for production...
102
106
  ✓ 45 modules transformed.
103
107
  rendering chunks (1)...
104
108
 
105
- vite-plugin-singlefile-compression 1.2.4 building...
109
+ vite-plugin-singlefile-compression 1.2.5 building...
106
110
 
107
111
  file:///D:/bddjr/Desktop/code/js/vite-plugin-singlefile-compression/test/dist/index.html
108
112
  101.02 KiB -> 46.52 KiB
@@ -110,7 +114,7 @@ vite-plugin-singlefile-compression 1.2.4 building...
110
114
  Finish.
111
115
 
112
116
  dist/index.html 47.64 kB
113
- ✓ built in 690ms
117
+ ✓ built in 716ms
114
118
  ```
115
119
 
116
120
  ## Clone
@@ -128,3 +132,5 @@ npm run build
128
132
  ## License
129
133
 
130
134
  [MIT](LICENSE.txt)
135
+
136
+ Adapted from [vite-plugin-singlefile](https://www.npmjs.com/package/vite-plugin-singlefile).
package/dist/index.js CHANGED
@@ -62,16 +62,22 @@ function KiB(size) {
62
62
  }
63
63
  function setConfig(config) {
64
64
  config.base = './';
65
- if (!config.build)
66
- config.build = {};
65
+ config.build ??= {};
67
66
  config.build.assetsInlineLimit = () => true;
68
67
  config.build.chunkSizeWarningLimit = Infinity;
69
68
  config.build.cssCodeSplit = false;
70
69
  config.build.assetsDir = 'assets';
71
70
  config.build.modulePreload = { polyfill: false };
72
- if (!config.build.rollupOptions)
73
- config.build.rollupOptions = {};
74
- config.build.rollupOptions.output = { inlineDynamicImports: true };
71
+ config.build.rollupOptions ??= {};
72
+ config.build.rollupOptions.output ??= {};
73
+ if (Array.isArray(config.build.rollupOptions.output)) {
74
+ for (const output of config.build.rollupOptions.output) {
75
+ output.inlineDynamicImports = true;
76
+ }
77
+ }
78
+ else {
79
+ config.build.rollupOptions.output.inlineDynamicImports = true;
80
+ }
75
81
  }
76
82
  async function generateBundle(bundle, config, options) {
77
83
  console.log(pc.cyan('\n\nvite-plugin-singlefile-compression ' + version) + pc.green(' building...'));
@@ -79,7 +85,7 @@ async function generateBundle(bundle, config, options) {
79
85
  return console.error("error: config.base has been changed!");
80
86
  if (config.build.assetsDir !== 'assets')
81
87
  return console.error("error: config.build.assetsDir has been changed!");
82
- const distURL = (u => u.endsWith('/') ? u : u + '/')(pathToFileURL(path.resolve(config.build.outDir)).href);
88
+ const distURL = pathToFileURL(path.resolve(config.build.outDir)).href + '/';
83
89
  const globalDelete = new Set();
84
90
  const globalDoNotDelete = new Set();
85
91
  const globalRemoveDistFileNames = new Set();
@@ -103,7 +109,9 @@ async function generateBundle(bundle, config, options) {
103
109
  const thisDel = new Set();
104
110
  // Fix async import
105
111
  const newJSCode = ["self.__VITE_PRELOAD__=void 0"];
106
- newJSCode.toString = () => newJSCode.join(';');
112
+ newJSCode.toString = function () {
113
+ return this.join(';');
114
+ };
107
115
  // remove html comments
108
116
  newHtml = newHtml.replaceAll(/<!--[\d\D]*?-->/g, '');
109
117
  // get css tag
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-singlefile-compression",
3
- "version": "1.2.4",
3
+ "version": "1.2.5",
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": "^2.0.1",
45
+ "base128-ascii": "^2.0.2",
46
46
  "esbuild": "^0.24.0",
47
47
  "html-minifier-terser": "^7.2.0",
48
48
  "mime": "^4.0.4",
@@ -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.6"
53
+ "vite": "^6.0.7"
54
54
  }
55
55
  }