How to copy React JS build files to Springboot Resources folder.

Unlike angular, where you could specify your build output, reacjs does not seem to have a way to do that (to my knowledge). So I had to write a simple shell script to do the copy after the build is done.

My ReactJS project is located under: src/main/webcontent
So the build files are located under: src/main/webcontent/build

However, the static resources spring boot uses are located under src/main/resources

Here is the resources folder:

So in order for me to copy these files after the build is done, I wrote a very simple shell script. The script changes directory to webapp folder, deletes any pre-existing files by iterarting through sub folders. It then iterates and delets the subfolders themselves. Finally, it changes directory over to the folder where the built ReactJS files are located. It they issues a xCopy command to copy them over to the static folder.

cd src\main\resources\webapp
del /S /F /Q *.*
RMDIR static /Q /S
cd ..\..\webcontent\build
xcopy *.* ..\..\resources\webapp\ /s /i

cd ..\..\..\..

I put this script on a .bat file along side pom.xml. So that I can just quickly issue the command after the maven build is done (which includes auto build of reactjs). So my sequence would be:

>mvn clean package

[My Video Promotion]
Tagged , , , , . Bookmark the permalink.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.