vite-plugin-build-version-file 0.1.10 → 0.1.11

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
@@ -78,6 +78,8 @@ export default defineConfig({
78
78
 
79
79
  注意:这里必须复用同一个 `buildVersion` 实例。不要分别调用两次 `buildVersionPlugin()`,否则 `transformHtml` 拿不到 Vite 插件阶段生成的 payload。
80
80
 
81
+ VitePress 构建会包含 client bundle 和 SSR bundle。插件只在最终静态产物 bundle 输出 `version.json`,避免同一次 VitePress build 出现重复日志或重复 emit。
82
+
81
83
  ## 默认行为
82
84
 
83
85
  默认配置下,插件会做这些事:
@@ -387,6 +389,23 @@ pnpm build:fixture
387
389
  pnpm build:vitepress
388
390
  ```
389
391
 
392
+ 完整检查打包流程:
393
+
394
+ ```bash
395
+ pnpm build
396
+ pnpm build:fixture
397
+ pnpm build:vitepress
398
+ npm pack --dry-run
399
+ ```
400
+
401
+ 建议检查:
402
+
403
+ - `debug/fixture-app/dist/version.json` 包含 `time`、`env`、`pkgName`、`pkgVersion`
404
+ - `debug/fixture-app/dist/index.html` 只注入一次 `window["__VERSION__"]`
405
+ - `debug/vitepress-app/.vitepress/dist/meta/version.json` 包含 `fixture`、`time`、`env`
406
+ - VitePress 每个 HTML 只注入一次 `window["__VERSION__"]`
407
+ - VitePress build 日志只输出一次插件 payload
408
+
390
409
  ## 发布
391
410
 
392
411
  ```bash
@@ -406,6 +425,7 @@ npm publish --access public
406
425
  - `version.json` 输出正常
407
426
  - 普通 Vite HTML 注入正常
408
427
  - VitePress `transformHtml` 接入后注入正常
428
+ - VitePress build 没有重复输出插件 payload 日志
409
429
 
410
430
  查看最终发包内容:
411
431
 
@@ -502,6 +522,8 @@ export default defineConfig({
502
522
 
503
523
  Use the same `buildVersion` instance in both places. Calling `buildVersionPlugin()` twice creates two isolated instances, and the VitePress `transformHtml` helper will not receive the payload created during the Vite plugin lifecycle.
504
524
 
525
+ VitePress build includes a client bundle and an SSR bundle. The plugin emits `version.json` only from the final static bundle, so one VitePress build does not print duplicate payload logs or emit the same asset twice.
526
+
505
527
  ## Default Behavior
506
528
 
507
529
  With default options, the plugin:
@@ -809,6 +831,23 @@ pnpm build:fixture
809
831
  pnpm build:vitepress
810
832
  ```
811
833
 
834
+ Full local package check:
835
+
836
+ ```bash
837
+ pnpm build
838
+ pnpm build:fixture
839
+ pnpm build:vitepress
840
+ npm pack --dry-run
841
+ ```
842
+
843
+ Check:
844
+
845
+ - `debug/fixture-app/dist/version.json` contains `time`, `env`, `pkgName`, and `pkgVersion`
846
+ - `debug/fixture-app/dist/index.html` injects `window["__VERSION__"]` once
847
+ - `debug/vitepress-app/.vitepress/dist/meta/version.json` contains `fixture`, `time`, and `env`
848
+ - each VitePress HTML file injects `window["__VERSION__"]` once
849
+ - VitePress build prints the plugin payload log once
850
+
812
851
  ## Publishing
813
852
 
814
853
  ```bash
@@ -828,6 +867,7 @@ Before publishing, check:
828
867
  - `version.json` output
829
868
  - normal Vite HTML injection
830
869
  - VitePress `transformHtml` injection
870
+ - no duplicate plugin payload logs during VitePress build
831
871
 
832
872
  Inspect the publish package:
833
873
 
package/dist/index.cjs CHANGED
@@ -184,6 +184,7 @@ function buildVersionPlugin(options = {}) {
184
184
  const timeZone = normalizeTimeZone(options.timeZone ?? DEFAULT_TIME_ZONE);
185
185
  const data = normalizeData(options.data);
186
186
  let payload;
187
+ let skipBundleEmit = false;
187
188
  const transformHtml = (code, ..._args) => {
188
189
  if (!injectToHtml || !payload) {
189
190
  return void 0;
@@ -193,6 +194,7 @@ function buildVersionPlugin(options = {}) {
193
194
  const plugin = {
194
195
  name: PLUGIN_NAME,
195
196
  configResolved(config) {
197
+ skipBundleEmit = Boolean(config.build.ssr) && !config.build.ssrEmitAssets;
196
198
  if (payload) {
197
199
  return;
198
200
  }
@@ -235,7 +237,7 @@ function buildVersionPlugin(options = {}) {
235
237
  return tags;
236
238
  },
237
239
  generateBundle() {
238
- if (!payload) {
240
+ if (!payload || skipBundleEmit) {
239
241
  return;
240
242
  }
241
243
  this.emitFile({
package/dist/index.mjs CHANGED
@@ -159,6 +159,7 @@ function buildVersionPlugin(options = {}) {
159
159
  const timeZone = normalizeTimeZone(options.timeZone ?? DEFAULT_TIME_ZONE);
160
160
  const data = normalizeData(options.data);
161
161
  let payload;
162
+ let skipBundleEmit = false;
162
163
  const transformHtml = (code, ..._args) => {
163
164
  if (!injectToHtml || !payload) {
164
165
  return void 0;
@@ -168,6 +169,7 @@ function buildVersionPlugin(options = {}) {
168
169
  const plugin = {
169
170
  name: PLUGIN_NAME,
170
171
  configResolved(config) {
172
+ skipBundleEmit = Boolean(config.build.ssr) && !config.build.ssrEmitAssets;
171
173
  if (payload) {
172
174
  return;
173
175
  }
@@ -210,7 +212,7 @@ function buildVersionPlugin(options = {}) {
210
212
  return tags;
211
213
  },
212
214
  generateBundle() {
213
- if (!payload) {
215
+ if (!payload || skipBundleEmit) {
214
216
  return;
215
217
  }
216
218
  this.emitFile({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-build-version-file",
3
- "version": "0.1.10",
3
+ "version": "0.1.11",
4
4
  "description": "A Vite plugin that emits version.json and injects version metadata into HTML.",
5
5
  "license": "MIT",
6
6
  "type": "module",