首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在我的webpack配置中,加载程序引用的错误/缺失在哪里?

问在我的webpack配置中,加载程序引用的错误/缺失在哪里?
EN

Stack Overflow用户
提问于 2020-01-28 11:55:37
回答 1查看 37关注 0票数 0

有一个相当典型的webpack配置,用一个新的项目无法捆绑我的任何反应代码。

错误读取

代码语言:javascript
复制
ERROR in ./index.jsx 47:6
Module parse failed: Unexpected token (47:6)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file.

这是我的webpack档案

代码语言:javascript
复制
const path = require('path');
const SRC_DIR = path.join(__dirname, '/client/src');
const DIST_DIR = path.join(__dirname, '/client/dist');

module.exports = {
  context: SRC_DIR,
  entry: './index.jsx',
  output: {
    filename: 'bundle.js',
    path: DIST_DIR
  },
  module: {
    rules: [
      {
        test: /\.jsx?/,
        exclude: /node_modules/,
        test: /\.css$/,
        use: ['style-loader', 'css-loader'],
        use: {
          loader: 'babel-loader',
          query: {
            presets: ['@babel/preset-env', '@babel/preset-react'],
            plugins: ['@babel/plugin-proposal-class-properties']
          }
        }
      }
    ]
  }
};

有一种感觉,有一个相当简单的东西,我错过了,会感激任何洞察力的问题可能是什么。

更新-包括Dist树

代码语言:javascript
复制
├── client
│   ├── src
│   │   ├── config
│   │   ├── components
│   │   │   ├── Form.jsx
│   │   │   ├── TableList.jsx
│   │   │   └── TableListItem.jsx
│   │   └── index.jsx
│   └── dist
│       ├── index.html
│       └── bundle.js
├── server
│   └── index.js
├── README.md
├── package.json
├── package-lock.json
└── webpack.config.js
EN

回答 1

Stack Overflow用户

发布于 2020-01-28 12:01:43

您需要babel-loader将您的.jsx转换为vanila。您需要在您的webpack.config文件中添加以下内容:

代码语言:javascript
复制
module: {
    rules: [
      {
        test: /\.css$/,
        use: ["style-loader", "css-loader"]
      },
      {
        test: /\.jsx?$/,
        exclude: /node_modules/,
        loader: "babel-loader",
        query: {
          presets: ["react"]
        }
      }
    ]
  },

希望这对你有用。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59948230

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档