This repository was archived by the owner on Jun 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
302 lines (260 loc) · 9.28 KB
/
Copy pathgulpfile.js
File metadata and controls
302 lines (260 loc) · 9.28 KB
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
var gulp = require("gulp"),
browserSync = require("browser-sync").create(),
sass = require('gulp-sass'),
notify = require('gulp-notify'),
minifyCss = require('gulp-minify-css'),
rename = require('gulp-rename'),
autoprefixer = require('gulp-autoprefixer'),
del = require("del"),
gutil = require("gulp-util"),
concatCss = require("gulp-concat-css"),
gulpif = require("gulp-if"),
uglify = require("gulp-uglify"),
imagemin = require("gulp-imagemin"),
uncss = require('gulp-uncss'),
filter = require("gulp-filter"),
ftp = require("vinyl-ftp"),
wiredep = require("wiredep").stream,
useref = require("gulp-useref"),
size = require("gulp-size"),
compass = require('gulp-compass'),
plumber = require('gulp-plumber'),
spritesmith = require('gulp.spritesmith'),
// До выхода gulp 4 версии временное решение
//runSequence = require('run-sequence'),
RS_CONF = require('./rs-conf.js');
// * ====================================================== *
// DEV
// * ====================================================== *
// sass
// ******************************************************
gulp.task("sass", function () {
return gulp.src(RS_CONF.path.scssСonnect)
.pipe(sass())
.pipe(gulp.dest(RS_CONF.path.cssDirDest))
.pipe(browserSync.stream())
.pipe(notify("Scss"));
});
// autoprefixer
// ******************************************************
gulp.task('autoprefixer', function () {
return gulp.src(RS_CONF.path.cssDir)
.pipe(autoprefixer({
browsers: ['last 6 versions', "ie 8"],
cascade: false
}))
.pipe(gulp.dest(RS_CONF.path.cssDirDest));
});
// wiredep
// ******************************************************
gulp.task("wiredep-bower", function () {
return gulp.src(RS_CONF.path.htmlDir)
.pipe(wiredep({
directory: RS_CONF.path.bowerDir,
overrides: {
"qtip2": {
"main": ["./jquery.qtip.min.js", "./jquery.qtip.min.css"],
"dependencies": {
"jquery": ">=1.6.0"
}
}/*,
"bootstrap": {
"main": ["dist/js/bootstrap.min.js", "dist/css/bootstrap.css"] // подключение bootstrap в html
}*/
},
exclude: ["bower/modernizr/"],
ignorePath: /^(\.\.\/)*\.\./
}))
.pipe(gulp.dest(RS_CONF.path.baseDir));
});
// spritesmith
// ******************************************************
gulp.task('sprite', function () {
var spriteData = gulp.src(RS_CONF.path.spriteDir)
.pipe(spritesmith({
imgName: 'sprite.png',
cssName: '_sprite.scss',
cssFormat: 'scss',
padding: 10,
algorithm: 'top-down'
//cssTemplate: './custom.scss.template.handlebars',
//cssVarMap: function (sprite) {
// sprite.name = 's-' + sprite.name
//}
}));
//spriteData.img.pipe(gulp.dest(path.src.srcImg()));
//spriteData.css.pipe(gulp.dest(path.src.scss() + "utilities/"));
return spriteData.pipe(gulp.dest(RS_CONF.path.imgDestDir));
});
// scss-compass
// ******************************************************
gulp.task('compass', function () {
gulp.src(RS_CONF.path.scssDir)
.pipe(plumber())
.pipe(compass({
config_file: RS_CONF.path.compassConfig,
css: RS_CONF.path.cssDirDest,
sass: RS_CONF.path.scssDirDest,
image: RS_CONF.path.iconDir
}));
});
// browsersync front-end
// ******************************************************
gulp.task("server", ["compass", "autoprefixer", "wiredep-bower"], function () {
browserSync.init({
port: 9000,
open: false,
notify: false,
server: {
baseDir: RS_CONF.path.baseDir
}
});
// для компиляции можно использовать saas или compass
// compass хорошо создает спрайты
//gulp.watch(RS_CONF.path.scssDir, ["sass"]);
gulp.watch(RS_CONF.path.scssDir, ["compass"]);
gulp.watch("bower.json", ["wiredep-bower"]);
gulp.watch(RS_CONF.path.cssDir, ["autoprefixer"]).on("change", browserSync.reload);
gulp.watch(RS_CONF.path.htmlDir).on("change", browserSync.reload);
gulp.watch(RS_CONF.path.jsDir).on("change", browserSync.reload);
});
// browsersync local-host
// ******************************************************
gulp.task("local-host", ["compass", "autoprefixer", "wiredep-bower"], function () {
browserSync.init({
proxy: "projectName/app"
});
// для компиляции можно использовать saas или compass
// compass хорошо создает спрайты
//gulp.watch(RS_CONF.path.scssDir, ["sass"]);
gulp.watch(RS_CONF.path.scssDir, ["compass"]);
gulp.watch("bower.json", ["wiredep-bower"]);
gulp.watch(RS_CONF.path.cssDir, ["autoprefixer"]).on("change", browserSync.reload);
gulp.watch(RS_CONF.path.htmlDir).on("change", browserSync.reload);
gulp.watch(RS_CONF.path.jsDir).on("change", browserSync.reload);
});
// default
// ******************************************************
gulp.task("default", ["server"]);
// local
// ******************************************************
gulp.task("local", ["local-host"]);
var log = function (error) {
console.log([
"",
"----------ERROR MESSAGE START----------",
("[" + error.name + " in " + error.plugin + "]"),
error.message,
"----------ERROR MESSAGE END----------",
""
].join("\n"));
this.end();
}
// * ====================================================== *
// BUILD
// * ====================================================== *
// Переносим CSS JS HTML в папку DIST (useref)
// ******************************************************
gulp.task("useref", function () {
var assets = useref.assets();
return gulp.src(RS_CONF.path.htmlDir)
.pipe(assets)
.pipe(gulpif("*.js", uglify()))
.pipe(gulpif("*.css", minifyCss({
compatibility: "ie8"
})))
.pipe(assets.restore())
.pipe(useref())
.pipe(gulp.dest(RS_CONF.path.distDir));
});
// Очищаем директорию DIST
// ******************************************************
gulp.task("clean-dist", function () {
return del(RS_CONF.path.distDelDir);
});
// Запускаем локальный сервер для DIST
// ******************************************************
gulp.task("dist-server", function () {
browserSync.init({
port: 2000,
open: false,
notify: false,
server: {
baseDir: RS_CONF.path.distDir
}
});
});
// Перенос шрифтов
// ******************************************************
gulp.task("fonts", function () {
gulp.src(RS_CONF.path.fontsDir)
.pipe(filter(["*.eot", "*.svg", "*.ttf", "*.woff", "*.woff2"]))
.pipe(gulp.dest(RS_CONF.path.distFontsDir))
});
// Перенос картинок
// ******************************************************
gulp.task("images", function () {
return gulp.src(RS_CONF.path.imgDir)
.pipe(imagemin({
progressive: true,
interlaced: true
}))
.pipe(filter(["*.jpg", "*.svg", "*.jpeg", "*.png", "*.webp", "*.gif", "!/icons"]))
.pipe(gulp.dest(RS_CONF.path.distImgDir));
});
// Перенос остальных файлов (favicon и т.д.)
// ******************************************************
gulp.task("extras", function () {
return gulp.src(RS_CONF.path.extraFiles)
.pipe(gulp.dest(RS_CONF.path.distDir));
});
// Вывод размера папки APP
// ******************************************************
gulp.task("size-app", function () {
return gulp.src(RS_CONF.path.allAppFiles).pipe(size({
title: "APP size: "
}));
});
// Сборка и вывод размера папки DIST
// ******************************************************
gulp.task("dist", ["useref", "images", "fonts", "extras", "size-app"], function () {
return gulp.src(RS_CONF.path.allDistFiles).pipe(size({
title: "DIST size: "
}));
});
// Собираем папку DIST - только когда файлы готовы
// ******************************************************
gulp.task("build", ["clean-dist", "wiredep-bower"], function () {
gulp.start("dist");
});
// * ====================================================== *
// DEPLOY
// * ====================================================== *
// Отправка проекта на сервер
// ******************************************************
gulp.task("deploy", function () {
var conn = ftp.create({
host: RS_CONF.conn.host,
user: RS_CONF.conn.user,
password: RS_CONF.conn.password,
parallel: 10,
log: gutil.log
});
return gulp.src(RS_CONF.conn.src, {
base: RS_CONF.conn.base,
buffer: false
})
.pipe(conn.dest(RS_CONF.conn.folder));
});
// * ====================================================== *
// Резерв
// * ====================================================== *
// uncss неработает пока
// ******************************************************
gulp.task('uncss', function () {
return gulp.src('app/css/style.min.css')
.pipe(uncss({
html: ['app/**/*.html']
}))
.pipe(gulp.dest('app/css/style.min.css'));
});