apollo-cli
apollo-cli(命令行工具),提供根據模闆新建項目,生成路由,生成頁面、生成 model 等功能。
快速開始
搭建前端開發環境
前端開發環境需安裝 NodeJS 和(hé / huò) npm。
Windows 用戶可以(yǐ)先安裝 Git 客戶端,MacOS 用戶請忽略。
- 安裝 NodeJS
請根據您的(de)操作系統,下載并安裝 NodeJS 版本:
- Windows 版本下載
- MacOS 版本下載
安裝 npm
安裝完 NodeJS 會自帶 npm,一(yī / yì /yí)般不(bù)需單獨安裝。
- 檢查是(shì)否安裝成功
在(zài) Git Bash(Windows)或終端(MacOS)中輸入以(yǐ)下命令:
$ node -v
v10.16.0 # 輸出(chū)版本号
$ npm -v
6.9.0 # 輸出(chū)版本号
輸出(chū)對應版本号,代表安裝成功。
着手開發
# 全局安裝 apollo-cli,--registry 爲(wéi / wèi) npm 私有倉庫的(de)地(dì / de)址
$ npm install apollo-cli -g --registry=http://xxx.x.x.x
# 創建應用
$ apollo new apolloApp --template blank
# 啓動應用
$ cd apolloApp
$ npm start
項目結構
├── public # 無需構建的(de)資源
├── src
│ ├── assets # 靜态資源目錄
│ ├── components # 通用組件
│ ├── models # 應用 Store 數據
│ ├── project # 業務邏輯組件
│ ├── router # 全局路由配置
│ ├── services # 接口數據請求
│ ├── utils # 其他(tā)工具方法
│ ├── index.ejs # 模闆文件
│ └── index.js # 入口文件
└── webpack.config.js # webpack 配置
支持的(de)命令
支持 3 種命令:new
,init
,g
apollo new
創建新路徑并創建應用。
使用示例
$ apollo new myapp --template mobile
$ apollo new myapp --template mobile@1.1
$ apollo new myapp --template mobile --registry=http://xxx.x.x.x
options 參數
--template
-- 從 npm 倉庫下載的(de)初始工程模闆,支持以(yǐ)下模闆參數- mobile:移動端模闆,包含組件庫和(hé / huò)示例頁面
- pure-mobile:移動端模闆,僅包含 webpack 配置等基礎支撐
- admin:桌面端,後台管理模闆,包含組件庫和(hé / huò)示例頁面
- blank:桌面端,僅包含 webpack 配置等基礎支撐。
- ie8:桌面端,自帶 IE8 支持的(de)模闆。
--no-install
-- 初始項目創建完成後,不(bù)安裝依賴包--registry
-- npm 私有倉庫地(dì / de)址
apollo init [options]
當前路徑創建應用,options 參數同 apollo new
。
使用示例
$ apollo init
$ apollo init --template mobile
apollo generate
生成路由,IE8 路由,頁面,IE8 頁面,model 和(hé / huò)組件。
使用示例
$ apollo g route user-list # 在(zài) router.js 生成根目錄 router,另外在(zài) pages 目錄下生成文件夾,文件夾裏面包含 Page,View 和(hé / huò) less 文件
$ apollo g route-ie8 user-edit
$ apollo g page user-list # 當前目錄下生成 Page, View 和(hé / huò) less 文件
$ apollo g page-ie8 user-edit
$ apollo g model user # 當前目錄下生成名爲(wéi / wèi) user 的(de) model
$ apollo g component Editor
$ apollo g component Users/UserModal
$ apollo g component Header --no-css
配置
apollo-cli 使用 apollo-build 構建和(hé / huò)運行項目,詳細的(de)文檔見這(zhè)裏
示例 Demo
完整包含 apollo 和(hé / huò) apollo-build 的(de) Demo 見這(zhè)裏