2013-07-26 9 views
9

mio Gruntfile.js di file:Utilizzando richiedere-js e grunt.js - Errore mancante sia un "nome", "include" o "moduli" opzione

module.exports = function (grunt) { 
    grunt.initConfig({ 
     pkg : grunt.file.readJSON('package.json'), 
     requirejs : { 
      compile: { 
       options: { 
        baseUrl: "public_html/js", 
        mainConfigFile: "public_html/js/config.js", 
        out: "public_html/app.min.js" 
       } 
      } 
     } 
    }); 

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

    grunt.registerTask('default', ['requirejs']); 
}; 

mio config.js di file:

'use strict'; 

require.config({ 
    deps: ['main'], 
    paths: { 
     jquery: 'vendor/jquery', 
     jquery_tokeninput: 'vendor/jquery.tokeninput', 
     underscore: 'vendor/underscore', 
     backbone: 'vendor/backbone' 
    }, 
    shim: { 
     jquery: [], 
     jquery_tokeninput: { 
      deps: ['jquery'] 
     }, 
     backbone: { 
      deps: ['vendor/underscore', 'vendor/jquery', 'vendor/jquery.tokeninput'], 
      exports: 'Backbone' 
     }, 
     underscore: { 
      exports: '_' 
     } 
    } 
}); 

require(['views/app'], function(AppView) { 
    new AppView; 
}); 

quando eseguo grunt requirejs errori IT con:

Running "requirejs:compile" (requirejs) task 
[Error: Error: Missing either a "name", "include" or "modules" option at function.build.createConfig (D:\project\node_modules\grunt-contrib-requirejs\node_modules\requirejs\bin\r.js:24829:19)] 

prima volta usando gruntjs e requirejs quindi non so perché sono ottenendo l'errore

risposta

10

aggiornato il file grunt.js di utilizzare il nome:

module.exports = function (grunt) { 
    grunt.initConfig({ 
     pkg : grunt.file.readJSON('package.json'), 
     requirejs : { 
      compile: { 
       options: { 
        name: "views/app", 
        baseUrl: "public_html/js", 
        mainConfigFile: "public_html/js/config.js", 
        out: "public_html/app.min.js" 
       } 
      } 
     } 
    }); 

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

    grunt.registerTask('default', ['requirejs']); 
}; 

e rimosso quanto segue dalla config.js:

require(['views/app'], function(AppView) { 
    new AppView; 
}); 
+4

vuol dire RequireJS richiama automaticamente 'new' sul modulo definito in' "views/app''? – blong

Problemi correlati