unplugin-version-injector 1.1.1-alpha.5 → 1.1.2-beta.0
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 +66 -110
- package/README.zh-CN.md +66 -109
- package/dist/rollup.d.mts +11 -0
- package/dist/rollup.d.ts +11 -0
- package/dist/rollup.js +72 -0
- package/dist/rollup.mjs +65 -0
- package/dist/vite.d.mts +5 -0
- package/dist/vite.d.ts +5 -0
- package/dist/vite.js +64 -0
- package/dist/vite.mjs +57 -0
- package/dist/webpack.d.mts +5 -4
- package/dist/webpack.d.ts +5 -4
- package/dist/webpack.js +54 -119
- package/dist/webpack.mjs +44 -90
- package/package.json +30 -25
- package/dist/core.d.mts +0 -6
- package/dist/core.d.ts +0 -6
- package/dist/core.js +0 -140
- package/dist/core.mjs +0 -112
- package/dist/types-DEOBLqEx.d.mts +0 -9
- package/dist/types-DEOBLqEx.d.ts +0 -9
package/README.md
CHANGED
@@ -1,178 +1,134 @@
|
|
1
|
-
|
1
|
+
### **🚀 `unplugin-version-injector` - Auto Inject Version & Build Time**
|
2
2
|
|
3
|
-
[🇨🇳
|
3
|
+
[🇨🇳 中文 README](./README.zh-CN.md) | [🇬🇧 English README](./README.md)
|
4
4
|
|
5
5
|
---
|
6
6
|
|
7
|
-
##
|
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)**.
|
8
9
|
|
9
|
-
|
10
|
-
|
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`
|
11
16
|
|
12
17
|
---
|
13
18
|
|
14
|
-
##
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
- ✅ Supports Webpack 4, Webpack 5, Vite, and Rollup
|
19
|
-
- ✅ Supports Multi-Page Applications (MPA)
|
20
|
-
- ✅ Supports custom version & timestamp format
|
21
|
-
- ✅ Tiny, fast, and zero-runtime dependency
|
22
|
-
|
23
|
-
---
|
24
|
-
|
25
|
-
## 📦 Installation
|
19
|
+
## **📦 Installation**
|
20
|
+
```sh
|
21
|
+
# Using Yarn
|
22
|
+
yarn add -D unplugin-version-injector
|
26
23
|
|
27
|
-
|
28
|
-
# With npm
|
24
|
+
# Using npm
|
29
25
|
npm install -D unplugin-version-injector
|
30
|
-
|
31
|
-
# With yarn
|
32
|
-
yarn add -D unplugin-version-injector
|
33
26
|
```
|
34
27
|
|
35
28
|
---
|
36
29
|
|
37
|
-
##
|
38
|
-
|
39
|
-
### ✅ Vite
|
30
|
+
## **🚀 Usage**
|
40
31
|
|
41
|
-
|
42
|
-
|
43
|
-
|
32
|
+
### **📌 Webpack 4/5**
|
33
|
+
Modify your `webpack.config.js`:
|
34
|
+
```js
|
35
|
+
const versionInjectorPlugin = require('unplugin-version-injector');
|
44
36
|
|
45
|
-
|
46
|
-
plugins: [
|
37
|
+
module.exports = {
|
38
|
+
plugins: [
|
39
|
+
versionInjectorPlugin.webpack({
|
40
|
+
version: '1.2.3', // (Optional) Manually specify version
|
41
|
+
})
|
42
|
+
],
|
47
43
|
};
|
48
44
|
```
|
49
45
|
|
50
46
|
---
|
51
47
|
|
52
|
-
###
|
53
|
-
|
48
|
+
### **📌 Vite**
|
49
|
+
Modify your `vite.config.js`:
|
54
50
|
```js
|
55
|
-
|
56
|
-
const versionInjector = require('unplugin-version-injector/webpack');
|
51
|
+
import versionInjectorPlugin from 'unplugin-version-injector';
|
57
52
|
|
58
|
-
|
59
|
-
plugins: [
|
60
|
-
versionInjector({
|
61
|
-
version: '1.2.3',
|
62
|
-
injectToHead: true,
|
63
|
-
injectToBody: true,
|
64
|
-
}),
|
65
|
-
],
|
53
|
+
export default {
|
54
|
+
plugins: [versionInjectorPlugin.vite()]
|
66
55
|
};
|
67
56
|
```
|
68
57
|
|
69
58
|
---
|
70
59
|
|
71
|
-
###
|
72
|
-
|
60
|
+
### **📌 Rollup**
|
61
|
+
Modify your `rollup.config.js`:
|
73
62
|
```js
|
74
|
-
|
75
|
-
import versionInjector from 'unplugin-version-injector/rollup';
|
63
|
+
import versionInjectorPlugin from 'unplugin-version-injector';
|
76
64
|
|
77
65
|
export default {
|
78
|
-
plugins: [
|
79
|
-
versionInjector({
|
80
|
-
dateFormat: 'YYYY-MM-DD HH:mm:ss',
|
81
|
-
}),
|
82
|
-
],
|
66
|
+
plugins: [versionInjectorPlugin.rollup()]
|
83
67
|
};
|
84
68
|
```
|
85
69
|
|
86
70
|
---
|
87
71
|
|
88
|
-
##
|
89
|
-
|
72
|
+
## **📜 Example Output**
|
73
|
+
After building, all HTML files will include the following:
|
90
74
|
```html
|
91
75
|
<head>
|
92
76
|
<meta name="version" content="1.2.3">
|
93
77
|
<meta charset="UTF-8">
|
78
|
+
<title>My App</title>
|
94
79
|
</head>
|
95
80
|
<body>
|
96
|
-
<h1>Hello</h1>
|
81
|
+
<h1>Hello World</h1>
|
97
82
|
<script>
|
98
|
-
console.log("%c Version: 1.2.3 ", "background: #222; color: #00ff00; font-size: 12px;");
|
99
|
-
console.log("%c Build Time:
|
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;");
|
100
85
|
</script>
|
101
86
|
</body>
|
102
87
|
```
|
103
88
|
|
104
|
-
✅ Console
|
105
|
-
|
89
|
+
✅ **Console Output (Colored Logs)**
|
106
90
|
```
|
107
|
-
🟢 Version: 1.2.3
|
108
|
-
🟡 Build Time:
|
91
|
+
🟢 Version: 1.2.3 (Green)
|
92
|
+
🟡 Build Time: 2024-03-01T12:00:00.000Z (Yellow)
|
109
93
|
```
|
110
94
|
|
111
95
|
---
|
112
96
|
|
113
|
-
##
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
| `
|
118
|
-
| `
|
119
|
-
| `dateFormat` | `string` | None | Uses `dayjs` to format time (requires installation) |
|
120
|
-
| `injectToHead` | `boolean` | `true` | Injects `<meta name="version">` into `<head>` |
|
121
|
-
| `injectToBody` | `boolean` | `true` | Injects version log `<script>` into `<body>` |
|
122
|
-
|
123
|
-
📦 If using `dateFormat`, please install `dayjs` manually:
|
124
|
-
|
125
|
-
```bash
|
126
|
-
npm install dayjs
|
127
|
-
```
|
128
|
-
|
129
|
-
---
|
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` |
|
130
103
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
injectToHead: true,
|
137
|
-
injectToBody: false,
|
138
|
-
dateFormat: 'YYYY/MM/DD HH:mm:ss',
|
104
|
+
### **Example: Custom Config**
|
105
|
+
```js
|
106
|
+
versionInjectorPlugin.webpack({
|
107
|
+
version: '2.0.0',
|
108
|
+
log: false, // Disable console logs
|
139
109
|
});
|
140
110
|
```
|
141
111
|
|
142
112
|
---
|
143
113
|
|
144
|
-
##
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
| **Webpack 5**| ✅ | Uses `processAssets` hook |
|
150
|
-
| **Webpack 4**| ✅ | Uses `emit` hook |
|
151
|
-
| **Rollup** | ✅ | Uses `generateBundle` hook |
|
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
|
152
119
|
|
153
120
|
---
|
154
121
|
|
155
|
-
##
|
156
|
-
|
157
|
-
- 🧪 Quickly identify deployed version & build time
|
158
|
-
- 📅 Useful for deployment tracking / diagnostics
|
159
|
-
- ⚡️ No runtime cost – build-time only
|
122
|
+
## **📜 License**
|
123
|
+
MIT License © 2024 [Nian YI](https://github.com/nianyi778)
|
160
124
|
|
161
125
|
---
|
162
126
|
|
163
|
-
##
|
164
|
-
|
165
|
-
MIT © [Nian YI](https://github.com/nianyi778)
|
166
|
-
|
167
|
-
---
|
168
|
-
|
169
|
-
## 🤝 Contributing
|
170
|
-
|
171
|
-
Contributions are welcome!
|
127
|
+
## **💡 Contributing**
|
128
|
+
Pull requests are welcome! If you encounter any issues, feel free to open an issue on GitHub.
|
172
129
|
|
173
|
-
GitHub
|
174
|
-
[https://github.com/nianyi778/unplugin-version-injector](https://github.com/nianyi778/unplugin-version-injector)
|
130
|
+
**GitHub Repository:** [🔗 unplugin-version-injector](https://github.com/nianyi778/unplugin-version-injector)
|
175
131
|
|
176
132
|
---
|
177
133
|
|
178
|
-
🔥
|
134
|
+
🔥 **`unplugin-version-injector` – The simplest way to keep track of your app's version & build time!** 🚀
|
package/README.zh-CN.md
CHANGED
@@ -1,178 +1,135 @@
|
|
1
|
-
#
|
1
|
+
# **🚀 `unplugin-version-injector` - 自动注入版本号 & 构建时间**
|
2
2
|
|
3
|
-
[🇬🇧 English README](./README.md) | [🇨🇳 中文 README](./README.zh-CN.md)
|
3
|
+
[🇬🇧 English README](./README.md) | [🇨🇳 中文 README](./README.zh-CN.md)
|
4
4
|
|
5
5
|
---
|
6
6
|
|
7
|
-
##
|
7
|
+
## **📌 简介**
|
8
|
+
`unplugin-version-injector` 是一个 **轻量级** 插件,可自动将 **版本号** 和 **构建时间** 注入到所有 HTML 文件中。
|
9
|
+
支持 **Webpack 4/5、Vite 和 Rollup**,适用于 **单页应用 (SPA) 和 多页应用 (MPA)**。
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
+
### **✨ 功能特点**
|
12
|
+
✅ **自动注入** `<meta name="version">` 到所有 HTML `<head>` 部分
|
13
|
+
✅ **自动注入 `<script>`**,在浏览器控制台打印 `版本号` & `构建时间`
|
14
|
+
✅ **兼容 Webpack 4 & 5、Vite 和 Rollup**
|
15
|
+
✅ **支持多页应用 (MPA)**,不会遗漏任何 HTML
|
16
|
+
✅ **支持手动指定版本号**,默认读取 `package.json`
|
11
17
|
|
12
18
|
---
|
13
19
|
|
14
|
-
##
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
- ✅ 支持 Webpack 4、Webpack 5、Vite、Rollup
|
19
|
-
- ✅ 支持多页应用(MPA),自动处理所有 HTML 文件
|
20
|
-
- ✅ 支持自定义版本号、自定义构建时间格式
|
21
|
-
- ✅ 体积小、零运行时依赖
|
22
|
-
|
23
|
-
---
|
24
|
-
|
25
|
-
## 📦 安装
|
20
|
+
## **📦 安装**
|
21
|
+
```sh
|
22
|
+
# 使用 Yarn
|
23
|
+
yarn add -D unplugin-version-injector
|
26
24
|
|
27
|
-
```bash
|
28
25
|
# 使用 npm
|
29
26
|
npm install -D unplugin-version-injector
|
30
|
-
|
31
|
-
# 使用 yarn
|
32
|
-
yarn add -D unplugin-version-injector
|
33
27
|
```
|
34
28
|
|
35
29
|
---
|
36
30
|
|
37
|
-
##
|
38
|
-
|
39
|
-
### ✅ Vite
|
31
|
+
## **🚀 使用方法**
|
40
32
|
|
41
|
-
|
42
|
-
|
43
|
-
|
33
|
+
### **📌 Webpack 4/5**
|
34
|
+
修改 `webpack.config.js`:
|
35
|
+
```js
|
36
|
+
const versionInjectorPlugin = require('unplugin-version-injector');
|
44
37
|
|
45
|
-
|
46
|
-
plugins: [
|
38
|
+
module.exports = {
|
39
|
+
plugins: [
|
40
|
+
versionInjectorPlugin.webpack({
|
41
|
+
version: '1.2.3', // (可选)手动指定版本号
|
42
|
+
})
|
43
|
+
],
|
47
44
|
};
|
48
45
|
```
|
49
46
|
|
50
47
|
---
|
51
48
|
|
52
|
-
###
|
53
|
-
|
49
|
+
### **📌 Vite**
|
50
|
+
修改 `vite.config.js`:
|
54
51
|
```js
|
55
|
-
|
56
|
-
const versionInjector = require('unplugin-version-injector/webpack');
|
52
|
+
import versionInjectorPlugin from 'unplugin-version-injector';
|
57
53
|
|
58
|
-
|
59
|
-
plugins: [
|
60
|
-
versionInjector({
|
61
|
-
version: '1.2.3',
|
62
|
-
injectToHead: true,
|
63
|
-
injectToBody: true,
|
64
|
-
}),
|
65
|
-
],
|
54
|
+
export default {
|
55
|
+
plugins: [versionInjectorPlugin.vite()]
|
66
56
|
};
|
67
57
|
```
|
68
58
|
|
69
59
|
---
|
70
60
|
|
71
|
-
###
|
72
|
-
|
61
|
+
### **📌 Rollup**
|
62
|
+
修改 `rollup.config.js`:
|
73
63
|
```js
|
74
|
-
|
75
|
-
import versionInjector from 'unplugin-version-injector/rollup';
|
64
|
+
import versionInjectorPlugin from 'unplugin-version-injector';
|
76
65
|
|
77
66
|
export default {
|
78
|
-
plugins: [
|
79
|
-
versionInjector({
|
80
|
-
dateFormat: 'YYYY-MM-DD HH:mm:ss',
|
81
|
-
}),
|
82
|
-
],
|
67
|
+
plugins: [versionInjectorPlugin.rollup()]
|
83
68
|
};
|
84
69
|
```
|
85
70
|
|
86
71
|
---
|
87
72
|
|
88
|
-
##
|
89
|
-
|
73
|
+
## **📜 生成的 HTML 示例**
|
74
|
+
构建完成后,所有 HTML 文件将包含以下内容:
|
90
75
|
```html
|
91
76
|
<head>
|
92
77
|
<meta name="version" content="1.2.3">
|
93
78
|
<meta charset="UTF-8">
|
79
|
+
<title>我的应用</title>
|
94
80
|
</head>
|
95
81
|
<body>
|
96
|
-
<h1>Hello</h1>
|
82
|
+
<h1>Hello World</h1>
|
97
83
|
<script>
|
98
|
-
console.log("%c 版本号: 1.2.3 ", "background: #222; color: #00ff00; font-size: 12px;");
|
99
|
-
console.log("%c 构建时间:
|
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;");
|
100
86
|
</script>
|
101
87
|
</body>
|
102
88
|
```
|
103
89
|
|
104
|
-
✅
|
105
|
-
|
90
|
+
✅ **浏览器控制台输出 (带颜色日志)**
|
106
91
|
```
|
107
|
-
🟢 版本号: 1.2.3
|
108
|
-
🟡 构建时间:
|
92
|
+
🟢 版本号: 1.2.3 (绿色)
|
93
|
+
🟡 构建时间: 2024-03-01T12:00:00.000Z (黄色)
|
109
94
|
```
|
110
95
|
|
111
96
|
---
|
112
97
|
|
113
|
-
##
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
| `
|
118
|
-
| `
|
119
|
-
| `dateFormat` | `string` | 无 | 使用 `dayjs` 格式化(需用户安装) |
|
120
|
-
| `injectToHead` | `boolean` | `true` | 是否注入 `<meta>` 标签 |
|
121
|
-
| `injectToBody` | `boolean` | `true` | 是否注入控制台日志脚本 |
|
122
|
-
|
123
|
-
📦 如果使用 `dateFormat`,请先安装:
|
124
|
-
|
125
|
-
```bash
|
126
|
-
npm install dayjs
|
127
|
-
```
|
128
|
-
|
129
|
-
---
|
98
|
+
## **🔧 配置选项**
|
99
|
+
| **选项** | **类型** | **描述** | **默认值** |
|
100
|
+
|---------|--------|---------|---------|
|
101
|
+
| `version` | `string` | 手动指定版本号 (如 `1.2.3`) | 自动读取 `package.json` |
|
102
|
+
| `log` | `boolean` | 是否在控制台打印版本信息 | `true` |
|
103
|
+
| `dateFormat` | `string` | 自定义构建时间格式 | `ISO 8601` |
|
130
104
|
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
injectToHead: true,
|
137
|
-
injectToBody: false,
|
138
|
-
dateFormat: 'YYYY/MM/DD HH:mm:ss',
|
105
|
+
### **📌 自定义配置示例**
|
106
|
+
```js
|
107
|
+
versionInjectorPlugin.webpack({
|
108
|
+
version: '2.0.0',
|
109
|
+
log: false, // 关闭控制台日志
|
139
110
|
});
|
140
111
|
```
|
141
112
|
|
142
113
|
---
|
143
114
|
|
144
|
-
##
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
| **Webpack 5**| ✅ 支持 | 使用 `processAssets` 钩子 |
|
150
|
-
| **Webpack 4**| ✅ 支持 | 使用 `emit` 钩子 |
|
151
|
-
| **Rollup** | ✅ 支持 | 使用 `generateBundle` 钩子 |
|
115
|
+
## **🌍 为什么选择 `unplugin-version-injector`?**
|
116
|
+
- 🛠 **开箱即用**:安装后立即生效,无需额外配置
|
117
|
+
- 🚀 **提升调试效率**:轻松查看当前版本信息
|
118
|
+
- 📅 **追踪构建时间**:方便监控不同版本的发布时间
|
119
|
+
- 🎯 **轻量高效**:几乎不会影响构建速度
|
152
120
|
|
153
121
|
---
|
154
122
|
|
155
|
-
##
|
156
|
-
|
157
|
-
- 🧪 快速定位部署版本与构建时间
|
158
|
-
- 📅 部署监控 / 运维可见性
|
159
|
-
- ⚡️ 零运行时依赖,构建时注入
|
123
|
+
## **📜 许可证**
|
124
|
+
MIT License © 2024 [Nian YI](https://github.com/nianyi778)
|
160
125
|
|
161
126
|
---
|
162
127
|
|
163
|
-
##
|
164
|
-
|
165
|
-
MIT © [Nian YI](https://github.com/nianyi778)
|
166
|
-
|
167
|
-
---
|
168
|
-
|
169
|
-
## 🤝 参与贡献
|
170
|
-
|
171
|
-
欢迎提交 PR 和 issue!
|
128
|
+
## **💡 贡献**
|
129
|
+
欢迎 PR!如有问题,欢迎在 GitHub 提交 issue。
|
172
130
|
|
173
|
-
GitHub
|
174
|
-
[https://github.com/nianyi778/unplugin-version-injector](https://github.com/nianyi778/unplugin-version-injector)
|
131
|
+
**GitHub 仓库**:[🔗 unplugin-version-injector](https://github.com/nianyi778/unplugin-version-injector)
|
175
132
|
|
176
133
|
---
|
177
134
|
|
178
|
-
🔥
|
135
|
+
🔥 **`unplugin-version-injector` - 让你的应用版本管理更简单!** 🚀🚀🚀
|
@@ -0,0 +1,11 @@
|
|
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
ADDED
@@ -0,0 +1,11 @@
|
|
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.js
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
var fs = require('fs');
|
4
|
+
var path = require('path');
|
5
|
+
|
6
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
7
|
+
|
8
|
+
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
9
|
+
var path__default = /*#__PURE__*/_interopDefault(path);
|
10
|
+
|
11
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
12
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
13
|
+
}) : x)(function(x) {
|
14
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
15
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
16
|
+
});
|
17
|
+
function getPackageVersion() {
|
18
|
+
try {
|
19
|
+
const packageJsonPath = path__default.default.resolve(process.cwd(), "package.json");
|
20
|
+
if (fs__default.default.existsSync(packageJsonPath)) {
|
21
|
+
return __require(packageJsonPath).version;
|
22
|
+
}
|
23
|
+
} catch (error) {
|
24
|
+
console.warn("[VersionInjector] Failed to read package.json:", error);
|
25
|
+
}
|
26
|
+
return "0.0.0";
|
27
|
+
}
|
28
|
+
function defaultFormatDate(date) {
|
29
|
+
return date.toISOString();
|
30
|
+
}
|
31
|
+
|
32
|
+
// src/core.ts
|
33
|
+
function createVersionInjector(options = {}) {
|
34
|
+
var _a, _b;
|
35
|
+
const version = (_a = options.version) != null ? _a : getPackageVersion();
|
36
|
+
((_b = options.formatDate) != null ? _b : defaultFormatDate)(/* @__PURE__ */ new Date());
|
37
|
+
const metaTag = `<meta name="version" content="${version}">
|
38
|
+
`;
|
39
|
+
const logScript = `<script data-injected="unplugin-version-injector">console.log(...)</script>`;
|
40
|
+
return function processHtml(html) {
|
41
|
+
if (!html.includes('<meta name="version"')) {
|
42
|
+
html = html.replace(/<head>/, `<head>
|
43
|
+
${metaTag}`);
|
44
|
+
}
|
45
|
+
if (!html.includes('<script data-injected="unplugin-version-injector"')) {
|
46
|
+
html = html.replace("</body>", ` ${logScript}
|
47
|
+
</body>`);
|
48
|
+
}
|
49
|
+
return html;
|
50
|
+
};
|
51
|
+
}
|
52
|
+
|
53
|
+
// src/rollup.ts
|
54
|
+
function versionInjector(options = {}) {
|
55
|
+
const shouldInject = options.log !== false;
|
56
|
+
if (!shouldInject) {
|
57
|
+
return { name: "unplugin-version-injector" };
|
58
|
+
}
|
59
|
+
const processHtml = createVersionInjector(options);
|
60
|
+
return {
|
61
|
+
name: "unplugin-version-injector",
|
62
|
+
generateBundle(_, bundle) {
|
63
|
+
for (const file of Object.values(bundle)) {
|
64
|
+
if (file.type === "asset" && file.fileName.endsWith(".html")) {
|
65
|
+
file.source = processHtml(file.source);
|
66
|
+
}
|
67
|
+
}
|
68
|
+
}
|
69
|
+
};
|
70
|
+
}
|
71
|
+
|
72
|
+
module.exports = versionInjector;
|
package/dist/rollup.mjs
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
import fs from 'fs';
|
2
|
+
import path from 'path';
|
3
|
+
|
4
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
5
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
6
|
+
}) : x)(function(x) {
|
7
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
8
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
9
|
+
});
|
10
|
+
function getPackageVersion() {
|
11
|
+
try {
|
12
|
+
const packageJsonPath = path.resolve(process.cwd(), "package.json");
|
13
|
+
if (fs.existsSync(packageJsonPath)) {
|
14
|
+
return __require(packageJsonPath).version;
|
15
|
+
}
|
16
|
+
} catch (error) {
|
17
|
+
console.warn("[VersionInjector] Failed to read package.json:", error);
|
18
|
+
}
|
19
|
+
return "0.0.0";
|
20
|
+
}
|
21
|
+
function defaultFormatDate(date) {
|
22
|
+
return date.toISOString();
|
23
|
+
}
|
24
|
+
|
25
|
+
// src/core.ts
|
26
|
+
function createVersionInjector(options = {}) {
|
27
|
+
var _a, _b;
|
28
|
+
const version = (_a = options.version) != null ? _a : getPackageVersion();
|
29
|
+
((_b = options.formatDate) != null ? _b : defaultFormatDate)(/* @__PURE__ */ new Date());
|
30
|
+
const metaTag = `<meta name="version" content="${version}">
|
31
|
+
`;
|
32
|
+
const logScript = `<script data-injected="unplugin-version-injector">console.log(...)</script>`;
|
33
|
+
return function processHtml(html) {
|
34
|
+
if (!html.includes('<meta name="version"')) {
|
35
|
+
html = html.replace(/<head>/, `<head>
|
36
|
+
${metaTag}`);
|
37
|
+
}
|
38
|
+
if (!html.includes('<script data-injected="unplugin-version-injector"')) {
|
39
|
+
html = html.replace("</body>", ` ${logScript}
|
40
|
+
</body>`);
|
41
|
+
}
|
42
|
+
return html;
|
43
|
+
};
|
44
|
+
}
|
45
|
+
|
46
|
+
// src/rollup.ts
|
47
|
+
function versionInjector(options = {}) {
|
48
|
+
const shouldInject = options.log !== false;
|
49
|
+
if (!shouldInject) {
|
50
|
+
return { name: "unplugin-version-injector" };
|
51
|
+
}
|
52
|
+
const processHtml = createVersionInjector(options);
|
53
|
+
return {
|
54
|
+
name: "unplugin-version-injector",
|
55
|
+
generateBundle(_, bundle) {
|
56
|
+
for (const file of Object.values(bundle)) {
|
57
|
+
if (file.type === "asset" && file.fileName.endsWith(".html")) {
|
58
|
+
file.source = processHtml(file.source);
|
59
|
+
}
|
60
|
+
}
|
61
|
+
}
|
62
|
+
};
|
63
|
+
}
|
64
|
+
|
65
|
+
export { versionInjector as default };
|
package/dist/vite.d.mts
ADDED