We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
一个偶然的机会,我在开发一个使用Vite搭建的多页面应用项目时,使用了下面这样的配置:
export default defineConfig({ build: { rollupOptions: { input: { index: 'index.html', 'pageA/index': 'src/pages/pageA/index.html', 'pageB/index': 'src/pages/pageB/index.html', } } } })
(为了说明问题,我简化了不必要的配置项) 该项目使用vite server 命令运行时,一切正常,页面表现也如预期。 而当我使用vite buiild 命令构建时,构建过程正常, 但构建产物中的*/index.html等文件,丢失了本应该有的 script type='module' js文件引入, 而这些js文件实际已经被构建到dist/asset目录下。 经过几个小时的各种测试与分析,最终发现,正确的配置应当如下:
vite server
vite buiild
*/index.html
script type='module'
dist/asset
import nodePath from 'node:path' export default defineConfig({ build: { rollupOptions: { input: { index: 'index.html', 'pageA/index': nodePath.resolve(__dirname, 'src/pages/pageA/index.html'), 'pageB/index': nodePath.resolve(__dirname, 'src/pages/pageB/index.html') } } } })
我认为这并非vitejs的一个bug,但是vitejs这么受前端开发者喜爱的工具,是否可以考虑对此进行一些有益的改进与优化?这应当会给vite的初学者解决掉一个难解的困惑, 也会让vite更符合文档中宣称的:"这确保了与开发服务器的工作方式保持一致的结构。". 非常感谢!
[建议] 建议在 vite build命令中,对于多页面应用(mpa),对于使用了相对路径作为入口文件的配置,给予必要的控制台警告或者 强制报错。
No response
The content you are editing has changed. Please copy your edits and refresh the page.
The text was updated successfully, but these errors were encountered:
Duplicate of #15992
Sorry, something went wrong.
v5.2.11
不过,我建议官方能在文档上进行一些必要说明,以避免一些未能及时更新新版vite的项目出现错误。
No branches or pull requests
Description
遇到的问题
一个偶然的机会,我在开发一个使用Vite搭建的多页面应用项目时,使用了下面这样的配置:
(为了说明问题,我简化了不必要的配置项)
该项目使用
vite server
命令运行时,一切正常,页面表现也如预期。而当我使用
vite buiild
命令构建时,构建过程正常, 但构建产物中的*/index.html
等文件,丢失了本应该有的script type='module'
js文件引入, 而这些js文件实际已经被构建到dist/asset
目录下。经过几个小时的各种测试与分析,最终发现,正确的配置应当如下:
正确配置
结论
我认为这并非vitejs的一个bug,但是vitejs这么受前端开发者喜爱的工具,是否可以考虑对此进行一些有益的改进与优化?这应当会给vite的初学者解决掉一个难解的困惑, 也会让vite更符合文档中宣称的:"这确保了与开发服务器的工作方式保持一致的结构。".
非常感谢!
Suggested solution
[建议]
建议在 vite build命令中,对于多页面应用(mpa),对于使用了相对路径作为入口文件的配置,给予必要的控制台警告或者 强制报错。
Alternative
No response
Additional context
No response
Validations
Tasks
The text was updated successfully, but these errors were encountered: