-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
90 lines (79 loc) · 2.24 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
let preprocessor = 'scss';
const {src, dest, parallel, series, watch} = require('gulp');
const browserSync = require('browser-sync').create();
const concat = require('gulp-concat');
const uglify = require('gulp-uglify-es').default;
const scss = require('gulp-sass')(require('sass'));
const autoprefixer = require('gulp-autoprefixer');
const cleancss = require('gulp-clean-css');
const imagemin = require('gulp-imagemin');
const newer = require('gulp-newer');
const del = require('del');
function cleaning() {
return del('app/images/dist/**/*', {force: true})
}
function cleandist() {
return del('dist/**/*', {force: true})
}
function browsersync() {
browserSync.init({
server: {
baseDir: 'app/'
},
notify: false,
online: true
})
}
function scripts() {
return src([
'node_modules/jquery/dist/jquery.min.js',
'app/js/app.js'
])
.pipe(concat('app.min.js'))
.pipe(uglify())
.pipe(dest('app/js/'))
.pipe(browserSync.stream())
}
function styles() {
return src('app/' + preprocessor + '/main.' + preprocessor + '')
.pipe(eval(preprocessor)())
.pipe(concat('main.min.css'))
.pipe(autoprefixer({
overrideBrowserslist: ['last 10 versions'],
grid: true
}))
.pipe(cleancss({
level: {1: {specialComments: 0}},
// format: 'beautify'
}))
.pipe(dest('app/css/'))
.pipe(browserSync.stream())
}
function images() {
return src('app/images/src/**/*')
.pipe(newer('app/images/dist/'))
.pipe(imagemin())
.pipe(dest('app/images/dist'))
}
function startWatch() {
watch(['app/**/' + preprocessor + '/**/*'], styles);
watch(['app/**/*.js', '!app/**/*.min.js'], scripts);
watch('app/**/*.html').on('change', browserSync.reload);
watch('app/images/src/**/*', images)
}
function buildCopy() {
return src([
'app/css/**/*.min.css',
'app/js/**/*.min.js',
'app/images/dist/**/*',
'app/**/*.html'
], {base: 'app'})
.pipe(dest('dist'))
}
exports.browsersync = browsersync;
exports.scripts = scripts;
exports.styles = styles;
exports.images = images;
exports.cleaning = cleaning;
exports.build = series(cleandist, styles, scripts, images, buildCopy);
exports.default = parallel(styles, scripts, browsersync, startWatch);