Get Started
Install
npm install @dice-roller/rpg-dice-roller
yarn add @dice-roller/rpg-dice-roller
<!-- Replace {VERSION} with the version you want to use -->
<script src="https://cdn.jsdelivr.net/npm/@dice-roller/rpg-dice-roller@{VERSION}/lib/umd/bundle.min.js"></script>
Setup
You can import the dice roller and use it in your application, using ES standard modules like so:
import * as rpgDiceRoller from '@dice-roller/rpg-dice-roller';
If you only want to import specific components, you can do so like:
import { DiceRoller } from '@dice-roller/rpg-dice-roller';
TIP
If you're using Node.js with ES modules (import
), instead of CommonJS (require
), follow the ESM section instead.
You can also load the library using CommonJS, AMD, etc. with the UMD build:
const rpgDiceRoller = require('@dice-roller/rpg-dice-roller');
If you only want to import specific components, you can do so like:
const { DiceRoller } = require('@dice-roller/rpg-dice-roller');
Browser support
The dice roller may not work with older browsers. Please check the environment support.
Dependencies
First, you'll need to include some third party dependencies:
<script src="https://unpkg.com/mathjs@11.8.2/lib/browser/math.js"></script>
<script src="https://cdn.jsdelivr.net/npm/random-js@2.1.0/dist/random-js.umd.min.js"></script>
Dice Roller
You can either download the file locally, or use the CDN (Note umd
in the path, instead of esm
):
<!-- local file -->
<script src="./path/to/lib/umd/bundle.min.js"></script>
<!-- or CDN - Replace {VERSION} with the version you want to use -->
<script src="https://cdn.jsdelivr.net/npm/@dice-roller/rpg-dice-roller@{VERSION}/lib/umd/bundle.min.js"></script>
The UMD bundle provides the global variable, rpgDiceRoller
, that is used to access the library.
<script>
// create a new instance of the DiceRoller
var diceRoller = new rpgDiceRoller.DiceRoller();
</script>