2020-07-22 12:05:56 +00:00
|
|
|
/*eslint-env node*/
|
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
const fs = require( 'fs' );
|
|
|
|
const glob = require( 'glob' );
|
|
|
|
|
|
|
|
// This is a simple webpack plugin to delete the JS files generated by MiniCssExtractPlugin.
|
|
|
|
|
|
|
|
function RemoveFilesPlugin( filePath = '' ) {
|
|
|
|
this.filePath = filePath;
|
|
|
|
}
|
|
|
|
|
2020-09-07 17:31:10 +00:00
|
|
|
RemoveFilesPlugin.prototype.apply = function ( compiler ) {
|
2020-07-22 12:05:56 +00:00
|
|
|
compiler.hooks.afterEmit.tap( 'afterEmit', () => {
|
|
|
|
const files = glob.sync( this.filePath );
|
|
|
|
files.forEach( ( f ) => {
|
|
|
|
fs.unlink( f, ( err ) => {
|
|
|
|
if ( err ) {
|
|
|
|
/* eslint-disable-next-line no-console */
|
|
|
|
console.log( `There was an error removing ${ f }.`, err );
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = RemoveFilesPlugin;
|