webpack-null-plugin
raw JSON → 0.0.2 verified Sat Apr 25 auth: no javascript deprecated
A tiny npm package (v0.0.2) that provides a no-op Webpack plugin using the null object pattern. It is intended to simplify Webpack configurations that conditionally include plugins by allowing a placeholder that does nothing. The package has no dependencies and has seen no updates since 2016. It is a simple alternative to inline conditional logic in the plugins array. Not actively developed.
Common errors
error TypeError: Class constructor NullPlugin cannot be invoked without 'new' ↓
cause Omitting 'new' when using NullPlugin (e.g., calling NullPlugin() instead of new NullPlugin())
fix
Use 'new NullPlugin()' instead of 'NullPlugin()'
error Module not found: Error: Can't resolve 'webpack-null-plugin' ↓
cause Package not installed or missing from package.json
fix
Run 'npm install webpack-null-plugin --save-dev'
Warnings
deprecated Package is deprecated: The null object pattern is unnecessary; simply conditionally include plugins in an array. ↓
fix Use inline conditional logic in the plugins array: plugins: [ condition && new Plugin() ].filter(Boolean)
gotcha Must be instantiated with 'new' before passing to webpack ↓
fix Always use 'new NullPlugin()' in the plugins array.
Install
npm install webpack-null-plugin yarn add webpack-null-plugin pnpm add webpack-null-plugin Imports
- default wrong
const NullPlugin = require('webpack-null-plugin')correctimport NullPlugin from 'webpack-null-plugin' - NullPlugin wrong
const { NullPlugin } = require('webpack-null-plugin')correctimport NullPlugin from 'webpack-null-plugin' - WebpackPluginInstance
import type { WebpackPluginInstance } from 'webpack'
Quickstart
const NullPlugin = require('webpack-null-plugin');
const shouldUsePlugin = process.env.USE_SOMETHING === 'true';
const webpack = require('webpack');
const compiler = webpack({
// ... other config
plugins: [
shouldUsePlugin ? new SomeRealPlugin() : new NullPlugin(),
],
});
compiler.run((err, stats) => {
if (err) {
console.error(err);
return;
}
console.log(stats.toString({ colors: true }));
});