我试图在play-framework 2.4.X app中包含一个gulp,angular项目。
有一个 node_modules 文件夹,其中包含大量文件和文件夹。 SBT在我的构建过程中包含这些文件;这使我的构建过程非常缓慢。
所以我想排除那些和其他不必要的文件和文件夹。我的build.sbt文件部分代码
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")
但那些不起作用,SBT包括来自admin-panel文件夹的所有文件和文件夹。任何人都可以帮助我,因为我是SBT的新手。
答案 0 :(得分:0)
我的解决方案是......
<强> build.sbt 强>
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))
project / Gulp.scala
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
}
}