原文连接:https://github.com/AlloyTeam/omi/blob/master/docs/deep_in/cn_omi-cli.mdcss
一般认为,命令行界面(CLI)没有图形用户界面(GUI)那么方便用户操做。可是CLI比GUI节约资源,在熟悉命令以后,CLI会比GUI更加高效地帮你完成想要的任务。html
下面来介绍下pasturn童鞋为Omi开发的CLI的两种使用姿式:git
$ npm install omi-cli -g //安装cli $ omi init your_project_name //初始化项目 $ cd your_project_name //转到项目目录 $ npm run dev //开发 $ npm run dist //部署发布
当咱们在一个空文件夹的时候,能够执行下面的命令。github
$ npm install omi-cli -g //安装cli $ omi init //初始化项目 $ npm run dev //开发 $ npm run dist //部署发布
这里不用再去跳转目录了,当前目录就是项目的目录。web
安装omi-cli:npm
安装初始化项目omi init:编程
上面的成功的界面。注意:初始化项目会自动安装相关的npm依赖包,因此时间较长,请耐心等待。
安装完成以后,在项目目录下你能够看到下面的目录结构:浏览器
开发 npm run dev:框架
若是,你看到了上面的界面,说明一切OK了。建立出来的项目主要基于 Gulp + Webpack + Babel + BrowserSync 进行开发和部署。Gulp用来串联整个流程,Webpack + Babel让你能够写ES6和打包,BrowserSync用来帮你刷浏览器,不用F5了。ui
页面的组件都在component目录:
你能够把组件的HTML、CSS和JS分离成三个文件,而后经过require的方式使用,如:
import Omi from 'omi'; const tpl = require('./index.html'); const css = require('./index.css'); class Footer extends Omi.Component { constructor (data) { super(data); } style () { return css; } render () { return tpl; } } export default Footer;
也能够直接all in js的方式:
import Omi from 'omi'; class Header extends Omi.Component { constructor (data) { super(data); } style () { return ` <style> .menu a:hover{ color: white; } </style> `; } render () { return ` <div class="head bord-btm"> <div class="logo_box"> <a href="https://github.com/AlloyTeam/omi"></a> </div> <ul class="menu"> <li class="github_li"><a href="https://github.com/AlloyTeam/omi">Github</a> <li><a href="http://alloyteam.github.io/omi/example/playground/">Playground</a></li> <li><a href="https://github.com/AlloyTeam/omi/tree/master/docs">[Edit the Docs]</a></li> </li> </ul> </div>`; } } export default Header;
若是须要更多动态编程能力,能够all in js。若是纯静态不怎么须要改动的话,直接分离成三个文件经过require进来即可。
更多脚手架模板以及更多功能的命令正在开发中,若是有什么意见或者建议欢迎让咱们知道。