SlexAxton / require-handlebars-plugin

A plugin for handlebars in require.js (both in dev and build)
803 stars 202 forks source link

Sometimes "Handlebars" or "JSON" are undefined in hbs.js #241

Open chechenev opened 9 years ago

chechenev commented 9 years ago

I use this plugin with Backbone, materialize and sometimes (about once every ten loads) "Handlebars" and "JSON" in hbs.js are undefined, so I have some errors like "Cannot read property 'stringify' of undefined" or if Handlebars is undefined "Cannot read property 'registerHelper' of undefined". My requirejs config:

require.config({
    urlArgs: "bust=" + (new Date()).getTime(),
    paths: {
        jquery: 'libs/jquery.min',
        tinymce: 'libs/tinymce/tinymce.min',
        tinymcejquery: 'libs/tinymce/jquery.tinymce.min',
        underscore: 'libs/underscore-min',
        backbone: 'libs/backbone-min',
        magicsuggest: "libs/magicsuggest-min",
        autocomplete: "libs/jquery.auto-complete.min",
        text: 'libs/text',
        jqueryui: 'libs/jquery-ui-1.11.4.custom/jquery-ui.min',
        settings: 'app/settings',
        dateformat: 'libs/dateFormat',
        scrollbar: 'libs/perfect-scrollbar.jquery.min',
        socketio: 'libs/socket.io-1.3.5',
        magnificpopup: 'libs/magnificpopup',
        moment: 'libs/moment-with-locales.min',

        hbs: 'libs/hbs',

        materialize: '../materialize-AMD-master/bin/materialize',
        'hammerjs': '../materialize-AMD-master/js//hammer.min',
        'jquery.easing': '../materialize-AMD-master/js//jquery.easing.1.3',
        'velocity': '../materialize-AMD-master/js//velocity.min',
        'picker': '../materialize-AMD-master/js//date_picker/picker',
        'picker.date': '../materialize-AMD-master/js//date_picker/picker.date',
        'waves': '../materialize-AMD-master/js//waves',
        'global': '../materialize-AMD-master/js//global',
        'animation': '../materialize-AMD-master/js//animation',
        'collapsible': '../materialize-AMD-master/js//collapsible',
        'dropdown': '../materialize-AMD-master/js//dropdown',
        'leanModal': '../materialize-AMD-master/js//leanModal',
        'materialbox': '../materialize-AMD-master/js//materialbox',
        'tabs': '../materialize-AMD-master/js//tabs',
        'sideNav': '../materialize-AMD-master/js//sideNav',
        'parallax': '../materialize-AMD-master/js//parallax',
        'scrollspy': '../materialize-AMD-master/js//scrollspy',
        'tooltip': '../materialize-AMD-master/js//tooltip',
        'slider': '../materialize-AMD-master/js//slider',
        'cards': '../materialize-AMD-master/js//cards',
        'buttons': '../materialize-AMD-master/js//buttons',
        'pushpin': '../materialize-AMD-master/js//pushpin',
        'character_counter': '../materialize-AMD-master/js//character_counter',
        'toasts': '../materialize-AMD-master/js//toasts',
        'forms': '../materialize-AMD-master/js//forms',
        'scrollFire': '../materialize-AMD-master/js//scrollFire',
        'transitions': '../materialize-AMD-master/js//transitions',
        'jquery.hammer': '../materialize-AMD-master/js//jquery.hammer'
    },
    shim: {

        'jquery.easing': {
            deps: ['jquery']
        },
        'animation': {
            deps: ['jquery']
        },
        'jquery.hammer': {
            deps: ['jquery', 'hammerjs', 'waves']
        },
        'global': {
            deps: ['jquery']
        },
        'toasts': {
            deps: ['global']
        },
        'collapsible': {
            deps: ['jquery']
        },
        'dropdown': {
            deps: ['jquery']
        },
        'leanModal': {
            deps: ['jquery']
        },
        'materialbox': {
            deps: ['jquery']
        },
        'parallax': {
            deps: ['jquery']
        },
        'tabs': {
            deps: ['jquery']
        },
        'tooltip': {
            deps: ['jquery']
        },
        'sideNav': {
            deps: ['jquery']
        },
        'scrollspy': {
            deps: ['jquery']
        },
        'forms': {
            deps: ['jquery', 'global']
        },
        'slider': {
            deps: ['jquery']
        },
        'cards': {
            deps: ['jquery']
        },
        'pushpin': {
            deps: ['jquery']
        },
        'buttons': {
            deps: ['jquery']
        },
        'transitions': {
            deps: ['jquery','scrollFire']
        },
        'scrollFire': {
            deps: ['jquery', 'global']
        },
        'waves': {
            exports: 'Waves'
        },
        'character_counter': {
            deps: ['jquery']
        },

        'jqueryui': {
            deps: ['jquery']
        },
        'autocomplete': {
            deps: ['jquery']
        },
        hbs: {
            exports: 'hbs'
        },
        'socketio': {
            exports: 'io'
        },
        tinymce: {
            deps: [ 'jquery' ],
            exports: 'tinyMCE',
            init: function () {
                this.tinyMCE.DOM.events.domLoaded = true;
                return this.tinyMCE;
            }
        },
        tinymcejquery : {
            deps: [ 'jquery' ]
        },
         'materialize': {
         deps: ['jquery', 'hammerjs', 'velocity']
         }

    },

    hbs : {
        templateExtension : 'hbs',
        helperDirectory : "templates/helpers/"
    },
});

require([

    // Load our app module and pass it to our definition function
    'app/views/app',
    'jquery.easing',
    'animation',
    'velocity',
    'hammerjs',
    'jquery.hammer',
    'global', // very important do not remove!
    'collapsible',
    'dropdown',
    'leanModal',
    'materialbox',
    'parallax',
    'tabs',
    'tooltip',
    'waves',
    'toasts',
    'sideNav',
    'scrollspy',
    'forms',
    'slider',
    'cards',
    'pushpin',
    'buttons',
    'scrollFire',
    'transitions',
    'picker',
    'picker.date',
    'character_counter'
], function( App){
    new App();
});
chechenev commented 9 years ago

Also I trying to use r.js (for minimize to one file) with almond, but I have error " hbs is not defined":


Tracing dependencies for: ../../../node_modules/almond/almond
ReferenceError: hbs is not defined
In module tree:
    main
      app/views/app
        app/views/filter
          hbs

Error: ReferenceError: hbs is not defined
In module tree:
    main
      app/views/app
        app/views/filter
          hbs

    at eval (eval at <anonymous> (C:\Users\chechenev_m\WebstormProjects\tass web
\client-side\r.js:28066:64), <anonymous>:1:1)

My build file:

({
    baseUrl: 'js/',
    mainConfigFile: 'js/main.js',

    out: 'dist/output.min.js',
    optimize: 'uglify2',

    include: ['main'],
    name: '../../../node_modules/almond/almond',
})