yeoman / generator-backbone

Scaffold out a Backbone.js project
http://yeoman.io
638 stars 157 forks source link

r.js optimization - use of modules [] #59

Open oliverpfeffer opened 11 years ago

oliverpfeffer commented 11 years ago

Hi! I'm relatively new to yeoman as well as grunt so this may be a silly question!

I'm trying to make use of require.js r.js' optimization of files into modules as specified in jburke's example.build.js (https://github.com/jrburke/r.js/blob/master/build/example.build.js). This file is referenced in this generator's Gruntfile (around line 160).

However, when I try to run grunt build having specified multiple modules, it aborts with an error saying that "out" and "dir" cannot be provided at the same time. It looks as if this generator aims to concat all scripts into one file. I believe this is done by grunt's usemin module, correct?

Is it possible to update Gruntfile.js to incorporate multiple js module files instead of concatenating all in one?

Thanks all!

addyosmani commented 11 years ago

Please pardon the delay in getting back to your question! I think @revathskumar has been a little busy lately. So, are you basically asking if there's a way to get the r.js setup in the project scaffolded to not concat everything into one file? I mean, r.js should be doing that anyway with the exception of those modules that you need to be loading in dynamically. Could you share your Gruntfile for us so we can help you further?

oliverpfeffer commented 11 years ago

I have the stock Gruntfile and have been playing with various options for usemin to play nicely w/ r.js optimizer but haven't been able to figure it out without disabling usemin all together...

And yes, I'd love to use almond.js to load modules dynamically after page load. Instead of concatentating it all in one main.js file

revathskumar commented 11 years ago

@addyosmani I was able to reproduce this issue. usemin is adding out and name properties to requirejs config. I am not sure whether there is an option to skip this if modules is used.

https://github.com/revathskumar/yeoman-backbone/tree/requirejs-multipage

cc\ @sleeper

revathskumar commented 11 years ago

@sleeper ping

keriati commented 10 years ago

Just encountered this issue. Some quick win would be in file:

node_modules/grunt-usemin/tasks/usemin.js

Lines 174-175:

if ( ! options.hasOwnProperty('modules') ) {
  options.name = options.name || block.requirejs.name;
  options.out = options.out || block.requirejs.dest;
}

However after this change i get this error in the build:

Updating config with the following assets:

  • dist/scripts/main.js Warning: Arguments to path.join must be strings Used --force, continuing.

Quick win for this is changing in file:

node_modules/grunt-usemin/tasks/usemin.js

line:

options.mainConfigFile = options.mainConfigFile || path.join(options.baseUrl, options.name) + '.js';

to:

options.mainConfigFile = options.mainConfigFile || path.join(options.baseUrl, 'main') + '.js';

as long we use main.js as the file name, this should works...

keriati commented 10 years ago

Usemin seems to make a lot of problems here, maybe another job that skips usemin but can handle r.js modules config should be added. Instead

grunt build

something like

grunt build-rmodules

Would that be possible?