-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
83 lines (71 loc) · 2.78 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
// gulpfile.js
var gulp = require('gulp');
var server = require('gulp-express');
var sass = require('gulp-sass');
var autoprefixer = require('gulp-autoprefixer');
var notify = require('gulp-notify');
var sourcemaps = require('gulp-sourcemaps');
var gulpif = require('gulp-if');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var clean = require('gulp-clean');
var argv = require('minimist')(process.argv.slice(2));
var env = argv.e; //gulp server -e build -e后面的值
// 将.scss/.sass文件实时转变为.css文件
gulp.task('styles', function() {
return gulp.src('static/scss/**/*.scss')
.pipe(gulpif(env!='build', sourcemaps.init()))
.pipe(sass({outputStyle: 'compressed'}))
.pipe(gulpif(env!='build', sourcemaps.write()))
// auto prefix
.pipe(autoprefixer('last 2 version', 'safari 5', 'ie 9', 'opera 12.1', 'ios 6', 'android 4'))
// css格式化、美化(因为有f2ehint,故在此不再做语法等的检查与修复)
// 将编译后的.css文件存放在.scss文件所在目录下
.pipe(gulp.dest(function(file) {
return './public/css/';
}))
// 编译成功后的提示(频繁提示会有点烦人,可将successNotify设置为:false关闭掉)
.pipe(notify(function(file) {
return 'scss/sass编译成功!';
}));
});
gulp.task('jshint',function(){
return gulp.src('static/js/**/*.js')
.pipe(gulpif(env!='build', sourcemaps.init()))
.pipe(uglify())
.pipe(gulpif(env!='build', sourcemaps.write()))
.pipe(rename({suffix:'.min'}))
.pipe(gulp.dest('./public/js/'))
.pipe(notify(function(file) {
return 'js编译成功!';
}));
});
gulp.task('img',function(){
return gulp.src('static/images/**/*')
.pipe(gulp.dest('./public/images/'))
.pipe(notify(function(file) {
return 'img copy done!';
}));
});
gulp.task("clean", function(){
return gulp.src('./public**')
.pipe(clean());
})
gulp.task('server', function () {
//启动node服务
server.run(['./bin/www']);
//监听文件修改
gulp.watch(['static/scss/**/*.scss'], ['styles']);
gulp.watch(['static/js/**/*.js'], ['jshint']);
gulp.watch(['static/images/**/*'], ['img']);
// 监听文件修改并刷新浏览器
gulp.watch(['app.js', 'routes/**/*.js'], [server.run]);
gulp.watch(['views/**/*.html'], server.notify);
gulp.watch(['public/images/**/*'], server.notify);
gulp.watch(['public/css/**/*.css'], server.notify);
gulp.watch(['public/js/**/*.js'], server.notify);
});
// 发布线上 gulp build -e build 【发布时请关闭编辑器】
// gulp.task('build',['clean'],function(){
// gulp.start('styles', 'jshint', 'img');
// });