• 取消生产环境/开发环境 控制台输出


    取消生产环境控制台输出

    const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
    
    
    module.exports = {
        devServer: {
            port: 8899,     // 端口
        },
        lintOnSave: false,   // 取消 eslint 验证
    
        configureWebpack:{
            optimization: {
                minimizer: [
                    new UglifyJsPlugin({
                        uglifyOptions: {
                            compress: {
                            // warnings: false,
                            drop_console: true,//console
                            drop_debugger: false,
                            pure_funcs: ['window.console.log']//移除console
                            }
                        }
                    })
                ]
            }
        }
        
        // configureWebpack: (config)=>{
        //     if(process.env.NODE_ENV === 'production'){
        //       config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true
        //     }
        // }
    
        // if(isProduction) {
        //     minimizer:[
        //     new UglifyJsPlugin({
        //         uglifyOptions: {
        //             mangle: {
        //                 safari10: true
        //             },
        //             compress: {
        //                 warnings: false,
        //                 drop_debugger: true,//console
        //                 drop_console: true,
        //                 pure_funcs: ['console.log']//移除console
        //             },
        //         },
        //         sourceMap: config.build.productionSourceMap,
        //         cache: true,
        //         parallel: true,
                        
        //       }),
        //     ]
        // }
    
        
        // configureWebpack: config => {
        //     if (process.env.NODE_ENV === 'production') {
        //       // 为生产环境修改配置
        //       config.plugins.push(
        //           new UglifyJsPlugin({
        //               uglifyOptions: {
        //                   compress: {
        //                       drop_debugger: true,
        //                       drop_console: true,  //生产环境自动删除console
        //                   },
        //                   warnings: false,
        //               },
        //               sourceMap: false,
        //               parallel: true,//使用多进程并行运行来提高构建速度。默认并发运行数:os.cpus().length - 1。
        //           })
        //       );
        //     }
        // }
    
        // minimizer:[
        //     new UglifyJsPlugin({
        //         uglifyOptions: {
        //             mangle: {
        //                 safari10: true
        //             },
        //             compress: {
        //                 warnings: false,
        //                 drop_debugger: true,//console
        //                 drop_console: true,
        //                 pure_funcs: ['console.log']//移除console
        //             },
        //         },
        //         sourceMap: config.build.productionSourceMap,
        //         cache: true,
        //         parallel: true,
                        
        //       }),
        // ]
        
    };
    
    
    
    // terser-webpack-plugin
    // module.exports = {
    //     devServer: {
    //         port: 8899,     // 端口
    //     },
    //     lintOnSave: false,   // 取消 eslint 验证
    //     configureWebpack: (config)=>{
    //       if(process.env.NODE_ENV === 'production'){
    //         config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true
    //       }
    //     }
    // }
    

    一种简单粗暴的方法

    在加载完成后,重写console.log

    console.log = function() {}
    window.console.log = function(){}
    
  • 相关阅读:
    Python常用函数
    Mock测试&Postman mockserver详细教程
    openpyxl模块
    adb 'grep' 不是内部或外部命令,也不是可运行的程序或批处理文件
    Appium-Python-Windows环境搭建笔记
    调用类方法时报错:missing 1 required positional argument: 'self'
    RE正则表达式-元字符
    微分方程
    操作系统学习记录
    Mybatis基础配置
  • 原文地址:https://www.cnblogs.com/marvelousone/p/12028936.html
Copyright © 2020-2023  润新知