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 +98 -74
- package/README.zh-CN.md +59 -68
- package/package.json +1 -1
- package/dist/rollup.d.mts +0 -11
- package/dist/rollup.d.ts +0 -11
package/README.md
CHANGED
@@ -1,134 +1,158 @@
|
|
1
|
-
|
1
|
+
# 🚀 `unplugin-version-injector` – Auto Inject Version & Build Time
|
2
2
|
|
3
|
-
[🇨🇳
|
3
|
+
[🇨🇳 中文文档](./README.zh-CN.md) | [🇺🇸 English README](./README.md)
|
4
4
|
|
5
5
|
---
|
6
6
|
|
7
|
-
##
|
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
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
✅
|
15
|
-
✅
|
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
|
-
##
|
20
|
-
```sh
|
21
|
-
# Using Yarn
|
22
|
-
yarn add -D unplugin-version-injector
|
21
|
+
## 📦 Installation
|
23
22
|
|
24
|
-
|
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
|
-
##
|
36
|
+
## 🚀 Usage
|
31
37
|
|
32
|
-
###
|
33
|
-
Modify your `webpack.config.js`:
|
34
|
-
```js
|
35
|
-
const versionInjectorPlugin = require('unplugin-version-injector');
|
38
|
+
### ▶ Vite
|
36
39
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
-
###
|
49
|
-
|
51
|
+
### ▶ Webpack (4 or 5)
|
52
|
+
|
50
53
|
```js
|
51
|
-
|
54
|
+
// webpack.config.js
|
55
|
+
const versionInjector = require('unplugin-version-injector/webpack')
|
52
56
|
|
53
|
-
|
54
|
-
plugins: [
|
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
|
-
###
|
61
|
-
|
68
|
+
### ▶ Rollup
|
69
|
+
|
62
70
|
```js
|
63
|
-
|
71
|
+
// rollup.config.js
|
72
|
+
import versionInjector from 'unplugin-version-injector/rollup'
|
64
73
|
|
65
74
|
export default {
|
66
|
-
plugins: [
|
67
|
-
}
|
75
|
+
plugins: [versionInjector()],
|
76
|
+
}
|
68
77
|
```
|
69
78
|
|
70
79
|
---
|
71
80
|
|
72
|
-
##
|
73
|
-
|
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
|
-
|
82
|
-
<script>
|
83
|
-
console.log("%c Version: 1.2.3 ", "background
|
84
|
-
console.log("%c Build Time: 2024-03-01T12:00:
|
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
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
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
|
-
##
|
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
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
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
|
-
##
|
115
|
-
|
116
|
-
|
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
|
-
##
|
123
|
-
|
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
|
-
##
|
128
|
-
|
150
|
+
## 🤝 Contributing
|
151
|
+
|
152
|
+
Feel free to submit issues or PRs 🙌
|
129
153
|
|
130
|
-
|
154
|
+
GitHub → https://github.com/nianyi778/unplugin-version-injector
|
131
155
|
|
132
156
|
---
|
133
157
|
|
134
|
-
🔥
|
158
|
+
🔥 Simple, reliable version & build timestamp injection – that just works!
|
package/README.zh-CN.md
CHANGED
@@ -1,25 +1,26 @@
|
|
1
|
-
|
1
|
+
### **🚀 `unplugin-version-injector` - 自动注入版本号与构建时间**
|
2
2
|
|
3
|
-
[🇬🇧 English README](./README.md) | [🇨🇳
|
3
|
+
[🇬🇧 English README](./README.md) | [🇨🇳 中文文档](./README.zh-CN.md)
|
4
4
|
|
5
5
|
---
|
6
6
|
|
7
|
-
## **📌
|
8
|
-
`unplugin-version-injector`
|
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
|
-
|
13
|
-
|
14
|
-
✅
|
15
|
-
✅
|
16
|
-
✅
|
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
|
-
```
|
22
|
-
# 使用
|
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
|
-
### **📌
|
34
|
-
|
35
|
-
```
|
36
|
-
|
34
|
+
### **📌 Vite**
|
35
|
+
`vite.config.ts` 中配置:
|
36
|
+
```ts
|
37
|
+
import versionInjector from 'unplugin-version-injector/vite';
|
37
38
|
|
38
|
-
|
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
|
-
### **📌
|
50
|
-
|
46
|
+
### **📌 Webpack 4/5**
|
47
|
+
`webpack.config.js` 中配置:
|
51
48
|
```js
|
52
|
-
|
49
|
+
const versionInjector = require('unplugin-version-injector/webpack');
|
53
50
|
|
54
|
-
|
55
|
-
plugins: [
|
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
|
-
|
63
|
+
`rollup.config.js` 中配置:
|
63
64
|
```js
|
64
|
-
import
|
65
|
+
import versionInjector from 'unplugin-version-injector/rollup';
|
65
66
|
|
66
67
|
export default {
|
67
|
-
plugins: [
|
68
|
+
plugins: [versionInjector()],
|
68
69
|
};
|
69
70
|
```
|
70
71
|
|
71
72
|
---
|
72
73
|
|
73
|
-
##
|
74
|
-
|
74
|
+
## **🧪 示例输出**
|
75
|
+
|
76
|
+
构建后的 HTML 文件中将自动注入:
|
77
|
+
|
75
78
|
```html
|
76
79
|
<head>
|
77
80
|
<meta name="version" content="1.2.3">
|
78
|
-
|
79
|
-
<title>我的应用</title>
|
81
|
+
...
|
80
82
|
</head>
|
81
83
|
<body>
|
82
|
-
|
84
|
+
...
|
83
85
|
<script>
|
84
|
-
console.log("%c
|
85
|
-
console.log("%c
|
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
|
-
🟢
|
93
|
-
🟡
|
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
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
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
|
-
## **🌍
|
116
|
-
- 🛠 **开箱即用**:安装后立即生效,无需额外配置
|
117
|
-
- 🚀 **提升调试效率**:轻松查看当前版本信息
|
118
|
-
- 📅 **追踪构建时间**:方便监控不同版本的发布时间
|
119
|
-
- 🎯 **轻量高效**:几乎不会影响构建速度
|
111
|
+
## **🌍 为什么选择这个插件?**
|
120
112
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
113
|
+
- 🛠 零配置,开箱即用
|
114
|
+
- 🚀 快速定位版本问题
|
115
|
+
- 📅 跟踪构建时间
|
116
|
+
- 🎯 支持多构建工具
|
117
|
+
- 🧩 高度可配置,灵活插拔
|
125
118
|
|
126
119
|
---
|
127
120
|
|
128
|
-
##
|
129
|
-
|
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
|
-
🔥
|
126
|
+
🔥 `unplugin-version-injector` —— 最轻巧的版本信息注入解决方案!
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "unplugin-version-injector",
|
3
|
-
"version": "
|
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 };
|