-
Notifications
You must be signed in to change notification settings - Fork 8
/
gulpfile.js
52 lines (47 loc) · 1.67 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
var gulp = require('gulp');
var sass = require('gulp-sass')(require('sass-embedded'));
var postcss = require('gulp-postcss');
var autoprefixer = require('autoprefixer');
var browserSync = require('browser-sync').create();
var cssFolderPath = 'main/css';
var scssFolderPath = 'main/scss';
function reload(done) {
browserSync.reload();
done();
};
gulp.task('browserSync', gulp.series(function (done) {
browserSync.init({
server: {
baseDir: 'main'
},
notify: false
})
done();
}));
function compileCss(file) {
return gulp.src(scssFolderPath+'/'+file+'.scss')
.pipe(sass().on('error', sass.logError))
.pipe(postcss([autoprefixer()]))
.pipe(gulp.dest(cssFolderPath))
.pipe(browserSync.reload({
stream: true
}));
};
function compileGlobals(file) {
return gulp.src(scssFolderPath+'/'+file+'.scss')
.pipe(sass().on('error', sass.logError))
.pipe(postcss([autoprefixer()]))
.pipe(gulp.dest(cssFolderPath));
};
gulp.task('watch', gulp.series(['browserSync'], function () {
gulp.watch('main/*.html', gulp.series(reload));
gulp.watch('main/scss/**/*.scss').on('change', function(file) {
compileCss('style');
if(file.includes('config.scss') || file.includes('buttons.scss')) compileGlobals('buttons');
if(file.includes('config.scss') || file.includes('forms.scss')) compileGlobals('forms');
if(file.includes('config.scss') || file.includes('icons.scss')) compileGlobals('icons');
if(file.includes('config.scss') || file.includes('typography.scss')) compileGlobals('typography');
if(file.includes('config.scss') || file.includes('util.scss')) compileGlobals('util');
if(file.includes('reset.scss')) compileGlobals('reset');
});
}));