0

I have one problem. In my project i'm using runtime module injection. When i use require.js framework all works ok. But when i try to make solid js file with grunt-contrib-requirejs it doesn't find my injecting module.

piece of my code whre i'm injecting module

_.each(collection.models, function (model) {
    require(['application/views/' + model.get("className")], function (view) {
       view();
    });
});
serg
  • 5
  • 1

1 Answers1

0

http://requirejs.org/docs/1.0/docs/optimization.html

The optimizer will only combine modules that are specified in arrays of string literals that are passed to top-level require and define calls, or the require('name') string literal calls in a simplified CommonJS wrapping. So, it will not find modules that are loaded via a variable name:

var mods = someCondition ? ['a', 'b'] : ['c', 'd'];
require(mods);`

To include dynamically loaded files, use the include option in your task configuration:

include: ['a.js', 'b.js', 'c.js']
jgillich
  • 71,459
  • 6
  • 57
  • 85
  • Unfortunatly i don't know which module will be included before running the task. All modules described in my config file. All modules stored in one folder in my project tree. May be i can include whole folder? – serg Jul 29 '14 at 12:06
  • I found the way. But i can't unswer to my question because i haven't quiet reputation. Thats why i posted my solution into github GIST https://gist.github.com/syul/2dec564929d91b63d1f4 – serg Jul 29 '14 at 13:21