Skip to content

Instantly share code, notes, and snippets.

@wpscholar
Created April 26, 2018 12:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpscholar/0859fecb232a67246982191a8843fd5e to your computer and use it in GitHub Desktop.
Save wpscholar/0859fecb232a67246982191a8843fd5e to your computer and use it in GitHub Desktop.
A custom WebPack 4 plugin for removing generated JS files that aren't needed.
function() {
// Custom webpack plugin - remove generated JS files that aren't needed
this.hooks.done.tap( 'webpack', function( stats ) {
stats.compilation.chunks.forEach( chunk => {
if (!chunk.entryModule._identifier.includes( '.js' )) {
chunk.files.forEach( file => {
if (file.includes( '.js' )) {
fs.unlinkSync( path.join( __dirname, `/${file}` ) );
}
} );
}
} );
} );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment