Wepack Plugins

Table of Contents

How Plugins Work discussion

function ConsoleLogOnBuildWebpackPlugin() {

};

ConsoleLogOnBuildWebpackPlugin.prototype.apply = function(compiler) {
  compiler.plugin('run', function(compiler, callback) {
    console.log("The webpack build process is starting!!!");

    callback();
  });
};

HtmlWebpackPlugin plugin

Automatically generate a html file for serving your bundle. Within dist/index.html:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>webpack App</title>
  </head>
  <body>
    <script src="index_bundle.js"></script>
  </body>
</html>

DefinePlugin plugin

new webpack.DefinePlugin({
  PRODUCTION: JSON.stringify(true),
  VERSION: JSON.stringify("5fa3b9"),
  BROWSER_SUPPORTS_HTML5: true,
  TWO: "1+1",
  "typeof window": JSON.stringify("object")
})

CleanWebpackPlugin plugin

plugins: [
  new CleanWebpackPlugin(['dist'], {
    root: path.join(__dirname, '..')
  }),
  ...
]