Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demonstrate using requirejs optimized files? #16

Open
pkaeding opened this issue Apr 2, 2014 · 5 comments
Open

Demonstrate using requirejs optimized files? #16

pkaeding opened this issue Apr 2, 2014 · 5 comments

Comments

@pkaeding
Copy link

pkaeding commented Apr 2, 2014

I am trying to figure out how to use the RequireJs optimizer that seems to be built into Play with Webjars. Does it work? I notice that if I run this sample app in production mode, it is still making individual requests for each file. Could you make the changes needed to optimize the js loading, so I can hopefully see what I am doing wrong in my project?

Thanks!

@jamesward
Copy link
Contributor

This should "just work" but sounds like there is an issue somewhere. I thought #15 fixed this.

@pkaeding
Copy link
Author

pkaeding commented Apr 3, 2014

When I run stage on this project, I see this error, and I see the js files being loaded individually:

[info] RequireJS optimization has begun...
[info] app.build.js:
[info] ({appDir: "javascripts",
[info]           baseUrl: ".",
[info]           dir:"javascripts-min", mainConfigFile: "javascripts/app.js", modules: [{name: "app"}]})
Error: /private/tmp/angular-seed-play/target/scala-2.10/classes/public/javascripts/app.js does not exist.
[info] RequireJS optimization finished.

From reading the play docs, it sounds like its optimizer only runs over javascript files in app/assets/javascripts, not public/js.

So, in my own project, I moved my js code there. When I run stage, I see this error:

[info] RequireJS optimization has begun...
[info] app.build.js:
[info] ({appDir: "javascripts",
[info]           baseUrl: ".",
[info]           dir:"javascripts-min", mainConfigFile: "javascripts/app.js", modules: [{name: "app"}]})

Tracing dependencies for: app
JavaException: java.io.FileNotFoundException: /Users/pkaeding/prj/gmaps-play/target/scala-2.10/classes/public/javascripts-min/jquery.js (No such file or directory)
In module tree:
    app

jQuery is loaded properly from webjars when I run in dev mode, so I'm not sure what is happening there. When I try to run my app in production mode, my app.js 404s, which I guess is not surprising, because clearly there was a problem generating it.

@jamesward
Copy link
Contributor

Well this is nasty but RequireJS needs to see the WebJar contents for some reason. And the WebJar contents are inside Jars. Here is a possible workaround:
https://github.com/typesafehub/angular-seed-play/compare/minify-support

This all gets better in Play 2.3 with sbt-web. Until then we might need some hacks.

@pkaeding
Copy link
Author

pkaeding commented Apr 3, 2014

In that case, you aren't actually using the webjars, right? you are just using dependencies from a CDN?

@jamesward
Copy link
Contributor

That is just for the requirejs optimizer to run. I don't think in this case it actually uses them from the CDN at runtime because I'm not actually using that config at runtime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants