问题描述
我正在尝试在 play-framework 2.4.X 应用程序中包含一个 gulp、angular 项目.
有一个 node_modules 文件夹,其中包含许多文件和文件夹.SBT 在我的构建过程中包含这些文件;这使我的构建过程非常缓慢.
所以我想排除那个和其他不必要的文件和文件夹.我的 build.sbt 文件部分代码
lazy val gulpDirectory = baseDirectory { _/"admin-panel" }资产中的非托管资源目录 //file.getParent == "bower_components" ||//file.getParent == "tmp" ||//file.getParent == "dist"//)//}在非托管资源目录中的资产中包含过滤器 := "bower_components" ||分布" ||tmp"excludeFilter in Assets in unmanagedResourceDirectories := new SimpleFileFilter(_.getParent == "node_modules")
但那些不起作用,SBT 包括管理面板文件夹中的所有文件和文件夹.任何人都可以帮助我,因为我是 SBT 的新手.
我的解决方案是...
build.sbt
import play.sbt.PlayImport.PlayKeys.playRunHooks懒惰的 val gulpDirectory = baseDirectory {_/管理面板"}excludeFilter := HiddenFileFilter -- ".tmp"资产中的非托管资源目录 <+= gulpDirectory { _/"dist"}资产中的非托管资源目录 <+= gulpDirectory { _/".tmp"}资产中的非托管资源目录 <+= gulpDirectory { _/"bower_components"}//这是开发环境资产中的非托管资源目录 <+= gulpDirectory { _/"src"/"app"}playRunHooks Gulp(path))
项目/Gulp.scala
import play.sbt.PlayRunHook导入 sbt._导入 java.net.InetSocketAddress对象吞咽{def apply(base: File): PlayRunHook = {对象 GulpProcess 扩展了 PlayRunHook {val gulpFile = "gulpfile.js"var 进程:选项[进程] = 无覆盖 def beforeStarted(): Unit = {如果(是Windows){Process("cmd/c gulp build", base).run} 别的 {Process("gulp build", base).run}}覆盖 def afterStarted(addr: InetSocketAddress): Unit = {如果(是Windows){Some(Process("cmd/c gulp serve", base).run)} 别的 {Some(Process("gulp serve", base).run)}}覆盖 def afterStopped(): Unit = {process.map(p => p.destroy())过程 = 无}私有定义 isWindows: Boolean = {System.getProperty("os.name").startsWith("Windows")}}吞咽过程}}
I am trying to include a gulp, angular project within a play-framework 2.4.X app.
There is a node_modules folder, which contain lots of files and folders. SBT is including those files in my build process; this make my build process very slow.
So I want to exclude that and other unnecessary files and folders. My build.sbt files partial code
lazy val gulpDirectory = baseDirectory { _ / "admin-panel" }
unmanagedResourceDirectories in Assets <+= gulpDirectory
//includeFilter in Assets in unmanagedResourceDirectories := {
// new SimpleFileFilter( file =>
// file.getParent == "bower_components" ||
// file.getParent == "tmp" ||
// file.getParent == "dist"
// )
//}
includeFilter in Assets in unmanagedResourceDirectories := "bower_components" || "dist" || "tmp"
excludeFilter in Assets in unmanagedResourceDirectories := new SimpleFileFilter(_.getParent == "node_modules")
But those aren't working, and SBT including all files and folders from admin-panel folder. Can anyone help me out, as I am new to SBT.
My solution was...
import play.sbt.PlayImport.PlayKeys.playRunHooks
lazy val gulpDirectory = baseDirectory {
_ / "admin-panel"
}
excludeFilter := HiddenFileFilter -- ".tmp"
unmanagedResourceDirectories in Assets <+= gulpDirectory { _ / "dist"}
unmanagedResourceDirectories in Assets <+= gulpDirectory { _ / ".tmp"}
unmanagedResourceDirectories in Assets <+= gulpDirectory { _ / "bower_components"}
//this is for development environment
unmanagedResourceDirectories in Assets <+= gulpDirectory { _ / "src" / "app"}
playRunHooks <+= gulpDirectory.map(path => Gulp(path))
import play.sbt.PlayRunHook
import sbt._
import java.net.InetSocketAddress
object Gulp {
def apply(base: File): PlayRunHook = {
object GulpProcess extends PlayRunHook {
val gulpFile = "gulpfile.js"
var process: Option[Process] = None
override def beforeStarted(): Unit = {
if (isWindows) {
Process("cmd /c gulp build", base).run
} else {
Process("gulp build", base).run
}
}
override def afterStarted(addr: InetSocketAddress): Unit = {
if (isWindows) {
Some(Process("cmd /c gulp serve", base).run)
} else {
Some(Process("gulp serve", base).run)
}
}
override def afterStopped(): Unit = {
process.map(p => p.destroy())
process = None
}
private def isWindows: Boolean = {
System.getProperty("os.name").startsWith("Windows")
}
}
GulpProcess
}
}
这篇关于在 sbt/play-framework 中包含/排除资产文件夹/目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!