国产成人精品无码青草_亚洲国产美女精品久久久久∴_欧美人与鲁交大毛片免费_国产果冻豆传媒麻婆精东

18143453325 在線咨詢 在線咨詢
18143453325 在線咨詢
所在位置: 首頁 > 營銷資訊 > 建站知識 > 詳解html-webpack-plugin使用

詳解html-webpack-plugin使用

時間:2023-03-03 11:51:01 | 來源:建站知識

時間:2023-03-03 11:51:01 來源:建站知識

詳解html-webpack-plugin使用:

這篇文章主要介紹了html-webpack-plugin使用,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下

最近在react項目中初次用到了html-webapck-plugin插件,用到該插件的兩個主要作用:

為html文件中引入的外部資源如script、link動態(tài)添加每次compile后的hash,防止引用緩存的外部文件問題

可以生成創(chuàng)建html入口文件,比如單頁面可以生成一個html文件入口,配置N個html-webpack-plugin可以生成N個頁面入口

1、安裝

cnpm i webpack-plugin -D

2、在webpack.config.json中引用

const path = require('path')
const htmlWebpackPlugin = require('html-webpack-plugin') //第一步
module.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({ //第二步
        template: path.join(__dirname, './src/index.html'), //指定生成模板的路徑
        filename: 'index.html' //指定生成頁面的名稱
        })
    ]
}

3、html-webpack-plugin的作用

一、在內(nèi)存中生成一個指定模板的文件,在訪問時速度更快

二、自動為指定模板文件添加bundle.js文件

總結(jié)

到此這篇關(guān)于詳解html-webpack-plugin使用的文章就介紹到這了,更多相關(guān)html-webpack-plugin使用內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持腳本之家!

來源:腳本之家

鏈接:https://www.jb51.net/web/745178.html

關(guān)鍵詞:使用

74
73
25
news

版權(quán)所有? 億企邦 1997-2025 保留一切法律許可權(quán)利。

為了最佳展示效果,本站不支持IE9及以下版本的瀏覽器,建議您使用谷歌Chrome瀏覽器。 點擊下載Chrome瀏覽器
關(guān)閉