Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

remove-files-webpack-plugin

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

remove-files-webpack-plugin

A plugin for webpack which removes files and folders before and after compilation.

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
30K
decreased by-2.91%
Maintainers
1
Weekly downloads
 
Created
Source

Removing of folders and files for Webpack

A plugin for webpack which removes files and folders before and after compilation.

Installation

npm install remove-files-webpack-plugin --save-dev

Usage

const RemovePlugin = require('remove-files-webpack-plugin');

module.exports = {
    plugins: [
        new RemovePlugin({
            before: {
                // parameters.
            },
            after: {
                // parameters.
            }
        })
    ]
}

Be aware! You cannot undo deletion of folders/files. Use the emulate option if you not sure about correctness of the parameters.

Options

NameTypeDefaultDescription
rootString__dirnameThe root directory. A not absolute paths will appends to this.
includeArray<String>[]The folders/fils for remove.
excludeArray<String>[]The files for exclude.
testArray<TestObject>[]The custom testing.
TestObject.folderStringRequiredThe folder for custom testing.
TestObject.method(filePath: String) => BooleanRequiredThe method for custom testing.
TestObject.recursiveBooleanfalseTest in all subfolders, not just in TestObject.folder.
logBooleantruePrint which folders/files has been removed.
emulateBooleanfalseEmulate remove. Print which folders/files will be removed without actually removing them. Ignores log value.
allowRootAndOutsideBooleanfalseAllow remove the root directory and outside the root directory. It's kinda safe mode. Don't turn on it if you don't know what you actually want!
Example how to set these options:

You can pass the options into both before and after keys. Each key is optional, but at least one should be specified.

before - before compilation, after - after compilation.

const RemovePlugin = require('remove-files-webpack-plugin');

module.exports = {
    plugins: [
        new RemovePlugin({
            before: {
                include: ['dist']
            },
            after: {
                test: [
                  {
                    folder: 'dist/styles',
                    method: (filePath) => {
                        return new RegExp(/\.map$/, 'm').test(filePath);
                    }
                  } 
                ]
            }
        })
    ]
}

Examples

/**
 * Before compilation:
 * - delete the "dist" folder.
 * 
 * After compilation:
 * - remove all css maps in the "dist/styles" folder except the "popup.css.map".
 */

new RemovePlugin({
    before: {
        include: ['dist']
    },
    after: {
        exclude: ['dist/styles/popup.css.map'],
        test: [
            {
                folder: 'dist/styles',
                method: (filePath) => {
                    return new RegExp(/\.map$/, 'm').test(filePath);
                }
            }
        ]
    }
})
/**
 * After compilation:
 * - remove all css maps in "dist/styles" folder and all subfolders (e.g. "dist/styles/a").
 */

new RemovePlugin({
    after: {
        test: [
            {
                folder: 'dist/styles',
                method: (filePath) => {
                    return new RegExp(/\.map$/, 'm').test(filePath);
                },
                recursive: true
            }
        ]
    }
})
/**
 * Before compilation:
 * - remove the "manifest.json" file;
 * - remove the "dist/js" folder.
 */

new RemovePlugin({
    before: {
        include: ['dist/manifest.json', 'dist/js']
    }
})
/**
 * After compilation:
 * - remove all css maps in the "dist/styles" folder;
 * - remove all js maps in the "dist/scripts" folder and all subfolders (e.g. "dist/styles/a").
 */

new RemovePlugin({
    after: {
        test: [
            {
                folder: 'dist/styles',
                method: (filePath) => {
                    return new RegExp(/\.map$/, 'm').test(filePath);
                }
            },
            {
                folder: 'dist/scripts',
                method: (filePath) => {
                    return new RegExp(/\.js.map$/, 'm').test(filePath);
                },
                recursive: true
            }
        ]
    }
})

Issues and requests

Feel free to use issues. Pull requests are also always welcome!

Keywords

FAQs

Package last updated on 05 Jun 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc