假设index.html需要使用titiel 可以写 <%= title %>
然后再vite.config.js中使用 createHtmlPlugin 来实现;
import {createHtmlPlugin} from 'vite-plugin-html';
//在plugins中使用createHtmlPlugin来创建一个模板变量
plugins: [vue(), createHtmlPlugin({
inject: {
data: {
title:"Mtab书签",
},
},
})],
//在idnex.html中使用
<title><%= title %></title>
打包的时候会将<%= title %>替换为Mtab书签
一般适合vue打包后将index.html用其他的程序模板渲染一些seo信息的用途。
本文介绍了如何在Vue项目中使用Vite的createHtmlPlugin插件,实现在index.html文件中动态插入由vite.config.js定义的SEO信息,如<title>标签内容,适用于vue打包后的模板渲染需求。
703





