代码之家  ›  专栏  ›  技术社区  ›  Michel H.

给定include时,Webpack jsx模块加载程序失败

  •  0
  • Michel H.  · 技术社区  · 8 年前

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

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

    我的网页配置似乎很标准

    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: [] 失败并出现相同错误。

    有人有主意吗?

    1 回复  |  直到 8 年前
        1
  •  1
  •   loganfsmyth    8 年前

    include 就像 test .

    • include: [] 表示“不包含任何内容”`
    • include: ["./include"] 表示“仅在 包括 目录“

    所以如果排除 ./App.js .