-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgulpfile.js
130 lines (116 loc) · 3.06 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
const { src, dest, task, series, watch, parallel } = require("gulp");
const rm = require('gulp-rm');
const sass = require('gulp-sass');
const concat = require('gulp-concat');
const browserSync = require('browser-sync').create();
const reload = browserSync.reload;
const sassGlob = require('gulp-sass-glob');
const autoprefixer = require('gulp-autoprefixer');
const gcmq = require('gulp-group-css-media-queries');
const cleanCSS = require('gulp-clean-css');
const sourcemaps = require('gulp-sourcemaps');
const babel = require('gulp-babel');
const uglify = require('gulp-uglify');
const svgo = require('gulp-svgo');
const svgSprite = require('gulp-svg-sprite');
const gulpif = require('gulp-if');
const env = process.env.NODE_ENV;
sass.compiler = require('node-sass');
task('clean', () => {
return src('dist/**/*', { read: false })
.pipe(rm())
})
task('copy:html', () => {
return src('src/*.html')
.pipe(dest('dist'))
.pipe(reload({ stream: true }));
})
task('copy:img', () => {
return src('src/images/**/*')
.pipe(dest('dist/images'))
.pipe(reload({ stream: true }));
})
const styles = [
'node_modules/normalize.css/normalize.css',
'src/styles/main.scss'
];
task('styles', () => {
return src(styles)
.pipe(gulpif(env === 'dev', sourcemaps.init()))
.pipe(concat('main.min.scss'))
.pipe(sassGlob())
.pipe(sass().on('error', sass.logError))
.pipe(gulpif(env === 'prod', autoprefixer({
browsers: ['last 2 versions'],
cascade: false
})))
.pipe(gulpif(env === 'prod', gcmq()))
.pipe(gulpif(env === 'prod', cleanCSS()))
.pipe(gulpif(env === 'dev', sourcemaps.write()))
.pipe(dest('dist'))
.pipe(reload({ stream: true }));
});
const libs = [
'node_modules/jquery/dist/jquery.js',
'node_modules/slick-carousel/slick/slick.js',
'node_modules/jquery-touchswipe/jquery.touchSwipe.js',
'src/scripts/*.js'
];
task('scripts', () => {
return src(libs)
.pipe(gulpif(env === 'dev', sourcemaps.init()))
.pipe(concat('main.min.js', {newLine: ';'}))
.pipe(gulpif(env === 'prod', babel({
presets: ['@babel/env']
})))
.pipe(gulpif(env === 'prod', uglify()))
.pipe(gulpif(env === 'dev', sourcemaps.write()))
.pipe(dest('dist'))
.pipe(reload({ stream: true }));
});
task('icons', () => {
return src('src/images/icons/toSprite/*.svg')
.pipe(svgo({
plugins: [
{
removeAttrs: {
attrs: '(fill|stroke|style|width|height|data.*)'
}
}
]
}))
.pipe(svgSprite({
mode: {
symbol: {
sprite: '../sprite.svg'
}
}
}))
.pipe(dest('dist/images'));
});
task('server', () => {
browserSync.init({
server: {
baseDir: "./dist"
},
open: false
});
});
task('watch', () => {
watch('./src/styles/**/*.scss', series('styles'));
watch('./src/*.html', series('copy:html'));
watch('./src/scripts/*.js', series('scripts'));
watch('./src/images/icons/*.svg', series('icons'));
});
task('default',
series(
'clean',
parallel('copy:html', 'copy:img', 'styles', 'scripts', 'icons'),
parallel('watch', 'server')
)
);
task('build',
series(
'clean',
parallel('copy:html', 'copy:img', 'styles', 'scripts', 'icons'))
);