webpack打包指定HTML的文件並引入指定的chunks


1. 安裝 html-webpack-plugin

npm install html-webpack-plugin --save-dev

2. 在webpack.config.js中配置

const htmlWebpackPlugin=require('html-webpack-plugin')

module.exports={
    //...code
    plugins:[
        new htmlWebpackPlugin({
            template:"./src/index.html",
            filename:"index.html",//生成的文件名
            minify:{
                minimize:true,//是否打包為最小值
                removeAttrbuteQuotes:true,//去除引號
                removeComments:true,//去掉注釋
                collapseWhitespace:true,//去掉空格
                minifyCss:true,//壓縮css
                removeEmptyElements:false,//清理內容為空的元素
            },
            chunks: ['base', 'index'], //引入對應的js(對應(entry)中的入口文件)
            hash:true//引入產出的資源時加上哈希避免緩存
        })
    ]
}

3. 使用方法

直接啟動webpack進行項目打包即可


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM