-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
87 lines (74 loc) · 2.5 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
var gulp = require('gulp');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var cleanCSS = require('gulp-clean-css');
// 串行执行任务
var gulpSequence = require('gulp-sequence');
var eslint = require('gulp-eslint');
// 头部注释
var header = require('gulp-header');
var pkg = require('./package.json');
var banner = ['/**',
' * <%= pkg.name %> - <%= pkg.description %>',
' * @version v<%= pkg.version %>',
' * @author <%= pkg.author %>',
' * <%= pkg.homepage %>',
' */',
''
].join('\n');
// 暂且将debug和release放在一起
var debugPath = './dist/debug/';
var releasePath = './dist/';
// eslint代码检查,方便调试
gulp.task('eslint_js', function() {
return gulp.src(['./src/**/*.js'])
.pipe(eslint())
.pipe(eslint.format());
// 开启后如果报错会退出
//.pipe(eslint.failAfterError());
});
// 核心文件的打包
gulp.task('pack_bizlogic_js', function() {
return gulp.src(['./src/minirefresh.dataprocess.js',
'./src/minirefresh.dataprocess.v6path.js', './src/minirefresh.dataprocess.v7path.js',
'./src/minirefresh.bizlogic.js'])
.pipe(concat('minirefresh.bizlogic.js'))
.pipe(gulp.dest(debugPath));
});
// 原生主题文件
gulp.task('pack_native_theme', function() {
return gulp.src(['./src/minirefresh.theme.native.js'])
.pipe(gulp.dest(debugPath));
});
// 压缩发布的源文件
gulp.task('js_uglify', function() {
return gulp.src([debugPath + '**/*.js', '!' + debugPath + '**/*.min.js'])
.pipe(uglify())
// 压缩时进行异常捕获
.on('error', function(err) {
console.log('line number: %d, message: %s', err.lineNumber, err.message);
this.end();
})
.pipe(rename({
suffix: '.min'
}))
.pipe(header(banner, {
pkg: pkg
}))
.pipe(gulp.dest(releasePath));
});
gulp.task('lint', ['eslint_js']);
gulp.task('pack_debug', ['pack_bizlogic_js', 'pack_native_theme']);
gulp.task('pack_release', ['js_uglify']);
gulp.task('default', function(callback) {
gulpSequence('lint', 'pack_debug', 'pack_release')(callback);
});
// 看守
gulp.task('watch', function() {
// 看守所有位在 dist/ 目录下的档案,一旦有更动,便进行重整
// gulp.watch([config.src+'/gulpWatch.json']).on('change', function(file) {
// console.log("改动");
// });
gulp.watch('./src/**/*', ['default']);
});