README
Why?
Both copy-webpack-plugin
and clean-webpack-plugin
are very large packages for the functionality they provide (91.3kb
and 15.3kb
minzipped respectively).
Both of these packages rely on fs
, so why not bundle them together whilst also minifiying the bundle size?
Usage
webpack.config.js
const FsWebpackPlugin = require('fs-webpack-plugin');
module.exports = {
plugins: [
new FsWebpackPlugin([{
// Delete folder `build` recursively
type: 'delete',
files: 'build'
}, {
// Delete file `build/index.test.js`
type: 'delete',
files: 'build/index.test.js'
}, {
// Delete file `build/index.test.js`,
type: 'delete',
files: 'index.test.js',
root: path.resolve(__dirname, 'build') // [!] Must be absolute
}, {
// Delete file `build/index.test.js` and folder `build/test`
type: 'delete',
files: [
'index.test.js',
'test'
],
root: path.resolve(__dirname, 'build')
}, {
// Copy folder `assets` recursively to `build/assets`
type: 'copy',
files: { from: 'assets', to: 'build' }
}, {
// Copy file `assets/image.png` to `build/image.png`
type: 'copy',
files: { from: 'assets/image.png', to: 'build' }
}])
]
}
Options
new FsWebpackPlugin(actions, options)
actions (Action[])
- Array of action objectsoptions.verbose (Boolean)
- Enable logging (defaultfalse
)options.strict (Boolean)
- Should throw errors instead of logging them (defaultfalse
)options.dry (Boolean)
- Enable dry run (defaultfalse
). Please note thatoptions.dry
will not output to console ifoptions.verbose
isfalse
Action
type (String)
- Action type, must be one ofcopy
,delete
files (String|String[]|{ from: String, to: String}|{ from: String, to: String}[]
- File(s) or directory(s) to delete.copy
only accepts{ from, to }
. Paths are relative to rootroot (String)
- Absolute path used byfiles
, defaults toprocess.cwd()
hooks (String[])
- Webpack hooks to run action on, defaults to['beforeRun']