0

A 对 JamJS 来说相对较新,并且很难使其正常工作。我有一个基于 Backbone 和 RequireJS 的非常简单的项目,其中我使用 JamJS 来管理依赖项,即:Backbone、_、Less、$、modernizr、下划线、引导程序。

我倾向于遵循 Backbone Boilerplate 使用的方法。

这是我用来获取 Jam 编译的 requireJS 配置文件的代码,以及我的应用程序特定的 require 配置:

在 html 中:

<script data-main="/assets/js/app/config" src="/assets/js/jam/compiled.min.js"> </script>

'Compiled.min.js' 显然是 Jam 生成的 600kb 缩小文件。'/app/config' 文件是我的 Require.js 配置文件,我打算在其中包含我所有的项目特定代码,而不是由依赖项管理器管理。

这是应用程序/config.js:

require.config({
  baseUrl:'/assets/js/',
  deps: ['less','modernizer','bootstrap-jam','app/main'],
  paths: {
    'homeView': 'app/views/homeView'
    // Use the underscore build of Lo-Dash to minimize incompatibilities.
    ,'lodash': '../jam/lodash/dist/lodash.underscore.min'
  },
  map: {
  },
  shim: {
  }
});

(deps 中的文件是我在每个页面上都需要的文件 + 我的 main.js - 一种路由器。

问题是,在我的 homeView(由 main.js 初始化)中,我做了这样的事情:

define(['backbone'], function (Backbone) {
    return Backbone.View.extend({
        el:$('#homepageWrapper'),
        initialize: function () {
            this.$('#subTitle').text('This text is generated by homeView - the     default Backbone View.');
        }
    })
});

如您所见,我希望 Backbone 在此视图中可用。我假设它可以通过编译后的 Jam 代码使用,但是当我查看 Web Inspector 中的网络面板时,我看到这个依赖项是单独引入的——这发生在我尝试使用的任何资源上,而不仅仅是 Backbone。

我怀疑这可能与我得到的错误有关,我无法弄清楚。使用编译后的 jam 配置时,我得到:

未捕获的错误:尚未为上下文加载模块名称“下划线”:_。使用要求([])

我真的很感激这方面的帮助

谢谢。

4

0 回答 0