I am trying my first steps with CoffeeScript in Play 2.1.0. I created a new application and placed my CoffeeScript file main.coffee in app/assets/javascripts/.
I expected that upon starting the play application (entering 'run' in the play console) my CoffeeScript would be compiled and the resulting main.js to be placed in the public/javascripts directory.
But no main.js gets created in that directory. Do I have to add some configuration somewhere else?
As stated in the CoffeeScript doc:
Note that managed resources are not copied directly into your application’s public folder, but maintained in a separate folder in target/scala-2.x.x/resources_managed.
And you have to access it through the Assets
controller using reverse routing:
<script src="@routes.Assets.at("javascripts/main.js")">
As the documentation describes:CoffeeScript sources are compiled automatically during an assets command, or when you refresh any page in your browser while you are running in development mode.
So, if you are not in development mode
, you should use assets
command to compile your CoffeeScript manually.
Before type in the assets
command, make sure you have add the sbt-coffeescript
plugin in your project by adding the following line in your project/plugins.sbt
file:
addSbtPlugin("com.typesafe.sbt" % "sbt-coffeescript" % "1.0.0")
After enable CoffeeScript compilation by adding the previous line, go into your project's root dirctory and type in sbt
command. In the sbt
interact shell you can type in assets
command and you will get some output like this:
$ assets
[info] CoffeeScript compiling on 1 source(s)
[success] Total time: 4 s, completed May 30, 2015 9:43:29 PM
As you can see, CoffeeScript compile successfully.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With