Add all browser bundles

This commit is contained in:
tim 2017-06-21 17:39:19 +02:00
parent 52c3505b32
commit 9e6c2c9e25
2 changed files with 108 additions and 12 deletions

View File

@ -23,13 +23,15 @@
* [Authors](#authors)
* [License](#license)
## Installation
## Node.js
### Installation
```bash
npm install bigchaindb-driver
```
### Example: Create a transaction
#### Example: Create a transaction
```js
import * as driver from 'bigchaindb-driver'
@ -74,6 +76,69 @@ conn.postTransaction(txSigned)
.then((res) => console.log('Transaction status:', res.status))
```
## Browser
### Installation and Usage
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>HTML5 boilerplate all you really need…</title>
<!-- Adjust version to your needs -->
<script src="https://unpkg.com/bigchaindb-driver@0.1.0/dist/browser/bundle.window.min.js"></script>
<script>
// BigchainDB server instance or IPDB (e.g. https://test.ipdb.io/api/v1/)
const API_PATH = 'http://localhost:9984/api/v1/'
// Create a new user with a public-private key pair
// (or a whole bunch of them, nobody's counting)
const alice = new BigchainDB.Ed25519Keypair()
// Construct a transaction payload
// `BigchainDB.Transaction.makeCreateTransaction()`: create a new asset
// `BigchainDB.Transaction.makeTransferTransaction()`: transfer an existing asset
const tx = BigchainDB.Transaction.makeCreateTransaction(
{ assetMessage: 'My very own asset...' },
{ metaDataMessage: 'wrapped in a transaction' },
// A transaction needs an output
// `BigchainDB.Transaction.makeOutput()`: requires a crypto-condition
// `BigchainDB.Transaction.makeEd25519Condition()`: simple public key output
[ BigchainDB.Transaction.makeOutput(
BigchainDB.Transaction.makeEd25519Condition(alice.publicKey))
],
alice.publicKey
)
// Optional: You've got everything you need, except for an asset
// and metadata. Maybe define them here, any JSON-serializable object
// will do
// Ok, now that you have a transaction, you need to *sign* it
// cause, you know... cryptography and ¯\_(ツ)_/¯
// Sign/fulfill the transaction with private keys
const txSigned = BigchainDB.Transaction.signTransaction(tx, alice.privateKey)
// Send the transaction off to BigchainDB
let conn = new BigchainDB.Connection(API_PATH, { 'Content-Type': 'application/json' })
conn.postTransaction(txSigned)
.then(() => conn.getStatus(txSigned.id))
.then((res) => console.log('Transaction status:', res.status))
</script>
</head>
<body id="home">
<h1>Hello BigchainDB</h1>
</body>
</html>
```
## BigchainDB Documentation
- [HTTP API Reference](https://docs.bigchaindb.com/projects/server/en/latest/http-client-server-api.html)

View File

@ -14,6 +14,39 @@ const PATHS = {
NODE_MODULES: path.resolve(__dirname, 'node_modules'),
}
const OUTPUTS = [
{
filename: PRODUCTION ? 'bundle.window.min.js' : 'bundle.window.js',
library: 'BigchainDB',
libraryTarget: 'window',
path: PATHS.BUNDLE,
},
{
filename: PRODUCTION ? 'bundle.umd.min.js' : 'bundle.umd.js',
library: 'bigchaindb-driver',
libraryTarget: 'umd',
path: PATHS.BUNDLE,
},
{
filename: PRODUCTION ? 'bundle.cjs.min.js' : 'bundle.cjs.js',
library: 'bigchaindb-driver',
libraryTarget: 'commonjs',
path: PATHS.BUNDLE,
},
{
filename: PRODUCTION ? 'bundle.cjs2.min.js' : 'bundle.cjs2.js',
library: 'bigchaindb-driver',
libraryTarget: 'commonjs2',
path: PATHS.BUNDLE,
},
{
filename: PRODUCTION ? 'bundle.amd.min.js' : 'bundle.amd.js',
library: 'bigchaindb-driver',
libraryTarget: 'amd',
path: PATHS.BUNDLE,
}
]
/** PLUGINS **/
const PLUGINS = [
@ -40,18 +73,9 @@ if (PRODUCTION) {
PLUGINS.push(...PROD_PLUGINS)
}
/** EXPORTED WEBPACK CONFIG **/
const config = {
const configBoilerplate = {
entry: [PATHS.ENTRY],
output: {
filename: PRODUCTION ? 'bundle.min.js' : 'bundle.js',
library: 'js-bigchaindb-driver',
libraryTarget: 'umd',
path: PATHS.BUNDLE,
},
devtool: PRODUCTION ? '#source-map' : '#inline-source-map',
resolve: {
@ -77,4 +101,11 @@ const config = {
},
}
/** EXPORTED WEBPACK CONFIG **/
const config = OUTPUTS.map(output => {
const configCopy = Object.assign({}, configBoilerplate)
configCopy.output = output
return configCopy
})
module.exports = config