Created
April 26, 2018 12:14
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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