1.從零開始搭建webpack+react開發環境
2.引入typescript
* 安裝依賴
npm i -s @types/react @types/react-domnpm i -d typescript awesome-typescript-loader source-map-loader
* 新建tsconfig.json
,
"include": [
"./src/**/*"
]}
// webpack.config.js
const path = require('path');
const htmlwebpackplugin = require('html-webpack-plugin');
const webpack = require('webpack');
module.exports = ,
output: ,
devtool: "source-map",
// add '.ts'
and'.tsx' as resolvable extensions.
resolve: ,
module: ,,,
},// all files with a '.ts'
or'.tsx' extension will be handled by
'awesome-typescript-loader'.,]
},plugins: [
new htmlwebpackplugin(),
new webpack.namedmodulesplugin(),
new webpack.hotmodulereplacementplugin()
],devserver: ,
};
3.引入less並支援import less modules
* 安裝依賴
npm i -d less less-loadertips: typings-for-css-modules-loadernpm i -d typings-for-css-modules-loader
打包時將樣式模組化,我們可以通過import或require引入樣式,並且相互不衝突。
> demo.less.d.ts
//.demo->
export
const
demo: string;
import * as styles from 'demo.less'
// webpack.config.js
const path = require('path');
const htmlwebpackplugin = require('html-webpack-plugin');
const webpack = require('webpack');
module.exports = ,
output: ,
devtool: "source-map",
//add .less
resolve: ,
module: ,
//import less modules,name:demo__demo___hash,,
,},,]
},plugins: [
new htmlwebpackplugin(),
new webpack.namedmodulesplugin(),
new webpack.hotmodulereplacementplugin()
],devserver: ,
};
4.引入react-routerv4
npm i -s react-router-dom
import from 'history';
export
default createhashhistory();
import react from 'react';
import reactdom from 'react-dom';
import * as styles from "./index.less";
import history from './helpers/history';
import from 'react-router-dom';
import hello from "./router/hello";
import todolist from "./router/todolist";
const privateroute = () => render=/>
)}/>
);}reactdom.render(
history= >
classname=>
to="/">homeslink>
li>
to="/todo">todolistlink>
li>
ul>
exact
path="/"
component=/>
/>*/}
path="/todo"
component= />
switch>
div>
router>,
document.getelementbyid('root')
);
npm i -s babel-preset-stage-2修改.babelrc
5.引入mobx狀態管理
npm i -s mobx mobx-react
> npm i -d babel-plugin
-transform
-decorators
-legacy
修改.babelrc
「`github
React全家桶專案
利用業餘時間,做了個react專案,算是成品吧,比較簡單,還有很多瑕疵。目錄結構相當簡單。沒有資料庫,你們執行不起來。想執行起來的話,把express呼叫資料庫的部分全刪掉,寫死資料。這個整合了react全家桶,可以直接執行,也可以直接在生產環境使用。最好用谷歌遊覽器進行體驗,其他遊覽器沒測。封裝了...
React學習筆記 二 react全家桶專案實戰
技術棧 react redux react redux react router dom redux thunk axios ui框架是採用螞蟻金服的 antd design 因為只實現了幾個功能,頁面較少,所以採用的架構是按照型別劃分頁面結構,並且採用容器元件與ui元件分離的方式,這樣的話ui元件...
react環境搭建
react webpack資料夾是開發目錄,在此目錄下執行命令,假設你已經正確安裝了 nodejs 一 參照教程搭建環境 以下模式請用 超級管理員來執行 npm install g yo 安裝 yeoman 可選 npm install g generator react webpack 安裝生成器...