11# vite-plugin-html
22
3- A simple vite plugin. It is developed based on lodash template
3+ ** English ** | [ 中文 ] ( ./README.zh_CN.md )
44
5- ## Getting Started
5+ [ ![ npm] [ npm-img ]] [ npm-url ] [ ![ node] [ node-img ]] [ node-url ]
6+
7+ A vite plugin for processing html. It is developed based on lodash template
68
79### Install (yarn or npm)
810
911** node version:** >=12.0.0
1012
11- ** vite version:** >=2.0.0-beta.3
13+ ** vite version:** >=2.0.0-beta.4
14+
15+ ` yarn add vite-plugin-html@next -D ` or ` npm i vite-plugin-html@next -D `
1216
13- ` yarn add vite-plugin-html -D ` or ` npm i vite-plugin-html -D `
17+ ### Example
1418
1519** Run Example**
1620
@@ -29,21 +33,35 @@ yarn serve
2933- Config plugin in vite.config.ts
3034
3135``` ts
32- import VitePluginHtml from ' vite-plugin-html' ;
33-
34- export default {
35- plugins: [
36- VitePluginHtml ({
37- title: ' Vite App' ,
38- minify: process .env .NODE_ENV === ' production' ,
39- options: {
40- injectConfig: ' <script src="./a.js"></script>' ,
41- },
42- }),
43- ],
36+ import { UserConfigExport , ConfigEnv } from ' vite' ;
37+ import vue from ' @vitejs/plugin-vue' ;
38+
39+ import html from ' vite-plugin-html' ;
40+
41+ export default ({ command , mode }: ConfigEnv ): UserConfigExport => {
42+ return {
43+ plugins: [
44+ vue (),
45+ html ({
46+ title: ' Vite App' ,
47+ minify: command === ' build' ,
48+ options: {
49+ injectConfig: ' <script src="./a.js"></script>' ,
50+ },
51+ tags: [
52+ {
53+ tag: ' div' ,
54+ attrs: {
55+ src: ' ./' ,
56+ },
57+ children: ' content' ,
58+ injectTo: ' body' ,
59+ },
60+ ],
61+ }),
62+ ],
63+ };
4464};
45-
46- // plugins: [VitePluginHtml(Options)],
4765```
4866
4967### Options Description
@@ -52,15 +70,15 @@ export default {
5270
5371type: ` string `
5472
55- default:''
73+ default: ''
5674
5775description: The content of the title tag of the index.html tag
5876
5977** minify**
6078
6179type: ` boolean|Options ` , [ Options] ( https://github.com/terser/html-minifier-terser#options-quick-reference )
6280
63- default: ` isBuild?true:false ` .
81+ default: ` command === 'build' ` .
6482
6583If it is an object type,Default:
6684
@@ -78,7 +96,7 @@ description: html compression configuration
7896
7997** options**
8098
81- type: ` {[key: string]: any} ` ,
99+ type: ` Record< string, any> ` ,
82100
83101default: ` {} `
84102
@@ -109,17 +127,23 @@ e.g
109127** vite.config.ts**
110128
111129``` ts
112- import VitePluginHtml from ' vite-plugin-html' ;
113-
114- export default {
115- plugins: [
116- VitePluginHtml ({
117- options: {
118- opt1: ' <script src="./a.js"></script>' ,
119- opt2: ' <script src="./a.js"></script>' ,
120- },
121- }),
122- ],
130+ import { UserConfigExport , ConfigEnv } from ' vite' ;
131+ import vue from ' @vitejs/plugin-vue' ;
132+
133+ import html from ' vite-plugin-html' ;
134+
135+ export default ({ command , mode }: ConfigEnv ): UserConfigExport => {
136+ return {
137+ plugins: [
138+ vue (),
139+ html ({
140+ options: {
141+ opt1: ' <script src="./a.js"></script>' ,
142+ opt2: ' <script src="./a.js"></script>' ,
143+ },
144+ }),
145+ ],
146+ };
123147};
124148```
125149
@@ -140,3 +164,8 @@ export default {
140164## License
141165
142166MIT
167+
168+ [ npm-img ] : https://img.shields.io/npm/v/vite-plugin-html.svg
169+ [ npm-url ] : https://npmjs.com/package/vite-plugin-html
170+ [ node-img ] : https://img.shields.io/node/v/vite-plugin-html.svg
171+ [ node-url ] : https://nodejs.org/en/about/releases/
0 commit comments