In an Angular project, the assets folder is a directory in the project structure used to store static files. Files at the top level of the src/ directory support running the application. Subfolders within src/ contain the application source code and application-specific configuration. The assets folder can contain images, fonts, data files, and other resources (asset files) that need to be served as static files by the development server and copied as-is when you build the application.
Example of the project structure
src/
├── app/
│ ├── components/
│ ├── services/
│ ├── app.config.ts
│ └── app.routes.ts
├── assets/
│ ├── images/
│ │ └── logo.png
│ ├── data/
│ │ └── sample-data.json
│ ├── fonts/
│ │ └── custom-font.ttf
│ ├── i18n/
│ │ └── en.json
│ └── ...
├── index.html
└── styles.css
Adding assets folder
To add an assets folder to your project, you need to follow these steps:
Create assets folder
Open a terminal or command prompt and go to the root directory of the Angular project. Type the following command to create a new directory named “assets”.
mkdir src/assets
Update angular.json file
To include the newly created assets folder in your Angular project, open the angular.json file, locate the “assets” property, and append “src/assets/” to the array.
Before:
"assets": [
{
"glob": "**/*",
"input": "public"
}
],
After:
"assets": [
{
"glob": "**/*",
"input": "public"
},
"src/assets/"
],
Verify that you have applied this modification to all occurrences of the ‘assets’ property within the file.
Once you’ve made the changes to the angular.json file, you’ll need to restart the development server for the changes to take effect. To do this, stop the development server by pressing Ctrl + C in the terminal where it’s running and then restart it using the npm start command.
Test assets folder
Create an “i18n” folder within the assets directory, and inside it, create a JSON file named en.json containing the following data:
en.json (src/assets/i18n/en.json)
{ "HELLO": "Hello!" }
Stop the development server by pressing Ctrl + C in the terminal where it’s running and then restart it using the npm start command. Open your web browser and enter the following URL into the address bar:
http://localhost:4200/assets/i18n/en.json
If everything is set up correctly, you should see the contents of the en.json file displayed in the browser window.
Excellent post. I was checking constantly this blog and I am impressed!
Very helpful info particularly the last part 🙂 I care for
such info much. I was looking for this certain information for a long
time. Thank you and good luck.
Heya i’m for the first time here. I found this board and I find It truly useful & it helped me out a
lot. I hope to give something back and help others like you aided me.
Excellent beat ! I wish to apprentice while you amend your website,
how can i subscribe for a blog website? The account helped me a acceptable deal.
I had been a little bit acquainted of this your broadcast provided bright clear idea
Thanks for finally talking about > Getting Started With Angular 17: Adding an Assets Folder to Your Project < Liked it!
Hello, I enjoy reading all of your article. I wanted to write a little
comment to support you.