This is folder's structure of my project.
project_frontend /
app/
package.json
project_backend/
api/
static/
index.html
So I launch npm run build
from project_frontend and I need to put build files into project_backend. Also I don't need to put into there files like "manifest.json", "asset-manifest.json".
Thanks.
In your package.json
you have:
"scripts": {
"build": "react-scripts build"
You can add another script called postbuild
that does something after the build and will be called by npm/Yarn automatically.
"postbuild": "mv build ../project_backend/"
You could also run a custom script that does more.
"postbuild": "node postbuild.js"
Hope this helps!
i don't think this is a valid solution because it assumes that the build
directory is not being used by some other service. For example, i have backend code that compiles to a build
directory, then this would also affect those files as well.
True, a proper separation of concerns here would be the right move, making each their own codebase and repository, but would definitely like to see an option to set a build-dir option in react scripts
I found a way to get it to work. I was facing the same issue of moving my react build to ../public folder, since I am writing a test application and using node back end. You can run the npm run eject
to get all the webpack files. then change the ./config/path.js file to update appBuild: resolveApp('../public'),
Hope that helps
@sairathb I wouldn't eject just for this, losing the ability to update.
I absolutely agree with you @pasichnyk , I have the same issues I always ejecting my react.js projects for changing the build path or adding one or two plugins to my webpack and I lose the ability to update my scripts.
I hope that react team @gaearon takes into consideration this problem and try to find
a good solution for us" React.js users" to add configurations to env or webpack without ejecting and losing the ability of updates, it's can help us a lot, for example creating new open source project that depends on create-react-app.
tanks you react team for hooks :D
Most helpful comment
In your
package.json
you have:You can add another script called
postbuild
that does something after the build and will be called by npm/Yarn automatically.You could also run a custom script that does more.
Hope this helps!