-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
123 lines (111 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
113
114
115
116
117
118
119
120
121
122
123
'use strict';
// gulp plugins
var gulp = require('gulp'),
sass = require('gulp-sass'),
concat = require('gulp-concat'),
cleanCSS = require('gulp-clean-css'),
autoprefixer = require('gulp-autoprefixer'),
sourceMaps = require('gulp-sourcemaps'),
gulpif = require('gulp-if'),
clean = require('gulp-clean'),
browserSync = require('browser-sync').create(),
imagemin = require('gulp-imagemin'),
pngquant = require('imagemin-pngquant'),
cache = require('gulp-cache'),
babel = require('gulp-babel'),
uglify = require('gulp-uglify');
// ENVIRONMENT
var ENV = 'dev',
reload = browserSync.reload,
serverSettings = {
server: {
baseDir: "."
},
notify: false,
port: 9000,
open: false,
};
//objects
var path = {
app: {
js: "app/main.js",
sass: "app/*.scss",
img: "app/img/**/*.*"
},
dest: {
js: "dest",
css: "dest",
img: "dest/img"
},
watch: {
html: "index.html",
js: "app/*.js",
sass: "app/**/*.scss",
img: "app/img/**/*.*"
},
clean: "dest"
};
// ******************************* TASKS ********************************************
// Default task
gulp.task('default', ()=> {
ENV = 'production';
gulp.start([
'build'
]);
});
// HTML building task
gulp.task('buildHtml', ()=> {
gulp.src(path.watch.html)
.pipe(reload({stream: true}));
});
// CSS building task
gulp.task('buildCss', ()=> {
gulp.src(path.app.sass)
.pipe(gulpif(ENV != 'production', sourceMaps.init()))
.pipe(sass.sync().on('error', sass.logError))
.pipe(autoprefixer({browsers: ['last 4 versions'], cascade: false}))
.pipe(cleanCSS())
.pipe(gulpif(ENV != 'production', sourceMaps.write()))
.pipe(gulp.dest(path.dest.css))
.pipe(reload({stream: true}));
});
// JS building task
gulp.task('buildJs', ()=> {
gulp
.src(path.app.js)
//.pipe(babel({ presets: ["es2015"] }))
//.pipe(uglify())
.pipe(gulpif(ENV != 'production', sourceMaps.init()))
.pipe(gulpif(ENV != 'production', sourceMaps.write()))
.pipe(gulp.dest(path.dest.js))
.pipe(reload({ stream: true }));
});
// Images building task
gulp.task('buildImage', ()=> {
gulp.src(path.app.img)
.pipe(cache(imagemin({
progressive: true,
svgoPlugins: [{removeViewBox: false}],
use: [pngquant()],
interlaced: true
})))
.pipe(gulp.dest(path.dest.img))
});
// Destination folder clearance task
gulp.task('clean', ()=> {
gulp.src('dest/*', {read: false})
.pipe(clean());
});
// Server initialization task
gulp.task('server', ()=> {
browserSync.init(serverSettings);
});
//Project building task
gulp.task('build', ['buildCss', 'buildJs','buildImage']);
// Autorun task
gulp.task('watch', () => {
gulp.watch(path.watch.html, ["buildHtml"]);
gulp.watch(path.watch.sass, ['buildCss']);
gulp.watch(path.watch.js, ['buildJs']);
gulp.watch(path.watch.img, ['buildImage']);
});