From 40380fbafda4ee50814e74090a1a1877b35ff3cc Mon Sep 17 00:00:00 2001 From: Jim Date: Mon, 29 Feb 2016 12:47:30 -0800 Subject: [PATCH] Create section on using React with package managers. --- _data/nav_docs.yml | 5 ++ docs/09-tooling-integration.md | 75 +------------------ docs/09.1-language-tooling.md | 79 ++++++++++++++++++++ docs/09.2-package-management.md | 126 ++++++++++++++++++++++++++++++++ docs/10-addons.md | 2 +- docs/getting-started.md | 96 +----------------------- 6 files changed, 219 insertions(+), 164 deletions(-) create mode 100644 docs/09.1-language-tooling.md create mode 100644 docs/09.2-package-management.md diff --git a/_data/nav_docs.yml b/_data/nav_docs.yml index e3b5183f..c679cb51 100644 --- a/_data/nav_docs.yml +++ b/_data/nav_docs.yml @@ -48,6 +48,11 @@ title: Refs to Components - id: tooling-integration title: Tooling Integration + subitems: + - id: language-tooling + title: Language Tooling + - id: package-management + title: Package Management - id: addons title: Add-Ons subitems: diff --git a/docs/09-tooling-integration.md b/docs/09-tooling-integration.md index 8c90f512..a1e97e70 100644 --- a/docs/09-tooling-integration.md +++ b/docs/09-tooling-integration.md @@ -3,78 +3,11 @@ id: tooling-integration title: Tooling Integration permalink: tooling-integration.html prev: more-about-refs.html -next: addons.html +next: language-tooling.html --- -Every project uses a different system for building and deploying JavaScript. We've tried to make React as environment-agnostic as possible. +We've tried to make React as environment-agnostic as possible. People use React in a variety of languages (JavaScript, TypeScript, ClojureScript, etc) and in a variety of environments (web, iOS, Android, NodeJS, Nashorn, etc). There are many tools to help you build great applications. In these sections we introduce some of the tools that are most commonly used together with React. -## React +* [Language Tooling](/react/docs/language-tooling.html) describes how to set up tools like Babel to transpile JSX for a better development experience. +* [Package Management](/react/docs/package-management.html) describes how to configure React as a dependency of your project. -### CDN-hosted React - -We provide CDN-hosted versions of React [on our download page](/react/downloads.html). These pre-built files use the UMD module format. Dropping them in with a simple ` + + + + +
+ + + +``` + +## Using React from Bower + +Bower is a package manager optimized for the front-end development. If multiple packages depend on a package - jQuery for example - Bower will download jQuery just once. This is known as a flat dependency graph and it helps reduce page load. For more info, visit http://bower.io/ + +If you'd like to use bower, it's as easy as: + +``` +bower install --save react +``` + +```html + + + + + + + + Hello React! + + + + + +
+ + + +``` + + +## Using master + +We have instructions for building from `master` [in our GitHub repository](https://github.com/facebook/react). + diff --git a/docs/10-addons.md b/docs/10-addons.md index 1cf0294c..5aec660d 100644 --- a/docs/10-addons.md +++ b/docs/10-addons.md @@ -2,7 +2,7 @@ id: addons title: Add-ons permalink: addons.html -prev: tooling-integration.html +prev: package-management.html next: animation.html --- diff --git a/docs/getting-started.md b/docs/getting-started.md index cd93f379..341add1f 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -12,52 +12,10 @@ The easiest way to start hacking on React is using the following JSFiddle Hello * **[React JSFiddle](https://jsfiddle.net/reactjs/69z2wepo/)** * [React JSFiddle without JSX](https://jsfiddle.net/reactjs/5vjqabv3/) -## Using React from npm -We recommend using React with a CommonJS module system like [browserify](http://browserify.org/) or [webpack](https://webpack.github.io/). Use the [`react`](https://www.npmjs.com/package/react) and [`react-dom`](https://www.npmjs.com/package/react-dom) npm packages. +## Starter Pack -```js -// main.js -var React = require('react'); -var ReactDOM = require('react-dom'); - -ReactDOM.render( -

Hello, world!

, - document.getElementById('example') -); -``` - -To install React DOM and build your bundle with browserify: - -```sh -$ npm install --save react react-dom babelify babel-preset-react -$ browserify -t [ babelify --presets [ react ] ] main.js -o bundle.js -``` - -To install React DOM and build your bundle with webpack: - -```sh -$ npm install --save react react-dom babel-preset-react -$ webpack -``` - -> Note: -> -> If you are using ES2015, you will want to also use the `babel-preset-es2015` package. - -**Note:** by default, React will be in development mode, which is slower, and not advised for production. To use React in production mode, set the environment variable `NODE_ENV` to `production` (using envify or webpack's DefinePlugin). For example: - -```js -new webpack.DefinePlugin({ - "process.env": { - NODE_ENV: JSON.stringify("production") - } -}); -``` - -## Quick Start Without npm - -If you're not ready to use npm yet, you can download the starter kit which includes prebuilt copies of React and React DOM. +If you're just getting started, you can download the starter kit. The starter kit includes prebuilt copies of React and React DOM for the browser, as well as a collection of usage examples to help you get started.
@@ -110,58 +68,12 @@ Then reference it from `helloworld.html`: Note that some browsers (Chrome, e.g.) will fail to load the file unless it's served via HTTP. -### Offline Transform - -First install the [Babel](http://babeljs.io/) command-line tools (requires [npm](https://www.npmjs.com/)): +## Using React with npm or Bower -``` -npm install --global babel-cli -npm install babel-preset-react -``` - -Then, translate your `src/helloworld.js` file to plain JavaScript: - -``` -babel --presets react src --watch --out-dir build -``` - -> Note: -> -> If you are using ES2015, you will want to also use the `babel-preset-es2015` package. - -The file `build/helloworld.js` is autogenerated whenever you make a change. Read the [Babel CLI documentation](http://babeljs.io/docs/usage/cli/) for more advanced usage. - -```javascript{2} -ReactDOM.render( - React.createElement('h1', null, 'Hello, world!'), - document.getElementById('example') -); -``` - - -Update your HTML file as below: - -```html{8,12} - - - - - Hello React! - - - - - -
- - - -``` +You can also use React with package managers like npm or Bower. You can learn more in our [Package Managers](/react/docs/package-management.html) section. ## Next Steps Check out [the tutorial](/react/docs/tutorial.html) and the other examples in the starter kit's `examples` directory to learn more. -We also have a wiki where the community contributes with [workflows, UI-components, routing, data management etc.](https://github.com/facebook/react/wiki/Complementary-Tools) - Good luck, and welcome!