A webpack plugin to clean specified files after build
Install the plugin:
npm install webpack-clean --save-dev
yarn add webpack-clean --dev
new WebpackCleanPlugin(files: array|string, [ { [basePath: string], [removeMaps: boolean] } ])
files
- array of files or string for a single file relative to thebasePath
or to thecontext
of your config (if thebasePath
param is not specified),basePath
(optional) - string - directory to be resolved toremoveMaps
(optional) - boolean - specify if the.map
files should be automatically removed. Disabled by default.forceDelete
(optional) - boolean - specify if the files should be force deleted in case of compile errors. IfforceDelete
is not enabled, the compile errors will be logged tostdout
but the deletion of the files will not take place. Disabled by default.
var WebpackCleanPlugin = require('webpack-clean');
module.exports = {
context: path.join(__dirname, './'),
entry: './src/index.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist')
},
plugins: [
new WebpackCleanPlugin([
'dist/test1.js',
'dist/test2.js'
])
]
};
module.exports = {
plugins: [
new WebpackCleanPlugin(
'dist/fileA.js',
{basePath: path.join(__dirname, './')}
)
]
};
module.exports = {
plugins: [
new WebpackCleanPlugin([
'fileA.js',
'fileB.js'
], {basePath: path.join(__dirname, 'dist'))}
]
};
module.exports = {
plugins: [
new WebpackCleanPlugin([
'fileA.js',
'fileB.js'
], {basePath: path.join(__dirname, 'dist'), removeMaps: true)}
]
};
module.exports = {
plugins: [
new WebpackCleanPlugin([
'fileA.js',
'fileB.js'
], {basePath: path.join(__dirname, 'dist'), removeMaps: true, forceDelete: true)}
]
};