Skip to content

Commit

Permalink
Build as UMD instead of AMD module.
Browse files Browse the repository at this point in the history
Add download and use bundle to README.

#113
  • Loading branch information
jasny committed Jul 5, 2023
1 parent 642ad31 commit f650a35
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
42 changes: 40 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ or
yarn add @ltonetwork/lto
```

## Basic usage
Alternatively you can [download the library as bundle](#download-bundle).

## Usage

The chain id is 'L' for the mainnet and 'T' testnet.

Expand Down Expand Up @@ -47,6 +49,42 @@ lto.getData(account);

_Amounts are in `LTO * 10^8`. Eg: 12.46 LTO is `12_46000000`._

## Advanced usage
### Advanced usage

For more advanced use cases, please [read the documentation](https://docs.ltonetwork.com/libraries/javascript).

## Download bundle

The library is also available as a bundle. This bundle includes the library and all its dependencies. This bundle is
useful if you want to use the library in a browser environment.

You can download the bundle from the [GitHub releases page](https://github.com/ltonetwork/lto-api.js/releases).

The library is bundles as a UMD module. This means you can use it in the browser as a global variable, or you can
import it as a module in your JavaScript code.

### Browser

```html
<script src="lto.js"></script>
<script>
const { LTO } = window.LTO;
const lto = new LTO('T');
const account = lto.account();
console.log(account.address);
</script>
```

### Troubleshooting

Global variable `LTO` is an object with all exported classes and functions. It contains the `LTO` class,
which is the main class of the library. If you try to do `new LTO()` you will get the error:

TypeError: LTO is not a constructor

Make sure you do

```js
const { LTO } = window.LTO;
```
6 changes: 3 additions & 3 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const path = require('path');

module.exports = {
experiments: {
outputModule: true,
outputModule: false,
},
entry: './src/index.ts',
devtool: 'source-map',
Expand All @@ -12,8 +12,8 @@ module.exports = {
filename: 'lto.js',
asyncChunks: true,
library: {
name: 'lto',
type: 'amd',
name: 'LTO',
type: 'umd',
},
},
module: {
Expand Down

0 comments on commit f650a35

Please sign in to comment.