How to set up Babel 6 stage 0 with React and Webpack

前端 未结 6 2057
抹茶落季
抹茶落季 2020-12-23 19:11

My understanding from the docs

I see that Babel 6 has three presets for now: es2015, react and stage-x. I read that I can set those in .babelrc like s

6条回答
  •  青春惊慌失措
    2020-12-23 19:57

    Here is a working example with Babel 6, React, Webpack and Sequelize:

    https://github.com/BerndWessels/react-webpack

    Basically this is the .babelrc

    {
      "presets": [
        "es2015",
        "react",
        "stage-0"
      ],
      "env": {
        "development": {
          "plugins": [
            "babel-relay-plugin-loader",
            [
              "react-transform",
              {
                "transforms": [
                  {
                    "transform": "react-transform-hmr",
                    "imports": [
                      "react"
                    ],
                    "locals": [
                      "module"
                    ]
                  },
                  {
                    "transform": "react-transform-catch-errors",
                    "imports": [
                      "react",
                      "redbox-react"
                    ]
                  }
                ]
              }
            ]
          ]
        },
        "production": {
          "plugins": [
            "babel-relay-plugin-loader"
          ]
        }
      }
    }
    

    and these are the module versions

    babel-core@6.3.17
    babel-loader@6.2.0
    babel-plugin-react-transform@2.0.0-beta1
    babel-preset-es2015@6.3.13
    babel-preset-react@6.3.13
    babel-preset-stage-0@6.3.13
    

    That works for me.

提交回复
热议问题