tuplejump / play-yeoman

Play + Yeoman integration sbt and play plugins
Apache License 2.0
237 stars 58 forks source link

Scala Templates not being processed by Grunt #35

Closed milliondreams closed 8 years ago

milliondreams commented 10 years ago

@kompot @jtammen

This is following the comment - https://github.com/tuplejump/play-yeoman/issues/12#issuecomment-32167677

Don't know whether I did something wrong or it's not there - when running ~run everything works ok, but after dist I see the same template, without being processed by Grunt.

I mean blocks like

are the same in production templates after dist task.

Am I missing anything?

Seems like there is hard coded app dir in this code https://github.com/tuplejump/play-yeoman/blob/develop/sbt-yeoman/app/com/tuplejump/sbt/yeoman/Yeoman.scala#L102-L108 that should be changed to dist when running in production?

I am assuming that you have index.scala.html and it is getting compiled as a play view but not being processed by Grunt? Is my assumption correct?

Can you share a sample app for me to try out and debug the issue?

jtammen commented 10 years ago

I think my problem was caused by the fact that I put all my view files into the ui/app/views folder (as opposed to just ui/app) and so the Grunt htmlmin task did not process and copy them to the target folder...

@kompot are you doing something similar? Maybe we can give some hint when you share the log output of your grunt run.

jtammen commented 10 years ago

@milliondreams @kompot

I am a little bit stuck right now as I don't know whether it is possible to achieve what I am trying to do. Maybe I am just a victim of a misunderstanding (-;

What needs to be done in my case:

In both cases, I need to be able to inject some server-side data into the HTML pages (e.g. data about the currently logged in user). Also, both pages contain links to (different) stylesheet and JavaScript files (they both contain an AngularJS application), which means they should be processed by Grunt so that those files get concatenated and minified for production mode.

What I currently don't seem to understand: is it possible to use a server-rendered template from the ui/dist directory?

I put together a simple demo app based on the installation instructions for play-yeoman and yo-demo. It contains following routes:

Any ideas on how to restructure my project in order to achieve what I need?

Thanks for your support and greets.

milliondreams commented 10 years ago

@jtammen

Thanks a lot for the problem explanation and the sample app.

Some background -

  1. The .scala.html files are processed by the Play Scala Template compiler and the classes generated from them are used when we use them in our controllers.
  2. The files are fetched from the "unmanagedDirectories" settings in the Build. Thus it worked when @kompot set the value to "dist"
  3. Grunt doesn't create the "dist" folder when running as a server (development mode). So this will fail while in development. You will have to run grunt everytime you change the .scala.html files so that they become available in the "dist directory. But this is not the way to do it.

So in conclusion we should be able to set different "unmanagedDirectories" settings while in "run" and "dist/stage" @sbt

I am not sure how to do this yet! Will be great if anyone has any knowledge about this.

jtammen commented 10 years ago

Hey @milliondreams, thanks for the explanation.

Phew, sounds as if there is no easy solution for this problem ... and unfortunately, I have really close to zero knowledge about sbt, so I won't be of any help here :-/

Could I use @kompot's workaround to temporarily "fix" this and create a deployable distribution of my app? Or maybe I should switch back to pure client-side templates and fetch all data needed from the server via separate calls to my backend...

jtammen commented 10 years ago

@milliondreams Any idea how to fix or work around this? I am currently a bit lost, as I need to create a deployable version of my app soon...

milliondreams commented 10 years ago

@jtammen You could override the settings in your project's build file as per kompot's workaround before you use dist to create a build.

Apologies as I am neck deep in some other things, so will not be able to give a timely fix here!

jtammen commented 10 years ago

@milliondreams Never mind, I really appreciate all of your precious time you are putting into this very helpful project!

I will try @kompot's workaround – thanks for your feedback.

markterm commented 10 years ago

Another important point here is that the grunt build needs to complete before the play template compilation starts otherwise some or all the processed templates won't be in the dist folder yet.

jtammen commented 10 years ago

Any update on this topic? I managed to create a working distribution of my app using @kompot's workaround, i.e. swap "app" with "dist" in the settings–but this is just a workaround, as it forces me to make changes to my Build.scala when I need to create a release...

Is there any possibility this issue will be fixed? If not, is there any other option to combine sever-rendered Scala templates and the client-side templates managed by yeoman/grunt?

milliondreams commented 10 years ago

@jtammen Sorry I haven't got around to work on play-yeoman for a while. Things loaded at work.

Does anyone out there have any idea how to set different settings for dist task and the run/stage task???

milliondreams commented 10 years ago

@jtammen @kompot

This should be solved in the new release. 0.7.0

jtammen commented 10 years ago

:+1: Will have a look at this soon, thanks!

treyhyde commented 10 years ago

BTW, with 0.7.1-SNAPSHOT, this issue remains. I can get templates for "dist" but not for dev mode.

Shiti commented 8 years ago

From, 0.9.0, templates are generated on compile.