Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

README.md 1.9 KiB

3 år sedan
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # babel-preset-react-app
  2. This package includes the Babel preset used by [Create React App](https://github.com/facebook/create-react-app).<br>
  3. Please refer to its documentation:
  4. - [Getting Started](https://github.com/facebook/create-react-app/blob/master/README.md#getting-started) – How to create a new app.
  5. - [User Guide](https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md) – How to develop apps bootstrapped with Create React App.
  6. ## Usage in Create React App Projects
  7. The easiest way to use this configuration is with [Create React App](https://github.com/facebook/create-react-app), which includes it by default. **You don’t need to install it separately in Create React App projects.**
  8. ## Usage Outside of Create React App
  9. If you want to use this Babel preset in a project not built with Create React App, you can install it with following steps.
  10. First, [install Babel](https://babeljs.io/docs/setup/).
  11. Then install babel-preset-react-app.
  12. ```sh
  13. npm install babel-preset-react-app --save-dev
  14. ```
  15. Then create a file named `.babelrc` with following contents in the root folder of your project:
  16. ```js
  17. {
  18. "presets": ["react-app"]
  19. }
  20. ```
  21. This preset uses the `useBuiltIns` option with [transform-object-rest-spread](http://babeljs.io/docs/plugins/transform-object-rest-spread/) and [transform-react-jsx](http://babeljs.io/docs/plugins/transform-react-jsx/), which assumes that `Object.assign` is available or polyfilled.
  22. ## Usage with Flow
  23. Flow is enabled by default. Make sure you have a `.flowconfig` file at the root directory. You can also use the `flow` option on `.babelrc`:
  24. ```
  25. {
  26. "presets": [["react-app", { "flow": true, "typescript": false }]]
  27. }
  28. ```
  29. ## Usage with TypeScript
  30. TypeScript is enabled by default. Make sure you have a `tsconfig.json` file at the root directory. You can also use the `typescript` option on `.babelrc`:
  31. ```
  32. {
  33. "presets": [["react-app", { "flow": false, "typescript": true }]]
  34. }
  35. ```