RoccoC / webpack-build-notifier

A Webpack plugin that generates OS notifications for build steps using node-notifier.
MIT License
162 stars 24 forks source link

Add ability to customize the success message #67

Closed astorije closed 3 years ago

astorije commented 3 years ago

This allows customization like the following successful notification:

Screen Shot 2021-04-25 at 7 46 07 PM

This can be done using the following configuration:

// webpack.config.ts
import WebpackBuildNotifierPlugin from 'webpack-build-notifier';

let address: string;

export default {
  // ... snip ...
  devServer: {
    // ... snip ...
    onListening(server) {
      const { port } = server.listeningApp.address();
      address = `http://localhost:${port}`;
    },
  },
  plugins: [
    // ... snip ...
    new WebpackBuildNotifierPlugin({
      formatSuccess() {
        return address
          ? `Your application is now running at ${address}`
          : undefined; // Fallback when not running the devServer
      },
    }),
  ],
  // ... snip ...
};

formatMessage is a () => string function instead of a simple string parameter so that it can be passed a dynamic value. This is useful in cases like the example above, where the message to display depends on a value set after the plugin has been initialized.

coveralls commented 3 years ago

Pull Request Test Coverage Report for Build 161


Totals Coverage Status
Change from base Build 160: 0.2%
Covered Lines: 130
Relevant Lines: 134

💛 - Coveralls
astorije commented 3 years ago

@RoccoC, rebased on master and fixed conflicts on that one as well. I expect this might cause further conflicts with https://github.com/RoccoC/webpack-build-notifier/pull/70 if you merge either of them, but I don't mind fixing conflicts while it's fresh :)

astorije commented 3 years ago

Rebased on master and fixed conflicts.

RoccoC commented 3 years ago

Merged and published in 2.3.0