vite-plugin-htmladdtags
v1.0.4
Published
a vite plugin for add tags in index.html
Downloads
10
Readme
This plugin helps us add tags into html
Install
node version: >=12.0.0
vite version: >=2.0.0
npm i -D vite-plugin-htmladdtags
Usage
// vite.config.js
import addHtmlTagsPlugin from 'vite-plugin-addhtmltags';
export default ({ command, mode }) => {
return {
plugins: [
addHtmlTagsPlugin({
addTags:
process.env.APP_ENV === "test"
? [
// test环境在head前插入js
{
tag: "script",
attrs: {
src: "http://www.src.js",
},
injectTo: "head",
},
]
: [
// 其它环境在head前插入
{
tag: "script",
attrs: {
src: "http://www.src2.js",
},
injectTo: "head",
},
{
tag: "css",
attrs: {
src: "http://www.src.css",
},
injectTo: "head",
},
],
}),
],
};
};
api
addHtmlTagsPlugin(options:{
addTags:HtmlTagDescriptor[]
})
interface HtmlTagDescriptor {
tag: string
attrs?: Record<string, string>
children?: string | HtmlTagDescriptor[]
/**
* 默认: 'head-prepend'
*/
injectTo?: 'head' | 'body' | 'head-prepend' | 'body-prepend'
}