1. 修改package.json,添加需要安装的包


{
"name": "myapp",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "webpack",
"start": "cross-env NODE_ENV=development webpack-dev-server --hotOnly --open"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"babel-core": "^6.26.3",
"babel-eslint": "^8.2.3",
"babel-loader": "^7.1.4",
"babel-polyfill": "^6.26.0",
"babel-preset-react-app": "^3.1.1",
"clean-webpack-plugin": "^0.1.19",
"cross-env": "^5.2.0",
"eslint": "^4.19.1",
"eslint-config-airbnb": "^16.1.0",
"eslint-plugin-import": "^2.12.0",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-react": "^7.8.2",
"html-webpack-plugin": "^3.2.0",
"webpack": "^4.8.3",
"webpack-cli": "^2.1.3",
"webpack-dev-server": "^3.1.4"
},
"dependencies": {
"lodash": "^4.17.10",
"react": "^16.4.0",
"react-dom": "^16.4.0",
"react-redux": "^5.0.7",
"react-router-dom": "^4.2.2"
}
}

2. 运行 npm i ,安装。

3. 修改webpack.config.js

const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const webpack = require('webpack'); module.exports = {
entry: {
app: path.resolve(__dirname, './src/index.js')
},
devtool: 'inline-source-map',
devServer: {
contentBase: './dist',
hot: true
},
mode: 'development',
output: {
filename: '[name]_[hash:8].bundle.js',
path: path.resolve(__dirname, 'dist')
},
plugins: [
new CleanWebpackPlugin(['dist']),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, './public/index.html'), // src文件
filename: 'index.html'// dist文件
}),
new webpack.HotModuleReplacementPlugin()
],
module: {
rules: [
{
test: /\.jsx?$/,
loader: require.resolve('babel-loader'),
exclude: /node-modules/
}
]
}
};

4. 在根目录创建.eslintrc文件

{
"parser": "babel-eslint",
"extends": "airbnb",
"rules": {
"arrow-body-style": [],
"consistent-return": [],
"generator-star-spacing": [],
"global-require": [],
"import/extensions": [],
"import/no-extraneous-dependencies": [],
"import/no-unresolved": [],
"import/prefer-default-export": [],
"jsx-a11y/no-static-element-interactions": [],
"no-bitwise": [],
"no-cond-assign": [],
"no-else-return": [],
"no-nested-ternary": [],
"no-restricted-syntax": [],
"no-use-before-define": [],
"react/forbid-prop-types": [],
"react/jsx-filename-extension": [, { "extensions": [".js"] }],
"react/jsx-no-bind": [],
"react/prefer-stateless-function": [],
"react/prop-types": [],
"require-yield": [],
"no-unused-vars": [],
"space-infix-ops": [],
"object-shorthand": [],
"quotes": ,//[1, "single"],
"jsx-quotes": ,
"prefer-const": [],
"indent": [, ],
"react/jsx-indent": [, ],
"curly": [, "all"],
"comma-dangle": [, "never"],
"react/jsx-indent-props": ,
"react/jsx-curly-spacing": ,
"space-in-parens": ,
"no-irregular-whitespace": ,
"no-mixed-spaces-and-tabs": [, false],
"no-underscore-dangle": ,
"key-spacing": ,
"no-param-reassign": ,
"no-lonely-if": ,
"linebreak-style": ,
"max-len": [, ],
"class-methods-use-this": ,
"quote-props":,
"no-shadow": ,
"guard-for-in": ,
"no-labels": ,
"prefer-template": ,
"react/sort-comp":
},
"parserOptions": {
"ecmaFeatures": {
"experimentalObjectRestSpread": true
}
},
"env": {
"browser": true,
"node": true
}
}

5. 在根目录创建.babelrc文件

{
"presets": [
"react-app"
]
}

6. 修改index.js

import React from 'react';
import ReactDom from 'react-dom';
import { Router, Route } from 'react-router-dom'; class App extends React.Component {
render() {
return (
<div>Hello,React~</div>
)
}
}
ReactDom.render(
<App />,
document.getElementById('app'),
)

7. 在根目录新建public文件夹,将index.html移动到该文件下

<!DOCTYPE html>
<html lang="en"> <head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<title>react</title>
</head> <body>
<div id="app"></div>
</body> </html>

8. 运行 npm start ,浏览器显示页面

