背景:我们使用 Thymeleaf 和 React 作为前端堆栈制作 Springboot Web 应用程序。
我们团队的当前流程有两个模块,“客户端”和“服务器”,其中在 gradle 命令“clean build”上有一个自定义任务,该任务将采用已编译的前端(index.html 和静态 js 和css)并将其适当地放在文件夹中,如下所示:
当您在 Intellij 中运行应用程序时,您可以将项目配置为使用“Gradle”或“Intellij”运行。如下图:
当您使用 gradle 运行时,您实际上并不需要复制资源文件夹,而只需将它们放在 ${buildDir} 中即可。这是默认行为,并且在大多数情况下都有效。如果有人选择了“使用 Intellij 运行”,那么我们需要添加一个额外的复制任务,以便将编译的前端代码放入活动目录中。 (不确定那里的行话)
目标:找到一种运行应用程序的方法,无论您如何运行应用程序,都不需要在静态和模板文件夹中构建资源。
task copyClient(dependsOn: ":client:clientBuild") {
doLast {
//For Running with Gradle
copy {
from new File(project(":client").getProjectDir(), "build")
into "${buildDir}/resources/main/static"
}
//For Running with Intellij
copy {
from new File(project(":client").getProjectDir(), "build/index.html")
into "src/main/resources/static"
}
}
}