如何配置 craco 使用 jsx?

How to configure craco to use jsx?

我正在使用 craco 并试图找出如何配置 jsx。我不断收到以下错误

Support for the experimental syntax 'jsx' isn't currently enabled (4:17):

他们建议我在插件部分添加 `babel/preset-react 或使用 @babel/plugin-syntax-jsx 以启用解析,但我不确定该怎么做。

澄清一下,我正在尝试在我的 react-app

根目录之外使用 src 文件夹

craco.config.js

module.exports = {
  webpack: {
    alias: {},
    plugins: {
      add: [] /* An array of plugins */,
      remove:
        [] /* An array of plugin constructor's names (i.e. "StyleLintPlugin", "ESLintWebpackPlugin" ) */,
    },
    configure: {
      /* Any webpack configuration options: https://webpack.js.org/configuration */
    },
    configure: (webpackConfig, { env, paths }) => {
      console.log("WEBPACK");
      console.log(webpackConfig);
      webpackConfig.entry =
        "C:\Users\danie\Desktop\Code\JS\npm_packages\source\src\index.js";
      return webpackConfig;
    },
  },
  babel: {
    presets: [],
    plugins: [],
    loaderOptions: (babelLoaderOptions, { env, paths }) => {
      console.log("BABEL");
      console.log(babelLoaderOptions);
      return babelLoaderOptions;
    },
  },
};

通过将预设添加到我的配置文件来解决我的问题

craco.config.js

 babel: {
    presets: ['@babel/preset-react'],
    // plugins: [],
    loaderOptions: (babelLoaderOptions, { env, paths }) => {
      console.log("BABEL");
      console.log(babelLoaderOptions);
      return babelLoaderOptions;
    },
  },