Search code examples
webpackhtml-webpack-plugin

How to delete outputted index.js after Webpack finishes?


I am using HtmlWebpackInlineSourcePlugin with HtmlWebpackPlugin to inline all js and css files in the bundled html file. I want to delete these js and css files from the output directory after generating the html file as they are not needed anymore. Is there an option or plugin to do this?

I am also using CleanWebpackPlugin but it is not suitable for the job.

Thank you!


Solution

  • you can use webpack-shell-plugin

    install through npm:

    npm install --save-dev webpack-shell-plugin
    

    require in webpack.config.js

    const WebpackShellPlugin = require('webpack-shell-plugin');
    

    add to plugins array:

    plugins: [
        new WebpackShellPlugin({onBuildEnd:['rm dist/*.js']})
    ]