Skip to content
This repository has been archived by the owner on Mar 26, 2018. It is now read-only.

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

Open
oliverpfeffer opened this issue May 19, 2013 · 6 comments
Open

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

oliverpfeffer opened this issue May 19, 2013 · 6 comments
Milestone

Comments

@oliverpfeffer
Copy link

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
Copy link
Member

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
Copy link
Author

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
Copy link
Member

@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
Copy link
Member

@sleeper ping

@keriati
Copy link

keriati commented Feb 22, 2014

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
Copy link

keriati commented Feb 23, 2014

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?

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

No branches or pull requests

4 participants