Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Whats the default path for static files in Angular2?

I'm currently working on a small Angular2 project. In my case i have to reroute some of the requests (like "/faq", "/aboutus") back to my old backend server to get some server side rendered thymeleaf templates. Therefore i'm using the built in proxy to reroute to my backende server. Sadly for some weird reason it only servers the html files without any scripts and styles or images. (i used the angular-cli to create my project structure)

Thats why i wanted to add these static files into my angular2 folder but i can't find the correct place to make it available to my application. Does anyone else know how to correctly place these file inside the project structure ?

Thanks in advance for any help

like image 806
Lucca Avatar asked Nov 04 '16 14:11

Lucca


People also ask

Where are static files stored?

Static files are stored within the project's web root directory. The default directory is {content root}/wwwroot , but it can be changed with the UseWebRoot method. For more information, see Content root and Web root.

What are static files in ASP net core?

Static files like JavaScript files, images, CSS files that we have on the file system are the assets that ASP.NET Core application can serve directly to clients. Static files are typically located in the web root (wwwroot) folder.

What are static files?

What Are Static Files? Static files are files that don't change when your application is running. These files do a lot to improve your application, but they aren't dynamically generated by your Python web server like a usual HTML response.

Is an Angular App static?

Both React and Angular 2/4 compile to static code. Most of the time, the development build is served using some sort of build tool like webpack, but at the end of the day, your front end application can be served from a static location, like an S3 bucket.


1 Answers

According to the current angular-cli readme (v1.0.1):

You use the assets array in angular-cli.json to list files or folders you want to copy as-is when building your project:

"assets": [   "assets",   "favicon.ico" ] 

By default the assets folder is configured for this, so you can place your files into a structure like

├── src .   ├── assets .   .   ├── file1.txt .   .   ├── img     .   │   └── image1.png         └── css 

and serve them from url path /img/image1.png etc.

If you're not happy with the default option, add a folder name of your choice to angular-cli.json, i.e.

"assets": [   "static",   ... ] 

Create the ./src/static/ folder for your files and serve analogously to the default.

like image 157
mrkvon Avatar answered Oct 17 '22 02:10

mrkvon