VSCode - Spring Boot & React, 2022-11-18

sunj - Nov 18 '22 - - Dev Community

Image description

java : 11.0.15.1
spring boot : 2.7.4
nodejs : 16.17.1

spring boot 프로젝트 생성
https://dev.to/yesjin/visual-studio-code-spring-boot-2022-11-16-45l3

cd src/main
npx create-react-app frontend   # npx create-reeact {프로젝트명}

Enter fullscreen mode Exit fullscreen mode
cd src/main/{프로젝트명}
npm install http-proxy-middleware --save
Enter fullscreen mode Exit fullscreen mode

프론트엔드 - src/main/{프로젝트명}/package.json

"proxy": "http://localhost:8080"
Enter fullscreen mode Exit fullscreen mode

백엔드 - build.gradle

def webappDir = "$projectDir/src/main/frontend"

sourceSets {
    main {
        resources {
            srcDirs = ["$webappDir/build", "$projectDir/src/main/resources"]
        }
    }
}

processResources {
    dependsOn "copyWebApp"
}


task copyWebApp(type: Copy) {
    dependsOn "buildReact"
    from "$webappDir/build"
    into "$projectDir/src/main/resources/static"
}


task buildReact(type: Exec) {
    dependsOn "installReact"
    workingDir "$webappDir"
    inputs.dir "$webappDir"
    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 installReact(type: Exec) {
    workingDir "$webappDir"
    inputs.dir "$webappDir"
    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'
    }
}
Enter fullscreen mode Exit fullscreen mode
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player