generator-backbone icon indicating copy to clipboard operation
generator-backbone copied to clipboard

r.js optimization - use of modules []

Open oliverpfeffer opened this issue 11 years ago • 6 comments

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!

oliverpfeffer avatar May 19 '13 17:05 oliverpfeffer

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?

addyosmani avatar May 29 '13 14:05 addyosmani

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

oliverpfeffer avatar Jun 07 '13 01:06 oliverpfeffer

@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 avatar Jun 09 '13 20:06 revathskumar

@sleeper ping

revathskumar avatar Jun 14 '13 11:06 revathskumar

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 avatar Feb 22 '14 17:02 keriati

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?

keriati avatar Feb 23 '14 10:02 keriati