What are plugins and how do they differ from loaders?

Beginner

Answer

Plugins:

  • Perform actions on the entire bundle or compilation
  • Can modify the build process, add files, or optimize output
  • Work at the bundle level

Loaders:

  • Transform individual files during the build process
  • Work at the file level
  • Process files before they're added to the bundle
const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
  plugins: [
    new HtmlWebpackPlugin({
      template: './src/index.html'
    })
  ]
};