Blankman Blankman - 4 months ago 12
CoffeeScript Question

Where is my compiled coffee script js file?

I have a play 2.5.x app and I created the file in the following folder:

/app/assets/javascript/test.coffee


In my master.scala.html I have:

<script src="@routes.Assets.versioned("javascripts/test.js")" type="text/javascript"></script>


My plugins.sbt has:

// web plugins

addSbtPlugin("com.typesafe.sbt" % "sbt-coffeescript" % "1.0.0")

addSbtPlugin("com.typesafe.sbt" % "sbt-less" % "1.1.0")

addSbtPlugin("com.typesafe.sbt" % "sbt-jshint" % "1.0.3")

addSbtPlugin("com.typesafe.sbt" % "sbt-rjs" % "1.0.7")

addSbtPlugin("com.typesafe.sbt" % "sbt-digest" % "1.1.0")

addSbtPlugin("com.typesafe.sbt" % "sbt-mocha" % "1.1.0")

addSbtPlugin("org.irundaia.sbt" % "sbt-sassify" % "1.4.2")


When I run the app it doesn't create the file in my
/public/javascript/test.js
folder.

Trying to navigate to the file is a file not found error:

http://localhost:9000/assets/javascripts/test.js


My routes has:

GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)


How should this be working as I have never used this before?

Reference:
https://www.playframework.com/documentation/2.5.x/AssetsCoffeeScript

Answer

You made a mistake:
You have to put the test.coffee file in the folder /app/assets/javascripts/ - there is a s at the end of javascripts. Then it should work.

Also you should know that the compiled test.js file will not be put in the /public/javascript/ folder. Instead play uses the target folder for all compiled code (*.class files, compiled assets like your *.coffee file, etc.). In your particular case the compiled JavaScript file will be put in target/web/public/main/javascripts/ where play will pick it up when serving the file to a client. Just have a look through the target folder to get an idea of how Play organizes compiled resources. Tip: In case something doesn't work, doesn't compile etc. where you think it should it may sometimes is a got idea to just delete the target folder to start "fresh". (Or just use sbt clean or activator clean).