Vite 不怎么优雅但能用的多页面方式

在根目录下创建多页面入口 xxx.html:

1
2
3
4
5
6
7
8
9
10
11
12
<!DOCTYPE HTML>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>title</title>
</head>
<body style="margin: 0;">
<div id="root"></div>
<script type="module" src="/src/pages/xxx/main.jsx"></script>
</body>
</html>

vite.config.js 中配置解析(需要安装 vite-plugin-html)。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import { createHtmlPlugin } from 'vite-plugin-html'
import { resolve } from 'path'

// https://vitejs.dev/config/
export default defineConfig({
plugins: [
react(),
createHtmlPlugin({
minify: true,
pages: [{
entry: 'src/pages//login/main.jsx',
template: 'login.html',
filename: 'login.html'
}, {
entry: 'src/pages//panel/main.jsx',
template: 'panel.html',
filename: 'panel.html'
}, {
entry: 'src/pages//index/main.jsx',
template: 'index.html',
filename: 'index.html'
},
]
})
],
root: '.',
build: {
rollupOptions: {
input: {
index: 'index.html',
login: 'login.html',
panel: 'panel.html',
},
output: {
chunkFileNames: 'static/js/[name]-[hash].js',
entryFileNames: 'static/js/[name]-[hash].js',
assetFileNames: 'static/[ext]/[name]-[hash].[ext]',
}
},
}
})

Vite 不怎么优雅但能用的多页面方式

https://omn.cc/archives/62.html

作者

空指针

发布于

2024-02-10

更新于

2024-02-10

许可协议

You need to set install_url to use ShareThis. Please set it in _config.yml.
You forgot to set the business or currency_code for Paypal. Please set it in _config.yml.

评论

You forgot to set the shortname for Disqus. Please set it in _config.yml.
Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×