-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathGulpfile.js
97 lines (87 loc) · 2.11 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
/* jshint -W015 */
const gulp = require('gulp');
const clean = require('gulp-clean');
const watch = require('gulp-watch');
const jshint = require('gulp-jshint');
const uglify = require('gulp-uglify');
const less = require('gulp-less');
const fs = require('fs');
const paths = {
dev: {
js: './static/js/**/*.js',
css: './static/css/**/*.less',
copy: [
'./static/images/**/*',
'./static/css/lib/**/*',
'./libs/**/*',
'./views/**/*',
'./icons/**/*',
'./_locales/**/*',
'./manifest.json'
]
},
dist: {
default: './dist/',
js: './dist/static/js/',
css: './dist/static/css/'
}
};
/** __________________________________________
* clean
*/
gulp.task('clean', function() {
return gulp.src(paths.dist.default)
.pipe(clean());
});
/** __________________________________________
* JSHint
*/
gulp.task('jshint', function() {
return gulp.src(paths.dev.js)
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(jshint.reporter('fail'));
});
/** __________________________________________
* uglify
*/
gulp.task('copy-js', function() {
return gulp.src(paths.dev.js)
.pipe(gulp.dest(paths.dist.js))
});
gulp.task('uglify', function() {
return gulp.src(paths.dev.js)
.pipe(uglify({
output: {
beautify: false,
indent_level: 0,
ascii_only: true
}
}))
.pipe(gulp.dest(paths.dist.js))
});
/** __________________________________________
* less
*/
gulp.task('less', function() {
return gulp.src(paths.dev.css)
.pipe(less({
compress: true
}))
.pipe(gulp.dest(paths.dist.css));
});
/** __________________________________________
* copy
*/
gulp.task('copy', function() {
return gulp.src(paths.dev.copy, { base: './' })
.pipe(gulp.dest(paths.dist.default));
});
gulp.task('default', gulp.series('clean', 'uglify', 'less', 'copy', function(cb) {
return Promise.resolve('编译完成');
}));
gulp.task('watch', gulp.series('default', function() {
gulp.watch(paths.dev.js, [ /*'jshint',*/ 'copy-js']);
gulp.watch(paths.dev.css, ['less']);
gulp.watch(paths.dev.copy, ['copy']);
}));