0

我正在尝试构建 bitcore 以便 t 在浏览器中工作。这些是我运行的命令:

npm install bitcore

我制作了一个名为 index.js 的文件:

var Address = require('bitcore/lib/address');
var Block = require('bitcore/lib/block');
var BlockHeader = require('bitcore/lib/blockheader');
var HDPrivateKey = require('bitcore/lib/hdprivatekey');
var HDPublicKey = require('bitcore/lib/hdpublickey');
var PaymentProtocol = require('bitcore/lib/paymentprotocol');
var PrivateKey = require('bitcore/lib/privatekey');
var PublicKey = require('bitcore/lib/publickey');
var Script = require('bitcore/lib/script');
var Transaction = require('bitcore/lib/transaction');
var URI = require('bitcore/lib/uri');
var Unit = require('bitcore/lib/unit');

(这直接取自 bitcore 文档:http ://bitcore.io/guide/browser.html )

然后我运行了这个命令:

browserify index.js -o bitcore-browser.js

它似乎奏效了。这是输出文件的前几行:

(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
var Address = require('bitcore/lib/address');
var Block = require('bitcore/lib/block');
var BlockHeader = require('bitcore/lib/blockheader');
var HDPrivateKey = require('bitcore/lib/hdprivatekey');
var HDPublicKey = require('bitcore/lib/hdpublickey');
var PaymentProtocol = require('bitcore/lib/paymentprotocol');
var PrivateKey = require('bitcore/lib/privatekey');
var PublicKey = require('bitcore/lib/publickey');
var Script = require('bitcore/lib/script');
var Transaction = require('bitcore/lib/transaction');
var URI = require('bitcore/lib/uri');
var Unit = require('bitcore/lib/unit');

},{"bitcore/lib/address":2,"bitcore/lib/block":3,"bitcore/lib/blockheader":4,"bitcore/lib/hdprivatekey":18,"bitcore/lib/hdpublickey":19,"bitcore/lib/paymentprotocol":24,"bitcore/lib/privatekey":28,"bitcore/lib/publickey":29,"bitcore/lib/script":30,"bitcore/lib/transaction":33,"bitcore/lib/unit":42,"bitcore/lib/uri":43}],2:[function(require,module,exports){
(function (Buffer){
'use strict';

(我认为这意味着它工作正常。文件大约 2MB。)

当我将文件添加到页面时,没有任何对象存在:

<!DOCTYPE html>
<html>
    <head>
        <script src="bitcore.browser.js"></script>
    </head>
    <body>
        <script>
            var p = new PrivateKey(); // ReferenceError: PrivateKey is not defined
        </script>
    </body>
</html>

我什至尝试运行“uglify”,但没有任何效果。

4

0 回答 0