加载:长,ByteBuffer和ProtoBuff与要求
Loading: long, ByteBuffer and ProtoBuff with requirejs
使用ProtoBuff获取内容的项目。通过加载HTML中的javascript,使其工作一次。现在重构为使用需求来加载脚本。但是当我尝试使用脚本时,它给出一个错误告诉我脚本没有加载。
- Require.js加载到index.html
- Bower是用来管理依赖关系的。
我很确定我在这里错过了一件(简单的)事情,希望有人能帮助我。
requirejs.config({
long : "long",
ByteBuffer : "ByteBuffer",
ProtoBuf : "ProtoBuf"
});
requirejs([ "long", "ByteBuffer", "ProtoBuf" ],
function( long, ByteBuffer, ProtoBuf ) {
});
long.js、ByteBuffer.js和ProtoBuf.js这些文件都和App.js在同一个map中,在这个map中叫做。
*虽然这个关于需求和ByteBuffer的问题看起来很有希望,但我认为我在这里遗漏了一些东西。
这样做是有效的,这些文件中的函数可以在作用域的其余部分中访问:
requirejs([ "otherPage", "differentPage" ],
function( util ) {
});
您需要确保您已经正确地连接了需求,并且您已经加载了相关的原型库。
你可以使用wer来管理依赖关系。安装bower
和
bower install long byteBuffer protobuf requirejs-text requirejs-proto
最后的代码看起来像这样:
require.config({
paths: {
'Long': '../../bower_components/long/dist/Long',
'ByteBuffer': '../../bower_components/byteBuffer/dist/ByteBufferAB',
'ProtoBuf': '../../bower_components/protobuf/dist/ProtoBuf',
'text': '../../bower_components/requirejs-text/text',
'proto': '../../bower_components/requirejs-proto/proto'
},
proto: {
ext: 'proto',
convertFieldsToCamelCase: false,
populateAccessors: true
}
});
require(['proto!test'], function(builder) {
var pack = builder.build('pack');
var Message1 = builder.build('pack.Message1');
});
require(['proto!test::pack.Message1', 'proto!test::pack.Message2'], function(Message1, Message2) {
...
});
一些代码来自https://www.npmjs.com/package/requirejs-proto