react项目实践——(4)依赖安装与配置的更多相关文章

  1. React项目搭建及依赖安装

    一.前提 首先保证node.js已安装完成... 安装完成后,打开cmd命令行,输入 node -v 和 npm -v 来查看版本号,如果显示则安装完成. 二.安装react脚手架 在cmd命令行中输 ...

  2. react项目实践——(1)使用webpack创建项目

    1. 新建文件夹,命名为项目名称——myapp,并打开myapp文件夹. mkdir webpack-demo && cd webpack-demo 2. 在./myapp中打开命令行 ...

  3. CSS Modules入门及React中实践(内附webpack4配置)

    本篇文章以整理为主,自己进行了部分修改,如有侵权,请告知 CSS Modules介绍 CSS Modules是什么东西呢?首先,让我们从官方文档入手:GitHub – css-modules/css- ...

  4. 【React Natvie】React-native-swiper的安装和配置【ES6】

    react-native-swiper轮播图,是我们开发中特别常见的效果,首先感谢编写react-native-swiper的大神,让我们方便了很多.这个框架主要是用来做轮播图,焦点图等,内置了各种样 ...

  5. Umi + Dva + Antd的React项目实践

    记录一下最近项目所用到的技术React + Dva + Antd + umi ,以免忘记.之前没有用过它们其中一个,也是慢慢摸索,了解数据整个流程. 先了解下概念 React 不多说,3大框架之一: ...

  6. rabbitmq实践笔记(一):安装、配置与使用初探

    引言: 对于一个大型的软件系统来说,会有很多的组件.模块及不同的子系统一起协同工作,模块之间的通信需要一个可靠的通信管道来保证 ,通信管道需要解决解决很多问题,比如: 1)信息的发送者和接收者如何维持 ...

  7. react项目实践——(3)babel

    1. babel Babel是一个广泛使用的转码器,可以将ES6代码转为ES5代码,从而在现有环境执行. (1)安装 npm install --save-dev babel-core babel-e ...

  8. react项目实践——(2)webpack-dev-serve

    webpack-dev-server是一个小型的静态文件服务器,为webpack打包的资源文件提供Web服务.并且提供自动刷新和Hot Module Replacement(模块热替换:前端代码变动后 ...

  9. 在项目中添加ReactiveCocoa #安装与配置

    这是对官方教程的补充 To add RAC to your application: Add the ReactiveCocoa repository as a submodule of your a ...

随机推荐

  1. 解密Arm中国:全球最具影响力的芯片公司中国布局浮出水面

    经济观察报 记者 陈伊凡 沈怡然 李华清 对于Arm与中国合资公司事宜,5月4日下午,Arm授权的代表邮件回复<经济观察报>称:“合资公司目前刚开始运营”,“我们的重点是让这个新的合资公司 ...

  2. 美国汪利宏的蒙特卡洛及卷积模拟程序,可以模拟top-hat光束和高斯光束在生物组织中的传输

    链接:https://pan.baidu.com/s/1yaCsQ8TCVPSIZ4TVBZgfnw 密码:otzr

  3. 【27.85%】【codeforces 743D】Chloe and pleasant prizes

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  4. [CSS] Target Positional Elements Using *-Of-Type CSS pseudo-classes

    Learn how to target elements based on their position inside of a parent element in relation to its s ...

  5. 摘录-Mybatis - Integer值为0的数据 return false

    Mybatis在进行<if test="status != null and status != ''">判空操作时,如果status为0的时候,该判断条件的值为fal ...

  6. Android 用LinkedList实现队列

    队列 队列是一种特殊的线性表,它只允许在表的前端(front)进行删除操作,而在表的后端(rear)进行插入操作.进行插入操作的端称为队尾,进行删除操作的端称为队头.队列中没有元素时,称为空队列. 在 ...

  7. 【STL】各容器成员对比表

    http://www.cnblogs.com/fangyukuan/archive/2010/09/21/1832675.html Sequence containers Associative co ...

  8. MongoDB Shell 经常使用操作

    数组查询 数组查询 MongoDB 中有子文档的概念.一个文档中能方便的嵌入子文档,这与关系性数据库有着明显的不同,在查询时,语法有一些注意点. 样例代码,假如我们的一个集合(tests)中存在标签键 ...

  9. 怎样在log4j.xml配置文件中引入变量:小公司经验较多的我和阿里UC等大公司经验较多的Boss,一些技术交流和探讨

    从最初学习使用log4j的时候,网上和书本上主要都是使用"log4j.properties"这种属性格式,配置日志.多年以来,一直使用这种格式,总的来说,简单.够用.    而有十 ...

  10. HDU 5317 RGCDQ(素数个数 多校2015啊)

    题目链接:pid=5317" target="_blank">http://acm.hdu.edu.cn/showproblem.php?pid=5317 Prob ...