-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
170 lines (154 loc) · 4.87 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
const
gulp = require('gulp'),
sass = require('gulp-sass'),
browserSync = require('browser-sync').create(),
plumber = require('gulp-plumber'),
notify = require('gulp-notify'),
del = require('del'),
autoprefixer = require('gulp-autoprefixer'),
concat = require('gulp-concat'),
csso = require('gulp-csso'),
imagemin = require('gulp-imagemin'),
normalize = require('node-normalize-scss'),
rename = require('gulp-rename'),
replace = require('gulp-replace'),
sourcemaps = require('gulp-sourcemaps'),
uglify = require('gulp-uglify');
const paths = {
root: './prod',
html: {
src: 'src/*.html',
dest: 'prod/',
},
styles: {
src: 'src/scss/**/*.scss',
dest: 'prod/css/',
},
scripts: {
src: 'src/js/**/*.js',
dest: 'prod/js/',
},
images: {
src: 'src/img/{bg,content,icons}/**/*',
dest: 'prod/img/',
},
fonts: {
src: 'src/fonts/**/*.*',
dest: 'prod/fonts/',
},
server: {
src: 'src/*.php',
dest: 'prod/',
},
};
// Development
function templates() {
return gulp.src(paths.html.src)
.pipe(plumber())
.pipe(notify('Template success'))
.pipe(plumber.stop())
.pipe(gulp.dest(paths.html.dest));
}
function scss() {
return gulp.src('./src/scss/main.scss')
.pipe(plumber())
.pipe(sass({ includePaths: normalize.includePaths }))
.pipe(autoprefixer())
.pipe(sourcemaps.init())
.pipe(csso())
.pipe(sourcemaps.write())
.pipe(rename({ suffix: '.min' }))
.pipe(notify('Style success'))
.pipe(plumber.stop())
.pipe(gulp.dest(paths.styles.dest));
}
function scripts() {
return gulp.src('src/js/*.js')
.pipe(plumber())
.pipe(uglify())
.pipe(concat('main.min.js'))
.pipe(notify('Scripts success'))
.pipe(plumber.stop())
.pipe(gulp.dest(paths.scripts.dest));
}
function plugins() {
return gulp.src([
'./node_modules/jquery/dist/jquery.min.js',
'./node_modules/owl.carousel/dist/owl.carousel.min.js',
'./node_modules/fancybox/dist/js/jquery.fancybox.min.js',
'./node_modules/jquery.maskedinput/src/jquery.maskedinput.js',
'./node_modules/svg4everybody/dist/svg4everybody.min.js',
// './src/js/fancybox/dist/jquery.fancybox.js',
])
.pipe(plumber())
.pipe(concat('plugins.min.js'))
.pipe(notify('Plugins success'))
.pipe(plumber.stop())
.pipe(gulp.dest(paths.scripts.dest));
}
function pluginStyles() {
return gulp.src([
'./node_modules/owl.carousel/dist/assets/owl.carousel.css',
'./node_modules/fancybox/dist/css/jquery.fancybox.min.css',
])
.pipe(plumber())
.pipe(concat('plugins.min.css'))
.pipe(notify('pluginStyles success'))
.pipe(plumber.stop())
.pipe(gulp.dest(paths.styles.dest));
}
function imgMin() {
return gulp.src(paths.images.src)
.pipe(plumber())
.pipe(notify('Image success'))
.pipe(plumber.stop())
.pipe(gulp.dest(paths.images.dest));
}
function fonts() {
return gulp.src(paths.fonts.src)
.pipe(notify('Fonts success'))
.pipe(gulp.dest(paths.fonts.dest));
}
function php() {
return gulp.src(paths.server.src)
.pipe(notify('Server php success'))
.pipe(gulp.dest(paths.server.dest));
}
function clean() {
return del(paths.root);
}
function watch() {
gulp.watch(paths.html.src, templates);
gulp.watch(paths.styles.src, scss);
gulp.watch(paths.scripts.src, scripts);
gulp.watch(paths.images.src, imgMin);
gulp.watch(paths.fonts.src, fonts);
gulp.watch(paths.server.src, php);
}
function server() {
browserSync.init({
server: paths.root,
});
browserSync.watch(paths.root + '/**/*.*', browserSync.reload);
}
// Exports
// exports.sprites = sprites;
exports.templates = templates;
exports.scss = scss;
exports.scripts = scripts;
exports.plugins = plugins;
exports.pluginStyles = pluginStyles;
exports.imgMin = imgMin;
exports.fonts = fonts;
exports.php = php;
exports.clean = clean;
exports.watch = watch;
// Tasks
gulp.task('build', gulp.series(
clean,
gulp.parallel(templates, scss, scripts, plugins, pluginStyles, imgMin, fonts, php),
));
gulp.task('default', gulp.series(
gulp.parallel(templates, scss, scripts, plugins, pluginStyles, php),
gulp.parallel(watch, server),
));