react 环境快速搭建

前端之家收集整理的这篇文章主要介绍了react 环境快速搭建前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1. yum install nodejs

2.npm 淘宝镜像配置 参考http://blog.csdn.net/wangweiscsdn/article/details/53414965

3.node -v

4.npm -v


5. 项目目录搭建

[html] view plain copy
  1. //package.json
  2. {
  3. "name":"chatme",
  4. "version":"1.0.0",
  5. "description":"",108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> "author":"weiwei",248); line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> "scripts":{
  6. "start":"webpack-dev-server--hot--progress--colors--host0.0.0.0",248); line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> "build":"webpack--progress--colors--minimize"
  7. },248); line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> "dependencies":{
  8. "react":"^15.4.0",248); line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> "react-dom":"^15.4.0"
  9. "devDependencies":{
  10. "babel-core":"^6.26.0",248); line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> "babel-loader":"^7.1.2",108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> "babel-preset-es2015":"^6.24.1",248); line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> "babel-preset-react":"^6.24.1",108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> "css-loader":"^0.28.7",248); line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> "node-sass":"^4.5.3",108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> "sass-loader":"^6.0.6",248); line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> "style-loader":"^0.18.2",108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> "webpack":"^2.2.1",248); line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> "webpack-dev-server":"^2.4.2"
  11. "license":""
  12. }

[plain] copy
    //webpack.config.js
  1. varwebpack=require('webpack');
  2. varpath=require('path')
  3. module.exports={
  4. entry:['./app/main.js'],248); line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> output:{
  5. path:path.resolve(__dirname,'/build'),248); line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> filename:'bundle.js'
  6. module:{
  7. loaders:[
  8. {
  9. test:/\.js$/,248); line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> exclude:/node_modules/,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> loader:'babel-loader'
  10. },248); line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> test:/\.scss$/,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> loaders:["style-loader","css-loader","sass-loader"]
  11. test:/\.(otf|eot|svg|ttf|woff|png|jpg)/,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> loader:'url-loader?limit=8192&name=images/[hash:8].[name].[ext]'
  12. test:/\.(jsx|js)$/,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> loader:'babel-loader',108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> query:{
  13. presets:['react','es2015']
  14. }
  15. }
  16. ]
  17. plugins:[
  18. newwebpack.optimize.UglifyJsPlugin()
  19. }

copy
    //index.html
  1. <!doctypehtml>
  2. <htmllang="en">
  3. <head>
  4. <Metacharset="utf-8">
  5. <title>weiwei</title>
  6. <Metaname="viewport"content="width=device-width,initial-scale=1.0,user-scalable=no"/>
  7. </head>
  8. <body>
  9. <divid="weiwei"></div>
  10. <scriptsrc="./bundle.js"></script>
  11. </body>
  12. </html>

copy
    //main.js
  1. importReactfrom'react'
  2. importReactDOMfrom'react-dom'
  3. importReactStackfrom'./pages/ReactStack'
  4. ReactDOM.render(
  5. <ReactStack/>,108); list-style:decimal-leading-zero outside; color:inherit; line-height:18px; margin:0px!important; padding:0px 3px 0px 10px!important"> document.getElementById('weiwei')
  6. );

copy
    //ReactStack.js
  1. importReactfrom'react'//模块引入
  2. //import'../styles/reactStack.scss'
  3. classReactStackextendsReact.Component{//class特性
  4. render(){
  5. constlearner={name:'WEIWEI',age:18}//const定义变量
  6. constmainSkills=['React','ES6','Webpack','Babel','NPM',]
  7. constextraSkills=['Git','Postman']
  8. constskillSet=[...mainSkills,...extraSkills]
  9. const{name}=learner//解构赋值
  10. letgreetings=null//let定义变量
  11. if(name){
  12. greetings=`${name},欢迎来到${mainSkills[0]}的世界!`//字符模版
  13. //以下用了箭头函数
  14. return(
  15. <divclassName="skills">
  16. <div>{greetings}</div>
  17. <ol>
  18. {skillSet.map((stack,i)=><likey={i}>{stack}</li>)}
  19. </ol>
  20. </div>
  21. )
  22. exportdefaultReactStack//模块导出

6.npm install

7.启动 npm start

原文链接:https://www.f2er.com/react/302911.html

猜你在找的React相关文章