Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
82 lines (74 sloc) 1.77 KB
layout title description tags category keywords date
post
kclean kmc 文件配置
快速gulp-kclean任务
gulp
js
kclean
2015-04-20 04:03:31 -0700

kmc task

var abc = require('./abc.json');
var pkg = abc.group + '/' + abc.name + '/' + abc.version;
var comboSuffix = '-min';
kmc.config({
    packages: [{
        name: pkg,
        base: './src'
    }]
});


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'])
        //转换cmd模块为kissy模块
        .pipe(kmd())
        .pipe(kmc.convert({
            kissy: true
        }))
        //合并文件
        .pipe(kmc.combo({
            deps: 'mods.js',
            files: comboFiles
        }))
        //优化代码
        .pipe(kclean({
            files: cleanFiles
        }))
        .pipe(gulp.dest(dest))
        .pipe(filter(function (file) {
            var files = fileName.map(function (name) {
                return name + comboSuffix + '.js';
            });
            return files.indexOf(file.relative) == -1;
        }))
        .pipe(rename({
            suffix: '-min'
        }))
        .pipe(uglify())
        .pipe(gulp.dest(dest))
        .on('end', function () {
            gulp.start(['uglifyIndex'])
        })
}

gulp.task('uglifyIndex', function () {
    return gulp
        .src(dest + '/index-min.js')
        .pipe(uglify())
        .pipe(gulp.dest(dest))
})


gulp.task('kmc', function () {
    renderKmc(['index']);
});