forked from znjRoLS/bootstrap-imageupload
-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
112 lines (95 loc) · 3.25 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
'use strict';
// -----------------------------------------------------------------------------
// Modules
// -----------------------------------------------------------------------------
var autoprefixer = require('gulp-autoprefixer');
var browserSync = require('browser-sync').create();
var cleanCss = require('gulp-clean-css');
var del = require('del');
var gulp = require('gulp');
var header = require('gulp-header');
var jshint = require('gulp-jshint');
var less = require('gulp-less');
var pkg = require('./package.json');
var plumber = require('gulp-plumber');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
// -----------------------------------------------------------------------------
// Configuration
// -----------------------------------------------------------------------------
var headerText = [
'/**',
' * <%= pkg.name %> v<%= pkg.version %>',
' * <%= pkg.homepage %>',
' * Copyright 2016 <%= pkg.author %>',
' * Released under the <%= pkg.license %> license',
' */',
'\n'
].join('\n');
var errorHandler = function(error) {
console.log(error.message);
this.emit('end');
};
// -----------------------------------------------------------------------------
// Tasks
// -----------------------------------------------------------------------------
gulp.task('browser-sync:init', function() {
browserSync.init({
server: {
baseDir: './'
}
});
});
gulp.task('jshint', function() {
return gulp.src('src/js/**/*.js')
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(jshint.reporter('fail'));
});
gulp.task('browser-sync:reload', function() {
browserSync.reload();
});
gulp.task('build:css', function() {
return gulp.src('src/less/main.less')
.pipe(plumber({ errorHandler: errorHandler }))
.pipe(less())
.pipe(autoprefixer('last 3 versions'))
.pipe(header(headerText, { pkg: pkg }))
.pipe(rename({
basename: 'bootstrap-imageupload',
extname: '.css',
}))
.pipe(gulp.dest('dist/css'))
.pipe(cleanCss())
.pipe(header(headerText, { pkg: pkg }))
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('dist/css'));
});
gulp.task('build:js', ['jshint'], function() {
return gulp.src('src/js/main.js')
.pipe(plumber({ errorHandler: errorHandler }))
.pipe(header(headerText, { pkg: pkg }))
.pipe(rename({
basename: 'bootstrap-imageupload',
extname: '.js',
}))
.pipe(gulp.dest('dist/js'))
.pipe(uglify())
.pipe(header(headerText, { pkg: pkg }))
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('dist/js'));
});
gulp.task('build', ['build:css', 'build:js']);
gulp.task('clean:css', function() {
return del(['dist/css/**/*.css']);
});
gulp.task('clean:js', function() {
return del(['dist/js/**/*.js']);
});
gulp.task('clean', ['clean:css', 'clean:js']);
gulp.task('watch', ['browser-sync:init'], function() {
gulp.watch('index.html', ['browser-sync:reload']);
gulp.watch('src/less/**/*.less', ['build:css', 'browser-sync:reload']);
gulp.watch('src/js/**/*.js', ['build:js', 'browser-sync:reload']);
});
gulp.task('default', ['build', 'watch']);