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-scriptsVerified import paths — ran on the pinned version, not inferred.
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`.
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 })`.For Webpack 4 projects, use `webpack-fix-style-only-entries` instead. Ensure your project's `webpack` dependency meets the `'>=5.32.0'` requirement.
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`.
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');`.Install the package as a development dependency: `npm install --save-dev webpack-remove-empty-scripts` or `yarn add --dev webpack-remove-empty-scripts`.
Upgrade your project's Webpack version to `5.32.0` or higher: `npm install webpack@latest` or `yarn upgrade webpack`.