출처: https://velog.io/@cho876/SpringBoot-프로젝트-안에-React-프로젝트-넣기
./gradlew build
java -jar demo-0.0.1-SNAPSHOT.jar

Spring boot 프로젝트 내부에 React 프로젝트 넣기
/src/main/webapp/react프로젝트
webapp신규폴더를 생성하고 하위에 CRA를 활용해 react프로젝트 생성

react와 spring을 동시에 빌드하기 위해
/buld.gradle 코드에 아래 코드 추가
def reactDir = "$projectDir/src/main/webapp/react프로젝트명";
sourceSets{
main{
resources{
srcDirs = ["$projectDir/src/main/resources"]
}
}
}
processResources{
dependsOn "copyReactBuildFiles"
}
task installReact(type:Exec){
workingDir "$reactDir"
inputs.dir "$reactDir"
group = BasePlugin.BUILD_GROUP
if(System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows')){
commandLine "npm.cmd", "audit", "fix"
commandLine 'npm.cmd', 'install'
}else{
commandLine "npm", "audit", "fix"
commandLine 'npm', 'install'
}
}
task buildReact(type:Exec){
dependsOn "installReact"
workingDir "$reactDir"
inputs.dir "$reactDir"
group = BasePlugin.BUILD_GROUP
if(System.getProperty('os.name').toLowerCase(Locale.ROOT).contains('windows')){
commandLine "npm.cmd", "run-script", "build"
}else{
commandLine "npm", "run-script", "build"
}
}
task copyReactBuildFiles(type:Copy){
dependsOn "buildReact"
from "$reactDir/build"
into "$projectDir/src/main/resources/static"
}
이후 아래 코드로 jar파일 빌드하기
./gradlew build
/build/libs 에 있는demo-0.0.1-SNAPSHOT.jar 파일을 아래 코드로실행
java -jar demo-0.0.1-SNAPSHOT.jar