Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

java - Include/Exclude asset folder/directory in sbt/play-framework

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

My solution was...

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
    }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...