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.1.1
  • 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

  • With npm:
npm install remove-files-webpack-plugin
  • With Yarn:
yarn add remove-files-webpack-plugin

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 or files. Use the emulate option if you not sure about correctness of the parameters.

Parameters

NameTypeDefaultDescription
rootString.A root directory. Not absolute paths will be appended to this. Defaults to from which directory is called.
includeArray<String>[]A folders or files for removing.
excludeArray<String>[]A files for excluding.
testArray<TestObject>[]A folders for custom testing.
TestObject.folderStringRequiredA path to the folder.
TestObject.method(filePath: String) => BooleanRequiredA method that accepts an absolute file path and must return boolean value that indicates should be removed that file or not.
TestObject.recursiveBooleanfalseTest in all subfolders, not just in TestObject.folder.
logBooleantruePrint which folders or files has been removed.
emulateBooleanfalseEmulate remove process. Print which folders or files will be removed without actually removing them. Ignores log value.
allowRootAndOutsideBooleanfalseAllow remove of a root directory or outside the root directory. It's kinda safe mode. Don't turn it on, if you don't know what you actually do!
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 - executes before compilation;
  • after - executes after compilation.
const RemovePlugin = require('remove-files-webpack-plugin');

module.exports = {
    plugins: [
        new RemovePlugin({
            /**
             * Before compilation removes entire `dist` folder.
             */
            before: {
                include: ['dist']
            },

            /**
             * After compilation removes all files in `dist/styles` folder,
             * that have `.map` type.
             */
            after: {
                test: [
                    {
                        folder: 'dist/styles',
                        method: (filePath) => {
                            return new RegExp(/\.map$/, 'm').test(filePath);
                        }
                    } 
                ]
            }
        })
    ]
}

Examples

new RemovePlugin({
    /**
     * Before compilation removes entire `dist` folder.
     */ 
    before: {
        include: ['dist']
    },

    /**
     * After compilation removes all css maps 
     * in `dist/styles` folder except `popup.css.map` file.
     */
    after: {
        exclude: ['dist/styles/popup.css.map'],
        test: [
            {
                folder: 'dist/styles',
                method: (filePath) => {
                    return new RegExp(/\.map$/, 'm').test(filePath);
                }
            }
        ]
    }
})
new RemovePlugin({
    /**
     * After compilation removes all css maps in 
     * `dist/styles` folder and all subfolders 
     * (e.g. `dist/styles/header`).
     */
    after: {
        test: [
            {
                folder: 'dist/styles',
                method: (filePath) => {
                    return new RegExp(/\.map$/, 'm').test(filePath);
                },
                recursive: true
            }
        ]
    }
})
new RemovePlugin({
    /**
     * Before compilation removes `manifest.json` file and 
     * removes `js` folder.
     */
    before: {
        root: './dist',
        include: ['manifest.json', 'js']
    }
})
new RemovePlugin({
    /**
     * After compilation:
     * - removes all css maps in `dist/styles` folder.
     * - removes all js maps in `dist/scripts` folder and 
     * all subfolders (e.g. `dist/scripts/header`).
     */
    after: {
        root: './dist',
        test: [
            {
                folder: './styles',
                method: (filePath) => {
                    return new RegExp(/\.map$/, 'm').test(filePath);
                }
            },
            {
                folder: './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 20 Mar 2019

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