react项目实践——(4)依赖安装与配置
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)依赖安装与配置的更多相关文章
- React项目搭建及依赖安装
一.前提 首先保证node.js已安装完成... 安装完成后,打开cmd命令行,输入 node -v 和 npm -v 来查看版本号,如果显示则安装完成. 二.安装react脚手架 在cmd命令行中输 ...
- react项目实践——(1)使用webpack创建项目
1. 新建文件夹,命名为项目名称——myapp,并打开myapp文件夹. mkdir webpack-demo && cd webpack-demo 2. 在./myapp中打开命令行 ...
- CSS Modules入门及React中实践(内附webpack4配置)
本篇文章以整理为主,自己进行了部分修改,如有侵权,请告知 CSS Modules介绍 CSS Modules是什么东西呢?首先,让我们从官方文档入手:GitHub – css-modules/css- ...
- 【React Natvie】React-native-swiper的安装和配置【ES6】
react-native-swiper轮播图,是我们开发中特别常见的效果,首先感谢编写react-native-swiper的大神,让我们方便了很多.这个框架主要是用来做轮播图,焦点图等,内置了各种样 ...
- Umi + Dva + Antd的React项目实践
记录一下最近项目所用到的技术React + Dva + Antd + umi ,以免忘记.之前没有用过它们其中一个,也是慢慢摸索,了解数据整个流程. 先了解下概念 React 不多说,3大框架之一: ...
- rabbitmq实践笔记(一):安装、配置与使用初探
引言: 对于一个大型的软件系统来说,会有很多的组件.模块及不同的子系统一起协同工作,模块之间的通信需要一个可靠的通信管道来保证 ,通信管道需要解决解决很多问题,比如: 1)信息的发送者和接收者如何维持 ...
- react项目实践——(3)babel
1. babel Babel是一个广泛使用的转码器,可以将ES6代码转为ES5代码,从而在现有环境执行. (1)安装 npm install --save-dev babel-core babel-e ...
- react项目实践——(2)webpack-dev-serve
webpack-dev-server是一个小型的静态文件服务器,为webpack打包的资源文件提供Web服务.并且提供自动刷新和Hot Module Replacement(模块热替换:前端代码变动后 ...
- 在项目中添加ReactiveCocoa #安装与配置
这是对官方教程的补充 To add RAC to your application: Add the ReactiveCocoa repository as a submodule of your a ...
随机推荐
- Unity3d优化包的大小
http://wenku.baidu.com/link?url=MEUtNP6k1W7gXK2LcHdKXGqwoTD4HZDsBpsu9iFYjuL3WCIXgl2-rBHhBWP_zo5Xm4Yx ...
- [Angular] NgRx/effect, why to use it?
See the current implementaion of code, we have a smart component, and inside the smart component we ...
- Redis的增删改查、持久化你会了吗
原文:Redis的增删改查.持久化你会了吗 Redis是用C语言实现的,一般来说C语言实现的程序"距离"操作系统更近,执行速度相对会更快. Redis使用了单线程架构,预防了多线程 ...
- jquery pagination分页的两种实现方式
原文链接:http://blog.csdn.net/qq_37936542/article/details/79457012 此插件是jQuery的ajax分页插件.如果你用到此插件作分页的时候,涉及 ...
- 真机测试时出现 could not find developer disk image问题
解决Xcode在ipad/iphone 系统真机测试时出现could not find developer disk image问题 原因:手机系统版本比xcode版本高,sdk不支持 方法:更新Xc ...
- Android中再按一次退出实现
很多应用中都有一个在用户后退的时候显示"再按一次退出"的提醒,这个怎么实现呢?有两种方式 第一种方式(最常用) long waitTime = 2000; long touchTi ...
- Linux修改windows中文本文件出现的^M
换行符的Linux与windows文本文件是不一致的,需要通过 :%s/^M$//g 其中^M的输入使用ctrl+v+m 可以删除^M
- 将jar安装到本地mvn仓库
声明:仅限于将maven Repository下载的jar(使用maven打包的jar)安装到本地的maven仓库中,不保证全部成功,最初的时候添加依赖发现下载始终不成功,只能手动下载,但是手动下载完 ...
- 【hdu 2376】Average distance
[题目链接]:http://acm.hdu.edu.cn/showproblem.php?pid=2376 [题意] 让你计算树上任意两点之间的距离的和. [题解] 算出每条边的两端有多少个节点设为n ...
- hadoop 3.x 集群/单个节点的启动与停止
1.单个节点操作 启动|停止单个节点 hdfs --daemon start|stop datanode hdfs --daemon start|stop namenode 启动|停止单个节点的Nod ...