javascript - Handlebars not loading after Require.js optimization with grunt-requirejs -


i'm using yeoman backbone generator app. wanted use handlebars templates. when include shim, works great in development grunt serve.

// main.js  require.config({   shim: {     bootstrap: {       deps: ['jquery'],       exports: 'jquery'     },     handlebars: {       exports: 'handlebars'     }   },   paths: {     jquery: '../bower_components/jquery/dist/jquery',     backbone: '../bower_components/backbone/backbone',     underscore: '../bower_components/underscore/underscore',     bootstrap: '../bower_components/sass-bootstrap/dist/js/bootstrap',     handlebars: '../bower_components/handlebars/handlebars'   } }); 

however, when i'm trying build project grunt build, i'm getting error handlebars undefined when load page (cannot call registerpartial on undefined). same behavior in development when exclude shim handlebars.

this requirejs task in gruntfile looks like:

// gruntfile.js  requirejs: {     dist: {         options: {             baseurl: '.tmp/scripts',             optimize: 'none',             paths: {                 'templates':  '../../.tmp/scripts/templates',                 'jquery':     '../../<%= yeoman.app %>/bower_components/jquery/dist/jquery',                 'underscore': '../../<%= yeoman.app %>/bower_components/underscore/underscore',                 'backbone':   '../../<%= yeoman.app %>/bower_components/backbone/backbone',                 'bootstrap':  '../../<%= yeoman.app %>/bower_components/sass-bootstrap/dist/js/bootstrap',                 'handlebars': '../../<%= yeoman.app %>/bower_components/handlebars/handlebars'             },             shim: {                 handlebars: {                     exports: 'handlebars'                 }             },             preservelicensecomments: false,             usestrict: true,             wrap: true         }     } }, 

this project configured use grunt-requirejs grunt task. when task run grunt, output requirejs task, know shim both defined in gruntfile , in main.js.

// grunt console output requirejs task  requirejs: { dist:  { options:     { baseurl: '.tmp/scripts',       optimize: 'none',       paths:        { templates: '../../.tmp/scripts/templates',          jquery: '../../app/bower_components/jquery/dist/jquery',          underscore: '../../app/bower_components/underscore/underscore',          backbone: '../../app/bower_components/backbone/backbone',          bootstrap: '../../app/bower_components/sass-bootstrap/dist/js/bootstrap',          handlebars: '../../app/bower_components/handlebars/handlebars' },       shim: { handlebars: { exports: 'handlebars' } },       preservelicensecomments: false,       usestrict: true,       wrap: true,       name: 'main',       out: 'dist\\scripts\\main.js',       mainconfigfile: '.tmp\\scripts\\main.js' } } } 

is there else missing?

apparently had set wrapshim true in build configuration in gruntfile.

requirejs: {     dist: {         options: {             baseurl: '.tmp/scripts',             optimize: 'none',             paths: {                 'templates':  '../../.tmp/scripts/templates',                 'jquery':     '../../<%= yeoman.app %>/bower_components/jquery/dist/jquery',                 'underscore': '../../<%= yeoman.app %>/bower_components/underscore/underscore',                 'backbone':   '../../<%= yeoman.app %>/bower_components/backbone/backbone',                 'bootstrap':  '../../<%= yeoman.app %>/bower_components/sass-bootstrap/dist/js/bootstrap',                 'handlebars': '../../<%= yeoman.app %>/bower_components/handlebars/handlebars'             },             preservelicensecomments: false,             usestrict: true,             wrap: true,             wrapshim: true         }     } }, 

in fact, picked shim configuration main.js, great. helps out dealing same frustration.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -