[英]After r.js build Backbone and Handlebars are undefined in App Loader
[英]Moment js undefined after r.js building
有沒有人成功地將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,但這不是最佳的恕我直言。
我發現的最簡單的兩種方法:
1)用RequireJS API中指定的CommonJS包裝器代碼包裝backgrid-moment-cell.js。 您可以在構建過程中使用API中提到的轉換工具動態地執行此操作。
2)需要在單元格中內聯,並在build.js中將findNestedDependencies設置為false。
問題是,當下細胞的代碼將在this
本身,當它被初始化,並查找不是“exports.moment”或“this.moment。”
與此相關的是,無需在動量墊片中包含動量,並且從技術上講,您應包括下划線。 從API中 :
僅將其他“填充程序”模塊用作填充腳本的依賴性,或者將不具有依賴性的AMD庫也創建全局變量(如jQuery或lodash)后調用define()。 否則,如果您將AMD模塊用作墊片配置模塊的依賴項,則在構建之后,可能要等到構建中的填充代碼執行后,才能評估該AMD模塊,否則會發生錯誤。 最終的解決方法是將所有填充的代碼升級為具有可選的AMD define()調用。
Moment實際上是AMD模塊。
最可能的問題是您沒有在構建文件findNestedDependencies
指定findNestedDependencies
true。
看看這個提交(來自我在RquireJS和Backbone.Marionette上的書 ): https : //github.com/davidsulc/structuring-backbone-with-requirejs-and-marionette/commit/85d3d3dd40d0cebd858224c3903a12d6998d668d
我認為這與時刻不建議使用的全局對象有關。
2.4.0 - Deprecate globally exported moment, will be removed in next major
https://github.com/moment/moment
現在需要在特定模塊中定義矩。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.