【问题标题】:dojo build - nls bundles, build fails unless bundles are in "dojo/dojo"?dojo build - nls 捆绑包,除非捆绑包位于“dojo/dojo”中,否则构建会失败?
【发布时间】:2013-06-23 15:55:01
【问题描述】:

这是我对构建失败的提炼。症状是,当使用 shrinksafe 进行优化时,我的构建会失败并出现以下错误:

 [exec] js: "<eval'ed string>#1(Function)#1(eval)", line 127: uncaught JavaScript runtime exception: TypeError: Cannot read property "1" from null
 [exec]     at <eval'ed string>#1(Function)#1(eval):127
 [exec]     at <eval'ed string>#1(Function)#1(eval):163

如果我的代码使用诸如

之类的模式拉入它的 nls 文件
"dojo/i18n!./nls/MyResource"

但是,这种结构在许多构建干净的 dojo 代码中都很常见。因此,我通过将一些 dojo 代码复制到我的模块中来进行实验,发现如果将 nls 资源加载到 dojo/dojo 层中,那么我的层会正确构建,如果我在自己的层中加载相同的 nls 资源,则会出现上述故障。

因此,我将 dijit/form/_ComboBoxMenuMixin.js 复制到我自己的模块以及相应的 nls 资源中。

我有三个测试用例,一个有效,另外两个给出上面的失败。

我的问题:

似乎我需要在“dojo/dojo”层中包含我自己的nls资源,它必须正是这一层。这肯定不对吧?我的替代方案是什么?

工作简介:

layers: {
"dojo/dojo" : {
    customBase: false,
    include: [         
              "modules/nls/ComboBox",
    ],
    exclude: []
},
"MyLayer" : {
    customBase: false,
    include: [                            
              "modules/ComboCopy",                      
    ],
    exclude: []
},
}

失败:nls 在同一层

layers: {
"dojo/dojo" : {
    customBase: false,
    include: [         

    ],
    exclude: []
},
"MyLayer" : {
    customBase: false,
    include: [   
                  "modules/nls/ComboBox",                         
              "modules/ComboCopy",                      
    ],
    exclude: []
},
}

失败,以不同的层名加载 nls

 layers: {
"myNlsLayer" : {
    customBase: false,
    include: [         
              "modules/nls/ComboBox",
    ],
    exclude: []
},
"MyLayer" : {
    customBase: false,
    include: [                            
              "modules/ComboCopy",                      
    ],
    exclude: []
},

【问题讨论】:

    标签: dojo dojo-build


    【解决方案1】:

    不应将 NLS 模块指定为包含在层中。当您的层模块被处理时,它们的所有 NLS 依赖项将自动捆绑到相关层中,并带有与每个可能的语言环境相对应的文件名后缀。例如对于MyLayer.js 层,您还将获得MyLayer_en-us.jsMyLayer_es-es.js 等。这使访问者能够仅加载他们需要的语言包。

    如果您想在图层中强制包含特定语言环境(例如,因为您知道所有访问者只会说英语),您可以使用 includeLocales property 来执行此操作:

    layers: {
        MyLayer: {
            includeLocales: [ 'en-us' ]
        }
    }
    

    虽然您的第一个配置文件可能看起来有效,但它实际上不太可能按照您的预期进行,这可能就是 ShrinkSafe 崩溃的原因。

    其他几点说明:

    1. ShrinkSafe 已弃用;你真的应该使用 Closure Compiler 或 UglifyJS。
    2. customBase 标志仅适用于主要的dojo/dojo 层,表示“不自动包含默认的 Dojo 基本模块”。您无需将其应用到其他图层。

    【讨论】:

      猜你喜欢
      • 2017-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-29
      • 1970-01-01
      • 1970-01-01
      • 2021-10-19
      • 1970-01-01
      相关资源
      最近更新 更多