@noxx/webpack-tidy-plugin v3.0.1
Webpack Tidy Plugin
TL;DR - Keeps your output directories tidy when outputting files in watch-mode (doesn't work when using Webpack's Dev Server).

Imagine you have a project utilizing a node server that serves assets from a specific directory - and you want to use Webpack to rebuild bundles quickly but don't want to have those assets served via the Webpack server. Well, you'll most likely have WP output a manifest with the generated files, and the server will read from that to load the most current hashed bundle.
The catch to the above setup, is that you'll end up with a folder full of generated files while in watch mode, or when you run a one-off build (say for production) you may have some straggling files from a previous Dev session.
This plugin will ensure that there's only ever one version of the current bundle in your output directories.
Install
yarn add -D @noxx/webpack-tidy-plugin
# or
npm i -D @noxx/webpack-tidy-pluginConfiguration
| Prop | Type | Default | Description |
|---|---|---|---|
dryRun | Boolean | false | Will not delete files, just displays info about what could be deleted. |
hashLength | Number | 5 | The length of the hash in the bundle name. |
plugins: [
new TidyPlugin({
dryRun: true,
hashLength: 8,
}),
],I have a couple example files that demonstrate common setups.
- webpack.config.js utilizes
path,publicPath, andfilenamein theoutputsection. This setup assumes there'll ever only be oneoutputdirectory. - webpack.config-nopath.js allows for a
more custom
outputsetup. You'll notice that there's just afilenamespecified with the output path included. Then theExtractTextPluginpulls any styles from thejsfiles and dumps them in acsspath.
Notes
- This only works when using the
watchoption forwebpack, not while using thewebpack-dev-server. This is due to the dev-server not emitting actual files, but rather keeping them in memory.