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,清除了空格和注释,

  • 相关阅读:
    前端请求跨域理解
    可视化交互行为
    文章标题
    在map上标记point
    基于force布局的map
    stack布局
    python一些特有语法
    histogram布局用法
    patition布局
    Shell命令行处理JSON
  • 原文地址:https://www.cnblogs.com/shanlu0000/p/13052150.html
Copyright © 2011-2022 走看看