Run npm build for play framework within sbt

3.5k views Asked by At

I'm not very much familiar with sbt/play configuration. I'm using play 2.3.8 to serve my javascript application. In the project there is:

.enablePlugins(SbtWeb)
.enablePlugins(play.PlayScala)
.settings(
  ...
  libraryDependencies ++= WebDependancies :+ evobufAkka,
  pipelineStages in Assets := Seq(closure, digest),
  ...
  // Some closure compiler settings
)

The project is using closure compiler to minify the code etc. But I would like to change it. I would like to stop using closure compiler and instead just use simple npm packages. I'm aware that sbt can run some shell task. The reason for all that is to separate server from frontend, so all tasks related to frontend like (less, uglify, fingerprinting, etc.) are actually done by javascript tool like node. I was reading about sbt-web but I would like to avoid that if possible. What I have in mind is: 1. start sbt, open my project 2. run compile: - sbt would run my npm tasks which ends up some build.js file which then can be served via play framework from /public directory or whatever. 3. I would like to have possibility to have a separate process for unit tests if possible.

In terms of npm setup I was thinking about putting package.json in my project/public folder, unless its better to put it in project/app/assets.

Is that all possible?

Update 8/8/2015

I did some research and found out about external processes. Based on some example I created:

lazy val npmBuildTask = taskKey[Unit]("Execute the npm build command to build the ui")

npmBuildTask := {
  "cd public/ && npm install" !
}  

but not sure how can I add this task to the compile process?

1

There are 1 answers

0
danielnixon On BEST ANSWER

You could make the compile task depend on your npmBuildTask task:

compile <<= (compile in Compile) dependsOn npmBuildTask