Skip to content

5.2.0 Beta

Pre-release
Pre-release
Compare
Choose a tag to compare
@PeytonRG PeytonRG released this 03 Jun 21:50
· 5 commits to module-test since this release

ESM Module Support

You read that right, Bootstrap Toaster can finally be imported as an ESM module!
For example, the following will allow you to use the Toast class and the enums for status, placement, theme, and timers.

import { Toast, TOAST_STATUS } from "bootstrap-toaster";

Quirks

  • Unfortunately, I couldn't figure out how to support existing users without making breaking API changes that would affect the UMD build, so ESM users will have to do an admittedly janky import below. Alternatively, you could just import Bootstrap's JS in an HTML script tag to get that global bootstrap variable that I use, but I'm sure many would rather go all-in on modules.
import * as bootstrap from "bootstrap";
...
window.bootstrap = bootstrap;
  • In supporting existing users via the UMD module without breaking changes, I had to make global variables for Toast, TOAST_STATUS, TOAST_PLACEMENT, TOAST_THEME, and TOAST_TIMERS. I believe this is necessary for UMD builds but they are technically globals in the ESM build as well, even though you obviously have to import them to be able to use them.

Help Me!

If you know how I could accomplish this better without the above quirks, please reach out! I used rollup.js to build the UMD and ESM modules, and this whole process is very new to me.