-
Notifications
You must be signed in to change notification settings - Fork 112
/
gulpfile.js
84 lines (73 loc) · 2.12 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
'use strict';
var gulp = require('gulp'),
del = require('del'),
plugins = require('gulp-load-plugins')();
var path = {
src: {
jshint: ['public/scripts/js/**/*.js','app/**/*.js','*.js','route/**','test/**'],
scripts: 'public/scripts/js/**/*.js',
sass: 'public/sass/**/*.scss',
images: 'public/images/**',
clean: 'public/libs/**'
},
dest: {
scripts: 'public/libs/scripts/js/',
sass: 'public/libs/css/',
images: 'public/libs/images',
}
};
// 将scss文件转成css文件并压缩
gulp.task('styles', function() {
return plugins.rubySass(path.src.sass)
.on('error', plugins.rubySass.logError)
.pipe(plugins.autoprefixer({ // 自动添加游览器前缀
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(plugins.rename({suffix:'.min'}))
.pipe(plugins.minifyCss())
.pipe(gulp.dest(path.dest.sass));
});
// js代码校验
gulp.task('jshint', function() {
return gulp.src(path.src.jshint)
.pipe(plugins.jshint('.jshintrc'))
.pipe(plugins.jshint.reporter('default'));
});
// js代码压缩
gulp.task('scripts', function() {
return gulp.src(path.src.scripts)
.pipe(plugins.rename({suffix: '.min'}))
.pipe(plugins.uglify())
.pipe(gulp.dest(path.dest.scripts));
});
// 图片压缩
gulp.task('images', function() {
return gulp.src(path.src.images)
.pipe(plugins.cache(plugins.imagemin({ progressive: true, interlaced: true })))
.pipe(gulp.dest(path.dest.images));
});
// watch
gulp.task('watch', function() {
gulp.watch(path.src.sass,['styles']);
gulp.watch(path.src.jshint,['jshint']);
gulp.watch(path.src.scripts,['scripts']);
gulp.watch(path.src.images,['images']);
});
// 清除文件
gulp.task('clean', function(cb) {
del(path.src.clean, cb());
});
// 测试任务
gulp.task('test', function() {
return gulp.src('test/**/*.js', {read: false})
.pipe(plugins.mocha({reporter: 'spec'}));
});
// 实时监听入口文件
gulp.task('nodemon',function() {
plugins.nodemon({ script: 'app.js',
ignore: ['README.md', 'node_modules/**', '.DS_Store']
});
});
// 默认任务
gulp.task('default',['watch','nodemon']);