Home > Web Front-end > JS Tutorial > Understanding Vite's File Structure: Why index.html Belongs at the Root

Understanding Vite's File Structure: Why index.html Belongs at the Root

DDD
Release: 2025-01-21 12:42:13
Original
228 people have browsed it

Understanding Vite’s File Structure: Why index.html Belongs at the Root

A common question when using Vite is the location of the index.html file. Unlike traditional build tools such as Webpack, Vite requires that your index.html be located in the project root directory, not the public directory.

What happens if index.html is located in the public directory? You will get HTTP ERROR 404 error, which indicates that the server is running but the resource cannot be found:

<code>此localhost页面找不到
找不到网页地址:http://localhost:5173/
HTTP ERROR 404</code>
Copy after login

Why does Vite need to do this?

Vite uses index.html as the entry point to optimize and package your project. Placing it in the root directory allows Vite to: • Efficiently detect and handle linked resources (e.g., JS, CSS). • Inline scripts and styles directly during development. • Provide accurate paths for module resolution.

Correct project structure

This is the expected structure of a basic Vite project:

<code>my-project/
├── index.html      // 根目录入口点
├── src/            // 源文件(组件、样式等)
│   └── main.js
├── public/         // 静态资源(Vite不处理)
│   └── favicon.ico
└── vite.config.js</code>
Copy after login

The above is the detailed content of Understanding Vite's File Structure: Why index.html Belongs at the Root. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template