unplugin-version-injector 1.1.2-beta.3 → 2.0.0-beta.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
@@ -1,134 +1,158 @@
1
- ### **🚀 `unplugin-version-injector` - Auto Inject Version & Build Time**
1
+ # 🚀 `unplugin-version-injector` Auto Inject Version & Build Time
2
2
 
3
- [🇨🇳 中文 README](./README.zh-CN.md) | [🇬🇧 English README](./README.md)
3
+ [🇨🇳 中文文档](./README.zh-CN.md) | [🇺🇸 English README](./README.md)
4
4
 
5
5
  ---
6
6
 
7
- ## **📌 Introduction**
8
- `unplugin-version-injector` is a powerful and lightweight plugin that automatically injects the **version number** and **build timestamp** into all HTML files. It supports **Webpack 4/5, Vite, and Rollup**, making it ideal for both **Single Page Applications (SPA)** and **Multi-Page Applications (MPA)**.
7
+ ## 📌 Introduction
9
8
 
10
- ### **✨ Features**
11
- ✅ **Auto-injects** `<meta name="version">` into all HTML `<head>` sections
12
- **Auto-injects a `<script>`** that logs `version` & `build time` in the browser console
13
- ✅ **Supports Webpack 4 & 5, Vite, and Rollup**
14
- **Works in Multi-Page Applications (MPA)**
15
- **Highly configurable**: Supports manually specifying the version or using `package.json`
9
+ **`unplugin-version-injector`** is a lightweight plugin that automatically injects **version number** and **build timestamp** into all your HTML files.
10
+
11
+ ### Features
12
+
13
+ - Auto-injects `<meta name="version">` into `<head>`
14
+ - Auto-injects `<script>` for version & build log
15
+ - ✅ Supports **Vite**, **Webpack 4/5**, and **Rollup**
16
+ - ✅ Works with **SPA / MPA**
17
+ - ✅ Fully configurable and tree-shakable
16
18
 
17
19
  ---
18
20
 
19
- ## **📦 Installation**
20
- ```sh
21
- # Using Yarn
22
- yarn add -D unplugin-version-injector
21
+ ## 📦 Installation
23
22
 
24
- # Using npm
23
+ ```bash
24
+ # npm
25
25
  npm install -D unplugin-version-injector
26
+
27
+ # yarn
28
+ yarn add -D unplugin-version-injector
29
+
30
+ # pnpm
31
+ pnpm add -D unplugin-version-injector
26
32
  ```
27
33
 
28
34
  ---
29
35
 
30
- ## **🚀 Usage**
36
+ ## 🚀 Usage
31
37
 
32
- ### **📌 Webpack 4/5**
33
- Modify your `webpack.config.js`:
34
- ```js
35
- const versionInjectorPlugin = require('unplugin-version-injector');
38
+ ### Vite
36
39
 
37
- module.exports = {
38
- plugins: [
39
- versionInjectorPlugin.webpack({
40
- version: '1.2.3', // (Optional) Manually specify version
41
- })
42
- ],
43
- };
40
+ ```ts
41
+ // vite.config.ts
42
+ import versionInjector from 'unplugin-version-injector/vite'
43
+
44
+ export default {
45
+ plugins: [versionInjector()],
46
+ }
44
47
  ```
45
48
 
46
49
  ---
47
50
 
48
- ### **📌 Vite**
49
- Modify your `vite.config.js`:
51
+ ### Webpack (4 or 5)
52
+
50
53
  ```js
51
- import versionInjectorPlugin from 'unplugin-version-injector';
54
+ // webpack.config.js
55
+ const versionInjector = require('unplugin-version-injector/webpack')
52
56
 
53
- export default {
54
- plugins: [versionInjectorPlugin.vite()]
55
- };
57
+ module.exports = {
58
+ plugins: [
59
+ versionInjector({
60
+ version: '1.2.3', // Optional custom version
61
+ }),
62
+ ],
63
+ }
56
64
  ```
57
65
 
58
66
  ---
59
67
 
60
- ### **📌 Rollup**
61
- Modify your `rollup.config.js`:
68
+ ### Rollup
69
+
62
70
  ```js
63
- import versionInjectorPlugin from 'unplugin-version-injector';
71
+ // rollup.config.js
72
+ import versionInjector from 'unplugin-version-injector/rollup'
64
73
 
65
74
  export default {
66
- plugins: [versionInjectorPlugin.rollup()]
67
- };
75
+ plugins: [versionInjector()],
76
+ }
68
77
  ```
69
78
 
70
79
  ---
71
80
 
72
- ## **📜 Example Output**
73
- After building, all HTML files will include the following:
81
+ ## 📜 Output Example
82
+
83
+ ### Injected into HTML
84
+
74
85
  ```html
75
86
  <head>
76
87
  <meta name="version" content="1.2.3">
77
- <meta charset="UTF-8">
78
- <title>My App</title>
79
88
  </head>
80
89
  <body>
81
- <h1>Hello World</h1>
82
- <script>
83
- console.log("%c Version: 1.2.3 ", "background: #222; color: #00ff00; font-size: 12px; padding: 4px; border-radius: 4px;");
84
- console.log("%c Build Time: 2024-03-01T12:00:00.000Z ", "background: #222; color: #ffcc00; font-size: 12px; padding: 4px; border-radius: 4px;");
90
+ ...
91
+ <script data-injected="unplugin-version-injector">
92
+ console.log("%c Version: 1.2.3 ", "background:#222; color:#00ff00;");
93
+ console.log("%c Build Time: 2024-03-01T12:00:00Z ", "background:#222; color:#ffcc00;");
85
94
  </script>
86
95
  </body>
87
96
  ```
88
97
 
