Using create react app, and having ES6 dependencies Using create react app, and having ES6 dependencies reactjs reactjs

Using create react app, and having ES6 dependencies


You can't use ES6 code with create-react-app, or most build systems.

npm packages shouldn't result in ES6 code because of existing tooling, and to a lesser extent, older node versions.

To set up your package, assuming the ES6 code is in the src directory:

npm install --save-dev babel-core babel-cli babel-preset-latest

.babelrc

{  "presets": ["latest"]}

package.json

  "main": "./lib",  "scripts": {    "build": "babel src --out-dir lib"  }

Then do npm run build before publishing.


Create a .gitignore with 'lib' in it, and a .npmignore that's empty. The .npmignore needs to exist.

You can run your tests on the src directory (or lib, doesn't much matter).