Webpack + UglifyJs:如何忽略有关第 3 方库代码的警告
Webpack + UglifyJs: how to ignore warnings about 3rd party library code
使用 Webpack,我从 UglifyJSPlugin 收到了针对我所有第 3 方代码的大量警告。
是否可以只关闭某些库的警告?
不,根据 UglifyJS 压缩器选项,目前只能关闭所有警告:https://github.com/mishoo/UglifyJS2#compressor-options
您可以通过将 UglifyJS 选项传递给 Webpack 的 UglifyJsPlugin 的构造函数来关闭所有警告:https://webpack.github.io/docs/list-of-plugins.html#uglifyjsplugin
在你的 webpack.config.js 中,你需要有类似的东西:
var webpack = require('webpack');
module.exports = {
...
plugins: [
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
})
]
}
允许过滤丑化警告(自 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;
}
}),
],
使用 Webpack,我从 UglifyJSPlugin 收到了针对我所有第 3 方代码的大量警告。
是否可以只关闭某些库的警告?
不,根据 UglifyJS 压缩器选项,目前只能关闭所有警告:https://github.com/mishoo/UglifyJS2#compressor-options
您可以通过将 UglifyJS 选项传递给 Webpack 的 UglifyJsPlugin 的构造函数来关闭所有警告:https://webpack.github.io/docs/list-of-plugins.html#uglifyjsplugin
在你的 webpack.config.js 中,你需要有类似的东西:
var webpack = require('webpack');
module.exports = {
...
plugins: [
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
})
]
}
允许过滤丑化警告(自 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;
}
}),
],