This repository has been archived by the owner. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
144 lines (132 loc) · 3.86 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
var gulp = require('gulp');
var del = require('del');
var browserSync = require('browser-sync').create();
var sass = require('gulp-sass');
var autoprefixer = require('gulp-autoprefixer');
var concatCss = require('gulp-concat-css');
var cleanCSS = require('gulp-clean-css');
var rename = require("gulp-rename");
var uglify = require('gulp-uglify');
var plumber = require("gulp-plumber");
var ghPages = require('gulp-gh-pages');
var svgSprite = require('gulp-svg-sprite');
var svgmin = require('gulp-svgmin');
//Пути
const paths = {
styles: {
src: "src/styles/main.scss",
watch: "src/styles/**/*.scss",
dest: "dist/styles/"
},
stylesNlz: {
src: "src/styles/layout/normalize.css",
dest: "dist/styles/layout/"
},
stylesBoot: {
src: "src/styles/layout/bootstrap-grid.min.css",
dest: "dist/styles/layout/"
},
scripts: {
src: "src/scripts/main.js",
watch: "src/scripts/*.js",
dest: "dist/scripts/"
},
html: {
src: "src/*.html",
watch: "src/*.html",
dest: "dist/"
},
images: {
src: "src/images/**/*.*",
dest: "dist/images/"
},
fonts: {
src: "src/fonts/*.*",
dest: "dist/fonts/"
}
};
//Удаление папки dist
gulp.task("clean", () => {
return del("dist");
});
//Создание ветки gh-pages и загрузка туда содержимого папки dist
gulp.task("deploy", () => {
return gulp.src("./dist/**/*").pipe(ghPages());
});
//Перенос файлов
gulp.task('html', function() {
return gulp
.src(paths.html.src)
.pipe(plumber())
.pipe(gulp.dest(paths.html.dest));
});
gulp.task('stylesNlz', function() {
return gulp.src(paths.stylesNlz.src).pipe(gulp.dest(paths.stylesNlz.dest));
});
gulp.task('stylesBoot', function() {
return gulp.src(paths.stylesBoot.src).pipe(gulp.dest(paths.stylesBoot.dest));
});
gulp.task('images', function() {
return gulp.src(paths.images.src).pipe(gulp.dest(paths.images.dest));
});
gulp.task('scripts', function() {
return gulp.src(paths.scripts.src).pipe(gulp.dest(paths.scripts.dest));
});
gulp.task('fonts', function() {
return gulp.src(paths.fonts.src).pipe(gulp.dest(paths.fonts.dest));
});
gulp.task('serve', ['sass'], function() {
browserSync.init({
server: "src/"
});
//Слежение
gulp.watch(paths.styles.watch, ['sass']);
gulp.watch(paths.html.watch).on('change', browserSync.reload);
gulp.watch(paths.images.src).on('change', browserSync.reload);
});
//Компилируем scss в css + автопрефиксер
gulp.task('sass', function() {
return gulp
.src(paths.styles.src)
.pipe(plumber())
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(concatCss("main.css"))
.pipe(gulp.dest('src/'))
.pipe(browserSync.stream());
});
//Минимизируем css
gulp.task('mincss', function() {
return gulp
.src('src/main.css')
.pipe(plumber())
.pipe(rename({suffix: ".min"}))
.pipe(cleanCSS())
.pipe(gulp.dest(paths.styles.dest));
})
//Минимизируем js
gulp.task('minjs', function() {
return gulp
.src('src/scripts/main.js')
.pipe(plumber())
.pipe(rename({suffix: ".min"}))
.pipe(uglify())
.pipe(gulp.dest(paths.scripts.dest));
})
//Минимизируем svg
gulp.task('minsvg', function() {
return gulp
.src('src/images/icons/check.svg')
.pipe(plumber())
.pipe(rename({suffix: ".min"}))
.pipe(svgmin())
.pipe(gulp.dest('dist/images/icons/'));
})
gulp.task('min',['mincss', 'minjs']);
//Запуск сборки
gulp.task('build', ['clean', 'serve','html', 'stylesNlz', 'stylesBoot', 'minsvg', 'fonts', 'scripts', 'images', 'min']);
//Запуск default
gulp.task('default', ['build']);