Delete unused webpack chunked files

前端 未结 7 950
庸人自扰
庸人自扰 2021-01-03 19:03

I\'m looking for information on how to delete old webpack chunked files. Here is my current webpack configuration:

var path = require(\'path\');
var webpack          


        
7条回答
  •  一生所求
    2021-01-03 20:05

    You can solve the problem № 1 by using remove-files-webpack-plugin.

    Use this plugin like this:

    plugins: [
      new RemovePlugin({
        watch: {
          test: [
            {
              folder: './js',
              method: (absPath) => new RegExp(/(.*)-([^-\\\/]+)\.js/).test(absPath)
            }
          ]
        }
      })
    ]
    
    

    In "watch" mode (not normal compilation!) it grabs all files from ./js folder and tests them with this regular expression /(.*)-([^-\\\/]+)\.js/. Analyze this regular expression on regex101 (unit tests are included) if you have problems with understanding.

    Note: i'm the creator of this plugin.

提交回复
热议问题