This paper introduces

from scratch to build a react project development, for everyone to share, as follows:

1, NPM

2,.

init generated package.json file installation needs:

npm on install
--save react React.

npm - installed install
--save react-dom React installed Dom, this package is used to deal with virtual DOM. Here is the use of React Native, and here is the installation of react-native.

npm install
--save-dev webpack - install Webpack, now the most popular module package a small express server.

npm install
--save-dev webpack-dev-server tool - webpack official website of the main feature is support for.

npm install
thermal loading --save-dev babel-core Babel installed, you can convert ES6 to ES5, Babel's new V6 the babel-cli and babel-core version is divided into two modules, here only need to use babel-cor to.

to install other Babel dependent (Babel really is a family bucket, and detailed introduction to the official website to see it back again. I summarize here anyway, full fitting is:
) NPM install
--save babel-polyfill Babel includes - a Polyfill that includes a custom regenerator runtime and core.js. This will emulate a full ES6 environment

npm install
--save-dev babel-loader - webpack used in the loader.

npm install
--save babel-runtime Babel transform runtime - dependent.

npm install
plug-in --save-dev babel-plugin-transform-runtime references to helpers and - Externalise builtins, automatically polyfilling your code without polluting globals.

npm install
--save-dev babel-preset-e S2015 - Babel preset for all es2015 plugins.

npm install
--save-dev babel-preset-react Strip flow - Types and transform JSX into createElement calls.

npm install
--save-dev babel-preset-stage-2 All you - need to use stage 2 (and greater) plugins (experimental JavaScript).

3, open package.json and add the following scripts:

 {"scripts": "start" "webpack-dev-server --hot --inline --colors --content-base./build", "build": "webpack --progress --colors"}

NPM start command line input will activate webpack dev server.

NPM build will be the command line input

4,.

packaging production environment to start the webpack

Webpack package is our tools Specifically, is very important in our development environment, has very many convenient features, especially the hot reloading. webpack.config.js thermal loading is shown below the webpack configuration file. With the continuous change of app, the configuration file will constantly update, here we will use the default webpack.config.js to name the configuration file. If you use other names such as webpack.config.prod.js, then the above script requires a corresponding change in build configuration file specifies the corresponding name: "build": "webpack webpack.config.prod.js --progress --colors"

 var webpack ('webpack') = require; module.exports = entry: {'./src/app.js', output: {path: __dirname +'/build', filename: "bundle.js"}. Module: {rules: test: /.js$/ exclude: /node_modules/ [{. Loader:,'babel-loader', query: {plugins: ['transform-runtime'], presets: ['es2015','react','stage-2']}} {test:, /.css$/, loader: "style-loader! Css-loader"}]}}; 

OK, the basic configuration of our project was finally completed, it is time to start the basic configuration based.

write Reac code

React foundation - the establishment of the first Component

you in the above project, we started writing the first component React to be familiar with the writing and thought of component React.

first we build a new index.html file in the project root directory. In this basic project, we use the style of bootstrap to directly introduce a CDN. Then add a HTML tag < div id= "app" > < /div> our app will be injected into the <. The final introduction of < script src= "bundle.js" > < /script> this is the final packaged generated JS code. Below

is the complete code:

 <!! DOCTYPE html> < HTML lang= "en"; HTML; ";"; ";"; ";"; ";"; ";"; ";"; "the"; "the"; ";"; ";"; ";"; ";"; ";"; ";"; ";"; ";"; ";"; "


This concludes the body part