A brief analysis of the use of the HTML webpack plugin

A brief analysis of the use of the HTML webpack plugin

Using the html-webpack-plugin plug-in to start the page can put the html page into memory to increase the page loading speed and automatically set the path of the JS file introduced in the index.html page

Prerequisite: Webpack is installed in the project. Steps:

Step 1. Enter cnpm i html-webpack-plugin -D in the root directory of the project to install the html-webpack-plugin plug-in to the development dependency. Its function is to generate the corresponding HTML page in memory according to the specified template page.

insert image description here

Step 2 : Modify the configuration file of webpack.config.js after the plug-in is installed

Import the html-webpack-plugin plug-in in the configuration file and configure the template page path and the generated page name.

const path = require("path")
// Import html-webpack-plugin
const htmlWebpackPlugin = require("html-webpack-plugin")

module.exports={
    entry:path.join(__dirname,"./src/main.js"),
    output:{
        path:path.join(__dirname,"./dist"),
        filename:"bundle.js"
    },
    //Configure plugin nodes plugins:[
        // Create html-webpack-plugin plugin new htmlWebpackPlugin({ // Set parameters template:path.join(__dirname,"./src/index.html"), // Specify the template page to generate the page in memory according to the specified page filename:"index.html" // Specify the name of the generated page in memory })
    ]
}

After using the html-webpack-plugin plug-in, there is no need to manually process the reference path of bundle.js because the correct path of bundle.js has been automatically introduced in the generated HTML page in memory.

Summary - What plugins do:

1. Automatically generate a page in memory based on the specified page

2. Automatically introduce the packaged bundle.js into the page

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

<<:  How to set MySQL foreign keys for beginners

>>:  Nginx rtmp module compilation arm version problem

Recommend

The reason why MySQL uses B+ tree as its underlying data structure

We all know that the underlying data structure of...

Docker-compose steps to configure the spring environment

Recently, I need to package the project for membe...

Historical Linux image processing and repair solutions

The ECS cloud server created by the historical Li...

The actual process of implementing the guessing number game in WeChat applet

Table of contents Function Introduction Rendering...

Example analysis of mysql stored procedure usage

This article describes the usage of MySQL stored ...

Implementation of whack-a-mole game in JavaScript

This article shares the specific code for JavaScr...

Detailed explanation of JavaScript's built-in Date object

Table of contents Date Object Creating a Date Obj...

How to detect Ubuntu version using command line

Method 1: Use the lsb_release utility The lsb_rel...

Nginx's practical method for solving cross-domain problems

Separate the front and back ends and use nginx to...

3 codes for automatic refresh of web pages

In fact, it is very simple to achieve this effect,...

How to monitor multiple JVM processes in Zabbix

1. Scenario description: Our environment uses mic...

How to shut down/restart/start nginx

closure service nginx stop systemctl stop nginx s...