Vue Project Structure
When you create a new project using the official scaffolding create-vue, you'll get a clearly structured folder and file layout. Understanding this structure is crucial for subsequent development. Below is an explanation of the structure of a typical Vue 3 project:
Detailed Explanation of Key Files and Directories
-
index.htmlThis is the "shell" of your single-page application. It's a simple HTML file containing a<div id="app"></div>. The entire Vue application is eventually mounted to this DOM element. Vite automatically inserts the bundled CSS and JS files into this file during the build. -
src/This is the directory where you'll spend most of your time working, containing all the application's source code. -
src/main.js(ormain.ts) This is the entry point of the entire application. Its main roles are:- Import the
createAppfunction from Vue. - Import the root component
App.vue. - Create a Vue application instance and mount the root component to the
<div id="app">element inindex.html.
- Import the
-
src/App.vueThis is the application's root component. You can think of it as the container for all other components. The page views and main layout of the application are defined in this file. -
src/components/This directory is used to store all reusable child components. For example, you can create aButton.vueorNavbar.vuecomponent and reuse them in different places of the application. Component-based development is the core philosophy of Vue development. -
src/assets/This directory is used to store static resources that need to be processed by Vite during bundling, such as CSS files, Sass files, images, etc. When you reference a resource here, Vite will optimize and process it during the build. -
public/This directory is used to store static resources that do not need to be processed by bundling and need to be copied unchanged to the root directory of the build output. For example,robots.txtor some third-party library files that must maintain specific names or paths. -
package.jsonThe manifest file for Node.js projects. It defines the project's name, version, and most importantly—the project's dependencies (dependenciesanddevDependencies) and scripts that can be run (scripts, such asdev,build). -
vite.config.js(orvite.config.ts) This is the configuration file for the build tool Vite. You can configure plugins, define proxies, modify build options, etc. here.