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

后端 未结 1 1999
花落未央
花落未央 2020-12-21 10:49

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 fo

1条回答
  •  囚心锁ツ
    2020-12-21 11:31

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

    0 讨论(0)
提交回复
热议问题