Home

Awesome

vite-plugin-html-template

HTML template for vite app, like html-webpack-plugin for webpack.

It works perfectly together with vite-plugin-mpa.

<p align="center"> <img alt="wakatime" src="https://wakatime.com/badge/github/IndexXuan/vite-plugin-html-template.svg" /> <a href="https://github.com/IndexXuan/vite-plugin-html-template/actions/workflows/npm-publish.yml"> <img alt="NPM Publish" src="https://github.com/IndexXuan/vite-plugin-html-template/actions/workflows/npm-publish.yml/badge.svg" style="max-width:100%;"> </a> <a href="https://www.npmjs.com/package/vite-plugin-html-template" rel="nofollow"> <img alt="downloads" src="https://img.shields.io/npm/dt/vite-plugin-html-template.svg"> </a> <a href="https://www.npmjs.com/package/vite-plugin-html-template" rel="nofollow"> <img alt="npm version" src="https://img.shields.io/npm/v/vite-plugin-html-template.svg" style="max-width:100%;"> </a> <a href="https://github.com/IndexXuan/vite-plugin-html-template/blob/main/LICENSE"> <img alt="License: MIT" src="https://img.shields.io/badge/License-MIT-yellow.svg" style="max-width:100%;"> </a> </p>

Motivation

Usage

yarn add -D vite-plugin-html-template
// vite.config.ts
import htmlTemplate from 'vite-plugin-html-template'

// @see https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    // ...other plugins
    htmlTemplate(/* options */),
  ],
})

Options

// for SPA, there is nothing to do, just use `public/index.html` as template

// for MPA, customise the template path (default is `public/index.html`) and page title:
{
  // where is the pages' root directory?
  pagesDir: 'src/pages',
  // define pages like it is done in vue-cli
  pages: {
    index: {
      template: './public/index.html',
      title: 'Homepage',
    },
    subpage: {
      template: './src/pages/subpage/index.html',
      title: 'Subpage',
    },
  },
  // expose to template
  data: {
    title: 'Homepage',
  },
}

Underlying

Further