如何忽略要在play框架

时间:2017-08-04 14:53:38

标签: java playframework gulp sbt playframework-2.4

我有一个node_modules文件夹,它位于public文件夹中,它包含很多文件,导致我的localhost:9000继续加载数小时 我想在play框架中忽略这个文件夹 根据这个问题Include/Exclude asset folder/directory in sbt/play-framework

我已按照以下步骤操作: build.sbt

mappings in (Compile, packageBin) ~= { _.filterNot { case (_, name) =>
      name.startsWith("public\\node_modules")
}}

import play.sbt.PlayImport.PlayKeys.playRunHooks
    lazy val gulpDirectory = baseDirectory {
        _ / "admin-panel"//what should i write here? 
    } 
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
    }
}

我有两个问题 首先node_modules位于home/user/git/testproject/public/node_module 我应该写什么代替admin-panel中的build.sbt 我试着写public

import play.sbt.PlayImport.PlayKeys.playRunHooks
lazy val gulpDirectory = baseDirectory {
    _ / "public"
}

但是我得到了这个例外

java.io.IOException: Cannot run program "gulp" (in directory "home/user/git/testproject/public"): error=2, No such file or directory
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
Caused by: java.io.IOException: error=2, No such file or directory
    at java.lang.UNIXProcess.forkAndExec(Native Method)
    at java.lang.UNIXProcess.<init>(UNIXProcess.java:247)
    at java.lang.ProcessImpl.start(ProcessImpl.java:134)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
[trace] Stack trace suppressed: run last testproject/compile:run for the full output.
[error] (arteciate/compile:run) java.io.IOException: Cannot run program "gulp" (in directory "/home/user/git/testproject/public"): error=2, No such file or directory
[error] Total time: 2 s, completed Aug 4, 2017 7:44:14 PM

如果还有另一种方法可以忽略node_modules文件夹,请提供帮助,因为我无法debugtestrun我的项目。 我正在使用play 2.4

修改 我正在使用播放2.4我的播放应用程序工作正常然后我需要安装一些UI组件,如graunt bower ruby compass安装这些组件后我做激活器运行后reload clean compile并点击localhost:9000加载页面需要近一个小时或更长时间

1 个答案:

答案 0 :(得分:0)

由于node_modules文件夹仅包含Node.js不需要扫描和编译的sbt个模块,因此您可以在build.sbt中完全排除该文件夹< / p>

excludeFilter := {
    val public = (baseDirectory.value / "public" / "node_modules").getCanonicalPath
    new SimpleFileFilter(_.getCanonicalPath startsWith public)
}

要编译应用程序的Node.js前端部分,您必须使用专用的gulp build命令而不是使用Gulp.scala类。

$ cd /home/user/git/testproject/public/
/home/user/git/testproject/public$ gulp build

如果仍然需要安装Node.js中的某些node_modules依赖项,请在运行gulp build之前执行以下命令:

$ cd /home/user/git/testproject/public/
/home/user/git/testproject/public$ npm install

如果Node.js中的某些node_modules依赖关系已过期,请在运行gulp build之前执行以下命令:

$ cd /home/user/git/testproject/public/
/home/user/git/testproject/public$ npm update