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. ios开发之级联菜单(两个tableView实现)

    一:在ios项目实际开发中经常会看到级联菜单的效果:如图:点击左侧菜单,右侧菜单刷新数据.此篇用两个tableView来实现如图效果: 二:代码: 1:构造数据模型:利用kvc快速构建数据模型 #im ...

  2. linux ps命令,查看某进程cpu和内存占用率情况, linux ps命令,查看进程cpu和内存占用率排序。 不指定

    背景:有时需要单看某个进程的CPU及占用情况,有时需要看整体进程的一个占用情况.一. linux ps命令,查看某进程cpu和内存占用率情况[root@test vhost]# ps auxUSER  ...

  3. php 字符串 去掉 html标签

    echo strip_tags("Hello <b>world!</b>");

  4. 【24.34%】【codeforces 560D】Equivalent Strings

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

  5. oracle listener.ora的host不能使localhost,而应该是该机器名,否则不能用ip地址进行连接

    # listener.ora Network Configuration File: /u01/app/oracle/product/11.2.0/dbhome_1/network/admin/lis ...

  6. 定时清理tomcat日志文件

    原文链接:https://blog.csdn.net/qq_37936542/article/details/78788466 需求:最近公司服务器发现磁盘经常会被占满,查其原因是因为大量的日志文件. ...

  7. 一个好汉一个帮:前端UI改造

    今天是周六,继续工作中. 只是,不是自己亲自参与搞代码,让一起好的同事帮我美化界面. 虽说前端,我也可以搞定, but,but呀,所有的工作都让我来搞,实在是太累太烦了. 前端,样式,目前做很多是模仿 ...

  8. Python正則表達式

    Python正則表達式 正則表達式是一个特殊的字符序列,它能帮助你方便的检查一个字符串是否与某种模式匹配. Python 自1.5版本号起添加了re 模块,它提供 Perl 风格的正則表達式模式. r ...

  9. 最好用的中文速查表(Bash,Gdb,VIM,Nano)

    最好用的中文速查表(Cheatsheet) 当年学习 Linux 时就是靠着一张常用命令小卡片,敲啥命令忘记了,经常拿起来看看,后来知道这玩意儿叫做速查表(Cheatsheet),于是开始有意识收集和 ...

  10. UiwebView and html

    基础篇: NSURL介绍 http://blog.csdn.net/ysy441088327/article/details/7416759 网页执行js代码   复制代码 stringByEvalu ...