Spring Boot
springboot + gradle + front-end npm build
SO-BBANG
2022. 3. 16. 11:06
spec : vue-cli3
spring boot + npm 으로 front 관련 라이브러리 관리
plugins {
id 'com.github.node-gradle.node' version '3.2.1'
}
repositories {
mavenCentral()
maven { url "https://plugins.gradle.org/m2"}
}
/* 관련 node 정보 */
node {
download = false
version = "16.14.0"
npmVersion = ""
yarnVersion = ""
npmInstallCommand = "install"
npmWorkDir = file("${project.projectDir}/.gradle/npm")
yarnWorkDir = file("${project.projectDir}/.gradle/yarn")
nodeModulesDir = file(프론트디렉토리경로)
}
/* 프론트 dist 폴더 삭제, 백엔드 static 폴더 삭제 및 재생성 */
task cleanDistAndStatic(type: Delete) {
doFirst {
delete "${project.projectDir}/src/main/resources/static/"
delete "프론트디렉토리경로/dist/"
}
doLast {
File dir = new File("${project.projectDir}/src/main/resources/static/")
dir.mkdir()
}
}
/* 프론트 빌드 */
task npmBuild(type: NpmTask) {
dependsOn cleanDistAndStatic
dependsOn npmInstall
args = ['run', "build"]
}
/* dist 하위 파일을 static 폴더에 복사 */
task copyDistToStatic(type: Copy) {
from("프론트디렉토리경로/dist/")
into("${project.projectDir}/src/main/resources/static/")
includeEmptyDirs = true
}
/* build 실행시 jar 파일만들때 먼저 프론트 빌드관련 task 실행 */
bootJar {
archiveFileName = "app.jar"
dependsOn(npmBuild)
dependsOn(copyDistToStatic)
}