我使用 Marionette.js 框架,我需要重写 Marionette.TemplateCache 模块的一个函数,但不更新 marionette.js 文件。 所以,我为此创建了一个新模块:
define(['marionette'], function (Marionette) {
'use strict';
_.extend(Marionette.TemplateCache.prototype, {
loadTemplate: function(templateId){
var template = templateId;
if (!template || template.length === 0){
throwError("Could not find template: '" + templateId + "'", "NoTemplateError");
}
return template;
}
});
return Marionette;
});
但是,我不知道如何配置我的 requirejs main,因为当我加载 Marionette.js 框架时,我的模块会覆盖 Marionette.js。
你有什么想法吗?
谢谢。
乔纳森。
最佳答案
您可以将为原始库定义的路径重命名为类似marionette-core
的路径,并按如下方式更新您的模块
define(['marionette-core'], function (Marionette) {
'use strict';
_.extend(Marionette.TemplateCache.prototype, {
loadTemplate: function(templateId){
var template = templateId;
if (!template || template.length === 0){
throwError("Could not find template: '" + templateId + "'", "NoTemplateError");
}
return template;
}
});
return Marionette;
});
现在将您的模块的路径定义为 marionette
。
所以现在当你需要 marionette
时,require.js 将加载原始的 marionette
并返回你的自定义实例。
此外,如果需要,您仍然可以在其他地方使用 marionette-core
加载原始库
关于javascript - 如何使用 requirejs 覆盖 vendor 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33165399/