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)
}
'Spring Boot' 카테고리의 다른 글
Spring servlet container 이미지 (0) | 2021.09.02 |
---|---|
[SpringBoot] DateTime Format (0) | 2021.06.11 |
ehCache 설정하기 (0) | 2019.08.29 |
Spring Boot + Logback 설정 (0) | 2019.06.20 |
Spring Boot + Apache 연동 (0) | 2019.06.17 |