Home > Article > Backend Development > smartcomb: web module combiner implemented in PHP, smartcombweb_PHP tutorial
smartcomb is a web module splicer implemented in PHP. Compared with other code splicing tools, it has the following features:
github address: https://github.com/hafeyang/smartcomb
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>
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.php
Calling 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 jsmodules
: Modules that need to be combined, multiple modules can be used, split 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:)