php-flasher / flasher-js

This repository contains the necessary JavaScript files for displaying notification messages in web development projects using the Flasher library, including files for popular notification message plugins like Toastr, Noty, and PNotify.
https://php-flasher.io
MIT License
6 stars 1 forks source link

flasher global instance with webpack #5

Open jamesj2 opened 2 years ago

jamesj2 commented 2 years ago

I'm using webpack 5 for my project and in case anyone needs this. I was able to get a global instance of Flasher working using the following method.

webpack config:

module: {
        rules: [
            {
                test: require.resolve("toastr"),
                loader: "expose-loader",
                options: {
                    exposes: ["toastr"],
                },
            },
            {
                test: require.resolve("@flasher/flasher"),
                loader: "expose-loader",
                options: {
                    exposes: ["Flasher"],
                },
            }
        ]
}

in app.js:

import toastr from "toastr";

// toastr defaults
toastr.options.timeOut = 10000;
toastr.options.closeButton = true;
toastr.options.escapeHtml = true;
toastr.options.progressBar = true;
toastr.options.closeOnHover = false;

import { default as Flasher } from "@flasher/flasher";
import { default as ToastrFactory } from "@flasher/flasher-toastr";
Flasher.getInstance().addFactory("toastr", new ToastrFactory());
yoeunes commented 2 years ago

Hello @jamesj2 Thank you for the tips 🙏