noop-webpack-plugin
raw JSON → 1.0.1 verified Sat Apr 25 auth: no javascript
A tiny Webpack plugin that performs no operation, intended as a conditional placeholder when a noop is needed in the plugins array. Version 1.0.1 is the latest and only release. The package is stable but trivial – it creates a no-op plugin that does nothing. It has zero dependencies and is often used to replace a real plugin in development mode. Alternatives include using null or process.env checks directly, but this plugin provides a simple interface.
Common errors
error TypeError: noop is not a constructor ↓
cause Using `new noop()` instead of calling `noop()`.
fix
Use
noop() instead of new noop(). error Cannot find module 'noop-webpack-plugin' ↓
cause Package not installed or missing from node_modules.
fix
Run
npm install noop-webpack-plugin --save-dev. error Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema. - configuration.plugins[0] should be a Webpack plugin instance. ↓
cause Passing the noop function (not called) into plugins array.
fix
Change
plugins: [noop] to plugins: [noop()]. Warnings
gotcha noop() must be called to get a plugin instance; passing the function directly will cause Webpack to fail. ↓
fix Use noop() instead of noop in the plugins array.
deprecated The package is trivial and may not be actively maintained; prefer inline conditionals or use a package-specific noop like webpack's built-in noop? ↓
fix Consider using `plugins: [ isProd && new UglifyJsPlugin() ].filter(Boolean)` instead.
gotcha The package has no TypeScript typings, causing type errors in TypeScript projects. ↓
fix Create a declaration file: declare module 'noop-webpack-plugin' { const fn: () => any; export default fn; }
Install
npm install noop-webpack-plugin yarn add noop-webpack-plugin pnpm add noop-webpack-plugin Imports
- default wrong
import noop from 'noop-webpack-plugin';correctconst noop = require('noop-webpack-plugin'); - noop wrong
const { noop } = require('noop-webpack-plugin');correctconst noop = require('noop-webpack-plugin'); - noop() wrong
plugins: [ noop ]correctplugins: [ isProd ? new UglifyJsPlugin() : noop() ]
Quickstart
const webpack = require('webpack');
const noop = require('noop-webpack-plugin');
const isProd = process.env.NODE_ENV === 'production';
module.exports = {
entry: './src/index.js',
output: { path: './dist', filename: 'bundle.js' },
plugins: [
isProd ? new webpack.optimize.UglifyJsPlugin() : noop()
]
};