无法在规则中使用排除(抛出错误) - 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? }

如果我删除排除属性,它可以正常工作,但我想/需要排除。

排除在规则节点上,而不是在 use 节点上,所以它应该是

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

},

相关内容

最新更新