Webpack + UglifyJs: how to ignore warnings about 3rd party library code

孤者浪人 提交于 2019-12-21 09:24:38

问题


Using Webpack, I get a load of warnings from UglifyJSPlugin for all my 3rd party code.

Is it possible to turn off warnings for some libraries only?


回答1:


No, it's currently only possible to turn off all warnings, per the UglifyJS compressor options: https://github.com/mishoo/UglifyJS2#compressor-options

You can turn off all warnings by passing UglifyJS options to the constructor for Webpack's UglifyJsPlugin: https://webpack.github.io/docs/list-of-plugins.html#uglifyjsplugin

In your webpack.config.js, you'd need to have something like:

var webpack = require('webpack');

module.exports = {
    ...
    plugins: [
        new webpack.optimize.UglifyJsPlugin({
            compress: {
                warnings: false
            }
        })
    ]
}



回答2:


Allow to filter uglify warnings (since webpack 2.3.0).

https://github.com/webpack-contrib/uglifyjs-webpack-plugin/tree/v0.4.6

plugins: [
    new webpack.optimize.UglifyJsPlugin({
        compress: true,
        sourceMap: true,
        warningsFilter: (src) => {
            return src.split('node_modules\\classnames').length === 1;
        }
    }),
],


来源:https://stackoverflow.com/questions/33879517/webpack-uglifyjs-how-to-ignore-warnings-about-3rd-party-library-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!