2

I created new project in VS - ASP.NET Core Web Application. I used Core 3.1 + React.js and Redux template. When I run this project in ISS Express (Debug/Release) I am able to see all individual files from src in DevTools. I am doing something wrong? I thought that src files shouldn't be visible. Do I need to set some parameters or something like that? I try to also publish and deploy this on real IIS and result is basically the same.. I can see all from src folder.

Thank You!

Visual Studio 16.5.1 DevTools HostedFiles+DevTools DevTools3

1 Answers1

1

On localhost: This behavior of displaying source files in DevTools is probably just a feature of DevTools to make debugging easier in this tool. DevTools can detect it is running from localhost and find the location from where the web is running. That is why it can find the source files (ts, tsx, or jsx files).

When published: The published application does not contain source files anymore (ts, tsx, jsx). These source files are compiled into distribution js files in the ClientApp/build folder. The file structure in the picture was created by the browser based on javascript source map files (.map files). One solution would be to remove the source map files, but it is ok to leave them there, some arguments for it are in this post:

Source maps files in production - Is it safe?

There are two related lines of code in Startup.cs that configure static files handling.

1) UseStaticFiles - Serve files inside of web root (wwwroot folder).

app.UseStaticFiles();

2) UseSpaStaticFiles - Serve static file like image, css, js in asset folder of angular app

app.UseSpaStaticFiles();

Note. The folder wwwroot is not created by default when a new project is created from the React.js and Redux template. It can be added into the project and then it serves static files it contains.

Martin Staufcik
  • 5,801
  • 4
  • 32
  • 46
  • Hi @Martin Staufcik But now everyone can go through my components in DevTools when I deploy my production app? – Pavol Priezvisko Apr 25 '20 at 07:38
  • DevTools can probably detect it is running from localhost and find the location from where the web is running. This will not happen on for a site deployed to web server. – Martin Staufcik Apr 25 '20 at 07:43
  • But I also tried to publish production build app on real host server. In my ClientApp there is only build folder with generated files (without my visible components). But I can still find all components in DevTools even when it is normally hosted. Am I doing something wrong? – Pavol Priezvisko Apr 25 '20 at 07:54
  • When the app is published, the `ClientApp` folder contains a `build` folder with the compiled distribution files (javascript, css), there are no source files anymore. – Martin Staufcik Apr 25 '20 at 08:00
  • Exactly! However.. I took whole published .net core app (without source files in ClientApp) I push it to my hosting FTP and I still can see my components in DevTools .. that is what make me crazy – Pavol Priezvisko Apr 25 '20 at 08:05
  • Have you checked that there are no other files on your hosting FTP than those created by publishing the app? I mean, some files left from the past. – Martin Staufcik Apr 25 '20 at 08:09
  • Yes I checked it.. there are no such files =/ – Pavol Priezvisko Apr 25 '20 at 08:15
  • Could you post a picture what it looks like now when published in DevTools please? – Martin Staufcik Apr 25 '20 at 08:19
  • I just edited my questing with picture of FTP files + DevTools. – Pavol Priezvisko Apr 25 '20 at 08:24
  • Btw it is different site created also from template. I just use clear template in question for simplicity – Pavol Priezvisko Apr 25 '20 at 08:26
  • DevTools may use information from the `.map` files. What if you tried to delete the source maps (temporarily)? – Martin Staufcik Apr 25 '20 at 08:37
  • Now it has bunch of another components.. but it seems my are not longer there (another picture in question). Ok so what is and answer here? I need to delete .map files before publishing? I don't think this is the right approach. – Pavol Priezvisko Apr 25 '20 at 08:50
  • From this post: https://stackoverflow.com/questions/27345520/source-maps-files-in-production-is-it-safe: it gives some insights. It gives some arguments why it is ok to have source maps files in production. – Martin Staufcik Apr 25 '20 at 08:58
  • Thank you very much! You really helped me. Can you write this (about information from .map) as separate answer so I could accept is as right answer? – Pavol Priezvisko Apr 25 '20 at 09:01