Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/IndexXuan/vite-plugin-html-template
html template for vite, like html-webpack-plugin for webpack.
https://github.com/IndexXuan/vite-plugin-html-template
vite vite-plugin
Last synced: 15 days ago
JSON representation
html template for vite, like html-webpack-plugin for webpack.
- Host: GitHub
- URL: https://github.com/IndexXuan/vite-plugin-html-template
- Owner: IndexXuan
- Created: 2021-04-07T07:52:19.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-07-19T08:38:00.000Z (4 months ago)
- Last Synced: 2024-10-01T07:11:39.388Z (about 1 month ago)
- Topics: vite, vite-plugin
- Language: TypeScript
- Homepage:
- Size: 113 KB
- Stars: 121
- Watchers: 3
- Forks: 21
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# vite-plugin-html-template
> HTML template for vite app, like html-webpack-plugin for webpack.
> It works perfectly together with [vite-plugin-mpa](https://github.com/IndexXuan/vite-plugin-mpa).
## Motivation
- Vite needs an html entry file, which means we must have
- projectRoot/index.html for SPA
- projectRoot/src/pages/*/index.html for MPA
- Why not use html template for all entries
- Also we should support ejs/lodash.template syntax for the html content, like setting ``.## Usage
```sh
yarn add -D vite-plugin-html-template
``````ts
// vite.config.ts
import htmlTemplate from 'vite-plugin-html-template'// @see https://vitejs.dev/config/
export default defineConfig({
plugins: [
// ...other plugins
htmlTemplate(/* options */),
],
})
```## Options
- like [vue-cli#pages](https://cli.vuejs.org/config/#pages)
```ts
// 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',
},
}
```- [see more](https://github.com/IndexXuan/vite-plugin-html-template/blob/main/src/lib/options.ts)
## Underlying
- Thanks to [vite-plugin-virtual-html](https://github.com/Windson1806/vite-plugin-virtual-html)
- Thanks to [vite-plugin-vue-cli](https://github.com/IndexXuan/vite-plugin-vue-cli/blob/main/src/index.ts#L165)## Further
- [vue-cli-plugin-vite](https://github.com/IndexXuan/vue-cli-plugin-vite)
- [vite-plugin-mpa](https://github.com/IndexXuan/vite-plugin-mpa)