-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
113 lines (99 loc) · 3.14 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
const path = require('path');
const gulp = require('gulp');
const uglify = require('gulp-uglify');
const less = require('gulp-less');
const uglifycss = require('gulp-uglifycss');
const plumber = require('gulp-plumber');
const sourcemaps = require('gulp-sourcemaps');
const rename = require('gulp-rename');
const concat = require('gulp-concat');
const htmlmin = require('gulp-htmlmin');
const browserSync = require('browser-sync').create();
const publicDir = path.join(__dirname, 'public');
const del = require('del');
const fs = require('fs');
gulp.task('scripts', function () {
gulp.src([
publicDir + '/**/*.js',
'!' + publicDir + '/libs/**/*',
'!' + publicDir + '/**/*.min.js'
], {dot: true})
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(rename({suffix: '.min'}))
.pipe(uglify())
.pipe(sourcemaps.write())
.pipe(gulp.dest(publicDir));
});
gulp.task('less', function () {
gulp.src(publicDir + '/styles/**/*.less')
.pipe(plumber())
.pipe(less({
paths: [publicDir + '/styles/includes']
}))
.pipe(gulp.dest(publicDir + '/styles'));
});
gulp.task('css', function () {
gulp.src([
publicDir + '/styles/**/*.css',
'!' + publicDir + '/styles/**/*.min.css'
], {dot: true})
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(uglifycss())
.pipe(concat('styles.min.css'))
.pipe(gulp.dest(publicDir + '/styles'))
.pipe(browserSync.stream());
});
/*gulp.task('html', function () {
gulp.src(baseDir + '/!**!/!*.min.html')
.pipe(htmlmin())
.pipe(gulp.dest(baseDir))
});*/
var bs;
gulp.task('browser-sync', function () {
bs = browserSync.init({
proxy: 'localhost:3000'
});
});
gulp.task('restart-bs', function () {
if (bs) {
bs.server.close();
bs.server.listen(bs.options.get("port"));
}
});
gulp.task('watch', function () {
gulp.watch(publicDir + '/**/*.html', browserSync.reload);
gulp.watch(publicDir + '/styles/**/*.less', ['less']);
gulp.watch(publicDir + '/styles/**/*.css', ['css'], browserSync.reload);
gulp.watch([
publicDir + '/**/*.js',
'!' + publicDir + '/libs/**/*',
'!' + publicDir + '/**/*.min.js'
], ['scripts'], browserSync.reload);
gulp.watch('./bin/**/*.js', ['restart-bs'], browserSync.reload);
});
gulp.task('clean', function () {
del([
publicDir + '/**/*.min.*',
publicDir + '/libs/**',
publicDir + '/styles/styles.css'
]).then(function (paths) {
console.log('Build files cleaned');
});
});
gulp.task('gitignore-dev', function () {
fs.appendFile('.gitignore', 'public/libs/**/*' +
'!public/libs/**/' +
'!public/libs/**/*.js' +
'!public/libs/**/*.css', console.error);
});
gulp.task('gitignore-build', function () {
fs.appendFile('.gitignore', 'public/libs/**/*' +
'!public/libs/**/' +
'!public/libs/**/*.js' +
'!public/libs/**/*.css', console.error);
});
gulp.task('build', ['scripts', 'less', 'css'/*, 'gitignore-build'*/]);
gulp.task('serve', ['watch', 'browser-sync']);
gulp.task('default', ['watch']);