forked from dxq613/bui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
135 lines (116 loc) · 3.13 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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
'use strict';
var gulp = require('gulp');
var clean = require('gulp-clean');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var less = require('gulp-less');
var minifyCSS = require('gulp-minify-css');
var n2a = require('gulp-native2ascii');
var chug = require( 'gulp-chug' );
var through = require('through2');
var spawn = require('child_process').spawn;
//执行子任务
function subTask() {
// Creating a stream through which each file will pass
var stream = through.obj(function(file, enc, callback) {
//src 必须使用{read: false}
if (file.isNull()) {
var task = spawn('gulp', ['--gulpfile', file.path]);
task.stdout.on('data', function (data) {
console.log('stdout: ' + data);
});
task.stderr.on('data', function (data) {
console.log('stderr: ' + data);
});
task.on('close', function (code) {
console.log('child process exited with code ' + code);
});
}
return callback();
});
// returning the file stream
return stream;
};
var desDir = './build';
gulp.task('prepare', function() {
return gulp.src(desDir, {read: false})
.pipe(clean());
});
//
gulp.task('copy', function() {
return gulp.src(['src/common/adapter.js', 'src/extensions/**/*.js'])
.pipe(gulp.dest(desDir));
});
//子任务
gulp.task('chug', function () {
return gulp.src([
'./**/gulpfile.js',
//除去根目录下的gulpfile.js
'!./gulpfile.js',
//除去node_modules目录下的gulpfile.js
'!./node_modules/**/gulpfile.js'
], {read: false})
.pipe(subTask())
});
//合并js
gulp.task('seed.js', ['chug'], function(){
return gulp.src([
desDir + '/loader.js',
desDir + '/common.js',
desDir + '/cookie.js',
'./src/seed.js'
]).pipe(concat('seed.js'))
.pipe(gulp.dest(desDir));
});
gulp.task('bui.js', ['chug'], function(){
return gulp.src([
desDir + '/loader.js',
desDir + '/common.js',
desDir + '/cookie.js',
desDir + '/data.js',
desDir + '/overlay.js',
desDir + '/list.js',
desDir + '/picker.js',
desDir + '/form.js',
desDir + '/select.js',
desDir + '/mask.js',
desDir + '/menu.js',
desDir + '/tab.js',
desDir + '/toolbar.js',
desDir + '/progressbar.js',
desDir + '/calendar.js',
desDir + '/editor.js',
desDir + '/grid.js',
desDir + '/tree.js',
desDir + '/tooltip.js',
'./src/all.js'
]).pipe(concat('bui.js'))
.pipe(gulp.dest(desDir));
});
//压缩js
gulp.task('compress.js', ['seed.js', 'bui.js'], function(){
gulp.src(desDir + '/**/*.js')
.pipe(uglify({
output: {
ascii_only: true
},
mangle:{
except: ['require']
}
})
)
.pipe(rename({suffix: '-min'}))
.pipe(gulp.dest(desDir));
});
gulp.task('minify-css', function() {
gulp.src(desDir + '/**/*.css')
.pipe(minifyCSS())
.pipe(rename({suffix: '-min'}))
.pipe(gulp.dest(desDir));
});
// 默认任务
gulp.task('default', function() {
// gulp.start('copy', 'compress.js', 'minify-css');
gulp.start('chug');
});