webpack: fix babelification. upgrade to webpack3.
This commit is contained in:
parent
fb2a5c8534
commit
bf5ea72863
2
.babelrc
2
.babelrc
@ -1,7 +1,7 @@
|
||||
{
|
||||
"presets": ["es2015"],
|
||||
"plugins": [
|
||||
"transform-async-to-generator",
|
||||
["transform-async-to-generator"],
|
||||
["transform-runtime", {
|
||||
"polyfill": true,
|
||||
"regenerator": true
|
||||
|
||||
5
Makefile
5
Makefile
@ -8,7 +8,10 @@ clean:
|
||||
docs:
|
||||
@npm run docs
|
||||
|
||||
lint:
|
||||
@npm run lint
|
||||
|
||||
test:
|
||||
@npm test
|
||||
|
||||
.PHONY: all clean docs test
|
||||
.PHONY: all clean docs lint test
|
||||
|
||||
@ -3,12 +3,12 @@
|
||||
<head>
|
||||
<title>bcoin</title>
|
||||
<style>
|
||||
html {
|
||||
height: 100%;
|
||||
html {
|
||||
height: 100%;
|
||||
}
|
||||
body {
|
||||
height: 90%;
|
||||
padding: 20px;
|
||||
body {
|
||||
height: 90%;
|
||||
padding: 20px;
|
||||
}
|
||||
h1 {
|
||||
font: 3em monospace;
|
||||
@ -74,7 +74,7 @@
|
||||
overflow-y: scroll;
|
||||
}
|
||||
</style>
|
||||
<script src="/bcoin.min.js"></script>
|
||||
<script src="/bcoin.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Bcoin, the browser full node</h1>
|
||||
|
||||
@ -7,8 +7,8 @@ var server, proxy;
|
||||
|
||||
var index = fs.readFileSync(__dirname + '/index.html');
|
||||
var indexjs = fs.readFileSync(__dirname + '/index.js');
|
||||
var bcoin = fs.readFileSync(__dirname + '/bcoin.min.js');
|
||||
var master = fs.readFileSync(__dirname + '/bcoin-master.min.js');
|
||||
var bcoin = fs.readFileSync(__dirname + '/bcoin.js');
|
||||
var master = fs.readFileSync(__dirname + '/bcoin-master.js');
|
||||
var worker = fs.readFileSync(__dirname + '/bcoin-worker.js');
|
||||
|
||||
proxy = new WSProxy({
|
||||
@ -37,11 +37,11 @@ server.get('/index.js', function(req, res) {
|
||||
res.send(200, indexjs, 'js');
|
||||
});
|
||||
|
||||
server.get('/bcoin.min.js', function(req, res) {
|
||||
server.get('/bcoin.js', function(req, res) {
|
||||
res.send(200, bcoin, 'js');
|
||||
});
|
||||
|
||||
server.get('/bcoin-master.min.js', function(req, res) {
|
||||
server.get('/bcoin-master.js', function(req, res) {
|
||||
res.send(200, master, 'js');
|
||||
});
|
||||
|
||||
|
||||
@ -15,6 +15,7 @@
|
||||
* @exports Environment
|
||||
* @constructor
|
||||
* @property {Function} env - See {@link Environment}.
|
||||
* @property {Function} require - See {@link module:utils/lazy}.
|
||||
*
|
||||
* @property {Function} bn - See {@url https://github.com/indutny/bn.js}.
|
||||
* @property {Object} elliptic - See {@url https://github.com/indutny/elliptic}.
|
||||
@ -126,10 +127,6 @@
|
||||
function Environment() {
|
||||
this.env = Environment;
|
||||
|
||||
// BN
|
||||
this.bn = require('bn.js');
|
||||
this.elliptic = require('elliptic');
|
||||
|
||||
// Horrible BIP
|
||||
this.bip70 = require('./bip70');
|
||||
|
||||
@ -150,6 +147,7 @@ function Environment() {
|
||||
|
||||
// Crypto
|
||||
this.crypto = require('./crypto');
|
||||
this.bn = require('./crypto/bn');
|
||||
this.ec = require('./crypto/ec');
|
||||
this.pk = require('./crypto/pk');
|
||||
this.schnorr = require('./crypto/schnorr');
|
||||
@ -235,6 +233,7 @@ function Environment() {
|
||||
this.bloom = require('./utils/bloom');
|
||||
this.co = require('./utils/co');
|
||||
this.encoding = require('./utils/encoding');
|
||||
this.int64 = require('./utils/int64');
|
||||
this.lock = require('./utils/lock');
|
||||
this.reader = require('./utils/reader');
|
||||
this.staticwriter = require('./utils/staticwriter');
|
||||
@ -291,12 +290,7 @@ Environment.prototype.now = function now() {
|
||||
*/
|
||||
|
||||
Environment.prototype.cache = function cache() {
|
||||
this.bip70;
|
||||
this.common;
|
||||
this.crypto;
|
||||
this.fullnode;
|
||||
this.http;
|
||||
this.spvnode;
|
||||
;
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
17
lib/env.js
17
lib/env.js
@ -7,8 +7,6 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var lazy = require('./utils/lazy');
|
||||
|
||||
/**
|
||||
* A bcoin "environment" which exposes all
|
||||
* constructors for primitives, the blockchain,
|
||||
@ -128,7 +126,6 @@ var lazy = require('./utils/lazy');
|
||||
|
||||
function Environment() {
|
||||
this.env = Environment;
|
||||
this.require = lazy(require, this);
|
||||
|
||||
// Horrible BIP
|
||||
this.require('bip70', './bip70');
|
||||
@ -301,12 +298,26 @@ Environment.prototype.cache = function cache() {
|
||||
this.spvnode;
|
||||
};
|
||||
|
||||
/**
|
||||
* Cache all necessary modules.
|
||||
*/
|
||||
|
||||
Evironment.prototype.require = function _require(name, path) {
|
||||
var cache;
|
||||
this.__defineGetter__(name, function() {
|
||||
if (!cache)
|
||||
cache = require(path);
|
||||
return cache;
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
* Expose by converting `exports` to an
|
||||
* Environment.
|
||||
*/
|
||||
|
||||
exports.cache = Environment.prototype.cache;
|
||||
exports.require = Environment.prototype.require;
|
||||
exports.set = Environment.prototype.set;
|
||||
exports.now = Environment.prototype.now;
|
||||
|
||||
|
||||
@ -17,7 +17,6 @@ exports.fs = require('./fs');
|
||||
exports.Heap = require('./heap');
|
||||
exports.Int64 = require('./int64');
|
||||
exports.IP = require('./ip');
|
||||
exports.lazy = require('./lazy');
|
||||
exports.Lock = require('./lock');
|
||||
exports.MappedLock = exports.Lock.Mapped;
|
||||
exports.LRU = require('./lru');
|
||||
|
||||
@ -1,11 +0,0 @@
|
||||
/*!
|
||||
* lazy-browser.js - lazy loading for bcoin
|
||||
* Copyright (c) 2016-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
module.exports = function lazy(require, exports) {
|
||||
return function() {};
|
||||
};
|
||||
@ -1,25 +0,0 @@
|
||||
/*!
|
||||
* lazy.js - lazy loading for bcoin
|
||||
* Copyright (c) 2016-2017, Christopher Jeffrey (MIT License).
|
||||
* https://github.com/bcoin-org/bcoin
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Setup a lazy loader.
|
||||
* @alias module:utils.lazy
|
||||
* @param {Function} require
|
||||
* @param {Object} exports
|
||||
*/
|
||||
|
||||
module.exports = function lazy(require, exports) {
|
||||
return function _require(name, path) {
|
||||
var cache;
|
||||
exports.__defineGetter__(name, function() {
|
||||
if (!cache)
|
||||
cache = require(path);
|
||||
return cache;
|
||||
});
|
||||
};
|
||||
};
|
||||
@ -6,8 +6,6 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var unorm;
|
||||
|
||||
/**
|
||||
* Normalize unicode string.
|
||||
* @alias module:utils.nfkd
|
||||
@ -16,13 +14,7 @@ var unorm;
|
||||
*/
|
||||
|
||||
function nfkd(str) {
|
||||
if (str.normalize)
|
||||
return str.normalize('NFKD');
|
||||
|
||||
if (!unorm)
|
||||
unorm = require('../../vendor/unorm');
|
||||
|
||||
return unorm.nfkd(str);
|
||||
return str.normalize('NFKD');
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@ -9,7 +9,7 @@
|
||||
|
||||
/* jshint worker: true */
|
||||
|
||||
self.importScripts('/bcoin-master.min.js');
|
||||
self.importScripts('/bcoin-master.js');
|
||||
|
||||
self.onmessage = function onmessage(event) {
|
||||
var env;
|
||||
|
||||
57
package.json
57
package.json
@ -30,25 +30,24 @@
|
||||
"optionalDependencies": {
|
||||
"bcoin-native": "0.0.19",
|
||||
"leveldown": "1.7.0-0",
|
||||
"level-js": "2.2.4",
|
||||
"secp256k1": "3.2.5",
|
||||
"socket.io": "2.0.1",
|
||||
"socket.io-client": "2.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babelify": "^7.3.0",
|
||||
"babel-loader": "^6.4.1",
|
||||
"babel-preset-es2015": "^6.24.1",
|
||||
"babel-polyfill": "^6.23.0",
|
||||
"babel-core": "^6.25.0",
|
||||
"babel-loader": "^7.1.0",
|
||||
"babel-plugin-transform-async-to-generator": "^6.24.1",
|
||||
"babel-plugin-transform-runtime": "^6.23.0",
|
||||
"babel-plugin-transform-regenerator": "^6.24.1",
|
||||
"babel-plugin-transform-async-to-generator": "^6.24.1",
|
||||
"babel-polyfill": "^6.23.0",
|
||||
"babel-preset-es2015": "^6.24.1",
|
||||
"eslint": "^4.1.0",
|
||||
"hash.js": "^1.0.3",
|
||||
"jsdoc": "^3.4.3",
|
||||
"level-js": "2.2.4",
|
||||
"mocha": "^3.4.1",
|
||||
"uglify-js": "^3.0.5",
|
||||
"webpack": "^1.13.3"
|
||||
"webpack": "^3.0.0"
|
||||
},
|
||||
"main": "./lib/bcoin.js",
|
||||
"bin": {
|
||||
@ -58,15 +57,26 @@
|
||||
"bcoin": "./bin/bcoin"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha --reporter spec test/*-test.js",
|
||||
"test-file": "mocha --reporter spec ",
|
||||
"test-browser": "BCOIN_NO_NATIVE=1 BCOIN_USE_ELLIPTIC=1 mocha --reporter spec test/*-test.js",
|
||||
"clean": "rm browser/bcoin.min.js browser/bcoin-master.min.js",
|
||||
"lint": "eslint lib/ test/ migrate/ examples/ bench/ bin/cli bin/node bin/spvnode || exit 0",
|
||||
"clean": "rm browser/bcoin.js browser/bcoin-master.js browser/bcoin-worker.js",
|
||||
"docs": "jsdoc -c jsdoc.json",
|
||||
"webpack": "./node_modules/webpack/bin/webpack.js"
|
||||
"lint": "eslint lib/ test/ migrate/ examples/ bench/ bin/cli bin/node bin/spvnode || exit 0",
|
||||
"lint-file": "eslint",
|
||||
"test": "mocha --reporter spec test/*-test.js",
|
||||
"test-browser": "BCOIN_NO_NATIVE=1 BCOIN_USE_ELLIPTIC=1 mocha --reporter spec test/*-test.js",
|
||||
"test-file": "mocha --reporter spec",
|
||||
"webpack": "webpack"
|
||||
},
|
||||
"browser": {
|
||||
"bcoin-native": "./browser/empty.js",
|
||||
"child_process": "./browser/empty.js",
|
||||
"crypto": "./browser/empty.js",
|
||||
"dgram": "./browser/empty.js",
|
||||
"dns": "./browser/empty.js",
|
||||
"fs": "./browser/empty.js",
|
||||
"net": "./browser/empty.js",
|
||||
"os": "./browser/empty.js",
|
||||
"secp256k1": "./browser/empty.js",
|
||||
"socket.io": "./browser/empty.js",
|
||||
"./lib/blockchain/layout.js": "./lib/blockchain/layout-browser.js",
|
||||
"./lib/crypto/backend.js": "./lib/crypto/backend-browser.js",
|
||||
"./lib/crypto/ec.js": "./lib/crypto/ec-elliptic.js",
|
||||
@ -89,25 +99,8 @@
|
||||
"./lib/utils/native": "./browser/empty.js",
|
||||
"./lib/utils/nfkd": "./lib/utils/nfkd-browser.js",
|
||||
"./lib/utils/nexttick": "./lib/utils/nexttick-browser.js",
|
||||
"./lib/utils/lazy": "./lib/utils/lazy-browser.js",
|
||||
"./lib/wallet/http": "./browser/empty.js",
|
||||
"./lib/wallet/layout": "./lib/wallet/layout-browser.js",
|
||||
"./lib/wallet/server": "./browser/empty.js",
|
||||
"bcoin-native": "./browser/empty.js",
|
||||
"child_process": "./browser/empty.js",
|
||||
"crypto": "./browser/empty.js",
|
||||
"dgram": "./browser/empty.js",
|
||||
"dns": "./browser/empty.js",
|
||||
"ec": "./lib/crypto/ec-elliptic.js",
|
||||
"fs": "./browser/empty.js",
|
||||
"net": "./browser/empty.js",
|
||||
"os": "./browser/empty.js",
|
||||
"secp256k1": "./browser/empty.js",
|
||||
"socket.io": "./browser/empty.js"
|
||||
},
|
||||
"browserify": {
|
||||
"transform": [
|
||||
"babelify"
|
||||
]
|
||||
"./lib/wallet/server": "./browser/empty.js"
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,26 +1,30 @@
|
||||
const webpack = require('webpack')
|
||||
'use strict';
|
||||
|
||||
var webpack = require('webpack')
|
||||
var path = require('path');
|
||||
|
||||
module.exports = {
|
||||
target: 'web',
|
||||
entry: {
|
||||
'bcoin.min': './lib/bcoin',
|
||||
'bcoin-master.min': './lib/workers/master'
|
||||
'bcoin': './lib/bcoin',
|
||||
'bcoin-master': './lib/workers/master'
|
||||
},
|
||||
output: {
|
||||
path: './browser',
|
||||
path: path.resolve(__dirname, 'browser'),
|
||||
filename: '[name].js'
|
||||
},
|
||||
resolve: {
|
||||
extensions: ['', '.js', '.json'],
|
||||
packageAlias: 'browser'
|
||||
descriptionFiles: ['package.json'],
|
||||
modules: ['node_modules'],
|
||||
extensions: ['.js', '.json'],
|
||||
aliasFields: ['browser']
|
||||
},
|
||||
module: {
|
||||
loaders: [
|
||||
{ test: /\.js$/, loader: 'babel', exclude: /node_modules/ },
|
||||
{ test: /\.json$/, loader: 'json' }
|
||||
]
|
||||
},
|
||||
node: {
|
||||
fs: 'empty'
|
||||
rules: [{
|
||||
test: /\.js$/,
|
||||
exclude: path.resolve(__dirname, 'node_modules'),
|
||||
loader: 'babel-loader'
|
||||
}]
|
||||
},
|
||||
plugins: [
|
||||
new webpack.optimize.UglifyJsPlugin({
|
||||
@ -29,4 +33,4 @@ module.exports = {
|
||||
}
|
||||
})
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user