Omi命令行界面omi-cli發佈

原文連接: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進來即可。

後續

更多腳手架模板以及更多功能的命令正在開發中,若是有什麼意見或者建議歡迎讓咱們知道。

相關

  • Omi的Github地址https://github.com/AlloyTeam/omi
  • 若是想體驗一下Omi框架,能夠訪問 Omi Playground
  • 若是想使用Omi框架或者開發完善Omi框架,能夠訪問 Omi使用文檔
  • 若是你想得到更佳的閱讀體驗,能夠訪問 Docs Website
  • 若是你懶得搭建項目腳手架,能夠試試 omi-cli
  • 若是你有Omi相關的問題能夠 New issue
  • 若是想更加方便的交流關於Omi的一切能夠加入QQ的Omi交流羣(256426170)

相關文章
相關標籤/搜索