Webpack plugin for remove files from s3.
npm install --save-dev s3-remove-files-plugin
In your webpack.config.js
const S3RemoveFilesPlugin = require('s3-remove-files-plugin');
module.exports = {
// ...
plugins: [
new S3RemoveAssetsPlugin({
config: {
accessKeyId: process.env.S3_CREDENTIALS_ACCESS_KEY_ID,
secretAccessKey: process.env.S3_CREDENTIALS_SECRET_ACCESS_KEY,
region: process.env.S3_REGION
},
params: {
Bucket: process.env.S3_BUCKET,
Prefix: process.env.S3_BASE_PATH + 'assets'
},
include: /\.(js|css|gz)/,
var: 'BUILD_NUMBER', // variable name
count: 5 // number of builds to save
})
]
};