如何为容器使用不同的Web应用程序资源:SBT中的启动和打包任务 [英] How to have different webapp resources for container:start and package tasks in SBT

查看:143
本文介绍了如何为容器使用不同的Web应用程序资源:SBT中的启动和打包任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有纯JS前端和Scala后端的Web应用程序.我想在构建管道中使用Grunt来处理 src/main/webapp 到目标 dist/webapp 目录中,该目录具有串联/缩小的js和html文件,已编译的sass表等我还想保留原始的JS和HTML文件,以便使用container:start任务进行本地测试,而package任务将使用Grunt处理的资源来构建我的WAR文件. 当我在SBT中使用以下设置时:

I have a web application with pure JS frontend and Scala backend. I would like to use Grunt in my build pipeline to process src/main/webapp into target dist/webapp dir with concatenated/minified js and html files, compiled sass sheets etc. I also want to preserve original JS and HTML files for local testing using container:start task, while the package task would build my WAR file with resources processed by Grunt. When I use following setting in SBT:

webappResources in编译<< = baseDirectory {bd => Seq(bd/"dist"/"webapp")}

webappResources in Compile <<= baseDirectory { bd => Seq(bd / "dist" / "webapp") }

然后我实现了第二个目标-我的WAR是使用 dist/webapp 中的webapp资源构建的.但是,在本地开发过程中使用container:start时,我会绑定到同一目录. 有什么方法可以为不同的目的定义不同的目录吗?

then I achieve the second goal - my WAR gets built using the webapp resources in dist/webapp. However, when using container:start during local development I get bound to the same directory. Is there any way to define different dirs for different purposes?

推荐答案

xsbt-web-plugin支持SBT 0.13.1 ,因此您可以使用更精细的语法在Compile范围内定义webappResources:

xsbt-web-plugin supports SBT 0.13.1 so you can use the much-nicer syntax to define webappResources in the Compile scope:

webappResources in Compile := Seq(baseDirectory.value / "dist" / "webapp")

我可能会记错了,但是单独使用webappResources也可以.

I might be mistaken, but webappResources alone would work, too.

webappResources := Seq(baseDirectory.value / "dist" / "webapp")

甚至(除非您想替换原始值而不附加值):

or even (unless you want to replace the original value not to append a value):

webappResources += baseDirectory.value / "dist" / "webapp"

对于该解决方案,我将在build.sbt中使用以下内容(未经测试的):

As for the solution I'd use the following (untested) in build.sbt:

webappResources in package := Seq(baseDirectory.value / "dist" / "webapp")

,并保留webappResources设置的默认值以进行本地开发.

and leave the default value for the webappResources setting for local development.

阅读范围,以了解有关范围界定"的更多信息"设置,即为不同的 axes 设置不同的值.

Read Scopes to learn more about "scoping" settings, i.e. setting different values for different axes.

这篇关于如何为容器使用不同的Web应用程序资源:SBT中的启动和打包任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