-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
98 lines (87 loc) · 2.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
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
var gulp = require('gulp');
var server = require('gulp-develop-server');
var bs = require('browser-sync').create();
var clean = require('gulp-clean');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var rename = require('gulp-rename');
var replace = require('gulp-replace');
var fontmin = require('gulp-fontmin');
var imagemin = require('gulp-imagemin');
var minifyCss = require('gulp-minify-css');
var usemin = require('gulp-usemin');
var csso = require('gulp-csso');
var notify = require('gulp-notify');
var options = {
server: {
path: './bin/www',
execArgv: ['--harmony']
},
bs: {
proxy: {
target: 'http://localhost:9000',
middleware: function(req, res, next) {
next();
}
},
}
};
var serverFiles = [
'./app/public/styles/*',
'./app/public/images/*',
'./app/routes/*.js',
'./app/views/**/*',
];
gulp.task('server:start', function() {
server.listen(options.server, function(error) {
if (!error)
bs.init(options.bs);
});
});
gulp.task('server:restart', function() {
server.restart(function(error) {
if (!error) bs.reload();
});
});
gulp.task('clean', function() {
return gulp.src(['dist/styles', 'dist/scripts', 'dist/images'], { read: false })
.pipe(clean());
});
gulp.task('styles', ['clean'], function() {
return gulp.src('app/public/styles/**/*.css', {
base: 'app'
}) //引入所有CSS
.pipe(concat('main.css')) //合并CSS文件
.pipe(rename({ suffix: '.min' })) //重命名
.pipe(minifyCss()) //CSS压缩
.pipe(gulp.dest('dist/styles')) //压缩版输出
.pipe(notify({ message: '样式文件处理完成' }));
});
gulp.task('scripts', ['clean'], function() {
return gulp.src('app/public/scripts/**/*.js', {
base: 'app'
}) //引入所有需处理的JS
.pipe(concat('main.js')) //合并JS文件
.pipe(rename({ suffix: '.min' })) //重命名
.pipe(uglify()) //压缩JS
.pipe(gulp.dest('dist/scripts')) //压缩版输出
.pipe(notify({ message: 'JS文件处理完成' }));
});
// 图片处理任务
gulp.task('images', ['clean'], function() {
return gulp.src('app/public/images/**/*.{svg,png,jpg,gif}', {
base: 'app/public/images'
}) //引入所有需处理的图片
.pipe(imagemin({
progressive: true,
svgoPlugins: [{
removeViewBox: false
}]
}))
.pipe(gulp.dest('dist/images'));
// .pipe(notify({ message: '图片处理完成' }));
});
gulp.task('serve', ['server:start'], function() {
gulp.watch(serverFiles, ['server:restart'])
});
gulp.task('build', ['clean', 'styles', 'scripts', 'images']);