A Vue project has a folder setup that helps organize your code and files clearly. This makes it easier to build and maintain your app.
Vue project structure walkthrough
my-vue-project/ ├── node_modules/ ├── public/ ├── src/ │ ├── assets/ │ ├── components/ │ ├── views/ │ ├── App.vue │ ├── main.js │ └── router.js ├── index.html ├── package.json └── vite.config.js
src/ is where most of your app code lives.
public/ holds static files like favicon.ico that are served as-is without processing.
src/ ├── assets/ │ └── logo.png ├── components/ │ └── HelloWorld.vue ├── views/ │ └── HomeView.vue ├── App.vue └── main.js
index.html
package.json vite.config.js
This is a simple Vue component using the project structure. It loads an image from assets and a component from components folder.
<template>
<div>
<img alt="Vue logo" src="./assets/logo.png" />
<HelloWorld msg="Welcome to Vue!" />
</div>
</template>
<script setup>
import HelloWorld from './components/HelloWorld.vue'
</script>Keep your components small and focused for easier reuse.
Use the views folder for main pages to keep routing clear.
Public folder files are not processed by the build tool, so put only static files there.
Vue projects have a clear folder structure to organize code and assets.
src/ holds your app code, index.html is in the root, public/ holds static files.
Following this structure helps keep your app clean and easy to work on.
Practice
Solution
Step 1: Understand folder roles in Vue projects
Thesrc/folder is designed to hold your app's source code, including components and views.Step 2: Identify correct folder for main code
Thepublic/folder holds static files likeindex.html, not app code.Final Answer:
Inside thesrc/folder -> Option CQuick Check:
App code = src/ folder [OK]
- Confusing public/ with src/ folder
- Putting components in public/ folder
- Placing code in node_modules/ folder
Solution
Step 1: Identify entry point files in Vue
The entry point is usually a JavaScript or TypeScript file namedmain.jsormain.tsinsidesrc/.Step 2: Differentiate from other files
index.htmlis a static file inpublic/,package.jsonmanages dependencies, andREADME.mdis documentation.Final Answer:
main.js or main.ts insidesrc/-> Option DQuick Check:
Entry point = main.js/ts in src/ [OK]
- Choosing index.html as entry point
- Confusing package.json with entry point
- Selecting README.md as app start file
public/
index.html
src/
components/
HelloWorld.vue
App.vue
main.jsWhich file is responsible for mounting the Vue app to the HTML page?
Solution
Step 1: Understand mounting in Vue
Themain.jsfile usually creates the Vue app instance and mounts it to an element inindex.html.Step 2: Identify roles of other files
App.vueis the root component,index.htmlis the static HTML, andHelloWorld.vueis a child component.Final Answer:
main.js -> Option BQuick Check:
Mounting happens in main.js [OK]
- Thinking App.vue mounts the app
- Choosing index.html as mounting file
- Confusing child components with mounting logic
Cannot find module './components/HelloWorld.vue'What is the most likely cause related to project structure?
Solution
Step 1: Analyze the error message
The error says it cannot find the module./components/HelloWorld.vue, meaning the import path is broken.Step 2: Check folder structure relevance
If thecomponentsfolder is missing insidesrc/, the import will fail. Other options do not affect this import.Final Answer:
Thecomponentsfolder is missing insidesrc/-> Option AQuick Check:
Missing components folder breaks imports [OK]
- Ignoring folder location for components
- Thinking public/ folder affects imports
- Assuming main.js must be in root folder
Solution
Step 1: Identify best folder for global assets
Thesrc/assets/folder is used for styles and images that are part of the app source.Step 2: Include global CSS properly
Importing the CSS file inmain.jsensures it loads once and applies globally to all components.Final Answer:
Place it insrc/assets/and import it inmain.js-> Option AQuick Check:
Global CSS in src/assets, imported in main.js [OK]
- Linking CSS in App.vue instead of main.js
- Putting CSS in public/ folder without import
- Importing CSS separately in every component
Ready to prove it?
Pass the test and this pattern moves unknown
