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 = require('webpack'); module.exports = { debug: false, outputPathinfo: true, displayErrorDetails: true, context: __dirname, entry: { common: ['./src/common.coffee'], a: './src/a.cjsx', b: './src/b.cjsx' }, output: { filename: '[name]-[chunkhash].js', chunkFileName: '[name].[chunkhash].js', path: path.join(__dirname, 'js') }, plugins: [ new webpack.optimize.CommonsChunkPlugin('common', 'common-[chunkhash].js'), new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false } }) ], module: { preLoaders: [ { test: /\.coffee$/, exclude: /node_modules/, loader: 'coffeelint-loader' } ], loaders: [ { test: /\.coffee/, loader: 'coffee' }, { test: /\.cjsx$/, loaders: ['coffee', 'cjsx'] }, { test: /\.js$/, loader: 'jsx-loader?harmony' } ] } }
If I am running $(npm bin)/webpack --config webpack.js --watch
and make changes to a.cjsx
, it compiles a newer version of that file with a new chunkedhash. However, the old one remains and I'd like it to be deleted right away.
There is a clean-webpack-plugin for those purposes, or you can write a simple bash
script for npm
:
"scripts": { "build": "rm -r dist/* && webpack -p", "clean": "rm -r dist/*" }
Here is the webpack-clean-obsolete-chunks
plugin, which do what you want. It searches for all updated chunks and deletes obsolete files after each webpack
compilation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With