8

我正在使用 RequireJS、带有布局管理器的骨干样板、JamJS 来帮助管理包,并且在开发中一切正常,但是当我尝试使用连接文件创建生产版本时它不起作用。

看起来shim我的配置中的 可能没有被加载。例如,我在控制台中遇到的错误是Uncaught TypeError: Cannot set property 'cookie' of undefined,因此 jQuery 没有作为 jquery.cookie 的依赖项加载。这是我的应用程序配置:

// Set the require.js configuration for your application.
require.config({

  // Initialize the application with the main application file and the JamJS
  // generated configuration file.
  deps: ["../vendor/jam/require.config", "main"],

  paths: {
    baseUrl : '/',
    config : "config",

    // JavaScript folders.
    api : "libs/api",
    app : "app",

    // Libraries.
    almond : "../vendor/jam/js/libs/almond",
    engagement : "libs/engagement",
    environment : "libs/environment",
    jquery : "../vendor/jam/jquery/jquery",
    jqueryui : "../vendor/js/libs/jquery-ui-1.9.1.custom.min",

    "jquery-cookie" : "../vendor/jam/jquery-cookie/jquery.cookie",

    chosen : "../vendor/js/libs/jquery.chosen.min",
    colorpicker : "../vendor/js/libs/jquery.colorpicker",
    bootstrap : "../vendor/js/libs/bootstrap",
    jqueryuiwidget : "../vendor/js/libs/jquery.ui.widget",

    jstemplates : "../vendor/js/libs/tmpl",
    jsloadimage : "../vendor/js/libs/load-image",
    jscanvastoblob : "../vendor/js/libs/canvas-to-blob",
    iframetransport : "../vendor/js/libs/jquery.iframe-transport",
    fileupload : "../vendor/js/libs/jquery.fileupload",
    fileuploadfp : "../vendor/js/libs/jquery.fileupload-fp",
    fileuploadui : "../vendor/js/libs/jquery.fileupload-ui",
    fileuploadlib : "libs/fileupload",

    highchartsgraytheme : "../vendor/js/libs/gray",
    highchartsexporter : "../vendor/js/libs/exporting",

    adpin : "libs/adpin",

    val : "../vendor/js/libs/jquery.validate.min",
    valmethods : "../vendor/js/libs/additional-methods.min",

    advertiser : "libs/advertiser",
    messages : "libs/messages",

    user : "libs/user",
    zeroclipboard : "../vendor/js/libs/zero-clipboard",

    jqgrid : "../vendor/js/libs/jquery.jqGrid.min",
    jqgridsource : "../vendor/js/libs/grid.locale-en",

    reporting : "libs/reporting",
    adlift : "libs/adlift",
    utilities : "libs/utilities",
    qrcode : "../vendor/js/libs/jquery.qrcode.min",
    base64 : "../vendor/js/libs/base64",

    kinetic : "../vendor/js/libs/kinetic.min",
    canvaslib : "libs/canvas",

    socialstream : "libs/socialstream",
    analytics : "libs/analytics",

    classie : "../vendor/js/libs/classie",

    classie_modernizr : "../vendor/js/libs/modernizr.custom",

    qtip2 : "../vendor/js/libs/jquery.qtip",

    sponsored : 'libs/sponsoredcontent',

    publisher : 'libs/publisher',

    xml : '../vendor/jam/codemirror3/mode/xml/xml'
  },

  shim: {

    "jquery-cookie" : {
        deps : ["jquery"]
    },

    "api" : {
        deps : ["environment"]
    },

    "xml" : {
        deps : ["codemirror3"]
    },

    "classie" : {
        deps : ["classie_modernizr"]
    },

    "jqueryui" : {
        deps : ["jquery"]
    },

    "colorpicker":{
        deps : ["jquery"]
    },

    "jqueryuiwidget" : {
        deps : ["jquery"]
    },

    "jstemplates" : {
        deps : ["jquery"]
    },

    "jsloadimage" : {
        deps : ["jquery"]
    },

    "jscanvastoblob" : {
        deps : ["jquery"]
    },

    "fileupload" : {
        deps : ["jquery", "jqueryuiwidget"]
    },

    "fileuploadfp" : {
        deps : ["jquery", "jscanvastoblob", "fileupload"]
    },

    "fileuploadui" : {
        deps : ["jquery", "jstemplates", "jsloadimage", "fileuploadfp", "fileuploadlib"]
    },

    "qrcode" : {
        deps : ["jquery"]
    },

    "base64" : {
        deps : ["jquery"]
    },

    "highchartsgraytheme" : {
        deps : ["highcharts"]
    },

    "highchartsexporter" : {
        deps : ["highcharts"]
    },

    "utilities" : {
        deps : ["lodash", "jquery", "val"]
    },

    "val" : {
        deps : ["jquery"]
    },

    "valmethods" : { 
        deps: ["jquery", "val"]
    },

    "zeroclipboard": {
        deps : ["jquery"]
    },

    "jqgrid" : {
        deps : ["jquery", "jqgridsource"]
    },

    "jqgridsource" : {
        deps : ["jquery"]
    },

    "bootstrap" : {
        deps : ["jquery"]
    }
  }

});

这是我加载 require.js 文件的方式:

<script data-main="/app/config" src="/dist/debug/require.js"></script>

关于可能发生的事情有什么想法吗?当我使用bbb release时,一切都完成了,没有错误地创建该调试文件。

4

2 回答 2

3

我有一些建议,这听起来可能很愚蠢,但由于我没有掌握文件猜测是我能做的最好的,所以,确保没有:define(["jquery"], .....在你的 jquery-cookie 文件中,因为你应该要么将其包含在 shim 或此定义中,但不能同时包含两者,因为它可能会导致冲突。如果它有效,请告诉我添加解释为什么会发生这种情况,祝你好运。

于 2013-09-28T19:55:02.823 回答
2

埃文,我不确定你的问题到底是什么。为此,我建议从 JamJS 转而使用 Bower。谁知道呢,也许 Jam 中的构建被破坏了。

您的 shim 看起来是正确的,但我想知道您是否在该部分的文件mainConfigFile中设置了该选项。Gruntfile.jsrequirejs

bbb命令已被弃用,因此我鼓励您调查https://github.com/backbone-boilerplate/backbone-boilerplate/wiki/Installation我们的生成器应该可以很好地满足您的需求!

于 2013-10-01T20:16:53.047 回答