zoukankan      html  css  js  c++  java
  • html 和 js 压缩

    1,js 压缩:

    将 mode 改为“production" 即可,production 模式下,webpack 会自动压缩 js 文件

    2,html 压缩:

    src / index.html

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>webpack</title>
    </head>
    <body>
        <!-- 这是注释 -->
        <h1>hello webpack</h1>
    </body>
    </html>
    

    webpack配置:

    const {resolve} = require('path')
    const HtmlWebpackPlugin = require('html-webpack-plugin')
    
    module.exports={
        entry:'./src/index.js',
        output:{
            filename:'bundle.js',
            path:resolve(__dirname,'build')
        },
        plugins:[
            new HtmlWebpackPlugin({
                template:'./src/index.html',
                minify:{
                    collapseWhitespace:true, //移除空格
                    removeComments:true //移除注释
                }
            })
        ],
        mode:'development'
    }

    打包后的 index.html,清除了空格和注释,

  • 相关阅读:
    操作系统简介
    正则表达式
    Python socket
    计算机网络基础
    计算机基础
    Python常用模块
    Python模块和包
    Python反射和内置方法(双下方法)
    Python类的成员
    更改命令行,完全显示hostname
  • 原文地址:https://www.cnblogs.com/shanlu0000/p/13052150.html
Copyright © 2011-2022 走看看