詳解使用WebPack搭建React開(kāi)發(fā)環(huán)境
第一步、基礎(chǔ)環(huán)境
初始化
項(xiàng)目初始化
npm init -y
安裝webpack
npm i webpack
安裝react
npm i react react-dom -s
項(xiàng)目基礎(chǔ)框架
入口文件(src/index.js)
import React from 'react'
import {render} from 'react-dom'
import App from './App'
render(<App/>,document.getElementById('root'))
主組件(src/App.js)
import React,{Component} from 'react'
class App extends Component{
constructor(){
super()
}
redner(){
return(
<div>
App Module
</div>
)
}
}
webpack.config.js
const path = require('path')
const StyleLintPlugin = require('stylelint-webpack-plugin')
const STYLELINTENABLE = true
module.exports = {
mode:'development',
entry:'./src/index.js',
output:{
path:path.resolve(__dirname,'build'),
filename:'bundle.js'
},
module:{
rules:[
//處理js/jsx
{
test:/\.jsx?/i,
use:{
loader:'bebel-loader',
options:{
presets:['@babel/preset-react']
}
}
},
//處理css
{
test:/\.css$/i,
use:['style-loader','css-loader',{
loader:'postcss-loader',
options:{
plugins:require('autoprefixer')
}
}]
},
//處理圖片資源
{
test:/\.(png|jpg|gif)$/i,
use:{
loader:'url-loader',
options:{
outputPath:'imgs/',
limit:10*1024
}
}
},
//處理字體文件
{
test:/\.(eot|svg|ttf|woof|woof2)$/i,
use:{
loader:'url-loader',
options:{
outputPath:'fonts/',
limit:10*1024
}
}
},
//less
{
test:/\.less$/i,
use:['style-loader','css-loader','less-loader']
},
]
},
devtool:'source-map',
plugins:[
...STYLELINTENABLE ?[
new StyleLintPlugin({
files:['**/*.css','**/*.less','**/*.js','**/*.html','**/*.vue','**/*.scss']
})
]:[]
]
}
webpack.config.js
"stylelint": {
"extends": "stylelint-config-standard"
},
"browserslist":[
"> 0.5%",//市場(chǎng)占有率大于百分之零點(diǎn)5
"last 2 version",//最后兩個(gè)版本
"not dead"http://還沒(méi)有die
]
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 基于Webpack4和React hooks搭建項(xiàng)目的方法
- 基于webpack4.X從零搭建React腳手架的方法步驟
- Webpack 4.x搭建react開(kāi)發(fā)環(huán)境的方法步驟
- webpack4 + react 搭建多頁(yè)面應(yīng)用示例
- 基于webpack4搭建的react項(xiàng)目框架的方法
- 從零開(kāi)始搭建webpack+react開(kāi)發(fā)環(huán)境的詳細(xì)步驟
- 使用webpack搭建react開(kāi)發(fā)環(huán)境的方法
- 手動(dòng)用webpack搭建第一個(gè)ReactApp的示例
- 詳解基于webpack搭建react運(yùn)行環(huán)境
- 使用webpack5從0到1搭建一個(gè)react項(xiàng)目的實(shí)現(xiàn)步驟
相關(guān)文章
詳解在create-react-app使用less與antd按需加載
這篇文章主要介紹了詳解在create-react-app使用less與antd按需加載,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-12-12
react antd如何防止一份數(shù)據(jù)多次提交
這篇文章主要介紹了react antd如何防止一份數(shù)據(jù)多次提交問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-10-10
React 模塊聯(lián)邦多模塊項(xiàng)目實(shí)戰(zhàn)詳解
這篇文章主要介紹了React 模塊聯(lián)邦多模塊項(xiàng)目實(shí)戰(zhàn)詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-10-10
React函數(shù)組件傳參的實(shí)現(xiàn)
React函數(shù)組件通過(guò)接受props實(shí)現(xiàn)組件間的數(shù)據(jù)傳遞,通過(guò)組件標(biāo)簽的屬性向子組件傳遞數(shù)據(jù),并在子組件中通過(guò)參數(shù)接收,還可以使用ES6的解構(gòu)賦值,函數(shù)也能作為props傳遞,以實(shí)現(xiàn)父子組件間的交互和通信,下面就來(lái)具體了解一下2024-09-09
基于React的狀態(tài)管理實(shí)現(xiàn)一個(gè)簡(jiǎn)單的顏色轉(zhuǎn)換器
這篇文章主要介紹了用React的狀態(tài)管理,簡(jiǎn)簡(jiǎn)單單實(shí)現(xiàn)一個(gè)顏色轉(zhuǎn)換器,文中有詳細(xì)的代碼示例供大家參考,具有一定的參考價(jià)值,需要的朋友可以參考下2023-08-08
簡(jiǎn)談創(chuàng)建React Component的幾種方式
這篇文章主要介紹了創(chuàng)建React Component的幾種方式,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,,需要的朋友可以參考下2019-06-06

