简体   繁体   English

create-react-app 中的 JSX 文件

[英]JSX files in create-react-app

Just wondering how create-react-app uses.js files instead of.jsx for jsx markup.只是想知道 create-react-app 如何使用 .js 文件而不是 .jsx 来进行 jsx 标记。 Is it because of the special webpack configuration?是因为webpack的特殊配置吗? Btw, where can I find the webpack and babel configuration of my project created with create-react-app?顺便说一句,我在哪里可以找到我用 create-react-app 创建的项目的 webpack 和 babel 配置?

There's nothing special about the file extensions;文件扩展名没有什么特别之处; it's just a matter of what's being run through Babel.这只是通过 Babel 运行什么的问题。 For example:例如:

  module: {
    loaders: [
      {
        test:    /\.jsx?$/, 
        exclude: /(node_modules)/,
        loader:  'babel',
        query:   {
          presets: [
            'react',
            'es2015',
            'stage-0'
          ],
          plugins: [
            ["transform-decorators-legacy"],
          ]
        },
      }

This runs.js and.jsx through Babel with the React presets.这通过带有 React 预设的 Babel 运行 .js 和 .jsx。

The Webpack and Babel configs are inside create-react-app. Webpack 和 Babel 配置在 create-react-app 中。

You can eject them via:您可以通过以下方式弹出它们:

npm run eject to get them "externalized", but only do it if you really want to. npm run eject让它们“外部化”,但只有在你真的想要的时候才这样做。

https://github.com/facebookincubator/create-react-app#user-content-converting-to-a-custom-setup https://github.com/facebookincubator/create-react-app#user-content-converting-to-a-custom-setup

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在create-react-app创建的应用程序中使用jsx文件(不运行“npm run eject”)? - How to use jsx files in an app created by create-react-app (without run “npm run eject”)? 如果我们通过链接 React CDN 或通过 CRA(create-react-app)biolerplate 创建 App,我们可以使用 JSX 吗? - Can we use JSX, if we are creating App by linking React CDN or by CRA (create-react-app) biolerplate? create-react-app 和 TypeScript 错误:使用 JSX 时“React”必须在范围内 - create-react-app and TypeScript error: 'React' must be in scope when using JSX 使用 create-react-app 反应,不同的 env 文件 - React, different env files with create-react-app 使用 create-react-app 从 github 导入 JSX 文件时找不到模块 - Module not found when importing JSX file off github using create-react-app 使用Flask后端提供“ create-react-app”制作的文件 - Serving a 'create-react-app' made files with Flask backend create-react-app webpack 配置和文件在哪里? - where is create-react-app webpack config and files? 您可以将带有 wasm 文件的模块加载到 create-react-app 中吗? - Can you load modules with wasm files into create-react-app? 使用 create-react-app 的 writeToDisk 不显示工作文件 - writeToDisk with create-react-app not displaying work files 在 js 文件中使用 sass 变量 create-react-app - Use sass variables into js files create-react-app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM