webpack 之压缩js代码 和html文件

Posted HLLZ

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了webpack 之压缩js代码 和html文件相关的知识,希望对你有一定的参考价值。

1.压缩JS代码,mode设置为production后,打包时自动压缩代码

mode:production,

2.压缩html文件,html文件不需要处理兼容问题,压缩文件只需要在plugins中的HtmlWebpackPlugin中配置minify即可

new HtmlWebpackPlugin({
    template:./src/index.html,
    minify:{
      //移除空格
      collapseWhitespace:true,
      //移除注释
      removeComments:true
    },
}),

 

以上是关于webpack 之压缩js代码 和html文件的主要内容,如果未能解决你的问题,请参考以下文章