-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
85 lines (71 loc) · 2.1 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
'use strict';
var gulp = require('gulp');
var plumber = require('gulp-plumber');
var sass = require('gulp-sass');
var webserver = require('gulp-webserver');
var opn = require('opn');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var imagemin = require('gulp-imagemin');
var fileinclude = require('gulp-file-include');
var sourcePaths = {
styles: ['src/sass/**/*.scss'],
javascripts: ['src/js/**/*.js'],
images: ['src/images/**/*.{jpg,png,gif,svg}']
};
var distPaths = {
styles: 'assets/css',
javascripts: 'assets/js/',
images: 'assets/images/'
};
var server = {
host: 'localhost',
port: '8001'
}
gulp.task('sass', function () {
gulp.src( sourcePaths.styles )
.pipe(plumber())
.pipe(sass({outputStyle: 'expanded'})) //compressed
.pipe(gulp.dest( distPaths.styles ));
});
gulp.task('js', function(){
return gulp.src( sourcePaths.javascripts )
.pipe(plumber())
.pipe(concat('main.js'))
.pipe(uglify())
.pipe(gulp.dest( distPaths.javascripts ))
});
gulp.task('imagemin', function() {
return gulp.src( sourcePaths.images )
.pipe(plumber())
.pipe(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true }))
.pipe(gulp.dest( distPaths.images ));
});
gulp.task('html', function() {
return gulp.src('./src/html/pages/*.html')
.pipe(fileinclude({
prefix: '@@',
basepath: './src/html/includes/'
}))
.pipe(gulp.dest('./'))
});
gulp.task('webserver', function() {
gulp.src( '.' )
.pipe(webserver({
host: server.host,
port: server.port,
livereload: true,
directoryListing: false
}));
});
gulp.task('openbrowser', function() {
opn( 'http://' + server.host + ':' + server.port );
});
gulp.task('watch', function(){
gulp.watch('src/html/pages/*.html', ['html']);
gulp.watch('src/html/includes/*.html', ['html']);
gulp.watch(sourcePaths.styles, ['sass']);
gulp.watch(sourcePaths.javascripts, ['js']);
gulp.watch(sourcePaths.images, ['imagemin']);
});
gulp.task('default', ['sass', 'js', 'imagemin', 'html', 'webserver', 'watch', 'openbrowser']);