From b9a85a521f5cb55fa68a78059f87501e1c24a188 Mon Sep 17 00:00:00 2001 From: Burt <1020103647@qq.com> Date: Mon, 15 Jan 2024 11:17:55 +0800 Subject: [PATCH] =?UTF-8?q?refactor(vite):=20htmlPlugin=20=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE=E7=A7=BB=E5=8A=A8=E5=88=B0vite=E5=86=85=E9=83=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vite.config.ts | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/vite.config.ts b/vite.config.ts index 807df21..53003a1 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -26,14 +26,6 @@ import ViteRestart from 'vite-plugin-restart' import { visualizer } from 'rollup-plugin-visualizer' // import viteImagemin from 'vite-plugin-imagemin' -const htmlPlugin = () => { - return { - name: 'html-transform', - transformIndexHtml(html) { - return html.replace('%BUILD_DATE%', dayjs().format('YYYY-MM-DD HH:mm:ss')) - }, - } -} // https://vitejs.dev/config/ export default ({ command, mode }) => { console.log(mode === process.env.NODE_ENV) @@ -79,7 +71,13 @@ export default ({ command, mode }) => { // 通过这个插件,在修改vite.config.js文件则不需要重新运行也生效配置 restart: ['vite.config.js'], }), - process.env.UNI_PLATFORM === 'h5' && htmlPlugin(), + // h5环境增加编译时间 + process.env.UNI_PLATFORM === 'h5' && { + name: 'html-transform', + transformIndexHtml(html) { + return html.replace('%BUILD_DATE%', dayjs().format('YYYY-MM-DD HH:mm:ss')) + }, + }, // 打包分析插件 mode === 'production' && visualizer({