cloudchen / grunt-template-jasmine-requirejs

RequireJS template for grunt-contrib-jasmine task
111 stars 96 forks source link

Add 'mainRequireConfigFile' option to make it possible to extract config from a file (similar to r.js) #13

Closed reinseth closed 11 years ago

reinseth commented 11 years ago

This builds on the idea of #10 to let the user include a require configuration from an external file.

This pull request includes tools from r.js (the tools are copied from r.js instead of included as dependencies - see last comments on https://github.com/jrburke/r.js/issues/385). These tools are used to extract the config from options.mainRequireConfigFile and merge it with options.requireConfig (note that the latter overrides the former).

timsnadden commented 11 years ago

This looks like a good approach. Unfortunately (for my setup) it looks like the process of extracting the config strips the init function that can be configured to run once a library has been shimmed.

My config is as follows:

require.config({
  // ... paths etc.
  shim: {
    'cocktail': {
      deps: ['backbone', 'backbone.layoutmanager'],
      exports: 'Cocktail',
      // This function is removed from the resulting config
      init: function () {
        Cocktail.patch(Backbone);
      }
    }
  }
});

Any ideas?

reinseth commented 11 years ago

That is not good. Maybe it's a bug in r.js. I'll look into it.

reinseth commented 11 years ago

The problem is not with r.js, but is caused by doing JSON.stringify() on the config object (which in effect removes any function declarations). I'll figure out a different way to do this.

Thanks for spotting this, though.

cloudchen commented 11 years ago

I met same issue and fixed in my fork, check it out. https://github.com/jsoverson/grunt-template-jasmine-requirejs/pull/9

On Thu, Apr 11, 2013 at 4:41 PM, reinseth notifications@github.com wrote:

The problem is not with r.js, but is caused by doing JSON.stringify() on the config object (which in effect removes any function declarations). I'll figure out a different way to do this.

Thanks for spotting this, though.

— Reply to this email directly or view it on GitHubhttps://github.com/jsoverson/grunt-template-jasmine-requirejs/pull/13#issuecomment-16222836 .

reinseth commented 11 years ago

@cloudchen Didn't see your comment before I had it fixed myself. I used a slightly different solution though: I used the "replacer" argument to JSON.stringify to hook into the serialization.

there4 commented 11 years ago

+1 I'm using this fork, and it's a great new option. Greatly reduces redundancy in the grunt config.

andreu86 commented 11 years ago

+1, I think it is a missing key feature

andreu86 commented 11 years ago

Is this included in the last production version? I tried to use the last version (0.1.1) and it wasn't working