admin管理员组文章数量:1435859
I have a multi page app that I'm trying to build with Vite.js
(migrating from Webpack
). When building the Vite + React example code I see that it emits:
dist/index.html
dist/assets/<various assets>
However, when I try to make a multi page app as shown in the docs none of the HTMLs are emitted (but the rest of the content of /assets/
is there). Why is this?
// vite.config.js excerpt:
import { defineConfig } from 'vite'
import { dirname } from 'path';
import { fileURLToPath } from 'url';
export default defineConfig({
root: 'client',
build: {
outDir: 'dist',
rollupOptions: {
input: {
main: dirname(fileURLToPath(import.meta.url + 'index.html')),
login: dirname(fileURLToPath(import.meta.url + 'login.html')),
}
}
},
});
I have a multi page app that I'm trying to build with Vite.js
(migrating from Webpack
). When building the Vite + React example code I see that it emits:
dist/index.html
dist/assets/<various assets>
However, when I try to make a multi page app as shown in the docs none of the HTMLs are emitted (but the rest of the content of /assets/
is there). Why is this?
// vite.config.js excerpt:
import { defineConfig } from 'vite'
import { dirname } from 'path';
import { fileURLToPath } from 'url';
export default defineConfig({
root: 'client',
build: {
outDir: 'dist',
rollupOptions: {
input: {
main: dirname(fileURLToPath(import.meta.url + 'index.html')),
login: dirname(fileURLToPath(import.meta.url + 'login.html')),
}
}
},
});
Share
Improve this question
asked Aug 15, 2021 at 19:44
Michael JohansenMichael Johansen
5,1367 gold badges33 silver badges51 bronze badges
4
-
remove
dirname
which is removing the filename only directory names will be left out. – Chandan Commented Aug 18, 2021 at 6:07 -
@Chandan If I remove dirname I get an error during
vite build
that saysSyntaxError: Assigning to rvalue
. – Michael Johansen Commented Aug 19, 2021 at 17:29 -
try
new URL(
./index.html, import.meta.url)
as specified in the vite doc. – Chandan Commented Aug 20, 2021 at 3:30 -
Your suggestion worked @Chandan ! Put it in an answer and I'll accept it.
main: new URL('./client/index.html', import.meta.url).pathname,
– Michael Johansen Commented Aug 21, 2021 at 20:18
1 Answer
Reset to default 4 +150Try using the URL
for file input as specified in vite doc
main: new URL('./client/index.html', import.meta.url).pathname
本文标签: javascriptVitejs not emitting HTML files in multi page appStack Overflow
版权声明:本文标题:javascript - Vite.js not emitting HTML files in multi page app - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745667082a2669349.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论