2017-02-10 30 views
1

我嘗試排除時出現以下規則的錯誤。無法在規則中使用排除(錯誤拋出) - webpack 2

module: { 
    rules: [ 
     { 
      test: /\.js$/, 
      use: [ 
       { 
        loader: 'babel-loader', 
        options: { babelrc: true }, 
        exclude: [/node_modules/], 
       }, 
      ], 
     }, 
    ], 
}, 

文檔說有效的條件排除有:字符串,正則表達式,功能,陣列

但無論怎樣有效的條件,我把排除我得到這個錯誤:

Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema. 
- configuration.module.rules[0].use should be one of these: 
    non-empty string | function | object { loader?, options?, query? } | function | [non-empty string | function | object { loader?, options?, query? }] 
    Details: 
    * configuration.module.rules[0].use should be a string. 
    * configuration.module.rules[0].use should be an instance of function. 
    * configuration.module.rules[0].use should be an object. 
    * configuration.module.rules[0].use should be one of these: 
     non-empty string | function | object { loader?, options?, query? } 
    * configuration.module.rules[0].use should be an instance of function. 
    * configuration.module.rules[0].use[0] should be a string. 
    * configuration.module.rules[0].use[0] should be an instance of function. 
    * configuration.module.rules[0].use[0] has an unknown property 'exclude'. These properties are valid: 
     object { loader?, options?, query? } 
    * configuration.module.rules[0].use[0] should be one of these: 
     non-empty string | function | object { loader?, options?, query? } 

如果我刪除排除屬性它工作正常,但我想/需要排除。

+0

你必須設置'排除:/ node_modules /'在試驗的同一水平使用。 – Hosar

+0

是啊@Hosar是正確的。你在那裏不應該包括'exclude'字段。 – ickyrr

+0

好的遷移後:( – rgb

回答

0

排除不使用節點上的規則節點上,所以應該是

module: { 
rules: [ 
    { 
     test: /\.js$/, 
     exclude: [/node_modules/], 
     use: [ 
      { 
       loader: 'babel-loader', 
       options: { babelrc: true } 
      }, 
     ], 
    }, 
], 

},

相關問題