Package Exports
- remove-files-webpack-plugin
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (remove-files-webpack-plugin) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
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-pluginUsage
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
| Name | Type | Default | Description |
|---|---|---|---|
| root | String |
. |
A root directory. Not absolute paths will be appended to this. Defaults to from which directory is called. |
| include | Array<String> |
[] |
A folders or files for removing. |
| exclude | Array<String> |
[] |
A files for excluding. |
| test | Array<TestObject> |
[] |
A folders for custom testing. |
| TestObject.folder | String |
Required | A path to the folder. |
| TestObject.method | (filePath: String) => Boolean |
Required | A method that accepts an absolute file path and must return boolean value that indicates should be removed that file or not. |
| TestObject.recursive | Boolean |
false |
Test in all subfolders, not just in TestObject.folder. |
| log | Boolean |
true |
Print which folders or files has been removed. |
| emulate | Boolean |
false |
Emulate remove process. Print which folders or files will be removed without actually removing them. Ignores log value. |
| allowRootAndOutside | Boolean |
false |
Allow 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!