forked from Adalab/project-promo-m-module-2-team-1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
140 lines (122 loc) · 3.68 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
'use strict';
const autoprefixer = require('gulp-autoprefixer');
const browserSync = require('browser-sync');
// const combineMq = require('gulp-combine-mq');
const concat = require('gulp-concat');
const config = require('./config.json');
const del = require('del');
const gulp = require('gulp');
const htmlInclude = require('gulp-html-tag-include');
const notify = require('gulp-notify');
const plumber = require('gulp-plumber');
const sass = require('gulp-sass');
const sourcemaps = require('gulp-sourcemaps');
const uglify = require('gulp-uglify-es').default;
// secondary tasks
gulp.task('api', done => {
gulp.src(config.api.src).pipe(gulp.dest(config.api.dest));
done();
});
gulp.task('api-dist', done => {
gulp.src(config.api.src).pipe(gulp.dest(config.api.dist));
done();
});
gulp.task('bs-reload', done => {
browserSync.reload();
done();
});
gulp.task('clean', del.bind(null, [config.env.dev.dest]));
gulp.task('clean-dist', del.bind(null, [config.env.producction.dest]));
gulp.task('css', done => {
gulp
.src(config.css.src)
.pipe(sourcemaps.init())
.pipe(plumber({ errorHandler: notify.onError('Error: <%= error.message %>') }))
.pipe(sass({ outputStyle: 'extended' }))
// .pipe(combineMq({ beautify: true }))
.pipe(autoprefixer({ cascade: false }))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(config.css.dest))
.pipe(browserSync.reload({ stream: true }));
done();
});
gulp.task('css-dist', done => {
gulp
.src(config.css.src)
.pipe(plumber({ errorHandler: notify.onError('Error: <%= error.message %>') }))
.pipe(sass({ outputStyle: 'compressed' }))
// .pipe(combineMq({ beautify: false }))
.pipe(autoprefixer({ cascade: false }))
.pipe(gulp.dest(config.css.dist));
done();
});
gulp.task('html', done => {
gulp.src(config.html.src).pipe(htmlInclude()).pipe(gulp.dest(config.html.dest));
done();
});
gulp.task('html-dist', done => {
gulp.src(config.html.src).pipe(htmlInclude()).pipe(gulp.dest(config.html.dist));
done();
});
gulp.task('images', done => {
gulp
.src(config.images.src)
.pipe(plumber({ errorHandler: notify.onError('Error: <%= error.message %>') }))
.pipe(gulp.dest(config.images.dest));
done();
});
gulp.task('js', done => {
gulp
.src(config.js.src)
.pipe(sourcemaps.init())
.pipe(plumber({ errorHandler: notify.onError('Error: <%= error.message %>') }))
.pipe(concat('main.js'))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(config.js.dest))
.pipe(browserSync.reload({ stream: true }));
done();
});
gulp.task('js-dist', done => {
gulp
.src(config.js.src)
.pipe(plumber({ errorHandler: notify.onError('Error: <%= error.message %>') }))
.pipe(concat('main.js'))
.pipe(uglify())
.pipe(gulp.dest(config.js.dist));
done();
});
gulp.task('images-dist', done => {
gulp
.src(config.images.src)
.pipe(plumber({ errorHandler: notify.onError('Error: <%= error.message %>') }))
.pipe(gulp.dest(config.images.dist));
done();
});
// main tasks
gulp.task(
'default',
gulp.series(['clean', 'api', 'html', 'css', 'js', 'images'], done => {
browserSync.init({ server: { baseDir: './public/' } });
gulp.watch(config.api.src, gulp.series(['api', 'bs-reload']));
gulp.watch(config.css.src, gulp.series('css'));
gulp.watch(config.images.src, gulp.series(['images', 'bs-reload']));
gulp.watch(config.js.src, gulp.series(['js', 'bs-reload']));
gulp.watch(config.watch.html, gulp.series(['html', 'bs-reload']));
done();
})
);
gulp.task(
'docs',
gulp.series(
[
'clean-dist',
'api-dist',
'css-dist',
'html-dist',
'js-dist',
'images-dist'
// 'icons-dist'
],
done => done()
)
);