添加 dailyVersioning Vite 插件,将构建输出从 index.html 改为 grandclaw-archtype-YYYYMMDD.html 格式
33 lines
918 B
JavaScript
33 lines
918 B
JavaScript
import { defineConfig } from 'vite'
|
|
import react from '@vitejs/plugin-react'
|
|
import { viteSingleFile } from 'vite-plugin-singlefile'
|
|
import { renameSync } from 'node:fs'
|
|
import { join } from 'node:path'
|
|
|
|
function dailyVersioning() {
|
|
return {
|
|
name: 'daily-versioning',
|
|
enforce: 'post',
|
|
writeBundle(options, bundle) {
|
|
const now = new Date()
|
|
const date = now.getFullYear()
|
|
+ String(now.getMonth() + 1).padStart(2, '0')
|
|
+ String(now.getDate()).padStart(2, '0')
|
|
|
|
const oldPath = join(options.dir || 'dist', 'index.html')
|
|
const newName = `grandclaw-archtype-${date}.html`
|
|
const newPath = join(options.dir || 'dist', newName)
|
|
|
|
if (bundle['index.html']) {
|
|
renameSync(oldPath, newPath)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// https://vite.dev/config/
|
|
export default defineConfig({
|
|
base: './',
|
|
plugins: [react(), viteSingleFile(), dailyVersioning()],
|
|
})
|