有没有人在r.js构建中成功加载了moment.js(用杏仁)?
我正在使用backgrid和backgridMomentCell:在构建main.min.js文件之前,一切都很完美。构建时间之后没有定义时刻,因此无法通过backgridMomentCell扩展名找到。
我尝试了几种选择(甚至垫片)但没有成功。
如果somedoby有一个require.config工作可以共享吗?
编辑(抱歉没有及早回答,发布时间让我远离SO):
在构建文件BackGridMomentCell中继续抛出“片刻未定义”的错误。
我在评论中要求的代码
requirejs.config({
paths: {
backbone: 'vendor/backbone-1.1.0',
backbonePageable: 'vendor/backbone-pageable-1.4.1',
backgrid: 'vendor/backgrid/js/backgrid-0.2.6',
backgridPaginator: 'vendor/backgrid/js/extensions/paginator/backgrid-paginator',
backgridMomentCell: 'vendor/backgrid/js/extensions/moment-cell/backgrid-moment-cell',
bootstrap: 'vendor/bootstrap/js/bootstrap-3.0.1',
bootstrapDatepicker: 'vendor/bootstrap-datepicker/bootstrap-datepicker-fda46bb',
codemirror: 'vendor/codemirror/js/codemirror-3.20',
codemirrorMarkdown: 'vendor/codemirror/mode/markdown/markdown',
jsDiff: 'vendor/diff-1.0.7',
fullCalendar: 'vendor/fullcalendar/fullcalendar-1.6.4',
fullCalendarJqueryUiCustom: 'vendor/fullcalendar/jquery-ui-1.10.3.custom.min',
jquery: 'vendor/jquery-1.10.2',
marked: 'vendor/marked-0.2.10',
select2: 'vendor/select2/select2-3.4.5',
speakingurl: 'vendor/speakingurl-0.4.0',
underscore: 'vendor/underscore-1.5.2',
moment: 'vendor/moment.with.langs'
},
shim: {
backbone: {
deps: ['jquery', 'underscore'],
exports: 'Backbone'
},
backgrid: {
deps: ['jquery', 'backbone', 'underscore'],
exports: 'Backgrid'
},
backgridPaginator: {
deps: ['backgrid']
},
backgridMomentCell: {
deps: ['backgrid','moment']
},
bootstrap: {
deps: ['jquery']
},
bootstrapDatepicker: {
deps: ['jquery']
},
codemirror: {
exports: 'CodeMirror'
},
codemirrorMarkdown: {
deps: ['codemirror'],
exports: 'codemirrorMarkdown'
},
fullCalendar: {
deps: ['jquery', 'fullCalendarJqueryUiCustom']
},
fullCalendarJqueryUiCustom: {
deps: ['jquery']
},
select2: {
deps: ['jquery']
},
underscore: {
exports: '_'
}
}
});
模块的负责人
define([
'jquery',
'fullCalendar',
'underscore',
'backgrid',
'backgridPaginator',
'moment',
'backgridMomentCell',
'backbone',
'collections/ItemPaginatedCollection',
'utils/BackgridCustomUriCell'
], function ($, _fullCalendar, _, Backgrid, _backgridPaginator, moment, MomentCell,Backbone, ItemPaginatedCollection, BackgridCustomUriCell) {
"use strict";
....
编辑3:
在我编译的main.js工作之前加载moment.js,但不是最佳恕我直言。
答案 0 :(得分:1)
我找到的最简单的两种方法:
1)在RequireJS API中指定的CommonJS wrapper code中包装backgrid-moment-cell.js。您可以使用API中提到的转换工具在构建过程中动态执行此操作。
2)在build.js中要求moment-cell内联并将findNestedDependencies设置为false。
问题是,在初始化时,时刻单元代码会将this
传递给它自己,并查找“exports.moment”或“this.moment”。
在一个相关的说明中,包括片刻中的片刻时刻 - 细胞是不必要的,技术上你应该包括下划线。 From the API:
仅使用其他“shim”模块作为shimmed脚本的依赖项,或者 没有依赖关系的AMD库,并在它们之后调用define() 也创建一个全局(如jQuery或lodash)。否则,如果您使用 在构建之后,AMD模块作为shim配置模块的依赖项, 直到调整后的代码之后才能评估AMD模块 构建执行,并将发生错误。最终解决方案是 将所有已调整的代码升级为可选的AMD define()调用。
片刻实际上是一个AMD模块。
答案 1 :(得分:0)
您的问题很可能是您未在构建文件中指定findNestedDependencies
。
看看这个提交(来自我的book on RquireJS and Backbone.Marionette):https://github.com/davidsulc/structuring-backbone-with-requirejs-and-marionette/commit/85d3d3dd40d0cebd858224c3903a12d6998d668d
答案 2 :(得分:0)
我认为这与关闭时刻的全局对象有关。
2.4.0 - Deprecate globally exported moment, will be removed in next major
https://github.com/moment/moment
现在需要在特定模块中定义时刻。