-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
155 lines (136 loc) · 4.6 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
var gulp = require('gulp'),
sass = require('gulp-sass'),
smartgrid = require('smart-grid'),
htmlhint = require("gulp-htmlhint"),
htmlhintConfig = require('htmlhint-htmlacademy'),
browserSync = require('browser-sync'),
addsrc = require('gulp-add-src'),
sourcemaps = require('gulp-sourcemaps'),
gcmq = require('gulp-group-css-media-queries'),
concat = require('gulp-concat'),
uglify = require('gulp-uglifyjs'),
cssnano = require('gulp-cssnano'),
rename = require('gulp-rename'),
del = require('del'),
cache = require('gulp-cache'),
autoprefixer = require('gulp-autoprefixer');
// Таск для Sass
gulp.task('sass', async function() {
return gulp.src('app/scss/**/*.scss')
.pipe(sourcemaps.init())
.pipe(sass({
outputStyle: 'expanded',
errorLogToConsole: true
})).on('error', sass.logError)
.pipe(autoprefixer(['last 15 versions', '> 1%', 'ie 8', 'ie 7'], { cascade: true }))
.pipe(gcmq()) //группировка медиазапросов
.pipe(cssnano()) // минификация
.pipe(rename({suffix: '.min'}))
.pipe(sourcemaps.write('./maps/'))
.pipe(gulp.dest('app/css'))
.pipe(browserSync.reload({stream: true}));
});
//таск для синхонизации с браузером
gulp.task('browser-sync', async function(cb) {
browserSync({
server: {
baseDir: 'app'
},
notify: false
}, cb);
});
// настройки сетки smart-grid
gulp.task('smart-grid', (cb) => {
smartgrid('app/scss/stylesheets/', {
outputStyle: 'scss',
filename: '_smart-grid',
columns: 12, // number of grid columns
offset: '1.875rem', // gutter width - 30px
mobileFirst: false,
mixinNames: {
container: 'container'
},
container: {
maxWidth: '1170px',
fields: '0.9375rem' // side fields - 15px
},
breakPoints: {
xs: {
width: '20rem' // 320px
},
sm: {
width: '36rem' // 576px
},
md: {
width: '48rem' // 768px
},
lg: {
width: '62rem' // 992px
},
xl: {
width: '75rem' // 1200px
}
}
});
cb();
});
gulp.task('code', function() {
return gulp.src('app/**/*.html')
.pipe(htmlhint(htmlhintConfig))
.pipe(htmlhint.reporter())
.pipe(browserSync.reload({ stream: true }))
});
// Объединяем все js либы в один файл
gulp.task('scripts', async function() {
return gulp.src(['node_modules/jquery/dist/jquery.js'])
.pipe(addsrc.append('node_modules/magnific-popup/dist/jquery.magnific-popup.js'))
.pipe(concat('libs.js'))
.pipe(uglify())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('app/js'))
.pipe(browserSync.reload({stream: true}));
});
// объединям все css библиотеки в одну
gulp.task('css-lib', function() {
return gulp.src([
'node_modules/normalize.css/normalize.css',
'node_modules/magnific-popup/dist/magnific-popup.css'
])
.pipe(concat('libs.css'))
.pipe(cssnano()) // минификация
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('app/css'))
.pipe(browserSync.reload({stream: true}));
});
gulp.task('clean', async function() {
return del.sync('dist');
});
gulp.task('clear-cache', function (callback) {
return cache.clearAll();
});
gulp.task('prebuild', async function(){
var buildCSS = gulp.src(['app/css/**/*.css'])
.pipe(gulp.dest('dist/css'))
var buildFonts = gulp.src('app/fonts/**/*')
.pipe(gulp.dest('dist/fonts'))
var buildIMG = gulp.src('app/img/**/*')
.pipe(gulp.dest('dist/img'))
var buildJSLibs = gulp.src('app/js/libs.js')
.pipe(gulp.dest('dist/js'))
var buildJSCommon = gulp.src('app/js/common.js')
.pipe(uglify())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('dist/js'))
var buildHTML = gulp.src('app/**/*.html')
.pipe(gulp.dest('dist'))
});
// Следим за файлами
gulp.task('watch', function() {
gulp.watch('app/scss/**/*.scss', gulp.parallel('sass'));
gulp.watch('app/**/*.html', gulp.parallel('code'));
gulp.watch(['app/js/common.js'], gulp.parallel('scripts'));
});
gulp.task('default',
gulp.parallel('clear-cache', 'smart-grid', 'sass', 'css-lib', 'scripts', 'browser-sync', 'watch'));
gulp.task('build',
gulp.series('clean', 'clear-cache', 'prebuild'));