@@ -16,6 +16,12 @@ module.exports = function(gulp, common) {
1616 }
1717 }
1818
19+ var _replaceProjectParentDirectory = function ( _source ) {
20+ // 转换为以项目根目录为开头的路径形式
21+ var _projectParentDirectory = path . resolve ( '../../..' ) ;
22+ return _source . replace ( _projectParentDirectory , '' ) . replace ( / ^ [ \\ \/ ] / , '' ) ;
23+ }
24+
1925 // 合并文件
2026 for ( var _key in _mergeRule ) {
2127 // 后面变更文件时,需要的是每个文件在 HTML 中书写的路径,即相对模板文件的路径
@@ -25,12 +31,20 @@ module.exports = function(gulp, common) {
2531 _resultFileName = path . basename ( _resultFile ) ,
2632 _resultFilePath = path . dirname ( _resultFile ) ,
2733 _value = _mergeRule [ _key ] , // 来源文件原始路径获取
28- _childFiles = [ ] ;
34+ _childFiles = [ ] ,
35+ _childFilesString ; // 用于在 Log 中显示
2936
3037 // 遍历来源文件并给每个文件加上 '../'
3138 for ( var _i = 0 ; _i < _value . length ; _i ++ ) {
3239 var _childFilesRelative = '../' + _value [ _i ] ;
3340 _childFiles . push ( _childFilesRelative ) ;
41+
42+ // 拼接源文件名用于 Log 中显示
43+ if ( _i === 0 ) {
44+ _childFilesString = _replaceProjectParentDirectory ( path . resolve ( _childFilesRelative ) ) ;
45+ } else {
46+ _childFilesString = _childFilesString + ', ' + _replaceProjectParentDirectory ( path . resolve ( _childFilesRelative ) ) ;
47+ }
3448 }
3549
3650 var _condition = function ( _file ) {
@@ -49,10 +63,13 @@ module.exports = function(gulp, common) {
4963 . pipe ( common . plugins . concat ( _resultFileName ) )
5064 . pipe ( common . plugins . if ( _condition , common . plugins . uglify ( ) , common . plugins . cleanCss ( { compatibility : 'ie8' } ) ) )
5165 . pipe ( gulp . dest ( _resultFilePath ) ) ;
66+
67+ common . plugins . util . log ( common . plugins . util . colors . green ( 'QMUI Merge: ' ) + '文件 ' + _childFilesString + ' 合并压缩为 ' + _replaceProjectParentDirectory ( path . resolve ( path . join ( _resultFilePath , _resultFileName ) ) ) ) ;
5268 }
5369 // 变更文件引用路径
5470 gulp . src ( common . config . htmlResultPath + '/**/*.html' )
5571 . pipe ( common . plugins . merge ( _mergeRule ) )
5672 . pipe ( gulp . dest ( common . config . htmlResultPath ) ) ;
73+ common . plugins . util . log ( common . plugins . util . colors . green ( 'QMUI Merge: ' ) + '文件合并变更已完成' ) ;
5774 } ) ;
5875} ;
0 commit comments