这是我对构建失败的提炼。症状是,当使用 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: []
},
最佳答案
不应将 NLS 模块指定为包含在层中。当您的层模块被处理时,它们的所有 NLS 依赖项将自动捆绑到相关层中,文件名后缀对应于每个可能的语言环境。例如对于层 MyLayer.js
,您还将获得 MyLayer_en-us.js
、MyLayer_es-es.js
等。这使访问者能够只加载他们需要的语言包。
如果您想在图层中强制包含特定语言环境(例如,因为您知道所有访问者只会说英语),您可以使用 includeLocales property这样做:
layers: {
MyLayer: {
includeLocales: [ 'en-us' ]
}
}
虽然您的第一个配置文件可能看起来有效,但它实际上不太可能按照您的预期进行,这可能就是 ShrinkSafe 崩溃的原因。
其他几点说明:
- ShrinkSafe 已弃用;你真的应该使用 Closure Compiler 或 UglifyJS。
customBase
标志仅适用于dojo/dojo
主层,意思是“不自动包含默认的 Dojo Base 模块”。您无需将其应用到其他图层。
关于dojo build - nls bundle ,除非 bundle 位于 "dojo/dojo"中,否则构建会失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17262525/