@@ -59,6 +59,23 @@ function StatusFilePlugin(mode) {
5959 } ;
6060}
6161
62+ // A plugin which deletes old .map files. We can't use clean-webpack-plugin to
63+ // delete *.map before every compilation, because in watch mode, if a .js file
64+ // doesn't change then its .map file won't be regenerated.
65+ function CleanMapFilesPlugin ( ) {
66+ this . apply = function ( compiler ) {
67+ compiler . hooks . afterEmit . tapAsync ( 'CleanMapFilesPlugin' , function ( compilation , callback ) {
68+ fs . readdirSync ( outputPath ) . forEach ( file => {
69+ if ( file . match ( / \. m a p $ / ) && ! compilation . assets [ file ] &&
70+ compilation . assets [ file . replace ( / \. \w + \. m a p $ / , '' ) ] ) {
71+ fs . unlinkSync ( outputPath + '/' + file ) ;
72+ }
73+ } ) ;
74+ callback ( ) ;
75+ } ) ;
76+ }
77+ }
78+
6279module . exports = function ( env , args ) {
6380 const mode = args . mode ;
6481
@@ -70,11 +87,12 @@ module.exports = function (env, args) {
7087 output : {
7188 path : outputPath ,
7289 filename : mode == 'development' ? '[name].dev.js' : '[name].min.js' ,
73- sourceMapFilename : '[file].' + Date . now ( ) + ' .map', // it seems Chrome caches source maps even if "Disable cache" is enabled
90+ sourceMapFilename : '[file].[hash] .map' , // it seems Chrome caches source maps even if "Disable cache" is enabled
7491 } ,
7592 plugins : [
7693 new MiniCssExtractPlugin ( { filename : 'style.css' } ) ,
7794 new StatusFilePlugin ( mode == 'development' ? 'dev' : 'prod' ) ,
95+ new CleanMapFilesPlugin ( ) ,
7896 ] ,
7997 module : {
8098 rules : [
0 commit comments