Files
carpseeds.pl/wp-content/plugins/elementor-3.2.5-bck4/.grunt-config/remove-chunks.js
2024-07-15 11:28:08 +02:00

39 lines
844 B
JavaScript

const path = require( 'path' );
const fs = require( 'fs' );
class RemoveChunksPlugin {
constructor( chunkSuffix ) {
this.chunkSuffix = chunkSuffix;
}
apply( compiler ) {
compiler.hooks.afterPlugins.tap( 'RemoveChunksPlugin', () => this.removeChunks() );
}
removeChunks() {
if ( ! this.chunkSuffix ) {
return;
}
const chunksFolder = path.resolve( __dirname, '../assets/js' );
if ( fs.existsSync( chunksFolder ) ) {
fs.readdir( chunksFolder, ( err, files ) => {
if ( err ) throw err;
for ( const fileName of files ) {
const filePath = path.join( chunksFolder, fileName );
if ( -1 !== fileName.indexOf( this.chunkSuffix ) && fs.existsSync( filePath ) ) {
fs.unlink( filePath, err => {
if ( err ) throw err;
} );
}
}
} );
}
}
}
module.exports = RemoveChunksPlugin;