Grunt build successful but requirejs dependent libraries unavailable
Problem
I have a grunt build that completes successfully and most libraries are available except for those dependent on other libraries.
Example
For example, underscore-string depends on underscore and attaches itself to the underscore namespace as _.string but that function isn't available in the app. This is the same problem I have with moment.range.
RequireJS Config
{
"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"
...
]
}
Notes
The application works fine unoptimized and the string and range library are both included in the final build file. My guess is that the underscore and moment libraries are unavailable to attach to after the build file is loaded.
Solved it - underscore string needs to be included as "underscore.string" and not "string"
The config would then have a paths of
"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"
...
},
链接地址: http://www.djcxy.com/p/93632.html
上一篇: 与requirejs亲戚呆在一起