I just tried to build a library using the ‘grunt-contrib-requirejs’ Grunt task with some very simple options:

module.exports = function(grunt) {

  grunt.initConfig({

    requirejs: {
      client: {
        options: {
          baseUrl: 'multi/client',
          out: 'public/js/lib/multi.js',
          name: 'multi',
          paths: {
            'socket.io': 'empty:'
          },
          wrap: {
            end: 'define(["multi"], function(index) { return index; });'
          },
          optimize: 'none',
          generateSourceMaps : true,
          preserveLicenseComments : false
        }
      }
    }

  });

  grunt.loadNpmTasks('grunt-contrib-requirejs');

};

So, no fancy stuff here. But it turns out that running the grunt requirejs command removes every occurrence of “use strict” statement inside my modules – not exactly what I expected. The require.js optimizer documentation does not give any hints about this behavior, but the grunt-contrib-requirejs package does. The example config file lists all possible options including useStrict which is set to false by default:

// Allow “use strict”; be included in the RequireJS files.
// Default is false because there are not many browsers that can properly
// process and give errors on code for ES5 strict mode,
// and there is a lot of legacy code that will not work in strict mode.
useStrict: false,

After changing this option inside my Gruntfile everything worked as expected and the “use strict” directives showed up again:

module.exports = function(grunt) {

  grunt.initConfig({

    requirejs: {
      client: {
        options: {
          baseUrl: 'multi/client',
          out: 'public/js/lib/multi.js',
          name: 'multi',
          paths: {
            'socket.io': 'empty:'
          },
          wrap: {
            end: 'define(["multi"], function(index) { return index; });'
          },
          optimize: 'none',
          generateSourceMaps : true,
          preserveLicenseComments : false,
          useStrict: true
        }
      }
    }

  });

  grunt.loadNpmTasks('grunt-contrib-requirejs');

};

I can see why this is the default option. Many existing projects would break using strict mode. But any kind of warning or other hint for this rather unexpected default behavior would have been nice.