Skip to content

harrisoff/vite-plugin-template

Repository files navigation

VITE-PLUGIN-TEMPLATE

npm version license

A Vite plugin for modifying the entry html file.

中文文档

Installation

vite version: >=2.0.0

yarn add vite-plugin-template -D

or

npm i vite-plugin-template -D

Usage

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.

TODO

  • test

About

A Vite plugin for changing the input html template.

Topics

Resources

License

Stars

Watchers

Forks