89
- ✅ **Console Output (Colored Logs)**
90
- ```
91
- 🟢 Version: 1.2.3 (Green)
92
- 🟡 Build Time: 2024-03-01T12:00:00.000Z (Yellow)
98
+ ---
99
+
100
+ ## 🔧 Options
101
+
102
+ | Option | Type | Description | Default |
103
+ |--------------|-----------|------------------------------------------|--------------------------|
104
+ | `version` | `string` | Custom version string | From `package.json` |
105
+ | `log` | `boolean` | Whether to inject `<script>` console log | `true` |
106
+ | `dateFormat` | `string` | Use `dayjs` format string (if installed) | ISO timestamp string |
107
+ | `formatDate` | `fn` | Custom function for formatting date | `date.toISOString()` |
108
+
109
+ ```ts
110
+ versionInjector({
111
+ version: '2.0.0',
112
+ log: false,
113
+ dateFormat: 'YYYY-MM-DD HH:mm:ss', // requires dayjs
114
+ })
93
115
  ```
94
116
 
95
117
  ---
96
118
 
97
- ## **🔧 Configuration Options**
98
- | **Option** | **Type** | **Description** | **Default** |
99
- |------------|---------|----------------|-------------|
100
- | `version` | `string` | Custom version (e.g., `1.2.3`) | Auto-read from `package.json` |
101
- | `log` | `boolean` | Enable/Disable console logs | `true` |
102
- | `dateFormat` | `string` | Format for build time | `ISO 8601` |
119
+ ## 💡 Why Use This?
103
120
 
104
- ### **Example: Custom Config**
105
- ```js
106
- versionInjectorPlugin.webpack({
107
- version: '2.0.0',
108
- log: false, // Disable console logs
109
- });
110
- ```
121
+ - 🔍 Track build info in production
122
+ - 🕒 Know what you deployed & when
123
+ - ✅ No manual version updates
124
+ - 🚀 Great for debugging and multi-page apps
111
125
 
112
126
  ---
113
127
 
114
- ## **🌍 Why Use This Plugin?**
115
- - 🛠 **Works out of the box**: No extra setup needed
116
- - 🚀 **Improves debugging**: Always know what version is running in production
117
- - 📅 **Track build times**: Useful for monitoring deployments
118
- - 🎯 **Lightweight & fast**: Minimal overhead with maximum benefits
128
+ ## 📜 License
129
+
130
+ MIT © [@nianyi778](https://github.com/nianyi778)
119
131
 
120
132
  ---
121
133
 
122
- ## **📜 License**
123
- MIT License © 2024 [Nian YI](https://github.com/nianyi778)
134
+ ## 📂 Project Structure
135
+
136
+ ```
137
+ unplugin-version-injector/
138
+ ├── dist/
139
+ ├── src/
140
+ │ ├── vite.ts
141
+ │ ├── webpack.ts
142
+ │ ├── rollup.ts
143
+ │ └── shared/
144
+ ├── tsup.config.ts
145
+ └── package.json
146
+ ```
124
147
 
125
148
  ---
126
149
 
127
- ## **💡 Contributing**
128
- Pull requests are welcome! If you encounter any issues, feel free to open an issue on GitHub.
150
+ ## 🤝 Contributing
151
+
152
+ Feel free to submit issues or PRs 🙌
129
153
 
130
- **GitHub Repository:** [🔗 unplugin-version-injector](https://github.com/nianyi778/unplugin-version-injector)
154
+ GitHub https://github.com/nianyi778/unplugin-version-injector
131
155
 
132
156
  ---
133
157
 
134
- 🔥 **`unplugin-version-injector` The simplest way to keep track of your app's version & build time!** 🚀
158
+ 🔥 Simple, reliable version & build timestamp injection that just works!
package/README.zh-CN.md CHANGED
@@ -1,25 +1,26 @@
1
- # **🚀 `unplugin-version-injector` - 自动注入版本号 & 构建时间**
1
+ ### **🚀 `unplugin-version-injector` - 自动注入版本号与构建时间**
2
2
 
3
- [🇬🇧 English README](./README.md) | [🇨🇳 中文 README](./README.zh-CN.md)
3
+ [🇬🇧 English README](./README.md) | [🇨🇳 中文文档](./README.zh-CN.md)
4
4
 
5
5
  ---
6
6
 
7
- ## **📌 简介**
8
- `unplugin-version-injector` 是一个 **轻量级** 插件,可自动将 **版本号** 和 **构建时间** 注入到所有 HTML 文件中。
9
- 支持 **Webpack 4/5、Vite 和 Rollup**,适用于 **单页应用 (SPA) 和 多页应用 (MPA)**。
7
+ ## **📌 插件简介**
8
+ `unplugin-version-injector` 是一个轻量级插件,可在构建时自动向所有 HTML 文件注入 **版本号** 和 **构建时间戳**。支持 **Webpack 4/5、Vite 和 Rollup**,非常适合 **SPA / MPA 项目**使用。
10
9
 
11
- ### **✨ 功能特点**
12
- ✅ **自动注入** `<meta name="version">` 到所有 HTML `<head>` 部分
13
- **自动注入 `<script>`**,在浏览器控制台打印 `版本号` & `构建时间`
14
- **兼容 Webpack 4 & 5、Vite Rollup**
15
- **支持多页应用 (MPA)**,不会遗漏任何 HTML
16
- **支持手动指定版本号**,默认读取 `package.json`
10
+ ---
11
+
12
+ ## **✨ 功能亮点**
13
+ 自动注入 `<meta name="version">` HTML `<head>` 中
14
+ 自动注入 `<script>`,控制台输出 `版本号` 和 `构建时间`
15
+ 支持 Webpack 4 / 5、Vite、Rollup
16
+ ✅ 完美兼容多页面应用(MPA)
17
+ ✅ 支持自定义版本号、时间格式,默认读取 `package.json`
17
18
 
18
19
  ---
19
20
 
20
21
  ## **📦 安装**
21
- ```sh
22
- # 使用 Yarn
22
+ ```bash
23
+ # 使用 yarn
23
24
  yarn add -D unplugin-version-injector
24
25
 
25
26
  # 使用 npm
@@ -30,106 +31,96 @@ npm install -D unplugin-version-injector
30
31
 
31
32
  ## **🚀 使用方法**
32
33
 
33
- ### **📌 Webpack 4/5**
34
- 修改 `webpack.config.js`:
35
- ```js
36
- const versionInjectorPlugin = require('unplugin-version-injector');
34
+ ### **📌 Vite**
35
+ `vite.config.ts` 中配置:
36
+ ```ts
37
+ import versionInjector from 'unplugin-version-injector/vite';
37
38
 
38
- module.exports = {
39
- plugins: [
40
- versionInjectorPlugin.webpack({
41
- version: '1.2.3', // (可选)手动指定版本号
42
- })
43
- ],
39
+ export default {
40
+ plugins: [versionInjector()],
44
41
  };
45
42
  ```
