Detailed explanation of html-webpack-plugin usage

Detailed explanation of html-webpack-plugin usage

Recently, I used html-webapck-plugin plug-in for the first time in a react project. It has two main functions:

Dynamically add hash after each compile for external resources such as script and link introduced in HTML files to prevent problems with referencing cached external files

You can generate and create HTML entry files. For example, a single page can generate an HTML file entry. Configuring N html-webpack-plugin can generate N page entries.

1. Installation

cnpm i webpack-plugin -D

2. Reference in webpack.config.json

const path = require('path')
const htmlWebpackPlugin = require('html-webpack-plugin') //First stepmodule.exports = {
    entry: path.join(__dirname, './src/main.js'),
    output: {
        path: path.join(__dirname, './dist'),
        filename: 'bundle.js',
    },
    mode: 'development',
    devServer: {
        open: true,
        port: 8080,
        hot: true,
        contentBase: 'src'
    },
    plugins: [
        new htmlWebpackPlugin({ //Step 2 template: path.join(__dirname, './src/index.html'), //Specify the path of the generated template filename: 'index.html' //Specify the name of the generated page })
    ]
}

3. The role of html-webpack-plugin

1. Generate a file of the specified template in memory, which is faster to access 2. Automatically add bundle.js file to the specified template file

Summarize

This is the end of this article on the detailed use of html-webpack-plugin. For more information on the use of html-webpack-plugin, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

<<:  Detailed explanation of the background-position percentage principle

>>:  Why does your height:100% not work?

Recommend

Detailed explanation of MySQL from getting started to giving up - installation

What you will learn 1. Software installation and ...

Write a shopping mall card coupon using CSS in three steps

Today is 618, and all major shopping malls are ho...

TCP socket SYN queue and Accept queue difference analysis

First we must understand that a TCP socket in the...

About the problem of running git programs in jenkins deployed by docker

1. First, an error message is reported when assoc...

MySQL 5.7.18 installation and configuration method graphic tutorial (CentOS7)

How to install MySQL 5.7.18 on Linux 1. Download ...

Understanding innerHTML

<br />Related articles: innerHTML HTML DOM i...

Implementation steps for installing FTP server in Ubuntu 14.04

Table of contents Install Software Management Ano...

When is it appropriate to use dl, dt, and dd?

dl:Definition list Definition List dt:Definition t...

How to set npm to load packages from multiple package sources at the same time

Table of contents 1. Build local storage 2. Creat...

Detailed tutorial on deploying Django project using Docker on centos8

introduction In this article, we will introduce h...

Vue recursively implements custom tree components

This article shares the specific code of Vue recu...

Example of integrating Kafka with Nginx

background nginx-kafka-module is a plug-in for ng...

Implementation code of front-end HTML skin changing function

50 lines of code to change 5 skin colors, includi...

Add crontab scheduled tasks to debian docker container

Now most of the Docker images are based on Debian...