smartcomb:用php實現的web模組拼合器,smartcombweb_PHP教程

來源:互聯網
上載者:User

smartcomb:用php實現的web模組拼合器,smartcombweb


smartcomb是一個用php實現的web模組拼合器,相對於其他的代碼拼合工具,如下特性:

  • 可以拼合任意類型的檔案,不限於js檔案。
  • 集中並聲明依賴,自動分析依賴拼合,按需載入。
  • 支援多種配置切換
  • 自動修改css,less中的圖片路徑,無需擔心拼合後css圖片路徑出錯
  • 支援php命令列調用,支援命令直接產生拼合靜態檔案

github地址:https://github.com/hafeyang/smartcomb

模組聲明配置

smartcomb是由smartcomb.phpmodules.js構成,modules.js是一個json檔案,必須是嚴格的json格式,key需要加上雙引號,用於模組聲明。格式為:

{    [profile]:{        "basePath": "所有檔案共有的基礎路徑",        "modules":{            "[modulename]":{                [type1]:["file1","file2"],                "dependencies":["depend module name","",""]            }        }    } }

下面是一個demo:

{    "default":{        "basePath":"modules/",        "modules":{            "base":{                "js":["base/base.js","base/common.js"],                "css":["base/reset.css"],                "less":["base/reset.less"]             },             "pageA":{                 "js":["pageA/pageA-util.js","pageA/pageA.js"],                 "css":["pageA/pageA.css"],                 "dependencies":["base"]             }        }    }}

web中使用

上面的demo聲明了profile 為default的模組配置。聲明兩個模組base和pageA,pageA依賴於base模組。其中base模組包括兩個js檔案: modules/base/base.js,該路徑是相對於smartcomb.php的路徑,檔案類型可以任意定義,使用時指定類型即可。

如上設定檔,我們可以在頁面中如下引用:

pageA依賴於base模組。smartcomb自動拼合依賴的的檔案。

smartcomb.php調用參數:

  • profile:配置類型,預設為default。用該參數可以切換profile
  • type:檔案類型,模組聲明中的類型,可以是自訂的任何檔案類型,預設是js
  • modules:需要拼合的模組,多個模組可以用,分割

命令列中使用

可以直接使用 php命令,如:

php smartcomb.php -profile default -type js -modules pageA

命令直接在標準輸出中輸出拼合結果,可以直接組建檔案。

php smartcomb.php -profile default -type js -modules pageA > pageA-dep.js

參數與web調用方式一致

Thanks,任何問題,請與我聯絡:)

http://www.bkjia.com/PHPjc/942273.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/942273.htmlTechArticlesmartcomb:用php實現的web模組拼合器,smartcombweb smartcomb是一個用php實現的web模組拼合器,相對於其他的代碼拼合工具,如下特性: 可以拼合任...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.