Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Froedrick's avatar

How to build and deploy React app without exposing raw source files

I added the line : "build": "GENERATE_SOURCEMAP=false react-scripts build", to my package.json file but when I build and deploy clearing cache, DigitalOcean still serves the entire project folder. How would you deploy a react app minified without exposing your raw source files?

0 likes
14 replies
Sinnbeck's avatar

I'm unsure what you mean. How are the source files available?

Sinnbeck's avatar

@Froedrick ah I thought it was a react app inside of laravel. Either move your index file to a subdirectory and point your web server to it. Or you can set your webserver to deny access to those folders. What web server are you using?

Froedrick's avatar

@Sinnbeck from what I gather, DigitalOcean uses Nginx. Their questions section has many Nginx questions, a popular questions link regarding Nginx and absolutely no mention of Apache

Sinnbeck's avatar

@Froedrick then in your nginx config file you can deny certain folders

For example

server {
    location ^~ /src/ {
        deny all;
        return 403;
    }
    ...
} 
1 like
Sinnbeck's avatar

@Froedrick but as stated by both @martinbean and me, the recommended practice is moving your public code to a public folder, inside the project, and just change the root inside that nginx config file:)

root /current/path/public; //so just add public here and restart nginx 
1 like
martinbean's avatar

@froedrick You should only be serving a public folder and not your source folder. If you publish your source folder to a publicly-accessible location then yes, it will be publicly accessible.

Froedrick's avatar

@martinbean My source folder is separated from the public folder. This is a standard ReactJS folder structure. I have the project uploaded to Github. Then I use DigitalOcean's instructions to link my Github master branch to my app account and DigitalOcean builds and deploys with one click. I figured this would not be a problem.

https://imgur.com/gallery/Svjnji7

Please or to participate in this conversation.