未知属性“优化”

时间:2018-09-16 23:24:32

标签: webpack uglifyjs

我将尝试在Webpack中使用uglify,但出现此错误:

Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.
 - configuration has an unknown property 'optimization'. These properties are valid:
   object { amd?, bail?, cache?, context?, dependencies?, devServer?, devtool?, entry, externals?, loader?, module?, name?, node?, output?, performance?, plugins?, profile?, recordsInputPath?, recordsOutputPath?, recordsPath?, resolve?, resolveLoader?, stats?, target?, watch?, watchOptions? }

我有

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

optimization: {
        minimizer: [new UglifyJsPlugin()]
    }

在我的webpack.config.js中,好像webpack无法识别“优化”吗?

2 个答案:

答案 0 :(得分:3)

也许您使用的是旧版Webpack(3?),并且可能需要将插件实例放在plugin属性中:

module.exports = {
    ...
    plugins: [new UglifyJSPlugin()]
};

总是尝试查找与您使用的版本匹配的文档,或者将webpack更新为较新的版本。当前版本为4.19.0(于2018-09-17)。

答案 1 :(得分:1)

我也发生了同样的事情,请清除您的node_modules并重新安装它们。