vite-plugin-html
vite-plugin-html copied to clipboard
多入口的路由规则是怎样的
Vue3+Vite,按照readme
配置了index.html
和app.html
两个入口之后,访问localhost:3000/app.html
依然显示index.html
的内容,所以应该如何访问多个入口?
发现是我的配置错误,修改后可以正常访问。不过发现以下两个问题: 修改mpa目录中的vite.config.js为如下,并将index.html和other.html移动到src目录
createHtmlPlugin({
minify: true,
pages: [
{
entry: 'src/main.ts',
filename: 'index.html',
template: 'src/index.html',
injectOptions: {
data: {
title: 'index',
injectScript: `<script src="./inject.js"></script>`,
},
tags: [
{
injectTo: 'body-prepend',
tag: 'div',
attrs: {
id: 'tag1',
},
},
],
},
},
{
entry: 'src/other-main.ts',
filename: 'other.html',
template: 'src/other.html',
injectOptions: {
data: {
title: 'other page',
injectScript: `<script src="./inject.js"></script>`,
},
tags: [
{
injectTo: 'body-prepend',
tag: 'div',
attrs: {
id: 'tag2',
},
},
],
},
},
],
}),
- 必须创建filename路径指定的文件,否则无法访问
- template与filename不一致时,injectOptions失效