softprops / coffeescripted-sbt

pour some coffee for scala
MIT License
55 stars 5 forks source link

Interoperability issues with Play Framework and managed resources #18

Open jeffmay opened 11 years ago

jeffmay commented 11 years ago

Hey again,

I am still having issues with getting CoffeeScript set up with Play.

As you may remember from https://github.com/softprops/coffeescripted-sbt/issues/17, I was having trouble setting up CoffeeScript so that it would compile from the correct source directory to the correct resource directory. I didn't mention that after I did this, my Play build broke. I resorted to just using JavaScript (yuck). You can see the ticket I posted on Play's issue tracker for more info.

I thought I would get back to you about this to let you know that I am having trouble with getting this set up. It appears that I was having 3 issues going on in this project that made my situation unique:

  1. WebJars to load RequireJs and AngularJs
  2. Play project anatomy requires managed resources to be placed in particular places
  3. Compiling CoffeeScript to expected directory for AngularJs web jar

I found that 2 and 3 were incompatible and reported the issue with Play.

Another Attempt

I decided to give coffee script another try. I think the problem was that after adding coffee script directory to the resourceManaged setting, Play was upset by where I was managing resources (in that it didn't know how to deploy the resourceManaged directory, because it wasn't in Play's structured build layout). I thought the solution would be to reuse Play's natural way for deploying coffee script (as outlined here).

Even after using the correct project layout, no coffee script is compiled. If you clone this example project and run the project, you will see that nothing is compiled to the target/scala-2.10/resources_managed/main directory as it is supposed to.

The index page will load properly, but if you delete the whole public/javascripts directory, you'll notice that the page can't load any javascript. So now I'm back to the same issue again.

So now I switched back to using your plugin.

I need to compile the javascript to public/javascripts to get the project to work, but Play won't let me because I get errors like:

Unexpected exception
RuntimeException: No mapping for /Users/jeffmay/code/righttrack/target/scala-2.10/public/js/app.js
No source available, here is the exception stack trace:
->java.lang.RuntimeException: No mapping for /Users/jeffmay/code/righttrack/target/scala-2.10/public/js/app.js

And when I use what should "just simply work":

  myPlayProject.settings(coffeeSettings: _*)
    .settings(
      sourceDirectory in (Compile, CoffeeKeys.coffee) <<= (sourceDirectory in Compile)(_ / "assets" / "javascripts"),
      resourceManaged in (Compile, CoffeeKeys.coffee) <<= (resourceManaged in Compile)(_ / "javascripts")
    )

I see:

$ show coffee
[info] ArrayBuffer()
[success] Total time: 0 s, completed Jul 8, 2013 1:15:21 AM

I can't figure out how the heck I can use coffee script with angular. Since Play's coffee script compiler is still a mystery, I want to use your plugin to compile my scripts without breaking Play. Any ideas how I can accomplish this, I'm running out of steam on this, and I'm sure others are looking for a good solution too.

For the time being, I am going to use a separate Cake file and coffee script compiler to compile the files to the public directory without breaking Play.

Thanks ahead of time!

jeffmay commented 11 years ago

@softprops Nevermind, I found the problem. My directory was named app/assets.javascripts/ because IDEA failed to rename it properly.

Anyway, I switched to using Play's internal CoffeeScript compiler with WebJars. See my example project