2.3.0 • Published 3 years ago

webpack-build-notifier v2.3.0

Weekly downloads
35,956
License
MIT
Repository
github
Last release
3 years ago

webpack-build-notifier

A Webpack plugin that uses the node-notifier package to display OS-level notifications for Webpack build events.

webpack-build-notifier can generate notifications for compilation warnings and errors, as well as notify you when the compilation process is triggered and completes successfully. Take a look at the Config Options to learn more about what webpack-build-notifier can do.

NPM version Build Status Coverage Status

Are you tired of having to constantly switch between your IDE and terminal window to see whether your latest edits resulted in a failed build? Why didn't your latest changes get hot-loaded? Was there a syntax error or failed unit test? With this plugin, you will always be apprised of build problems without having to keep an eye on your terminal window.

To use, install the webpack-build-notifier package npm install webpack-build-notifier --save-dev and add the plugin to your Webpack configuration file:

// webpack.config.js
const WebpackBuildNotifierPlugin = require('webpack-build-notifier');

module.exports = {
  // ... snip ...
  plugins: [
    new WebpackBuildNotifierPlugin({
      title: "My Webpack Project",
      logo: path.resolve("./img/favicon.png"),
      suppressSuccess: true, // don't spam success notifications
    })
  ],
  // ... snip ...
}

Config Options

title

The notification title. Defaults to Webpack Build.

logo

The absolute path to the project logo to be displayed as a content image in the notification. Optional.

sound

The sound to play for notifications. Set to false to play no sound. Valid sounds are listedin the node-notifier project, here. Defaults to Submarine.

successSound

The sound to play for success notifications. Defaults to the value of the sound configuration option. Set to false to play no sound for success notifications. Takes precedence over the sound configuration option.

warningSound

The sound to play for warning notifications. Defaults to the value of the sound configuration option. Set to false to play no sound for warning notifications. Takes precedence over the sound configuration option.

failureSound

The sound to play for failure notifications. Defaults to the value of the sound configuration option. Set to false to play no sound for failure notifications. Takes precedence over the sound configuration option.

compilationSound

The sound to play for compilation notifications. Defaults to the value of the sound configuration option. Set to false to play no sound for compilation notifications. Takes precedence over the sound configuration option.

onCompileStart

A function which is invoked when compilation starts. Optional. The function is passed one parameter:

  • {webpack.compilation.Compilation} compilation - The webpack Compilation instance. Note that suppressCompileStart must be false.

onComplete

A function which is invoked when compilation completes. Optional. The function is passed two parameters:

  • {webpack.compilation.Compilation} compilation - The webpack Compilation instance.
  • {CompilationStatus} status - one of 'success', 'warning', or 'error'

suppressSuccess

Defines when success notifications are shown. Can be one of the following values:

  • false - Show success notification for each successful compilation (default).
  • true - Only show success notification for initial successful compilation and after failed compilations.
  • "always" - Never show the success notifications.
  • "initial" - Same as true, but suppresses the initial success notification.

showDuration

True to show the duration of a successful compilation, otherwise false (default).

suppressWarning

True to suppress the warning notifications, otherwise false (default).

suppressCompileStart

True to suppress the compilation started notifications (default), otherwise false.

activateTerminalOnError

True to activate (focus) the terminal window when a compilation error occurs. Note that this only works on Mac OSX (for now). Defaults to false. Regardless of the value of this config option, the terminal window can always be brought to the front by clicking on the notification.

successIcon

The absolute path to the icon to be displayed for success notifications. Defaults to the included ./src/icons/success.png.

Success

warningIcon

The absolute path to the icon to be displayed for warning notifications. Defaults to the included ./src/icons/warning.png.

Warning

failureIcon

The absolute path to the icon to be displayed for failure notifications. Defaults to the included ./src/icons/failure.png.

Failure

compileIcon

The absolute path to the icon to be displayed for compilation started notifications. Defaults to the included ./src/icons/compile.png.

Compile

formatSuccess

A function which returns a formatted notification message on successful compilation. This function must return a String. The default formatter will display "Build successful!". Note that the message will always be limited to 256 characters.

messageFormatter

A function which returns a formatted notification message on error or warning. The function is passed 4 parameters:

  • {Object} error/warning - The raw error or warning object.
  • {String} filepath - The path to the file containing the error/warning (if available).
  • {CompilationStatus} status - Error or warning
  • {number} count - How many errors or warnings were raised

This function must return a String. The default messageFormatter will display the filename which contains the error/warning followed by the error/warning message. Note that the message will always be limited to 256 characters.

notifyOptions

Any additional node-notifier options as documented in the node-notifier documentation. Note that options provided here will only be applied to the success/warning/error notifications (not the "compilation started" notification). The title, message, sound, contentImage (logo), and icon options will be ignored, as they will be set via the corresponding WebpackBuildNotifier config options (either user-specified or default).

onClick

A function called when the notification is clicked. By default it activates the Terminal application.

onTimeout

A function called when the notification times out and is closed. Undefined by default.

TypeScript

This project is written in TypeScript, and type declarations are included. You can take advantage of this if your project's webpack configuration is also using TypeScript (e.g. webpack.config.ts).

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

const config: webpack.Configuration = {
  // ... snip ...
  plugins: [
    new WebpackBuildNotifierPlugin({
      title: "My Webpack Project",
      logo: path.resolve("./img/favicon.png"),
      suppressSuccess: true, // don't spam success notifications
    })
  ],
  // ... snip ...
};

export default config;

Notes

After publishing this package I discovered a couple other similar plugins that are worth looking into:

Given the purpose and similarities, this project probably could have been a fork of one of these.

Changelog

View the changelog here.

2.3.0

3 years ago

2.2.1

3 years ago

2.2.0

3 years ago

2.1.1

3 years ago

2.1.1-alpha.1

3 years ago

2.1.1-alpha

3 years ago

2.0.1

4 years ago

2.1.0

4 years ago

2.0.0

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.1.1

5 years ago

1.1.0

5 years ago

2.0.0-alpha.3

5 years ago

2.0.0-alpha.2

5 years ago

2.0.0-alpha.1

5 years ago

2.0.0-alpha.0

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.1.32

5 years ago

0.1.31

5 years ago

0.1.30

5 years ago

0.1.29

6 years ago

0.1.28

6 years ago

0.1.27

6 years ago

0.1.26

6 years ago

0.1.25

6 years ago

0.1.24

6 years ago

0.1.23

6 years ago

0.1.22

6 years ago

0.1.21

6 years ago

0.1.20

6 years ago

0.1.19

6 years ago

0.1.18

6 years ago

0.1.17

6 years ago

0.1.16

7 years ago

0.1.15

7 years ago

0.1.14

7 years ago

0.1.13

7 years ago

0.1.12

8 years ago

0.1.11

8 years ago

0.1.10

8 years ago

0.1.9

8 years ago

0.1.8

8 years ago

0.1.7

8 years ago

0.1.6

8 years ago

0.1.5

8 years ago

0.1.4

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago