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 ...
随机推荐
- [Angular] How to styling ng-content
Let's say you are builing a reuseable component. The style structure like this: div > input If yo ...
- [HTML] Creating visual skip links in HTML and CSS
Skip links are an extremely helpful navigation pattern for keyboard and screen reader users, since t ...
- Android 获取签名证书的具体信息(Eclipse和Android studio通用)
今天要用到签名证书的MD5,可是这个仅仅有在第一次生成的时候我看到了,这可怎么办呢,幸亏我们有google,我们执行以下的命令就OK了. keytool -list -v -keystore 签名证书 ...
- php面试题7(1、unset变量是删除栈变量,并不删除堆变量)(2、php爬虫特别简单: 可以file_get_contents和直接fopen)
php面试题7(1.unset变量是删除栈变量,并不删除堆变量)(2.php爬虫特别简单: 可以file_get_contents和直接fopen) 一.总结 1.unset变量是删除栈变量,并不删除 ...
- springMVC注解@initbinder
在实际操作中经常会碰到表单中的日期 字符串和Javabean中的日期类型的属性自动转换, 而springMVC默认不支持这个格式的转换,所以必须要手动配置, 自定义数据类型的绑定才能实现这个功能. 比 ...
- 【35.20%】【CF 706D】Vasiliy's Multiset
time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standa ...
- [TypeScript] Simplify asynchronous callback functions using async/await
Learn how to write a promise based delay function and then use it in async await to see how much it ...
- jquery pagination分页的两种实现方式
原文链接:http://blog.csdn.net/qq_37936542/article/details/79457012 此插件是jQuery的ajax分页插件.如果你用到此插件作分页的时候,涉及 ...
- ARM汇编初探---汇编代码中都有哪几类指令---ARM伪指令介绍
要学习一个东西首先要把概念搞清楚,以下仅仅是自己的一些关于汇编的理解. 可运行文件里的01码是机器码,机器码不等于汇编码,尽管机器码能够非常easy翻译成汇编码. 汇编码中包括非常多汇编指令.伪指令和 ...
- Android学习Scroller(三)——控件平移划过屏幕 (Scroller简单使用)
MainActivity例如以下: package cc.cn; import android.os.Bundle; import android.view.View; import android. ...