Webpack jsx 模块加载器在包含给定时失败

Webpack jsx module loader fails when include given

我将我的问题归结为最低限度的测试。我有一个 App.js 文件,其中包含一些 jsx,将被编译为 ./bundle.js:

// App.js
module.exports = () => <div/>

我的 webpack 配置看起来很标准

module.exports = {
    entry: './App.js',
    output: {
        filename: './bundle.js'
    },
    module: {
        loaders: [
            {
                test: /\.js$/,
                loader: 'babel-loader',
                //include: ['./includes'],  // <- Problem line
                query: {
                    plugins: [
                        ['transform-react-jsx']
                    ]
                }
            }
        ]
    }
}

只有删除带有 include 的行才能正确编译。如果我启用该行然后我得到错误

Module parse failed: ./App.js Unexpected token (1:23)
You may need an appropriate loader to handle this file type.
| module.exports = () => <div/>

我不知道为什么当我为加载程序指定一个包含时它会失败,甚至 include: [] 也会失败并出现同样的错误。

有人知道吗?

include 就像 test

  • include: [] 表示 "include nothing"`
  • include: ["./include"] 表示 "only include files in the include directory"

所以如果那些将排除 ./App.js