Webpack Build Status Notifier
webpack-notifier is a webpack plugin that integrates with node-notifier to provide system-level notifications for webpack build statuses. It's currently at version 1.15.0 and seems to have a moderate release cadence, focusing on stability and compatibility. Key differentiators include its ability to notify on the first run (success/fail), all failed runs, and the first successful run after a failure, remaining silent otherwise to avoid notification spam. It notably improves upon its predecessor, webpack-error-notification, by adding robust support for Windows and eliminating the need for manual `terminal-notifier` installation on OS X, making it more cross-platform friendly. It leverages the underlying `node-notifier` library, which handles platform-specific notification mechanisms. The plugin offers various configuration options for notification titles, content images, and controlling when notifications are triggered (e.g., excluding warnings, always notifying, or only on error).
Common errors
-
TypeError: WebpackNotifierPlugin is not a constructor
cause Attempting to import WebpackNotifierPlugin as a named export when it is a default export.fixUse `const WebpackNotifierPlugin = require('webpack-notifier');` for CommonJS or `import WebpackNotifierPlugin from 'webpack-notifier';` for ESM. -
Error: stdout maxBuffer exceeded
cause This error often originates from `node-notifier` when the message content (especially with large stack traces in errors) is too long for the underlying notification system's stdout buffer.fixConsider using the `onlyOnError: true` and `excludeWarnings: true` options to reduce notification frequency, or implement a custom `message` function in the plugin configuration to truncate lengthy error messages before they are passed to the notifier. -
Notifications are not showing up on [OS Name]
cause The underlying `node-notifier` package might require specific system tools that are not installed on the user's OS, or system notification settings are preventing display.fixRefer to the `node-notifier` 'Requirements' section on its GitHub page (`https://github.com/mikaelbr/node-notifier#requirements`) for your specific OS and install any missing dependencies. Also, check your OS notification settings for the terminal or IDE running webpack.
Warnings
- gotcha webpack-notifier relies on the `node-notifier` package, which itself has platform-specific requirements. Users might need to install additional system tools (e.g., `growl` on macOS prior to Big Sur, or `snoretoast` on Windows for some versions) for notifications to function correctly.
- gotcha When migrating from `webpack-error-notification`, be aware that `webpack-notifier` provides improved Windows support and removes the need for `terminal-notifier` on OS X, simplifying setup but changing the underlying notification mechanism.
- gotcha Prior to v1.3.0, error and warning messages in notifications did not have specific prefixes. Since v1.3.0, messages are prefixed for clearer identification.
- gotcha If notifications are not appearing, ensure that your operating system's notification settings are configured to allow notifications from the application running webpack (e.g., your terminal or IDE).
Install
-
npm install webpack-notifier -
yarn add webpack-notifier -
pnpm add webpack-notifier
Imports
- WebpackNotifierPlugin
import { WebpackNotifierPlugin } from 'webpack-notifier';import WebpackNotifierPlugin from 'webpack-notifier'; // or for CommonJS const WebpackNotifierPlugin = require('webpack-notifier'); - Configuration options
new WebpackNotifierPlugin({ 'title': 'My Build' });new WebpackNotifierPlugin({ title: 'My Build', excludeWarnings: true }); - WebpackNotifierPlugin
import type WebpackNotifierPlugin from 'webpack-notifier';
Quickstart
const path = require('path');
const WebpackNotifierPlugin = require('webpack-notifier');
module.exports = {
mode: 'development',
entry: './src/index.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
},
plugins: [
new WebpackNotifierPlugin({
title: 'My Webpack Build',
alwaysNotify: true, // Be 'noisy' and notify on every build
contentImage: path.join(__dirname, 'logo.png'), // Ensure 'logo.png' exists for this to work
excludeWarnings: false, // Show warnings in notifications
skipFirstNotification: false // Notify on the initial build
}),
],
// Create a dummy logo.png for the example to be runnable
// For a real project, replace with an actual image path.
// This ensures the example is complete without external files.
// fs.writeFileSync(path.join(__dirname, 'logo.png'), 'dummy data'); // Not ideal for quickstart code but illustrates the point
};