-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
84 lines (75 loc) · 2 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
const {task, series, parallel, src, dest, watch} = require('gulp');
const sass = require('gulp-sass');
const browserSync = require('browser-sync');
const notify = require('gulp-notify');
const postcss = require('gulp-postcss');
const csscomb = require('gulp-csscomb');
const autoprefixer = require('autoprefixer');
const mqpacker = require('css-mqpacker');
const sortCSSmq = require('sort-css-media-queries');
const path = {
scssFolder: './assets/scss/',
scssFiles: './assets/scss/**/*.scss',
scssFile: './assets/scss/style.scss',
cssFolder: './assets/css/',
cssFile: './assets/css/style.css',
htmlFiles: './*.html',
jsFiles: './assets/js/**/*.js'
};
const plugins = [
autoprefixer({
overrideBrowserslist: [
'last 5 versions',
'> 1%'
],
cascade: true
}),
mqpacker({sort: sortCSSmq})
];
function scss() {
return src(path.scssFile).
pipe(sass({outputStyle: 'expanded'}).on('error', sass.logError)).
pipe(postcss(plugins)).
pipe(dest(path.cssFolder)).
pipe(notify({
message: 'Compiled!',
sound: false
})).
pipe(browserSync.reload({stream: true}));
}
function scssDev() {
return src(path.scssFile, {sourcemaps: true}).
pipe(sass({outputStyle: 'expanded'}).on('error', sass.logError)).
pipe(postcss(plugins)).
pipe(dest(path.cssFolder, {sourcemaps: true})).
pipe(notify({
message: 'Compiled!',
sound: false
})).
pipe(browserSync.reload({stream: true}));
}
function comb() {
return src(path.scssFiles).
pipe(csscomb()).
on('error', notify.onError((error) => `File: ${error.message}`)).
pipe(dest(path.scssFolder));
}
function syncInit() {
browserSync({
server: {baseDir: './'},
notify: false
});
}
async function sync() {
browserSync.reload();
}
function watchFiles() {
syncInit();
watch(path.scssFiles, series(scss));
watch(path.htmlFiles, sync);
watch(path.jsFiles, sync);
}
task('comb', series(comb));
task('scss', series(scss));
task('dev', series(scssDev));
task('watch', watchFiles);