gpt4 book ai didi

javascript - 使用 RequireJS 加载 Marionette (v3) 的正确方法是什么?

转载 作者:行者123 更新时间:2023-11-28 18:28:18 24 4
gpt4 key购买 nike

我在 Google 上徒劳地搜索了如何使用 RequireJS< 加载 Marionette v3-pre.4 - 截至目前的最新版本(2016 年 7 月)/strong>.

该库的捆绑版本似乎对于 RequireJS 来说已损坏,因此我必须手动包含“backbone.babysitter”和“backbone.radio”,这是此版本的 Marionette 所必需的。

根据:versioneye.com我需要:

  • backbone.babysitter1.0.0-pre.1
  • backbone.radio”* 2.0.0-pre.1*

所以我尝试使用 Bower 安装它们:

bower install backbone.babysitter

它返回:

Unable to find a suitable version for backbone.babysitter, please choose one by typing one of the numbers below:
1) backbone.babysitter#^0.1.12 which resolved to 0.1.12
2) backbone.babysitter#1.0.0-pre.1 which resolved to 1.0.0-pre.1 and is required by marionette#3.0.0-pre.4

Prefix the choice with ! to persist it to bower.json

我选择了第二个,如下所示:

?回答!2

它返回:

bower resolution    Saved backbone.babysitter#1.0.0-pre.1 as resolution

我对backbone.radio做了完全相同的事情:

bower install backbone.radio

返回:

Unable to find a suitable version for backbone.radio, please choose one by typing one of the numbers below:
1) backbone.radio#^1.0.5 which resolved to 1.0.5
2) backbone.radio#2.0.0-pre.1 which resolved to 2.0.0-pre.1 and is required by marionette#3.0.0-pre.4

Prefix the choice with ! to persist it to bower.json

已选择:

? Answer !2

返回:

bower resolution    Saved backbone.radio#2.0.0-pre.1 as resolution

一切似乎都没问题,但是当我检查每个“bower.json”文件中这两个库的版本时,我发现:

backbone.babysitter位于:

  "name": "backbone.babysitter",
"version": "0.1.11"

backbone.radio:

  "name": "backbone.radio",
"version": "1.0.4"

我哪里出错了?

这是我的bower.json:

{
"name": "Example App",
"authors": "Consta Gorgan",
"dependencies": {
"backbone": "~1.2.3",
"backbone.radio": "~2.0.0",
"backbone.babysitter": "~1.0.0",
"marionette": "~3.0.0",
"requirejs": "~2.1.15",
"requirejs-plugins": "~1.0.2"
},
"resolutions": {
"backbone.radio": "2.0.0-pre.1",
"backbone.babysitter": "1.0.0-pre.1"
}
}

这是我的填充文件:

requirejs.config({
paths: {
jquery: '../bower_components/jquery/dist/jquery',
underscore: '../bower_components/underscore/underscore',
backbone: '../bower_components/backbone/backbone',
'backbone.radio': '../bower_components/backbone.radio/build/backbone.radio',
'backbone.babysitter': '../bower_components/backbone.babysitter/src/build/backbone.babysitter',
marionette: '../bower_components/marionette/lib/core/backbone.marionette'
},
shim: {
jquery: {
exports: '$'
},
backbone: {
deps: [
'underscore',
'jquery'
],
exports: 'Backbone'
},
underscore: {
exports: '_'
},
marionette: {
deps: [ 'jquery', 'underscore', 'backbone', 'backbone.radio', 'backbone.babysitter' ],
exports: 'Marionette'
}
}
})

这就是我在 app.js 文件中使用 RequireJS 加载模块的方式:

define([
'jquery',
'underscore',
'backbone',
'marionette',
'router'
], function ($, _, Backbone, Marionette, Router) {
'use strict'

var init = function () {
Router.init()
}

return {
init: init
}
})

Aa这是我在浏览器中不断遇到的错误:

Cannot set property 'VERSION' of undefined - *image*

几秒钟后这个:

Load timeout for modules: backbone.radio - *image*

最佳答案

不要使用../bower_components/backbone.babysitter/src/build/backbone.babysitter,而是使用../bower_components/backbone.babysitter/lib/backbone.babysitter

关于javascript - 使用 RequireJS 加载 Marionette (v3) 的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38662517/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com