Closed3
webpack5 で build 前に dist folder を削除したい


output.clean
を true にすればOK
In general it's good practice to clean the /dist folder before each build, so that only used files will be generated. Let's take care of that with output.clean option.
webpack.config.js
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: {
index: './src/index.js',
print: './src/print.js',
},
plugins: [
new HtmlWebpackPlugin({
title: 'Output Management',
}),
],
output: {
filename: '[name].bundle.js',
path: path.resolve(__dirname, 'dist'),
+ clean: true,
},
};

webpack4 だと clean-webpack-plugin を利用する必要があったみたい。今でもググると clean-webpack-plugin の情報が出てくるけど、webpack5 なら追加の plugin は必要なし。
このスクラップは2023/09/28にクローズされました