xxx from UglifyJs DefaultsError: `warnings` is not a supported option

vue项目运行时不报错,打包时报错xxx from UglifyJs DefaultsError: `warnings` is not a supported option

该问题解决方案

1.  修改 warnings:false的书写位置  版本更新后 书写方式有改变

  config.optimization

                    .minimizer([

                        new UglifyJsPlugin({

                            uglifyOptions: {

                                warnings: false,  

                                compress: {

                                    //warnings: false,   旧版本该代码在此  

                                    drop_console: true,

                                    drop_debugger: true,

                                    pure_funcs: ['console.log']

                                }

                            }

                        })

                    ]);

2. 更改插件

将   const UglifyJsPlugin = require('uglifyjs-webpack-plugin');  

更改为  const TerserPlugin = require('terser-webpack-plugin');

在package.json 中 将  "uglifyjs-webpack-plugin": "^2.0.1"

更改为  "terser-webpack-plugin": "^4.2.3",

使用方法

 config.optimization

                    .minimizer([

                        new TerserPlugin({

                            cache: true,

                            // sourceMap: false,

                            parallel: true,

                            terserOptions: {

                                compress: {

                                    drop_debugger:true,

                                    drop_console:true,

                                },

                            },

                        })

                    ]);

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容