Home  >  Article  >  Backend Development  >  smartcomb: web module combiner implemented in PHP_PHP tutorial

smartcomb: web module combiner implemented in PHP_PHP tutorial

WBOY
WBOYOriginal
2016-07-14 10:08:06673browse

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, which must be in strict json format. The key needs to be enclosed in double quotes for module declaration. The format is:
{
[profile]:{
"basePath": "The base path common to all files",
"modules":{
"[modulename]":{
              [type1]:["file1","file2"],
"dependencies":["depend module name","",""]
      }
}
}
}
Here is a 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"]
      }
}
}
}
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. This 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:
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 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:
php smartcomb.php -profile default -type js -modules pageA
The
command directly outputs the stitching results in the standard output, and can directly generate files.
php smartcomb.php -profile default -type js -modules pageA > pageA-dep.js
The parameters are consistent with the web calling method
Thanks, any questions, please contact me:)

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/477823.htmlTechArticlesmartcomb is a web module splicer implemented in PHP. Compared with other code splicing tools, it has the following features: Yes Splice any type of files, not limited to js files. Focus and declare...
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