1

问题

我有一个成功完成的 grunt 构建,除了依赖于其他库的库之外,大多数库都可用。

例子

例如,下划线字符串依赖于下划线并将自身附加到下划线命名空间作为 _.string 但该功能在应用程序中不可用。这与我在 moment.range 中遇到的问题相同。

要求JS配置

{
 "name": "app",
 "dir": "client-compress",
 "baseUrl": "client-dist",
 "preserveLicenseComments": true,
 "paths": {
   "underscore":     "bower_components/underscore/underscore",
   "backbone":       "bower_components/backbone/backbone-min",
   "requireLib":     "bower_components/requirejs/require",
   "moment":         "bower_components/moment/moment",
   "string":         "bower_components/underscore.string/lib/underscore.string",
   "momentrange":    "bower_components/moment-range/lib/moment-range"
    ...       
 },
 "shim": {
   "backbone":   { "exports": "Backbone", "deps": ["underscore", "jquery"] },
   "underscore": { "exports": "_" },      
   "string": { "deps": ["underscore"]},
   "moment": {"exports": "moment"},
   "momentrange": {"deps": ["moment"]}
   ...                
 },
  "include": [
   "requireLib",
   "underscore",
   "moment",
   "string",
   "backbone",
   "momentrange"
   ...
  ]
}

笔记

该应用程序在未优化的情况下可以正常工作,并且字符串和范围库都包含在最终构建文件中。我的猜测是加载构建文件后无法附加下划线和矩库。

4

1 回答 1

1

解决了 - 下划线字符串需要包含为“underscore.string”而不是“string”

然后配置将有一个路径

"paths": {
 "underscore":         "bower_components/underscore/underscore",
 "backbone":           "bower_components/backbone/backbone-min",
 "requireLib":         "bower_components/requirejs/require",
 "moment":             "bower_components/moment/moment",
 "underscore.string":  "bower_components/underscore.string/lib/underscore.string",
 "momentrange":        "bower_components/moment-range/lib/moment-range"
  ...       
},
于 2013-09-28T18:32:38.887 回答