webpack: fix babelification. upgrade to webpack3.

This commit is contained in:
Christopher Jeffrey 2017-06-26 17:41:11 -07:00
parent fb2a5c8534
commit bf5ea72863
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
13 changed files with 78 additions and 118 deletions

View File

@ -1,7 +1,7 @@
{ {
"presets": ["es2015"], "presets": ["es2015"],
"plugins": [ "plugins": [
"transform-async-to-generator", ["transform-async-to-generator"],
["transform-runtime", { ["transform-runtime", {
"polyfill": true, "polyfill": true,
"regenerator": true "regenerator": true

View File

@ -8,7 +8,10 @@ clean:
docs: docs:
@npm run docs @npm run docs
lint:
@npm run lint
test: test:
@npm test @npm test
.PHONY: all clean docs test .PHONY: all clean docs lint test

View File

@ -74,7 +74,7 @@
overflow-y: scroll; overflow-y: scroll;
} }
</style> </style>
<script src="/bcoin.min.js"></script> <script src="/bcoin.js"></script>
</head> </head>
<body> <body>
<h1>Bcoin, the browser full node</h1> <h1>Bcoin, the browser full node</h1>

View File

@ -7,8 +7,8 @@ var server, proxy;
var index = fs.readFileSync(__dirname + '/index.html'); var index = fs.readFileSync(__dirname + '/index.html');
var indexjs = fs.readFileSync(__dirname + '/index.js'); var indexjs = fs.readFileSync(__dirname + '/index.js');
var bcoin = fs.readFileSync(__dirname + '/bcoin.min.js'); var bcoin = fs.readFileSync(__dirname + '/bcoin.js');
var master = fs.readFileSync(__dirname + '/bcoin-master.min.js'); var master = fs.readFileSync(__dirname + '/bcoin-master.js');
var worker = fs.readFileSync(__dirname + '/bcoin-worker.js'); var worker = fs.readFileSync(__dirname + '/bcoin-worker.js');
proxy = new WSProxy({ proxy = new WSProxy({
@ -37,11 +37,11 @@ server.get('/index.js', function(req, res) {
res.send(200, indexjs, 'js'); 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'); 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'); res.send(200, master, 'js');
}); });

View File

@ -15,6 +15,7 @@
* @exports Environment * @exports Environment
* @constructor * @constructor
* @property {Function} env - See {@link Environment}. * @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 {Function} bn - See {@url https://github.com/indutny/bn.js}.
* @property {Object} elliptic - See {@url https://github.com/indutny/elliptic}. * @property {Object} elliptic - See {@url https://github.com/indutny/elliptic}.
@ -126,10 +127,6 @@
function Environment() { function Environment() {
this.env = Environment; this.env = Environment;
// BN
this.bn = require('bn.js');
this.elliptic = require('elliptic');
// Horrible BIP // Horrible BIP
this.bip70 = require('./bip70'); this.bip70 = require('./bip70');
@ -150,6 +147,7 @@ function Environment() {
// Crypto // Crypto
this.crypto = require('./crypto'); this.crypto = require('./crypto');
this.bn = require('./crypto/bn');
this.ec = require('./crypto/ec'); this.ec = require('./crypto/ec');
this.pk = require('./crypto/pk'); this.pk = require('./crypto/pk');
this.schnorr = require('./crypto/schnorr'); this.schnorr = require('./crypto/schnorr');
@ -235,6 +233,7 @@ function Environment() {
this.bloom = require('./utils/bloom'); this.bloom = require('./utils/bloom');
this.co = require('./utils/co'); this.co = require('./utils/co');
this.encoding = require('./utils/encoding'); this.encoding = require('./utils/encoding');
this.int64 = require('./utils/int64');
this.lock = require('./utils/lock'); this.lock = require('./utils/lock');
this.reader = require('./utils/reader'); this.reader = require('./utils/reader');
this.staticwriter = require('./utils/staticwriter'); this.staticwriter = require('./utils/staticwriter');
@ -291,12 +290,7 @@ Environment.prototype.now = function now() {
*/ */
Environment.prototype.cache = function cache() { Environment.prototype.cache = function cache() {
this.bip70; ;
this.common;
this.crypto;
this.fullnode;
this.http;
this.spvnode;
}; };
/* /*

View File

@ -7,8 +7,6 @@
'use strict'; 'use strict';
var lazy = require('./utils/lazy');
/** /**
* A bcoin "environment" which exposes all * A bcoin "environment" which exposes all
* constructors for primitives, the blockchain, * constructors for primitives, the blockchain,
@ -128,7 +126,6 @@ var lazy = require('./utils/lazy');
function Environment() { function Environment() {
this.env = Environment; this.env = Environment;
this.require = lazy(require, this);
// Horrible BIP // Horrible BIP
this.require('bip70', './bip70'); this.require('bip70', './bip70');
@ -301,12 +298,26 @@ Environment.prototype.cache = function cache() {
this.spvnode; 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 * Expose by converting `exports` to an
* Environment. * Environment.
*/ */
exports.cache = Environment.prototype.cache; exports.cache = Environment.prototype.cache;
exports.require = Environment.prototype.require;
exports.set = Environment.prototype.set; exports.set = Environment.prototype.set;
exports.now = Environment.prototype.now; exports.now = Environment.prototype.now;

View File

@ -17,7 +17,6 @@ exports.fs = require('./fs');
exports.Heap = require('./heap'); exports.Heap = require('./heap');
exports.Int64 = require('./int64'); exports.Int64 = require('./int64');
exports.IP = require('./ip'); exports.IP = require('./ip');
exports.lazy = require('./lazy');
exports.Lock = require('./lock'); exports.Lock = require('./lock');
exports.MappedLock = exports.Lock.Mapped; exports.MappedLock = exports.Lock.Mapped;
exports.LRU = require('./lru'); exports.LRU = require('./lru');

View File

@ -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() {};
};

View File

@ -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;
});
};
};

View File

@ -6,8 +6,6 @@
'use strict'; 'use strict';
var unorm;
/** /**
* Normalize unicode string. * Normalize unicode string.
* @alias module:utils.nfkd * @alias module:utils.nfkd
@ -16,13 +14,7 @@ var unorm;
*/ */
function nfkd(str) { function nfkd(str) {
if (str.normalize) return str.normalize('NFKD');
return str.normalize('NFKD');
if (!unorm)
unorm = require('../../vendor/unorm');
return unorm.nfkd(str);
} }
/* /*

View File

@ -9,7 +9,7 @@
/* jshint worker: true */ /* jshint worker: true */
self.importScripts('/bcoin-master.min.js'); self.importScripts('/bcoin-master.js');
self.onmessage = function onmessage(event) { self.onmessage = function onmessage(event) {
var env; var env;

View File

@ -30,25 +30,24 @@
"optionalDependencies": { "optionalDependencies": {
"bcoin-native": "0.0.19", "bcoin-native": "0.0.19",
"leveldown": "1.7.0-0", "leveldown": "1.7.0-0",
"level-js": "2.2.4",
"secp256k1": "3.2.5", "secp256k1": "3.2.5",
"socket.io": "2.0.1", "socket.io": "2.0.1",
"socket.io-client": "2.0.1" "socket.io-client": "2.0.1"
}, },
"devDependencies": { "devDependencies": {
"babelify": "^7.3.0", "babel-core": "^6.25.0",
"babel-loader": "^6.4.1", "babel-loader": "^7.1.0",
"babel-preset-es2015": "^6.24.1", "babel-plugin-transform-async-to-generator": "^6.24.1",
"babel-polyfill": "^6.23.0",
"babel-plugin-transform-runtime": "^6.23.0", "babel-plugin-transform-runtime": "^6.23.0",
"babel-plugin-transform-regenerator": "^6.24.1", "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", "eslint": "^4.1.0",
"hash.js": "^1.0.3", "hash.js": "^1.0.3",
"jsdoc": "^3.4.3", "jsdoc": "^3.4.3",
"level-js": "2.2.4",
"mocha": "^3.4.1", "mocha": "^3.4.1",
"uglify-js": "^3.0.5", "webpack": "^3.0.0"
"webpack": "^1.13.3"
}, },
"main": "./lib/bcoin.js", "main": "./lib/bcoin.js",
"bin": { "bin": {
@ -58,15 +57,26 @@
"bcoin": "./bin/bcoin" "bcoin": "./bin/bcoin"
}, },
"scripts": { "scripts": {
"test": "mocha --reporter spec test/*-test.js", "clean": "rm browser/bcoin.js browser/bcoin-master.js browser/bcoin-worker.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",
"docs": "jsdoc -c jsdoc.json", "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": { "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/blockchain/layout.js": "./lib/blockchain/layout-browser.js",
"./lib/crypto/backend.js": "./lib/crypto/backend-browser.js", "./lib/crypto/backend.js": "./lib/crypto/backend-browser.js",
"./lib/crypto/ec.js": "./lib/crypto/ec-elliptic.js", "./lib/crypto/ec.js": "./lib/crypto/ec-elliptic.js",
@ -89,25 +99,8 @@
"./lib/utils/native": "./browser/empty.js", "./lib/utils/native": "./browser/empty.js",
"./lib/utils/nfkd": "./lib/utils/nfkd-browser.js", "./lib/utils/nfkd": "./lib/utils/nfkd-browser.js",
"./lib/utils/nexttick": "./lib/utils/nexttick-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/http": "./browser/empty.js",
"./lib/wallet/layout": "./lib/wallet/layout-browser.js", "./lib/wallet/layout": "./lib/wallet/layout-browser.js",
"./lib/wallet/server": "./browser/empty.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"
]
} }
} }

View File

@ -1,26 +1,30 @@
const webpack = require('webpack') 'use strict';
var webpack = require('webpack')
var path = require('path');
module.exports = { module.exports = {
target: 'web',
entry: { entry: {
'bcoin.min': './lib/bcoin', 'bcoin': './lib/bcoin',
'bcoin-master.min': './lib/workers/master' 'bcoin-master': './lib/workers/master'
}, },
output: { output: {
path: './browser', path: path.resolve(__dirname, 'browser'),
filename: '[name].js' filename: '[name].js'
}, },
resolve: { resolve: {
extensions: ['', '.js', '.json'], descriptionFiles: ['package.json'],
packageAlias: 'browser' modules: ['node_modules'],
extensions: ['.js', '.json'],
aliasFields: ['browser']
}, },
module: { module: {
loaders: [ rules: [{
{ test: /\.js$/, loader: 'babel', exclude: /node_modules/ }, test: /\.js$/,
{ test: /\.json$/, loader: 'json' } exclude: path.resolve(__dirname, 'node_modules'),
] loader: 'babel-loader'
}, }]
node: {
fs: 'empty'
}, },
plugins: [ plugins: [
new webpack.optimize.UglifyJsPlugin({ new webpack.optimize.UglifyJsPlugin({
@ -29,4 +33,4 @@ module.exports = {
} }
}) })
] ]
} };