パッケージの詳細

webpack-build-notifier

RoccoC203.9kMIT3.1.0

A Webpack plugin that generates OS notifications for build steps using node-notifier.

webpack, notification, notify, node-notifier

readme

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 CircleCI Coverage Status

webpack-build-notifier-errorwebpack-build-notifier-success

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.

更新履歴

Changelog

3.1.0

May 28, 2024
  • Fixed commonjs default export and added esm entrypoint.

3.0.0

May 27, 2024
  • Added support for Webpack 5.
  • Bumped node-notifier to v10.0.1.
  • Fixes for #81 and #90)
  • Thanks, ImLunaHey! (PR)

2.3.0

June 19, 2021
  • Added formatSuccess config option.
  • Modified notifyOptions config option to accept a function.
  • Misc dependency upgrades for security fixes.

2.2.1

April 30, 2021
  • Fixed MessageFormatter type def; consolidated types between types.ts and index.ts.

2.2.0

April 28, 2021
  • Add compilation status and error/warning count parameters to messageFormatter (PR).

2.1.1

December 21, 2020
  • Bumped node-notifier to v9.0.0.

2.1.0

June 23, 2020
  • Upgraded dependencies to latest; fixed warning/error handling for child compilers (#53).

2.0.1

May 23, 2020
  • Fixed bug where setting sound to false had no effect (#51).

2.0.0

October 15, 2019
  • Converted to TypeScript, increased test coverage.

1.2.2

October 15, 2019
  • Updated node-notifier to fix #43; added test coverage.

1.2.1

October 15, 2019
  • Added showDuration config option for #48.

1.1.1

August 29, 2019
  • Updated node-notifier dependency to latest version to fix #45.

1.1.0

August 10, 2019
  • Added two new config options: onCompileStart, onComplete.

1.0.3

June 4, 2019
  • Updated dependencies to latest versions to fix high-severity js-yaml vulnerability.

1.0.2

May 3, 2019
  • Corrected sound TS types.

1.0.1

April 16, 2019
  • Updated README to include TS usage example.

1.0.0

April 16, 2019
  • Fixed TypeScript definition per issue #39. This is a breaking change for any consumers using TS; bumped major version.

0.1.32

April 16, 2019
  • Fixed TypeScript definitions per issues #38 and #39.

0.1.31

March 20, 2019
  • Added TypeScript definitions per issue #35.

0.1.30

October 7, 2018
  • Fix for #29 where error occurs on Windows 7 when attempting to register the SnoreToast app ID for notifications.

0.1.29

August 21, 2018
  • Fix for #30, compilation notifications no longer ignore sound option.
  • Added new config option: compilationSound

0.1.28

June 30, 2018
  • Fix for #28 to allow webpack build to complete while notification is visible. Updated to node-notifier@5.2.1.

0.1.27

June 1, 2018
  • Check that error/warning is not null before formatting it.

0.1.26

May 31, 2018
  • Added two new config options: notifyOptions and onTimeout per #26.

0.1.25

April 18, 2018
  • Updated Webpack 4 watchRun hook to use tapAsync to fix #25.

0.1.24

April 15, 2018
  • Updated to use new hooks API for Webpack 4.

0.1.23

February 21, 2018
  • Updated terminal activation to handle VS Code.

0.1.22

January 16, 2018
  • Merged PR to detect terminal application. #21.

0.1.21

December 13, 2017
  • Reworked previous "fix" to use default SnoreToast AppID for Windows toast notifications. #20.

0.1.19

December 13, 2017
  • Added appName parameter to notify config to resolve issue with notifications not being generated in Windows build >=1709 #20.

0.1.18

November 30, 2017
  • Updated node-notifier package version to latest; enforced max message length to 256 to fix #20.

0.1.17

November 6, 2017
  • Added notification hook for webpack "watch-run" compilation event to show notifications when the compilation process has started. Added suppressCompileStart and compileIcon configuration options to support this. This notification will not be shown by default; set suppressCompileStart to false to enable.

0.1.16

July 25, 2017
  • Updated suppressSuccess configuration option to support "always" and "initial" values.

0.1.15

July 17, 2017
  • Updated webpack icons.

0.1.14

June 14, 2017
  • Added warningSound configuration option.

0.1.13

October 19, 2016
  • Added messageFormatter configuration option to allow custom formatting of notification message.

0.1.12

July 25, 2016
  • Bugfix for #6, more null checking.

0.1.11

July 16, 2016
  • Bugfix for #6; added null check for error messages.

0.1.10

July 14, 2016
  • Added reference to strip-ansi NPM package to remove CLI color formatting from notifications.

0.1.9

July 5, 2016
  • Added new onClick configuration option to allow for specifying of notification click behavior.

0.1.8

February 17, 2016
  • Added new successSound and failureSound configuration options to allow different sounds depending upon the notification type. The sound configuration is still supported, but these two new options will take precedence.

0.1.7

January 18, 2016
  • Fixed sound configuration option to allow "false" value to disable sound.

0.1.6

December 17, 2015
  • Added suppressWarning configuration option.