Requirejs is not loading my handlebars dependencies like I expect

∥☆過路亽.° 提交于 2019-12-11 19:50:10

问题


I am trying to load some js files with require. Here is my config file:

define(function() {

  "use strict";

  require.config({
    hbs : {
      templateExtension : 'hbs',
      disableHelpers: true,
      disableI18n : true
    },

    shim: {
      'underscore': {
        exports: '_'
      },
      'backbone': {
        deps: [
          'underscore',
          'jquery'
        ],
        exports: 'Backbone'
      },
      json2 : {
        exports: "JSON"
      },
      'jqueryMockAjax': {
        exports: '$.mockjax',
        deps: ['jquery']
      }
    },

    paths: {

      jquery: 'libs/jquery/jquery',
      jqueryMockAjax: 'libs/jquery-mockjax/jquery.mockjax',
      underscore: 'libs/underscore/underscore',
      backbone: 'libs/backbone/backbone',

      handlebars : 'libs/hbs/handlebars',
      text: 'libs/text/text',
      hbs: 'libs/hbs/hbs',
      i18nprecompile : 'libs/i18nprecompile',
      json2 : 'libs/json2/json2'
    }
  });
});

As you can see my js vendor files are located in my libs directory. My directory structure looks like this:

+project
  +app
    +js
      +libs
    app.js
    main.js

Most of my dependencies are loading like they should, like jquery and underscore, but the handlebars stuff is not loading like it should. For example, I have a path to handlebars.js as libs/handlebars/handlebars and it is removing the libs part of the path. With other files it is not. Here is my network tab showing what gets pulled in and what doesnt.

You can see the libs part of the path being removed. I dont know what that means. Any help will be appreciated.


回答1:


The reason that I was having import issues, was that when bower pulled in the hbs plugin, it pulled in all of the files that I needed for that plugin to work. handlebars, i18nprecompile and json2 were all in a directory in the hbs plugin. When I referred to the copies in that file, then everything worked just like it was supposed to work. I don't understand why the previously defined paths did not work. If anybody has some info on that issue please comment.



来源:https://stackoverflow.com/questions/19905412/requirejs-is-not-loading-my-handlebars-dependencies-like-i-expect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!