问题描述
我不知道如何将javascript文件用于网络浏览器功能,当它被编码为node.js时。
I don't know how to get a javascript file to work for web-browser functionalit, when it's coded as node.js.
有问题的代码是来自github 。我想将此node.js代码转换为js:
The code in question is from a github graphenejs-lib. I want to convert this node.js code into js:
import {Apis} from "graphenejs-ws";
var {ChainStore} = require("graphenejs-lib");
Apis.instance("wss://bitshares.openledger.info/ws", true).init_promise.then((res) => {
console.log("connected to:", res[0].network);
ChainStore.init().then(() => {
ChainStore.subscribe(updateState);
});
});
let dynamicGlobal = null;
function updateState(object) {
dynamicGlobal = ChainStore.getObject("2.1.0");
console.log("ChainStore object update\n", dynamicGlobal ? dynamicGlobal.toJS() : dynamicGlobal);
}
同一个开发者还有另一个github,,显示node.js使用,浏览器在README默认页面中使用。
There is another github from the same developer, steemjs-lib, that shows both the node.js use, and the browser use in the README default page.
我不知道如何将graphenejs-lib导入浏览器javascript,就像steemjs-lib已被制作成常规的javascript工作版本一样。我联系了开发人员,但尚未收到回复。
I don't know how to make graphenejs-lib into browser javascript, like the steemjs-lib has been made into a regular javascript working version. I contact the dev, but have yet to receive a response.
我认为其他人实际上知道如何做开发人员为steemjs-lib做的事情,并获得graphenejs -lib在浏览器中工作。
I figured other people actually know how to do what the dev did for steemjs-lib, and get the graphenejs-lib to work in a browser.
你能帮助我吗?谢谢。
推荐答案
你可以使用可以帮助您:
You can use Browserify to help you with that:
请注意,并非所有Node的API都可以在浏览器中使用。
Note that not all of the Node's APIs will be available in the browser.
这篇关于如何将node.js代码转换为常规浏览器javascript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!