安裝 React 的學習環境
// 安裝創建 react 項目的工具
npm install -g create-react-app
// 創建一個項目
create-react-app jiajia-react
// 啓動項目
cd jiajia-react
npm start
目錄結構介紹
- node_modules 存放 npm 包的目錄。
- public 存放靜態資源,提供外部訪問。
- src 存放源代碼。
編譯生產環境的項目
// 編譯項目,會在項目目錄下生成一個 build 的文件夾。
npm run build
// 安裝 pushstate-server 用於將已經編譯好的項目部署
npm install -g pushstate-server
// 將編譯項目運行在本地查看效果
pushstate-server build
// Listening on port 9000 (http://0.0.0.0:9000)