@xiping/vite-version 1.0.66 → 1.0.70

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 +11 -5
  2. package/lib/index.js +27 -1
  3. package/package.json +3 -3
package/README.md CHANGED
@@ -14,9 +14,10 @@ pnpm i @xiping/vite-version
14
14
 
15
15
  ## Features
16
16
 
17
- - Automatically inject version information into your Vite application
17
+ - Automatically generate a version information file after build
18
18
  - Easy integration with your build process
19
- - Customizable version format
19
+ - Includes local build time, UTC build time, and build output size
20
+ - Customizable additional information via `infoText`
20
21
  - TypeScript support
21
22
 
22
23
  ## Usage
@@ -24,11 +25,14 @@ pnpm i @xiping/vite-version
24
25
  ```typescript
25
26
  // vite.config.ts
26
27
  import { defineConfig } from 'vite'
27
- import viteVersion from '@xiping/vite-version'
28
+ import { viteVersionPlugin } from '@xiping/vite-version'
28
29
 
29
30
  export default defineConfig({
30
31
  plugins: [
31
- viteVersion()
32
+ viteVersionPlugin({
33
+ filename: 'version.txt',
34
+ infoText: 'custom info here'
35
+ })
32
36
  ]
33
37
  })
34
38
  ```
@@ -52,7 +56,9 @@ interface ViteVersionOptions {
52
56
  - `infoText`: Additional text content that will be appended to the version file after the build time information.
53
57
 
54
58
  The generated version file will contain:
55
- - Build timestamp in the format "YYYY-MM-DD HH:mm:ss"
59
+ - Build time in local timezone, in the format `"YYYY-MM-DD HH:mm:ss (TimeZone)"`
60
+ - Build time in UTC, in ISO format (e.g. `"2026-03-13T02:25:30.123Z"`)
61
+ - Total build output size of `outDir` in a human-readable format (e.g. `"123.45 KB"`, `"12.34 MB"`), based on the raw file sizes on disk (not gzipped)
56
62
  - Optional additional information specified in `infoText`
57
63
 
58
64
  ## License
package/lib/index.js CHANGED
@@ -14,6 +14,29 @@ function formatDateTime(date) {
14
14
  const seconds = String(date.getSeconds()).padStart(2, "0");
15
15
  return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
16
16
  }
17
+ function getDirectorySize(dir) {
18
+ const entries = fs.readdirSync(dir, { withFileTypes: true });
19
+ return entries.reduce((total, entry) => {
20
+ const fullPath = path.join(dir, entry.name);
21
+ if (entry.isDirectory()) {
22
+ return total + getDirectorySize(fullPath);
23
+ }
24
+ if (entry.isFile()) {
25
+ const stat = fs.statSync(fullPath);
26
+ return total + stat.size;
27
+ }
28
+ return total;
29
+ }, 0);
30
+ }
31
+ function formatBytes(bytes) {
32
+ if (bytes === 0)
33
+ return "0 B";
34
+ const units = ["B", "KB", "MB", "GB", "TB"];
35
+ const k = 1024;
36
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
37
+ const size = bytes / Math.pow(k, i);
38
+ return `${size.toFixed(2)} ${units[i]}`;
39
+ }
17
40
  export function viteVersionPlugin(props) {
18
41
  const defaultOptions = {
19
42
  filename: "version.txt",
@@ -37,7 +60,10 @@ export function viteVersionPlugin(props) {
37
60
  const now = new Date();
38
61
  const timezoneName = Intl.DateTimeFormat().resolvedOptions().timeZone;
39
62
  const buildTime = `${formatDateTime(now)} (${timezoneName})`;
40
- let versionContent = `Build Time: ${buildTime}`;
63
+ const buildTimeUtc = now.toISOString();
64
+ const totalSizeBytes = getDirectorySize(outDir);
65
+ const totalSize = formatBytes(totalSizeBytes);
66
+ let versionContent = `Build Time: ${buildTime}\nBuild Time (UTC): ${buildTimeUtc}\nBuild Size: ${totalSize}`;
41
67
  if (options.infoText) {
42
68
  versionContent += `\n${options.infoText}`;
43
69
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xiping/vite-version",
3
- "version": "1.0.66",
3
+ "version": "1.0.70",
4
4
  "type": "module",
5
5
  "description": "vite-version",
6
6
  "author": "The-End-Hero <527409987@qq.com>",
@@ -25,7 +25,7 @@
25
25
  "bugs": {
26
26
  "url": "https://github.com/The-End-Hero/wang-ping/issues"
27
27
  },
28
- "gitHead": "477bf1fb5b65d5e34b2641eb24068bc064ebb648",
28
+ "gitHead": "61f56a865103626696a6b73c0527c2cb5fc859c1",
29
29
  "publishConfig": {
30
30
  "access": "public",
31
31
  "registry": "https://registry.npmjs.org/"
@@ -33,7 +33,7 @@
33
33
  "devDependencies": {
34
34
  "@types/node": "^24.10.15",
35
35
  "typescript": "^5.9.3",
36
- "vite": "^7.3.1"
36
+ "vite": "^8.0.0"
37
37
  },
38
38
  "peerDependencies": {
39
39
  "vite": ">=3.0.0"