Home  >  Article  >  Backend Development  >  smartcomb: web module combiner implemented in PHP, smartcombweb_PHP tutorial

smartcomb: web module combiner implemented in PHP, smartcombweb_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:09:50871browse

smartcomb: A web module splicer implemented in PHP. smartcombweb

smartcomb is a web module splicer implemented in PHP. Compared with other code splicing tools, it has the following features:

  • Can combine any type of files, not limited to js files.
  • Centralize and declare dependencies, automatically analyze dependencies and combine them, and load them on demand.
  • Supports multiple configuration switching
  • Automatically modify the image path in css and less, no need to worry about the wrong css image path after combining
  • Supports php command line calls and commands to directly generate combined static files

github address: https://github.com/hafeyang/smartcomb

Module declaration configuration

smartcomb is composed of smartcomb.php and modules.js. modules.js is a json file and must be in strict json format. The key needs to be enclosed in double quotes for module declaration. The format is:

<code>{
    [profile]:{
        "basePath": "所有文件共有的基础路径",
        "modules":{
            "[modulename]":{
                [type1]:["file1","file2"],
                "dependencies":["depend module name","",""]
            }
        }
    }
 }
</code>

Here is a demo:

<code>{
    "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"]
             }
        }
    }
}
</code>

Used in web

The above demo declares the module configuration with profile as default. Declare two modules base and pageA, pageA depends on the base module. The base module includes two js files: modules/base/base.js. The path is relative to smartcomb.php. The file type can be defined arbitrarily. Just specify the type when using it.

For the above configuration file, we can quote it in the page as follows:

<code><script type="text/javascript" src="path/to/smartcomb.php?type=js&modules=pageA"></script>
<link href="path/to/smartcomb.php?type=css&modules=pageA" type="text/css" charset="utf-8"/>
</code>

pageA depends on the base module. smartcomb automatically combines dependent files.

smartcomb.phpCalling parameters:

  • profile: Configuration type, default is default. Use this parameter to switch profile
  • type: File type, the type in the module declaration, can be any customized file type, the default is js
  • modules: Modules that need to be combined, multiple modules can be used, split

Use

in the command line

You can use php commands directly, such as:

<code>php smartcomb.php -profile default -type js -modules pageA
</code>
The

command directly outputs the stitching results in the standard output, and can directly generate files.

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

The parameters are consistent with the web calling method

Thanks, any questions, please contact me:)

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/942273.htmlTechArticlesmartcomb: a web module splicer implemented in PHP, smartcombweb smartcomb is a web module splicer implemented in PHP, Compared with other code stitching tools, it has the following features: Can stitch any...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn