如何找到.babelrc? [英] How to find .babelrc?

查看:892
本文介绍了如何找到.babelrc?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 Ant Design

在文档中,它说我需要更改.babelrc以模块化方式加载文件,同样从

In the docs, it says I need to change .babelrc to modularly load the files, also from https://medium.com/@GeoffMiller/how-to-customize-ant-design-with-react-webpack-the-missing-guide-c6430f2db10f..

但是,我找不到任何内容..我对Webpack/Babel/其他事物非常陌生...
我用create-react-app制作了React应用

But, I can't find any.. I'm very new to Webpack/Babel/other things...
I used create-react-app to make React app

请帮助.

这是我的package.json:

This is my package.json:

{
  "name": "ant",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "antd": "^3.0.3",
    "jquery": "^3.2.1",
    "react": "^16.2.0",
    "react-dom": "^16.2.0",
    "react-scripts": "1.0.17"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  },
  "devDependencies": {
    "babel-plugin-import": "^1.6.3",
    "css-loader": "^0.28.7",
    "less": "^2.7.3",
    "less-loader": "^4.0.5",
    "less-vars-to-js": "^1.2.1",
    "style-loader": "^0.19.1"
  }
}

推荐答案

如果您已使用create-react-app创建了React应用,则首先需要从应用中退出,以便可以使用自定义配置.查看有关自定义设置的官方文档:链接

If you have created React app using create-react-app, first you need to eject from the app so that you can use custom configuration. Check this official doc about custom setup : link

注意:这是单向操作.弹出后,您将无法返回!

Note: this is a one-way operation. Once you eject, you can’t go back!

在React应用程序中运行"npm run弹出"后,即可使用自定义babel预设.从项目弹出后,转到package.json,您将找到babel预设.

Once you run "npm run eject" when you are in a react app, you can then use custom babel presets. After ejecting from project, go to package.json and you will find babel presets.

有两种方法可以在React应用中编辑Babel配置

There are two ways to edit your Babel configuration in your react app

1)使用package.json直接

1) Edit directly using package.json :

{
  "babel": {      // nest config under "babel"
    "presets": [
      "es2015",
    ],
    "plugins": ["transform-class-properties"]
  }
}

2)创建新的.babelrc文件并编辑配置:

2) Create new .babelrc file and edit the configuration :

    //.babelrc
     {
  "presets": [
    "es2015",
  ],
  "plugins": ["transform-class-properties"]
}

这篇关于如何找到.babelrc?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