詳解使用WebPack搭建React開發(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://還沒有die ]
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 基于Webpack4和React hooks搭建項(xiàng)目的方法
- 基于webpack4.X從零搭建React腳手架的方法步驟
- Webpack 4.x搭建react開發(fā)環(huán)境的方法步驟
- webpack4 + react 搭建多頁(yè)面應(yīng)用示例
- 基于webpack4搭建的react項(xiàng)目框架的方法
- 從零開始搭建webpack+react開發(fā)環(huán)境的詳細(xì)步驟
- 使用webpack搭建react開發(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)文章
React router cache route實(shí)現(xiàn)緩存頁(yè)面流程介紹
react-router自身沒有路由緩存的特性,在5.x版本之前,我們可以基于react-router-cache-route來(lái)實(shí)現(xiàn)路由緩存功能。但是react-router 6.x在實(shí)現(xiàn)上做了比較大的變化,react-router-cache-route沒有提供相應(yīng)的支持2023-01-01React實(shí)現(xiàn)一個(gè)倒計(jì)時(shí)hook組件實(shí)戰(zhàn)示例
這篇文章主要為大家介紹了React實(shí)現(xiàn)一個(gè)倒計(jì)時(shí)hook組件,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-02-02React中使用axios發(fā)送請(qǐng)求的幾種常用方法
本文主要介紹了React中使用axios發(fā)送請(qǐng)求的幾種常用方法,主要介紹了get和post請(qǐng)求,具有一定的參考價(jià)值,感興趣的可以了解一下2021-08-08React+echarts?(echarts-for-react)?實(shí)現(xiàn)中國(guó)地圖及省份切換功能
這篇文章主要介紹了React+echarts?(echarts-for-react)?畫中國(guó)地圖及省份切換,有足夠的地圖數(shù)據(jù),可以點(diǎn)擊到街道,示例我只出到市級(jí),本文結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì)需要的朋友可以參考下2022-11-11react-native 完整實(shí)現(xiàn)登錄功能的示例代碼
本篇文章主要介紹了react-native 完整實(shí)現(xiàn)登錄功能的示例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-09-09react-native使用leanclound消息推送的方法
這篇文章主要介紹了react-native使用leanclound消息推送的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2018-08-08