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 that removes files and folders before and after compilation.

  • 1.2.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
28K
increased by4.69%
Maintainers
1
Weekly downloads
 
Created
Source

Removing of folders and files for Webpack

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

Content

  • Content
  • Installation
  • Support
  • Usage
  • Parameters
  • Examples
  • Contribution
  • License

Installation

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

Support

The plugin works on any OS and webpack >= 2.2.0.

Usage

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

module.exports = {
    plugins: [
        new RemovePlugin({
            before: {
                // parameters for "before compilation" stage.
            },
            after: {
                // parameters for "after compilation" stage.
            }
        })
    ]
};

Parameters

NameTypeDefaultDescription
rootstring.A root directory. Not absolute paths will be appended to this. Defaults to where package.json and node_modules are located.
includestring[][]A folders or files for removing.
excludestring[][]A files for excluding.
testTestObject[][]A folders for testing.
TestObject.folderstringRequiredA path to the folder.
TestObject.method(filePath: string) => booleanRequiredA method that accepts file path (root + directoryPath + fileName) and returns value that indicates should be this file be removed or not.
TestObject.recursivebooleanfalseTest in all subfolders, not just in TestObject.folder.
trashbooleantrueMove folders or files to trash (recycle bin) instead of permanent removing.
logbooleantruePrint messages of "info" level (example: "Which folders or files have been removed").
logWarningbooleantruePrint messages of "warning" level (example: "An items for removing not found").
logErrorbooleanfalsePrint messages of "error" level (example: "No such file or directory").
logDebugbooleanfalsePrint messages of "debug" level (used for developers of the plugin).
emulatebooleanfalseEmulate remove process. Print which folders or files will be removed without actually removing them. Ignores log value.
allowRootAndOutsidebooleanfalseAllow removing of root directory or outside root directory. It is kind of safe mode. Don't turn it on if you don't know what you actually do!
How to set

You can pass these parameters 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.
Example
const RemovePlugin = require('remove-files-webpack-plugin');

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

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

Examples

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

    /**
     * After compilation removes all css maps 
     * in `./dist/styles` folder to trash 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 to trash 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 both 
     * `./dist/manifest.json` file and `./dist/js` folder
     * to trash.
     */
    before: {
        root: './dist',
        include: [
            'manifest.json',
            'js'
        ]
    }
})
new RemovePlugin({
    /**
     * After compilation:
     * - removes all css maps in `./dist/styles` folder to trash.
     * - removes all js maps in `./dist/scripts` folder to trash 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
            }
        ]
    }
})
new RemovePlugin({
    /**
     * Before compilation permanently removes both 
     * `./dist/manifest.json` file and `./dist/js` folder.
     * Log only works for warnings and errors.
     */
    before: {
        root: './dist',
        include: [
            'manifest.json',
            'js'
        ],
        trash: false,
        log: false,
        logWarning: true,
        logError: true,
        logDebug: false
    }
})
new RemovePlugin({
    /**
     * Before compilation emulates remove process
     * for a file that outside of the root directory.
     * That file will be removed in trash.
     */
    before: {
        root: '.', // "D:\\remove-files-webpack-plugin-master"
        include: [
            "C:\\Desktop\\test.txt"
        ],
        trash: true,
        emulate: true,
        allowRootAndOutside: true
    }
})

Contribution

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

License

MIT.

Keywords

FAQs

Package last updated on 19 Jan 2020

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