July 2018
Beginner to intermediate
458 pages
9h 58m
English
Plugins are the heart of webpack. Let's take an example of a simple webpack.config.js file to understand plugin use:
const HtmlWebpackPlugin = require('html-webpack-plugin'); //installed via npmconst webpack = require('webpack'); //to access built-in pluginsconst config = { module: { rules: [ { test: /\.txt$/, use: 'raw-loader' } ] }, plugins: [ new HtmlWebpackPlugin({template: './src/index.html'}) ]};module.exports = config;
In this example, we are using HtmlWebpackPlugin, which creates an HTML file to serve a webpack bundle. It uses an HTML template stored in the src/index.html path.
There are a lot of out-of-the-box plugins available for webpack. They are listed at https://webpack.js.Org/plugins/.
Now that we understand the basics ...