Registry / devops / webpack-remove-empty-scripts

webpack-remove-empty-scripts

JSON →
library1.1.1jsnpmunverified

webpack-remove-empty-scripts is a Webpack plugin designed to eliminate superfluous empty JavaScript files generated by Webpack 5, particularly when an `entry` point consists solely of style assets (e.g., SCSS or CSS files). This issue frequently occurs even when `mini-css-extract-plugin` correctly processes and extracts styles into dedicated CSS files, leaving behind an empty `.js` file for each style entry. The plugin automatically detects and removes these redundant outputs, ensuring a cleaner and more efficient build directory. The current stable version is `1.1.1`, and the project demonstrates an active maintenance cadence with minor releases and patches occurring every few months. Its primary utility lies in streamlining the build output for Webpack 5 projects that heavily utilize CSS preprocessors and separate style extraction.

npm install webpack-remove-empty-scripts
INSTALL
IMPORT
SIG · WEBPACK-REMOVE-EMP
W
webpack-remove-empty-scripts
devopsjavascriptv1.1.1
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

RemoveEmptyScriptsPlugin
✓ import RemoveEmptyScriptsPlugin from 'webpack-remove-empty-scripts';
✗ import { RemoveEmptyScriptsPlugin } from 'webpack-remove-empty-scripts';
The plugin class is the default export of the package. For CommonJS, use `const RemoveEmptyScriptsPlugin = require('webpack-remove-empty-scripts');`
STAGE_AFTER_PROCESS_PLUGINS
✓ import RemoveEmptyScriptsPlugin from 'webpack-remove-empty-scripts'; // Then use: RemoveEmptyScriptsPlugin.STAGE_AFTER_PROCESS_PLUGINS
✗ import { STAGE_AFTER_PROCESS_PLUGINS } from 'webpack-remove-empty-scripts';
This constant is a static property of the `RemoveEmptyScriptsPlugin` class, used for fine-tuning the plugin's execution stage within Webpack's build process.
RemoveEmptyScriptsPluginOptions
✓ import type { RemoveEmptyScriptsPluginOptions } from 'webpack-remove-empty-scripts';
This TypeScript type definition can be used for explicit type hinting of the plugin's configuration options when defining a Webpack configuration.

This configuration demonstrates how to integrate `webpack-remove-empty-scripts` into a Webpack 5 setup, ensuring that empty JavaScript files are not generated for style-only entry points when using `mini-css-extract-plugin`.

import RemoveEmptyScriptsPlugin from 'webpack-remove-empty-scripts'; import MiniCssExtractPlugin from 'mini-css-extract-plugin'; import path from 'path'; export default { entry: { main: './src/index.js', styles: './src/styles.scss', // This will generate an empty JS file without the plugin legacyCss: './src/legacy.css', }, output: { path: path.resolve(__dirname, 'dist'), filename: '[name].js', clean: true, // Clean the output directory before emit. }, module: { rules: [ { test: /\.(scss|css)$/, use: [ MiniCssExtractPlugin.loader, 'css-loader', 'sass-loader' ], }, { test: /\.js$/, exclude: /node_modules/, use: { loader: 'babel-loader', options: { presets: ['@babel/preset-env'] } } } ], }, plugins: [ new MiniCssExtractPlugin({ filename: '[name].css', }), new RemoveEmptyScriptsPlugin({ // Optional: Set to true for more detailed output during build verbose: process.env.NODE_ENV === 'development', // Optional: If you need to revert to v0.8.2-0.8.4 behavior for specific compatibility // stage: RemoveEmptyScriptsPlugin.STAGE_AFTER_PROCESS_PLUGINS, }), ], devtool: 'source-map', mode: process.env.NODE_ENV === 'production' ? 'production' : 'development' };
Debug
Known issues
breakingThe default plugin execution stage was reverted in v1.0.1. It now executes before other plugins, which is generally the desired behavior but might alter how it interacts if you previously relied on its post-processing in versions v0.8.2-v0.8.4.
fix
If you need the previous `v0.8.2-v0.8.4` behavior where the plugin ran after most others, configure it explicitly with `new RemoveEmptyScriptsPlugin({ stage: RemoveEmptyScriptsPlugin.STAGE_AFTER_PROCESS_PLUGINS })`.
affects: >=1.0.1
gotchaThis plugin is designed exclusively for Webpack 5. It is not compatible with Webpack 4, and attempting to use it with older Webpack versions will likely result in build failures or simply no effect.
fix
For Webpack 4 projects, use `webpack-fix-style-only-entries` instead. Ensure your project's `webpack` dependency meets the `'>=5.32.0'` requirement.
affects: <5.0.0
gotchaWhile the default `stage` was optimized in v1.0.1, in very complex Webpack configurations with multiple plugins, you might still need to explicitly configure the `stage` option if other plugins temporarily require the presence of all generated script files before removal.
fix
If you encounter unexpected interactions with other plugins, try adjusting the plugin's execution order by setting the `stage` option, e.g., `stage: RemoveEmptyScriptsPlugin.STAGE_AFTER_PROCESS_PLUGINS`.
affects: >=0.8.0
Errors
Common errors & fixes
TypeError: RemoveEmptyScriptsPlugin is not a constructor
Attempting to import the default export (the plugin class) as a named export using curly braces, or incorrect CommonJS `require` usage.
fix
For ESM, change `import { RemoveEmptyScriptsPlugin } from 'webpack-remove-empty-scripts';` to `import RemoveEmptyScriptsPlugin from 'webpack-remove-empty-scripts';`. For CommonJS, use `const RemoveEmptyScriptsPlugin = require('webpack-remove-empty-scripts');`.
Module not found: Error: Can't resolve 'webpack-remove-empty-scripts'
The package `webpack-remove-empty-scripts` has not been installed or is not correctly located in `node_modules`.
fix
Install the package as a development dependency: `npm install --save-dev webpack-remove-empty-scripts` or `yarn add --dev webpack-remove-empty-scripts`.
Peer dependency webpack (>=5.32.0) not met.
The installed version of `webpack` in your project is older than the minimum required by `webpack-remove-empty-scripts`.
fix
Upgrade your project's Webpack version to `5.32.0` or higher: `npm install webpack@latest` or `yarn upgrade webpack`.
Upgrade
Version history
1.1.1latest on npm
Audit
Dependencies
webpackrequiredThis is a Webpack plugin and requires Webpack to function.
Agent activity
10 hits · last 30 days
node
8
OpenAI (training)
2
Resources
webpack-remove-empty-scripts — npm install webpack-remove-empty-scripts · libregistry