稻草网

新版Webpack不允许直接使用插件的问题

错误提示如下:

 For loader options: webpack 2 no longer allows custom properties in configuration.
     Loaders should be updated to allow passing options via loader options in module.rules.
     Until loaders are updated one can use the LoaderOptionsPlugin to pass these options to the loader:
     plugins: [
       new webpack.LoaderOptionsPlugin({
         // test: /\.xxx$/, // may apply this only for some modules
         options: {
           postcss: ...
         }
       })
     ]

也就是说,Webpack 2.1.0-beta23之后的版本,不能直接包含自定义配置项,如下:

 postcss: [
    require('autoprefixer')
  ],

必须要使用下面这样的方式

 plugins: [
        new webpack.LoaderOptionsPlugin({
            options: {
                postcss: [
                    require('autoprefixer')//调用autoprefixer插件
                ]               
            }
        })      
    ]

 

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注