I am implementing an admin panel and don't want to expose the panel's front-end code to clients. I figured the best approach would be to configure npm run build
to create two builds - one client build and one admin build. A and then the back-end would control which build gets returned based on authentication.
Possible duplicate with an answer, but doesn't actually explain how you would do that if you are not already familiar with how the build process works inside out. Also, webpack Entry Points do look like something that would be applied here, but as someone who is not very familiar with webpack the limited non beginner-friendly documentation kinda goes over my head.
Some information on my setup:
I have and ReactJS / NodeJS SPA. Front-end and back-end are configured in monorepo principle where both share node_modules
, package.json
, .env
, and so on. For that, I used react-app-rewired
to change the path for npm run build
and npm run start
commands without the need to mess with webpack.
Here is my file structure:
back-end/
...
front-end/
public/
src/
admin/ <- Would prefer the admin panel front-end to be here if possible
...
build/
...
build_admin/ <- This is what I want
...
node_modules/
...
.env
.gitignore
config-overrides.js
package.json
...
"scripts"
from package.json
:
"scripts": {
"start": "node ./back-end/server.js",
"build": "react-app-rewired build",
"front-end": "set HTTPS=true&&set SSL_CRT_FILE=...&&set SSL_KEY_FILE=...&&react-app-rewired start",
"back-end": "nodemon ./back-end/server.js",
"test": "react-app-rewired test",
"eject": "react-scripts eject"
},
So if my approach is practical - how do I set up npm run build
to make two builds from select* src/
files?
*By select I mean for the client build ignore the admin/
source files and for admin build just build with admin/
files.
Some additional points to get ahead of alternative solutions:
- I want to make the admin panel in React as a SPA so Node View Engine is not an option.
- I don't want to waste resources by spinning up a whole separate app just to run a basic admin panel and not to mention the headache of dealing with sharing data between two separate applications.
- Reason, why I am avoiding showing the admin panel front-end code in the first place, is not that there will be hard-coded sensitive data, but because you can infer quite a lot of information based on UI(input fields, description, button names, graphs, etc).