A Vite plugin for modifying the entry html file.
vite version: >=2.0.0
yarn add vite-plugin-template -D
or
npm i vite-plugin-template -D
Assuming you need index.dev.html
or index.prod.html
for different environments.
// vite.config.js
import { defineConfig } from 'vite'
import template from 'vite-plugin-template'
export default ({ mode }) => {
// https://github.com/vitejs/vite/issues/1930#issuecomment-783747858
const isProd = mode === 'production'
return defineConfig({
plugins: [
template({
template: isProd ? 'index.prod.html' : 'index.dev.html'
}),
// other plugins
]
})
}
NOTE THAT there must be an index.html
in the root directory to make sure Vite works properly, though this file will not actually be used.
- test