0
0
Svelteframework~10 mins

Project structure in Svelte - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Project structure
Start: Create project folder
Add src folder
Add main files: App.svelte, main.js
Add public folder for static files
Add package.json and config files
Run build or dev server
Project ready
This flow shows how a Svelte project is organized from creating folders to running the app.
Execution Sample
Svelte
my-svelte-project/
  src/
    App.svelte
    main.js
  public/
    global.css
  package.json
  svelte.config.js
This is a typical Svelte project folder structure with source code, public assets, and config files.
Execution Table
StepActionFolder/File CreatedPurpose
1Create project root foldermy-svelte-project/Holds all project files
2Create src foldersrc/Contains Svelte components and JS files
3Add App.sveltesrc/App.svelteMain Svelte component
4Add main.jssrc/main.jsEntry point to start app
5Create public folderpublic/Static files like images and CSS
6Add global.csspublic/global.cssGlobal styles for app
7Add package.jsonpackage.jsonProject dependencies and scripts
8Add svelte.config.jssvelte.config.jsSvelte build configuration
9Run dev servern/aStarts app for development
10Project readyn/aApp can be viewed in browser
💡 All necessary folders and files created, dev server running, project ready to use
Variable Tracker
Folder/FileInitialFinal
my-svelte-project/NoYes
src/NoYes
src/App.svelteNoYes
src/main.jsNoYes
public/NoYes
public/global.cssNoYes
package.jsonNoYes
svelte.config.jsNoYes
Key Moments - 3 Insights
Why do we need both src and public folders?
src holds the code that Svelte compiles, like components and scripts. public holds static files like images and CSS that don’t change during build. See steps 2 and 5 in execution_table.
What is the role of main.js in the project?
main.js is the entry point that tells Svelte where to put the app in the browser. It imports App.svelte and starts the app. See step 4 in execution_table.
Why do we have package.json in the root?
package.json manages dependencies and scripts for building and running the app. It’s essential for npm or yarn to work. See step 7 in execution_table.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, at which step is the main Svelte component created?
AStep 4
BStep 5
CStep 3
DStep 7
💡 Hint
Check the 'Folder/File Created' column for 'src/App.svelte'
According to variable_tracker, which folder is created first?
Amy-svelte-project/
Bsrc/
Cpublic/
Dpackage.json
💡 Hint
Look at the first row in variable_tracker for creation order
If we skip creating the public folder, what impact would it have?
AApp won’t start because main.js is missing
BNo static files like images or CSS will be served
CApp won’t compile
Dpackage.json will be invalid
💡 Hint
Refer to step 5 in execution_table about public folder purpose
Concept Snapshot
Svelte Project Structure:
- Root folder holds all files
- src/ contains App.svelte and main.js
- public/ holds static assets
- package.json manages dependencies
- svelte.config.js configures build
- Run dev server to start app
Full Transcript
A Svelte project starts with a root folder. Inside it, the src folder holds the main Svelte component App.svelte and the entry script main.js. The public folder stores static files like CSS and images that the app uses directly. The package.json file manages dependencies and scripts, while svelte.config.js sets build options. After creating these folders and files, running the development server launches the app in the browser. This structure keeps code and assets organized for easy development and deployment.