webpack-backup-output-plugin
v0.4.0
Published
Webpack plugin to create backup of and/or clean the output folder before files are emitted
Downloads
14
Maintainers
Readme
Webpack Backup Ouput Plugin
Webpack plugin to create backup of the output folder ("backup-folder/timestamp") upon first compile. Useful if your build is corrupted and you want to roll back to what you had before the compilation, but also if you just want to clean your directory before you emit the new files.
It supports multi webpack config instances which are run simultaneously, which means that the other webpack compilations won't emit files until the backup has been created and/or files have been deleted.
Note
The backup will only be performed once for each launch, which means that the backup will only be performed upon starting up a watch build. For subsequent build the backup will not be performed.
Warning
If you have activated removal of the output folder, you should activate the plugin for each build, otherwise the files and folders might be removed in the middle of files being emitted. If you give the same glob expression for files
each build will wait for the clean to complete.
Install
npm
npm install --save-dev webpack-backup-output-plugin
Options
- clean: [boolean=true] Remove the files in the output folder before emit
- backup: [boolean=true] Backup files in the output folder
- files: [string|string[]=
**/*.*
] Which files to backup and/or remove (glob expressions) - backupRoot: [string|boolean='_webpack-backup'] Folder where to put backups (relative to current work directory).
Usage
var WebpackBackupOutputPlugin = require('webpack-backup-output-plugin');
// In your webpack config
{
// ...
plugins: [
new WebpackBackupOutputPlugin({ /* options */ })
]
}
Setup multi bundler config
Defining the plugin for several config that are run simultaneously is possible, but you should make sure to define what type of file you want to handle in the setup. But often you just want one config to handle the backup, so you just add it to one config
Example of multi config backup
// Config 1
const config1 = {
output: {
path: `/public`,
filename: '[name].js?[chunkhash]'
},
// ...
plugins: [
new WebpackBackupOutputPlugin({
files: ['**/*.png', '*.js']
})
]
}
// Config 2
const config2 = {
output: {
// Same output path is needed to have it wait for the backup to complete
path: `/public`,
},
// ...
plugins: [
new WebpackBackupOutputPlugin({
files: '**/*.js'
)
]
}
// Config 3 (not affected by the previous backups)
const config3 = {
output: {
// Having another path makes it ignore other backups
// and only wait for its own backup to finish
path: `/web`
},
// ...
plugins: [
new WebpackBackupOutputPlugin()
]
}
return [config1, config2, config3]