create-react-app中的JSX文件

安德烈·塔鲁丁(Andrei Tarutin)

只是想知道create-react-app如何使用.js文件而不是.jsx进行jsx标记。是否由于特殊的webpack配置?顺便说一句,在哪里可以找到使用create-react-app创建的项目的webpack和babel配置?

戴夫·牛顿

文件扩展名没有什么特别的。这只是通过Babel运行的问题。例如:

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

这会通过Babel使用React预设运行.js和.jsx。

Webpack和Babel配置位于create-react-app中。

您可以通过以下方式弹出它们:

npm run eject 让他们“外部化”,但只有在您确实愿意的情况下才这样做。

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

create-react-app 的 index.js 文件是怎么解析 JSX 的?

将styled-jsx添加到弹出的create-react-app配置中

create-react-app中的src / images文件夹

在Create React App中导入文件中的NodeJ

如何在由create-react-app创建的应用程序中使用jsx文件(不运行“ npm run弹出”)?

使用“ react-jsx”作为create-react-app的jsx值的Visual Studio Code的问题

来自create-react-app中CSS的公用文件夹中的参考文件

是否可以通过public文件夹中的create-react-app服务静态文件?

从create-react-app Public文件夹中读取JSON文件

Create React App显示“除非提供'--jsx'标志,否则无法使用JSX”

Eject在Create React App中做什么?

create-react-app中的CSS链接

WebStorm中的create-react-app

使用Create React App进行React样式

部署create-react-app

在由create-react-app创建的环境中获取本地JSON文件时,JSON解析错误

使用typescript的create-react-app-如何将类型放入单独的文件中

src文件夹中的reactjs create-react-app缺少index.html

create-react-app --typescript中已编译js文件的默认位置

如何仅将JavaScript库包含在create-react-app的生产构建文件中?

什么是create-react-app中的public / manifest.json文件?

导入CSS文件并在create-react-app应用程序中反应组件?

上载图片/文件后,防止在create-react-app中重新加载页面

节点:将create-react-app模板中的文件移动到root用户安装后

在React JS中缩小.jsx文件

导入graphql文件时清理Create React App的缓存

Create React App serviceworker 不包含生成的文件之一

使用Flask后端提供“ create-react-app”制作的文件

从create-react-app发出构建文件