09、生产html模板

1、安装html-webpack-plugin插件

cnpm i html-webpack-plugin

2、配置

const HtmlWebpackPlugin = require('html-webpack-plugin');

module.exports = {
    plugins : [
        new HtmlWebpackPlugin({
            template : './src/index.html',
            filename : 'index.html',
            minify : {
                minimize : true, //是否打包为最小值
                removeAttributeQuotes : true, //去除引号
                removeComments : true, //去除注释
                collapseWhitespace : true, //去除空格
                minifyCSS : true, //压缩html内的样式
                minifyJS : true, //压缩html内的js
                removeEmptyElements : true, // 清理内容为空的元素,这个慎用,有时候内容不为空也会被清理掉
            },
            hash : true //引入外部文件时加上哈希码,避免缓存
        })
    ]
}

3、打包

打包前的html文件

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .aa{font-size: 100px;}
    </style>
</head>
<body>

    <h1></h1>
    <!--这里是注释-->
    <div class="aa">111222</div>
    <script src="./main.js"></script>
    <script>
        var abc = 100;
        console.log(abc);
    </script>
</body>
</html>

打包后的html文件

<!DOCTYPE html><html lang=en><head><meta charset=UTF-8><meta name=viewport content="width=device-width,initial-scale=1"><title>Document</title><style>.aa{font-size:100px}</style></head><body><div class=aa>111222</div><script src=./main.js></script><script>var abc=100;console.log(abc)</script><script src=main.js?a81f3b95d117653c4546></script></body></html>

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值