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. x265探索与研究(四):怎样编码视频?

    怎样编码视频?           本文介绍x265中的两种编码视频方法,一是採用命令行的方法.二是GUI的方式.   1.命令行的方法   (1).第一种方式生成*.265格式的视频文件       ...

  2. Lucene学习总结之六:Lucene打分公式的数学推导 2014-06-25 14:20 384人阅读 评论(0) 收藏

    在进行Lucene的搜索过程解析之前,有必要单独的一张把Lucene score公式的推导,各部分的意义阐述一下.因为Lucene的搜索过程,很重要的一个步骤就是逐步的计算各部分的分数. Lucene ...

  3. [Angular] Pluck value from Observable

    export class MailFolderComponent implements OnInit{ title: Observable<string>; messages: Obser ...

  4. Django之settings.py 的media路径设置

    在一个 models 中使用 FileField 或 ImageField 需要以下步骤: 1. 在你的 settings.py文件中, 定义一个完整路径给MEDIA_ROOT 以便让 Django在 ...

  5. php输出文件,数组

    file_put_contents('C://zll.txt',var_export($data,true));//输出数组 file_put_contents('C://zll.txt','你好啊' ...

  6. Android SqlDelight具体解释和Demo样例

    一.简单介绍 SQLDelight 和 SqlBrite 是 Square 公司推出的一个 Android 平台数据库解决方式. 在了解这个两个东西前,必须先得有Andorid的Sqlite的知识(S ...

  7. php课程 4-14 数组如何定义使用

    php课程 4-14  数组如何定义使用 一.总结 1.各种语言键值对取值和赋值赋值表达式左边的特点是什么? 键值对,用于取值和赋值,取值和赋值的左边都是一样的 2.各种语言键值对取值或者赋值的时候如 ...

  8. web项目的WEB-INF目录

    WEB-INF是Java的WEB应用的安全目录.所谓安全就是客户端无法访问,只有服务端可以访问的目录. 如果想在页面中直接访问其中的文件,必须通过web.xml文件对要访问的文件进行相应映射才能访问. ...

  9. erlang 符号相关基本语法

    http://blog.csdn.net/anghlq/article/details/6803332 ErLang语法约定: 大写字母开头的名字(比如Address),表示一个变量,包括参数.局部变 ...

  10. WPF 针对数据源某个属性进行排序

    原文:WPF 针对数据源某个属性进行排序 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/wanlong360599336/article/detai ...