46
43
 
47
44
  ---
48
45
 
49
- ### **📌 Vite**
50
- 修改 `vite.config.js`:
46
+ ### **📌 Webpack 4/5**
47
+ `webpack.config.js` 中配置:
51
48
  ```js
52
- import versionInjectorPlugin from 'unplugin-version-injector';
49
+ const versionInjector = require('unplugin-version-injector/webpack');
53
50
 
54
- export default {
55
- plugins: [versionInjectorPlugin.vite()]
51
+ module.exports = {
52
+ plugins: [
53
+ versionInjector({
54
+ version: '1.2.3', // 可选,自定义版本号
55
+ }),
56
+ ],
56
57
  };
57
58
  ```
58
59
 
59
60
  ---
60
61
 
61
62
  ### **📌 Rollup**
62
- 修改 `rollup.config.js`:
63
+ `rollup.config.js` 中配置:
63
64
  ```js
64
- import versionInjectorPlugin from 'unplugin-version-injector';
65
+ import versionInjector from 'unplugin-version-injector/rollup';
65
66
 
66
67
  export default {
67
- plugins: [versionInjectorPlugin.rollup()]
68
+ plugins: [versionInjector()],
68
69
  };
69
70
  ```
70
71
 
71
72
  ---
72
73
 
73
- ## **📜 生成的 HTML 示例**
74
- 构建完成后,所有 HTML 文件将包含以下内容:
74
+ ## **🧪 示例输出**
75
+
76
+ 构建后的 HTML 文件中将自动注入:
77
+
75
78
  ```html
76
79
  <head>
77
80
  <meta name="version" content="1.2.3">
78
- <meta charset="UTF-8">
79
- <title>我的应用</title>
81
+ ...
80
82
  </head>
81
83
  <body>
82
- <h1>Hello World</h1>
84
+ ...
83
85
  <script>
84
- console.log("%c 版本号: 1.2.3 ", "background: #222; color: #00ff00; font-size: 12px; padding: 4px; border-radius: 4px;");
85
- console.log("%c 构建时间: 2024-03-01T12:00:00.000Z ", "background: #222; color: #ffcc00; font-size: 12px; padding: 4px; border-radius: 4px;");
86
+ console.log("%c Version: 1.2.3 ", "background: #222; color: #00ff00;");
87
+ console.log("%c Build Time: 2024-04-01T12:00:00.000Z ", "background: #222; color: #ffcc00;");
86
88
  </script>
87
89
  </body>
88
90
  ```
89
91
 
90
- ✅ **浏览器控制台输出 (带颜色日志)**
92
+ 控制台输出:
93
+
91
94
  ```
92
- 🟢 版本号: 1.2.3 (绿色)
93
- 🟡 构建时间: 2024-03-01T12:00:00.000Z (黄色)
95
+ 🟢 Version: 1.2.3
96
+ 🟡 Build Time: 2024-04-01T12:00:00.000Z
94
97
  ```
95
98
 
96
99
  ---
97
100
 
