-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
83 lines (72 loc) · 2.41 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
var autoprefixer = require('gulp-autoprefixer');
var browserSync = require('browser-sync');
var cleancss = require('gulp-clean-css');
var concat = require('gulp-concat');
var cssimport = require('gulp-cssimport');
var del = require('del');
var gulp = require('gulp');
var jade = require('gulp-jade');
var less = require('gulp-less');
var path = require('path');
var reload = browserSync.reload;
var runSequence = require('run-sequence');
var sourcemaps = require('gulp-sourcemaps');
var uglify = require('gulp-uglify');
var imagemin = require('gulp-imagemin');
var SRC_DIR = path.resolve(__dirname, 'src');
var PATHS = {
dist: path.resolve(__dirname, 'dist'),
pages: path.resolve(SRC_DIR, 'pages'),
src: SRC_DIR,
static: path.resolve(SRC_DIR, 'static'),
js: path.resolve(SRC_DIR, 'js')
};
gulp.task('clean', function(cb) {
return del([PATHS.dist]);
});
gulp.task('build:less', function() {
return gulp.src(PATHS.src + '/**/*.less')
.pipe(sourcemaps.init())
.pipe(less())
.pipe(autoprefixer())
.pipe(cssimport())
.pipe(concat('index.css'))
.pipe(cleancss())
.pipe(sourcemaps.write())
.pipe(gulp.dest(PATHS.dist))
.pipe(browserSync.stream());
});
gulp.task('build:pages', function() {
return gulp.src(PATHS.pages + '/**/*.jade')
.pipe(jade())
.pipe(gulp.dest(PATHS.dist));
});
gulp.task('build:scripts', function() {
return gulp.src(PATHS.js + '/**/*.js')
.pipe(uglify())
.pipe(gulp.dest(PATHS.dist));
});
gulp.task('build:static', function() {
return gulp.src(PATHS.static + '/**/*')
.pipe(imagemin({ optimizationLevel: 2, progressive: true, interlaced: true }))
.pipe(gulp.dest(PATHS.dist));
});
gulp.task('build:pages:watch', ['build:pages'], browserSync.reload);
gulp.task('serve', ['clean', 'default'], function() {
gulp.watch(PATHS.src + '/**/*.jade', ['build:pages:watch']);
gulp.watch(PATHS.src + '/**/*.less', ['build:less']);
gulp.watch(PATHS.src + '/**/*.jpg', ['build:static']);
gulp.watch(PATHS.src + '/**/*.png', ['build:static']);
gulp.watch(PATHS.src + '/**/*.svg', ['build:static']);
gulp.watch(PATHS.src + '/**/*.otf', ['build:static']);
gulp.watch(PATHS.src + '/**/*.ttf', ['build:static']);
gulp.watch(PATHS.src + '/**/*.js', ['build:scripts']);
browserSync.init({server: PATHS.dist});
});
gulp.task('default', function(cb) {
runSequence(
'clean',
['build:less', 'build:scripts'],
['build:pages', 'build:static'],
cb);
});