2.0.5 • Published 6 years ago

clean-self-webpack-plugin v2.0.5

Weekly downloads
57
License
MIT
Repository
github
Last release
6 years ago

This module has been deprecated because it has been merged with johnagan/clean-webpack-plugin.

clean-self-webpack-plugin

npm Linux Build Status Windows Build Status Code Coverage

Webpack plugin to delete extraneous files created by Webpack

NOTE: Node v6+ and Webpack v2+ are supported and tested.

About

By default, this plugin will only remove files created by Webpack after compilation has completed. Zero config required. Although it can be configured to remove other files, it is not recommended.

Installation

npm install --save-dev clean-self-webpack-plugin

Usage

import webpack from 'webpack';
import path from 'path';
import del from 'del';
import CleanSelfWebpackPlugin from 'clean-self-webpack-plugin';

const outputPath = path.resolve(process.cwd(), 'build');

/*
 * Remove project files before webpack is loaded.
 * Be sure it is not async.
 *
 * It is HIGHLY recommended to handle the initial
 * build directory clean outside of this plugin / webpack.
 *
 * Popular existing packages:
 * https://github.com/isaacs/rimraf
 * https://github.com/sindresorhus/del
 *    -- I prefer this one, great glob support and has CLI (del-cli package)
 * https://github.com/jprichardson/node-fs-extra
 *
 */
del.sync([path.resolve(outputPath, '**/*')]);

const webpackConfig = {
    entry: path.resolve(process.cwd(), 'src/index.js'),
    output: {
        path: outputPath,
        filename: 'bundle.js',
    },
    plugins: [new CleanSelfWebpackPlugin()],
};

export default webpackConfig;

Options

new CleanSelfWebpackPlugin({
    /**
     * Simulate the removal of files
     *
     * default: false
     */
    dryRun: true,

    /**
     * Write Logs to Console
     * (Always enabled when dryRun is true)
     *
     * default: false
     */
    verbose: true,

    /**
     * **WARNING**
     *
     * Notes on the below options customPatterns and initialPatterns:
     *
     * Neither of these options are recommended.
     * Use only if you know what you are doing.
     *
     * They are unsafe...so test initially with dryRun: true.
     *
     * Relative to Webpack's output.path directory.
     * If outside of webpack's output.path directory,
     *    use path.resolve(process.cwd(), '')
     *
     * These options extend del's pattern matching API.
     * See https://github.com/sindresorhus/del#patterns
     *    for pattern matching documentation
     */

    /**
     * Custom pattern matching
     *
     * Removes files on after every build that match this pattern.
     * Used for files that are not created directly by Webpack.
     *
     * default: disabled
     */
    customPatterns: ['static*.*', '!static1.js'],

    /**
     * Removes files once prior to Webpack compilation
     *
     * Again, this should be handled outside of Webpack.
     * See Usage example.
     *
     * NOTE: customPatterns ARE included with this
     *
     * default: disabled
     */
    initialPatterns: ['**'],
});

Thanks To / Related Projects

This package was created with the great work / lessons learned from:

2.0.5

6 years ago

2.0.4

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago