最近有多页面项目需要重构,就想试试使用vite,但是网上很多方法不太全面踩了不少的坑,
网上的多页面配置方案也不少,我只给出了我成功配置并在使用的方案
目录结构
{
dist: // 存放打包后的文件,
node_modules: ,
src: {
assets: // 一些静态文件,
components: // 公用组件,
index: { // 页面1
index.html,
main.js,
App.vue,
...
},
page: { // 页面2
index.html,
main.js,
App.vue,
...
},
...
index.html // 用于页面初始进入时重定向
},
package.json: ,
vite.config.js: // 配置文件
}
Tips
:在src
中放一个index.html
是为了编译或打包后,输入localhost:3000/
能够直接跳转到需要展示的页面,而不是出现文件目录或空白页面,对应代码为:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>vite多页面</title>
</head>
<body>
<script>
window.location.href = 'index/index.html' // 需要重定向的页面
</script>
</body>
</html>
多页面使用时,vite配置项中注意点
-
修改