1

I have a node_modules folder which resides in public folder it contains lot of files which is causing my localhost:9000 to keep on loading for hours I want to ignore this folder in play framework according to this question Include/Exclude asset folder/directory in sbt/play-framework

I have followed the steps: 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))

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

I have two questions first is node_modules is located at home/user/git/testproject/public/node_module what should I write instead to admin-panel in build.sbt I have tried to write public

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

But I am getting this exception

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

Second if there is another method to ignore node_modules folder please help because I am unable to debug, test, run my project. I am using play 2.4

Edit I am using play 2.4 My play app was working fine then I needed to install some UI components like graunt bower ruby compass after installing these components when I do activator run after reload clean compile and hit localhost:9000 it takes almost an hour or more to load the page

swaheed
  • 3,671
  • 10
  • 42
  • 103

1 Answers1

1

Since the node_modules folder contains only Node.js modules that don't need to be scanned and compiled by sbt, you can exclude completely that folder in the build.sbt

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

To compile the Node.js front-end part of your application you have to use the dedicated gulp build command instead of using the Gulp.scala class.

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

If some Node.js dependency in node_modules still needs to be installed, before running gulp build execute the following command:

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

If some Node.js dependency in node_modules is out of date, before running gulp build execute the following command:

$ cd /home/user/git/testproject/public/
/home/user/git/testproject/public$ npm update
tuxy
  • 111
  • 1
  • 6