Questions
1 of 1
01 / 01

What are plugins?

While loaders are used to transform certain types of modules, plugins can be leveraged to perform a wider range of tasks like bundle optimization, asset management and injection of environment variables.

In order to use a plugin, you need to require() it and add it to the plugins array. Most plugins are customizable through options. Since you can use a plugin multiple times in a configuration for different purposes, you need to create an instance of it by calling it with the new operator.
  1. 1

    A webpack plugin is a JavaScript object that has an apply method. This apply method is called by the webpack compiler, giving access to the entire compilation lifecycle.

  2. 2

    Plugins are used for performing actions or tasks on the entire bundle.

  3. 3

    They can be used for various purposes, such as code splitting, minification, and adding environment-specific variables.

the html-webpack-plugin generates an HTML file for your application and automatically injects all your generated bundles into this file.