-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
66 lines (57 loc) · 1.63 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
'use strict';
const gulp = require('gulp');
const concat = require('gulp-concat');
const uglify = require('gulp-uglify');
const imagemin = require('gulp-imagemin');
const sourcemaps = require('gulp-sourcemaps');
const minicss = require('gulp-mini-css');
const header = require('gulp-header');
const del = require('del');
const pkg = require('./package.json');
const banner = ['/**',
' * <%= pkg.name %> - <%= pkg.description %>',
' * @version v<%= pkg.version %>',
' * @link <%= pkg.homepage %>',
' * @license <%= pkg.license %>',
' */',
''].join('\n');
const paths = {
script: 'public/js/*.js',
css: 'public/css/*.css',
images: 'public/images/*'
}
gulp.task('clean', function() {
return del(['build']);
})
gulp.task('script', ['clean'], function() {
return gulp.src(paths.script)
.pipe(sourcemaps.init())
.pipe(header(banner, { pkg : pkg } ))
.pipe(uglify())
.pipe(concat('index.min.js'))
.pipe(sourcemaps.write())
.pipe(gulp.dest('bulid/js'))
})
gulp.task('images', ['clean'], function() {
return gulp.src(paths.images)
.pipe(imagemin({
optimizationLevel: 5,
progressive: true,
interlaced: true,
multipass: true
}))
.pipe(gulp.dest('build/img'));
})
gulp.task('css', ['clean'], function() {
return gulp.src(paths.css)
.pipe(header(banner, { pkg : pkg } ))
.pipe(minicss())
.pipe(gulp.dest('build/img'));
})
gulp.task('watch', function() {
gulp.watch(paths.script, ['script']);
gulp.watch(paths.images, ['images']);
});
gulp.task('default', ['watch', 'script,', 'css', 'images'], function() {
console.log("Gulp 领跑前端流自动化构建----Awesomes")
});