-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
68 lines (60 loc) · 1.77 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
// 引入 gulp
var gulp = require('gulp');
// 引入组件
var jshint = require('gulp-jshint');
var sass = require('gulp-sass');
var cssmin=require('gulp-minify-css');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var jade = require('gulp-jade');
var imagemin = require('gulp-imagemin');
/*js检查任务*/
gulp.task('jshints', function() {
gulp.src('./src/js/*.js')
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
/*jade转换任务*/
gulp.task('templates',function(){
gulp.src('./src/view/*.jade')
.pipe(jade())
.pipe(gulp.dest('./dist/view'));
})
/*Sass转换任务*/
gulp.task('sass', function() {
gulp.src('./src/sass/*.scss')
.pipe(concat('jiui.scss'))
.pipe(sass())
.pipe(gulp.dest('./dist/css'))
.pipe(rename('jiui.min.css'))
.pipe(cssmin())
.pipe(gulp.dest('./dist/css'));
});
// 合并,压缩文件
gulp.task('scripts',['jshints'], function() {
gulp.src('./src/js/*.js')
.pipe(concat('jiui.js')) //合并所有文件为all.js
.pipe(gulp.dest('./dist/js')) //输出到指定文件夹
.pipe(rename('jiui.min.js')) //重命名为all.min.js
.pipe(uglify()) //压缩混淆js文件
.pipe(gulp.dest('./dist/js')); //输出到指定文件夹
});
/*image照片压缩*/
gulp.task('imgmin',function(){
gulp.src('./src/images/*')
.pipe(imagemin())
.pipe(gulp.dest('./dist/images'));
})
// 默认任务
gulp.task('default', function(){
gulp.run( 'sass', 'scripts','templates','imgmin');
});
// 监听文件变化
gulp.watch([
'./src/js/*.js',
'./src/sass/*.scss',
'./src/view/**/*.jade'
], function(){
gulp.run( 'default');
});