Commit 5b85a362 authored by Ville Immonen's avatar Ville Immonen Committed by Dan Abramov
Browse files

Extract Babel configuration to babel-preset-react-app (#701)

parent d3ecd6df
No related merge requests found
Showing with 99 additions and 65 deletions
+99 -65
# babel-preset-react-app
This package includes the Babel preset used by [Create React App](https://github.com/facebookincubator/create-react-app).
## Usage in Create React App Projects
The easiest way to use this configuration is with [Create React App](https://github.com/facebookincubator/create-react-app), which includes it by default. **You don’t need to install it separately in Create React App projects.**
## Usage Outside of Create React App
If you want to use this ESLint configuration in a project not built with Create React App, you can install it with following steps.
First, [install Babel](https://babeljs.io/docs/setup/).
Then create a file named `.babelrc` with following contents in the root folder of your project:
```js
{
"presets": ["react-app"]
}
```
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';
var path = require('path');
module.exports = {
presets: [
// Latest stable ECMAScript features
require.resolve('babel-preset-latest'),
// JSX, Flow
require.resolve('babel-preset-react')
],
plugins: [
// class { handleClick = () => { } }
require.resolve('babel-plugin-transform-class-properties'),
// { ...todo, completed: true }
require.resolve('babel-plugin-transform-object-rest-spread'),
// function* () { yield 42; yield 43; }
[require.resolve('babel-plugin-transform-regenerator'), {
// Async functions are converted to generators by babel-preset-latest
async: false
}],
// Polyfills the runtime needed for async/await and generators
[require.resolve('babel-plugin-transform-runtime'), {
helpers: false,
polyfill: false,
regenerator: true,
// Resolve the Babel runtime relative to the config.
moduleName: path.dirname(require.resolve('babel-runtime/package'))
}]
],
env: {
production: {
plugins: [
// Optimization: hoist JSX that never changes out of render()
// Disabled because of issues:
// * https://github.com/facebookincubator/create-react-app/issues/525
// * https://phabricator.babeljs.io/search/query/pCNlnC2xzwzx/
// * https://github.com/babel/babel/issues/4516
// TODO: Enable again when these issues are resolved.
// require.resolve('babel-plugin-transform-react-constant-elements')
]
}
}
};
{
"name": "babel-preset-react-app",
"version": "0.0.1",
"description": "Babel preset used by Create React App",
"repository": "facebookincubator/create-react-app",
"license": "BSD-3-Clause",
"bugs": {
"url": "https://github.com/facebookincubator/create-react-app/issues"
},
"files": [
"index.js"
],
"dependencies": {
"babel-plugin-transform-class-properties": "6.11.5",
"babel-plugin-transform-object-rest-spread": "6.8.0",
"babel-plugin-transform-react-constant-elements": "6.9.1",
"babel-plugin-transform-regenerator": "6.14.0",
"babel-plugin-transform-runtime": "6.15.0",
"babel-preset-latest": "6.14.0",
"babel-preset-react": "6.11.1",
"babel-runtime": "6.11.6"
}
}
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
*/ */
// @remove-on-eject-end // @remove-on-eject-end
var path = require('path');
var findCacheDir = require('find-cache-dir'); var findCacheDir = require('find-cache-dir');
module.exports = { module.exports = {
...@@ -23,29 +22,6 @@ module.exports = { ...@@ -23,29 +22,6 @@ module.exports = {
name: 'react-scripts' name: 'react-scripts'
}), }),
presets: [ presets: [
// Latest stable ECMAScript features require.resolve('babel-preset-react-app')
require.resolve('babel-preset-latest'),
// JSX, Flow
require.resolve('babel-preset-react')
],
plugins: [
// class { handleClick = () => { } }
require.resolve('babel-plugin-transform-class-properties'),
// { ...todo, completed: true }
require.resolve('babel-plugin-transform-object-rest-spread'),
// function* () { yield 42; yield 43; }
[require.resolve('babel-plugin-transform-regenerator'), {
// Async functions are converted to generators by babel-preset-latest
async: false
}],
// Polyfills the runtime needed for async/await and generators
[require.resolve('babel-plugin-transform-runtime'), {
helpers: false,
polyfill: false,
regenerator: true,
// Resolve the Babel runtime relative to the config.
// You can safely remove this after ejecting:
moduleName: path.dirname(require.resolve('babel-runtime/package'))
}]
] ]
}; };
...@@ -9,41 +9,10 @@ ...@@ -9,41 +9,10 @@
*/ */
// @remove-on-eject-end // @remove-on-eject-end
var path = require('path');
module.exports = { module.exports = {
// Don't try to find .babelrc because we want to force this configuration. // Don't try to find .babelrc because we want to force this configuration.
babelrc: false, babelrc: false,
presets: [ presets: [
// Latest stable ECMAScript features require.resolve('babel-preset-react-app')
require.resolve('babel-preset-latest'),
// JSX, Flow
require.resolve('babel-preset-react')
],
plugins: [
// class { handleClick = () => { } }
require.resolve('babel-plugin-transform-class-properties'),
// { ...todo, completed: true }
require.resolve('babel-plugin-transform-object-rest-spread'),
// function* () { yield 42; yield 43; }
[require.resolve('babel-plugin-transform-regenerator'), {
// Async functions are converted to generators by babel-preset-latest
async: false
}],
// Polyfills the runtime needed for async/await and generators
[require.resolve('babel-plugin-transform-runtime'), {
helpers: false,
polyfill: false,
regenerator: true,
// Resolve the Babel runtime relative to the config.
// You can safely remove this after ejecting:
moduleName: path.dirname(require.resolve('babel-runtime/package'))
}],
// Optimization: hoist JSX that never changes out of render()
// Disabled because of issues:
// * https://github.com/facebookincubator/create-react-app/issues/525
// * https://phabricator.babeljs.io/search/query/pCNlnC2xzwzx/
// TODO: Enable again when these issues are resolved.
// require.resolve('babel-plugin-transform-react-constant-elements')
] ]
}; };
...@@ -26,14 +26,7 @@ ...@@ -26,14 +26,7 @@
"babel-eslint": "6.1.2", "babel-eslint": "6.1.2",
"babel-jest": "15.0.0", "babel-jest": "15.0.0",
"babel-loader": "6.2.5", "babel-loader": "6.2.5",
"babel-plugin-transform-class-properties": "6.11.5", "babel-preset-react-app": "0.0.1",
"babel-plugin-transform-object-rest-spread": "6.8.0",
"babel-plugin-transform-react-constant-elements": "6.9.1",
"babel-plugin-transform-regenerator": "6.14.0",
"babel-plugin-transform-runtime": "6.15.0",
"babel-preset-latest": "6.14.0",
"babel-preset-react": "6.11.1",
"babel-runtime": "6.11.6",
"case-sensitive-paths-webpack-plugin": "1.1.4", "case-sensitive-paths-webpack-plugin": "1.1.4",
"chalk": "1.1.3", "chalk": "1.1.3",
"connect-history-api-fallback": "1.3.0", "connect-history-api-fallback": "1.3.0",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment