做網(wǎng)站怎么租個(gè)域名百度搜索引擎的優(yōu)缺點(diǎn)
在 Vite 項(xiàng)目中,默認(rèn)構(gòu)建 index.html
。但有時(shí)候我們需要修改 index.html
為其他文件名,比如 index-{時(shí)間戳}.html
。
我們可以這樣配置 vite.config.js:
import { defineConfig } from 'vite';
import type { PluginOption } from 'vite';// 自定義插件
type RenameHtmlPlugin = () => PluginOption;
const renameHtmlPlugin: RenameHtmlPlugin = () => {return {name: 'rename-index-html',enforce: 'post',generateBundle(_, bundle) {const currentTime = (Date.now() / 1000).toFixed(0);const newFileName = `index-${currentTime}.html`;bundle['index.html'].fileName = newFileName;},};
};export default defineConfig({// ... 其他配置plugins: [// ... 其他插件renameHtmlPlugin(),],
});
現(xiàn)在,執(zhí)行 pnpm build
構(gòu)建出來的就是 index-{時(shí)間戳}.html
啦。