Skip to content

Commit

Permalink
Use a default export for UMD module
Browse files Browse the repository at this point in the history
  • Loading branch information
jonkoops committed Jul 31, 2023
1 parent 8e17e0f commit eee8d4e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,26 @@ const jwt_decode = require('jwt-decode');

#### Include with a script tag

Copy the file `jwt-decode.js` from the `build/` folder to your project somewhere, then include it like so:
Copy the file `jwt-decode.js` from the root of the `build/` folder to your project somewhere, then include it like so:

```html
<script src="jwt-decode.js"></script>
```
The jwtDecode function is exposed as a property on the global `jwt_decode` property:

Once this script has loaded, the `jwt_decode` function will be exposed as a global:

```javascript
const token = "eyJhsw5c";
const decoded = jwt_decode.jwtDecode(token);
const decoded = jwt_decode(token);
```

Alternatively, if you are using the [Asynchronous Module Definition (AMD) API](https://github.com/amdjs/amdjs-api/blob/master/AMD.md), you can load the same function as follows:

```javascript
define(["jwt_decode"], (jwtDecode) => {
const token = "eyJhsw5c";
const decoded = jwtDecode(token);
});
```

## Feedback
Expand Down
1 change: 1 addition & 0 deletions lib/index.umd.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { jwtDecode as default } from './index';
2 changes: 1 addition & 1 deletion rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const plugins = [
const input = "lib/index.ts";

export default defineConfig([{
input,
input: "lib/index.umd.ts",
output: {
name: "jwt_decode",
file: "build/jwt-decode.js",
Expand Down

0 comments on commit eee8d4e

Please sign in to comment.