98
- ## **🔧 配置选项**
99
- | **选项** | **类型** | **描述** | **默认值** |
100
- |---------|--------|---------|---------|
101
- | `version` | `string` | 手动指定版本号 (如 `1.2.3`) | 自动读取 `package.json` |
102
- | `log` | `boolean` | 是否在控制台打印版本信息 | `true` |
103
- | `dateFormat` | `string` | 自定义构建时间格式 | `ISO 8601` |
101
+ ## **🔧 配置项说明**
104
102
 
105
- ### **📌 自定义配置示例**
106
- ```js
107
- versionInjectorPlugin.webpack({
108
- version: '2.0.0',
109
- log: false, // 关闭控制台日志
110
- });
111
- ```
103
+ | 选项 | 类型 | 说明 | 默认值 |
104
+ |----------------|-----------|-------------------------------|------------------|
105
+ | `version` | `string` | 指定版本号 | 自动读取 package.json |
106
+ | `log` | `boolean` | 是否输出控制台日志 | `true` |
107
+ | `dateFormat` | `string` | 使用 dayjs 自定义时间格式 | `ISO 格式` |
112
108
 
113
109
  ---
114
110
 
115
- ## **🌍 为什么选择 `unplugin-version-injector`?**
116
- - 🛠 **开箱即用**:安装后立即生效,无需额外配置
117
- - 🚀 **提升调试效率**:轻松查看当前版本信息
118
- - 📅 **追踪构建时间**:方便监控不同版本的发布时间
119
- - 🎯 **轻量高效**:几乎不会影响构建速度
111
+ ## **🌍 为什么选择这个插件?**
120
112
 
121
- ---
122
-
123
- ## **📜 许可证**
124
- MIT License © 2024 [Nian YI](https://github.com/nianyi778)
113
+ - 🛠 零配置,开箱即用
114
+ - 🚀 快速定位版本问题
115
+ - 📅 跟踪构建时间
116
+ - 🎯 支持多构建工具
117
+ - 🧩 高度可配置,灵活插拔
125
118
 
126
119
  ---
127
120
 
128
- ## **💡 贡献**
129
- 欢迎 PR!如有问题,欢迎在 GitHub 提交 issue。
130
-
131
- **GitHub 仓库**:[🔗 unplugin-version-injector](https://github.com/nianyi778/unplugin-version-injector)
121
+ ## **📜 开源许可**
122
+ MIT License © 2024 [Nian YI](https://github.com/nianyi778)
132
123
 
133
124
  ---
134
125
 
135
- 🔥 **`unplugin-version-injector` - 让你的应用版本管理更简单!** 🚀🚀🚀
126
+ 🔥 `unplugin-version-injector` —— 最轻巧的版本信息注入解决方案!
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unplugin-version-injector",
3
- "version": "1.1.2-beta.3",
3
+ "version": "2.0.0-beta.1",
4
4
  "author": "Nian Yi <nianyi778@gmail.com>",
5
5
  "license": "MIT",
6
6
  "description": "A universal plugin to inject version and build time into HTML (supports Webpack, Vite, Rollup)",
package/dist/rollup.d.mts DELETED
@@ -1,11 +0,0 @@
1
- import { Plugin } from 'rollup';
2
-
3
- interface VersionInjectorOptions {
4
- version?: string;
5
- log?: boolean;
6
- formatDate?: (date: Date) => string;
7
- }
8
-
9
- declare function versionInjector(options?: VersionInjectorOptions): Plugin;
10
-
11
- export { versionInjector as default };
package/dist/rollup.d.ts DELETED
@@ -1,11 +0,0 @@
1
- import { Plugin } from 'rollup';
2
-
3
- interface VersionInjectorOptions {
4
- version?: string;
5
- log?: boolean;
6
- formatDate?: (date: Date) => string;
7
- }
8
-
9
- declare function versionInjector(options?: VersionInjectorOptions): Plugin;
10
-
11
- export { versionInjector as default };