sbt / sbt-rjs

RequireJs optimizer plugin for sbt-web
Other
39 stars 28 forks source link

Clarify docs for getting started #20

Closed benmccann closed 10 years ago

benmccann commented 10 years ago

Thanks for the plugin. I wanted to check it out to see the way you guys develop JS. Some questions I have trying to get it to work:

* At what URL is the optimized JS available from?
* How does it work in development mode? Does it not run the optimization and I need to include an extra script in my page?
huntc commented 10 years ago

Hi Ben

rjs concats main.js (configurable) and the scripts it depends on into main.js. It does not therefore change the URL.

rjs is not normally used during dev, just prod.

HTH

huntc commented 10 years ago

We should update the docs to clarify this.

benmccann commented 10 years ago

Thanks @huntc. That's what I believed from a few presentations I saw online, but wasn't entirely sure.

It sounds like dev and prod mode have different usage, so would it be something like this then?

@if(play.Play.application().isProd()) {
  <script type="text/javascript" src="@routes.Assets.at("javascripts/main.js")"></script>
} else {
  <script data-main="@routes.Assets.at("javascripts/main.js")" src="@routes.Assets.at("lib/requirejs/require.js")"></script>
}
huntc commented 10 years ago

Nope, it is the same script statement for both:

  <script data-main="@routes.Assets.at('javascripts/main.js')" src="@routes.Assets.at('lib/requirejs/require.js')"></script>
benmccann commented 10 years ago

Hmm, really? That's surprising to me. I thought that I production mode that this plugin combined all the scripts. So in that case why do you still need to load require.js instead of just main.js (i.e. the optimized script)?

huntc commented 10 years ago

require.js is bootstrap script for RequireJs - you always need the data-main attribute.

benmccann commented 10 years ago

Ah, it looks like you're right. At least by default that's the behavior. It seems you may be able to make it behave in the manner I expected by setting some extra options, which I'll probably look into as it seems like it'd result in better latency for the end user.

benmccann commented 10 years ago

Thanks @huntc for the clarifications! I'm going to close this. I submitted a pull request for the extra docs