-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
117 lines (104 loc) · 2.97 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
var gulp = require('gulp');
var kmc = require('gulp-kmc');
var less = require('gulp-less');
var css = require('gulp-mini-css');
var kclean = require('gulp-kclean');
var rename = require("gulp-rename");
var filter = require('gulp-filter');
var minify = require('gulp-minify');
var autoprefixer = require('gulp-autoprefixer');
var XTemplate = require('xtemplate');
var gulpXTemplate = require('gulp-xtemplate');
var src = ".",
dest = "./build";
var config = require('./bower.json');
//包配置
var pkg = "kg/"+config.name+"/"+config.version;
var comboSuffix = '-combo';
kmc.config({
packages:[{
name: pkg,
base: src
}]
});
kmc.server({
port:8787,
fixModule:true,
path: dest,
kissy:true
});
//使用kmc合并并编译kissy模块文件
function renderKmc(fileName){
var comboFiles = fileName.map(function(name){
return {
src: pkg+"/"+name+".js",
dest: name + comboSuffix+".js"
};
});
var cleanFiles = fileName.map(function(name){
return {
src:name+comboSuffix+'.js',
outputModule:pkg+'/'+name
};
});
return gulp.src([src+'/**/*.js','!./node_modules/**/*.js','!./test/**/*.js','!./gulpfile.js','!./build/**/*.js'])
//转换cmd模块为kissy模块
.pipe(kmc.convert({
kissy: true,
ignoreFiles: ['-min.js']
}))
//合并文件
.pipe(kmc.combo({
deps:'deps.js',
files:comboFiles
}))
//优化代码
.pipe(kclean({
files:cleanFiles
}))
.pipe(minify())
.pipe(filter(function(file){
var files = fileName.map(function(name){
return name+comboSuffix+'.js';
});
return files.indexOf(file.relative) == -1;
}))
.pipe(rename(function(file){
fileName.forEach(function(name){
file.basename = file.basename.replace(name+comboSuffix+'-min',name+'-min');
})
}))
.pipe(gulp.dest(dest));
}
gulp.task('kmc', function() {
renderKmc(['index']);
});
gulp.task('mini-css', function(){
return gulp.src([src+'/**/*.css','!./node_modules/**/*.css','!./build/**/*.css'])
.pipe(gulp.dest(dest))
.pipe(css({ext:'-min.css'}))
.pipe(gulp.dest(dest));
});
gulp.task('less', function(){
return gulp.src([src+'/**/*.less','!./node_modules/**/*.less'])
.pipe(less())
.pipe(autoprefixer())
.pipe(gulp.dest(src));
});
gulp.task('css',['less','mini-css']);
gulp.task('xtpl',function(){
return gulp.src(src+'/**/*.xtpl')
.pipe(gulpXTemplate({
wrap: 'kissy',
XTemplate: XTemplate
}))
.on('error',function(e){
console.log(e);
})
.pipe(gulp.dest(src));
});
gulp.task('watch', function() {
gulp.watch(src+'/**/*.xtpl', ['xtpl']);
gulp.watch(src+'/**/*.less', ['css']);
});
gulp.task('default', ['kmc','css','watch']);