This repository has been archived by the owner on Dec 12, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
111 lines (95 loc) · 3.06 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
const gulp = require('gulp'),
fs = require('fs'),
pkg = require('./package.json'),
path = require('path'),
less = require('gulp-less'),
watch = require('gulp-watch'),
gulpif = require('gulp-if'),
gutil = require('gulp-util'),
debug = require('gulp-debug'),
uglify = require('gulp-uglify'),
csso = require('gulp-csso'),
autoprefixer = require('gulp-autoprefixer'),
plumber = require('gulp-plumber'),
concat = require('gulp-concat'),
imagemin = require('gulp-imagemin'),
sourcemaps = require('gulp-sourcemaps'),
GulpSSH = require('gulp-ssh'),
runSequence = require('run-sequence'),
cssbeautify = require('gulp-cssbeautify'),
rename = require("gulp-rename");
var isDebug = true;
var dist = false;
gulp.task('default',['styles', 'plugins', 'scripts'], function() {
});
gulp.task('dist', function() {
dist = true;
});
gulp.task('build', function() {
runSequence('dist', ['default']);
});
gulp.task('images', () => {
return gulp.src('src/images/*.{jpg,gif,png,svg}')
.pipe(imagemin({
progressive: true,
svgoPlugins: [{removeViewBox: false}]
}))
.pipe(gulp.dest('dist/images'))
});
gulp.task('styles', function () {
return gulp.src('src/styles/main.less')
.pipe(plumber(function (error) {
plumberError(error);
this.emit('end');
}))
.pipe(gulpif(!dist, sourcemaps.init() ))
.pipe(less())
.pipe(autoprefixer({
browsers: ['last 6 versions'],
cascade: false
}))
.pipe(gulpif(!dist, sourcemaps.write({includeContent: false, sourceRoot: '/source'} )))
.pipe(gulpif(isDebug, debug({verbose: true})))
.pipe(gulpif(dist, csso()))
.pipe(cssbeautify())
.pipe(gulp.dest('./public/css'))
});
gulp.task('scripts', function () {
return gulp.src(['./src/scripts/inc/*.js','./src/scripts/components/*.js', './src/scripts/main.js' ])
.pipe(plumber(function (error) {
plumberError(error);
this.emit('end');
}))
.pipe(concat('main.js'))
.pipe(gulpif(dist, uglify() ))
.pipe(gulpif(isDebug, debug({verbose: true})))
.pipe(gulp.dest('./public/js'))
});
gulp.task('plugins', function () {
return gulp.src('./src/plugins/*.js')
.pipe(plumber(function (error) {
plumberError(error);
this.emit('end');
}))
.pipe(concat('plugins.js'))
.pipe(gulpif(isDebug, debug({verbose: true})))
.pipe(gulp.dest('./public/js'))
});
gulp.task('watch', ['default', 'images'],function() {
watch('./src/**/*.less', function() {
gulp.start('styles');
});
watch(['./src/scripts/*.js', './src/scripts/**/*.js'], function() {
gulp.start('scripts');
});
watch('./src/plugins/*.js', function() {
gulp.start('plugins');
});
watch('./src/images/*.*', function() {
gulp.start('images');
});
});
var plumberError = function (err) {
//gutil.beep();
console.log(err);
};