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