-
Notifications
You must be signed in to change notification settings - Fork 60
/
gulpfile.js
82 lines (73 loc) · 2.18 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
/**
* Created by jfengjiang on 2015/1/14.
*/
var gulp = require('gulp');
var gutil = require('gulp-util');
var header = require('gulp-header');
var uglify = require('gulp-uglify');
var jshint = require('gulp-jshint');
var rename = require('gulp-rename');
var less = require('gulp-less');
var autoprefixer = require('gulp-autoprefixer');
var minify = require('gulp-minify-css');
var tap = require('gulp-tap');
var browserSync = require('browser-sync');
var pkg = require('./package.json');
gulp.task('build', function () {
gulp.src('src/example/**/*')
.pipe(gulp.dest('dist/example'));
var banner = ['/*!',
' * <%= pkg.name %> - <%= pkg.description %>',
' * @version v<%= pkg.version %>',
' * @link <%= pkg.repository.url %>',
' * @license <%= pkg.license %>',
' */',
''].join('\n');
gulp.src('src/swiper.less')
.pipe(less().on('error', function (e){
console.error(e.message);
this.emit('end');
}))
.pipe(autoprefixer())
.pipe(header(banner, { pkg : pkg } ))
.pipe(gulp.dest('dist'))
.pipe(minify())
.pipe(rename(function (file){
file.basename += '.min';
}))
.pipe(gulp.dest('dist'));
gulp.src('src/swiper.js')
.pipe(tap(function(file, t){
var contents = file.contents.toString();
contents = contents.replace('${version}', pkg.version);
file.contents = new Buffer(contents);
}))
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(header(banner, { pkg : pkg } ))
.pipe(gulp.dest('dist'))
.pipe(uglify())
.pipe(rename(function (file){
file.basename += '.min';
}))
.pipe(gulp.dest('dist'));
});
gulp.task('server', function () {
browserSync.init({
server: {
baseDir: "./dist"
},
ui: {
port: 8081,
weinre: {
port: 9090
}
},
port: 8080,
startPath: '/example'
});
});
gulp.task('watch', ['build', 'server'], function (){
gulp.watch('src/**/*', ['build']);
});
gulp.task('default', ['watch']);