#### 0.react依赖
PS: yarn add react
PS: yarn add react-dom
#### 1.index.js
PS: md src
PS: New-Item index.js
打开index.js加入以下代码
```javascript
import React from 'react'
import { render } from 'react-dom'
window.React = React
render(
<div>init react</div>,
document.getElementById('react-container')
)
```
#### 2.init webpack.config
PS: New-Item webpack.config.js
打开webpack.config.js写入一下相关配置
```javascript
var webpack = require("webpack")
var path = require("path")
process.noDeprecation = true
module.exports = {
entry: "./src/index.js",
output: {
path: path.join(__dirname, 'dist', 'assets'),
filename: "bundle.js",
sourceMapFilename: 'bundle.map'
},
devtool: '#source-map',
module: {
rules: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['env','stage-0','react']
}
}
},
{
test: /\.css$/,
use: ['style-loader','css-loader', {
loader: 'postcss-loader',
options: {
plugins: () => [require('autoprefixer')]
}}]
},
{
test: /\.scss/,
use: ['style-loader','css-loader', {
loader: 'postcss-loader',
options: {
plugins: () => [require('autoprefixer')]
}}, 'sass-loader']
}
]
},
plugins: [
new webpack.DefinePlugin({
"process.env": {
NODE_ENV: JSON.stringify("production")
}
})
// 此版本webpack已经没有UglifyJsPlugin的压缩了,需要修改package下的scripts就可以了
// 下边就讲到了
/* new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
warnings: false,
mangle: false
})*/
]
}
```
### 3.完善package
```json
"scripts": {
"build": "webpack --mode production",
"prestart": "npm run build",
"start": "opener http://localhost:3001 & httpster -p 3001 -d ./dist"
}
```
#### 4.完善index.html
在body最后,加入打包文件链接
```html
<script src="assets/bundle.js"></script>
```
- React进阶
- React进阶-组件 & Props
- React进阶-组件 & Props - 代码篇
- 组件扩展-组件生命周期
- 组件扩展-组件生命周期-代码篇
- React-Redux
- Redux入门教程-基本用法
- Redux入门教程-基本用法-代码篇
- Redux入门教程-中间件和异步操作
- Redux入门教程-React-Redux 的用法
- Redux入门教程-React-Redux的用法-代码篇
- ES6-变量的解构赋值
- 数组的解构赋值
- 对象的解构赋值
- React用法
- JSX技巧
- ES6-神奇的...
- yarn+webpack+react零基础创建项目
- 0-init
- 1-webpack.config.md
- 2-react相关依赖
- 3.编写react相关代码
- pnpx-react-config
- pnpx+create-react
- pnpm+react-config
- pnpm+react-antd