-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
125 lines (112 loc) · 4.3 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
// JavaScript Document
'use strict';
var gulp = require('gulp'),
//watch = require('gulp-watch'),
prefixer = require('gulp-autoprefixer'),
uglify = require('gulp-uglify'),
sass = require('gulp-sass'),
sourcemaps = require('gulp-sourcemaps'),
//rigger = require('gulp-rigger'),
cssmin = require('gulp-minify-css'),
//cleanCSS = require('gulp-clean-css'),
//rimraf = require('rimraf'),
//concat = require('gulp-concat'),
//concatCss = require('gulp-concat-css'),
through2 = require('through2').obj,
changed = require('gulp-changed'),
mkdirp = require('mkdirp'),
plumber = require('gulp-plumber');
gulp.task('style', function () {
gulp.src("src/public/**/*.sass")
.pipe(through2(function(file, enc, callback){
//console.log("--"+file.path);
callback(null, file);
}))
.pipe(plumber())
.pipe(changed("public", {extension: '.css'}))
.pipe(through2(function(file, enc, callback){
//console.log("++"+file.path);
callback(null, file);
}))
.pipe(sourcemaps.init())
.pipe(sass()) //Скомпилируем
//.pipe(prefixer()) //Добавим вендорные префиксы
.pipe(cssmin()) //Сожмем
.pipe(sourcemaps.write("."))
/*.pipe(through2(function(file, enc, callback){//Добавим к пути мап файлов ?a-pp=1
if(!/.map/.test(file.extname)) {
file.contents = new Buffer(file.contents.toString().replace(/(\.css\.map)([\S\s]{1,3}$)/gim, "$1?a-pp=1$2"));
callback(null, file);
}
}))*/
.pipe(gulp.dest("public"));
});
gulp.task('css', function () {
gulp.src("src/public/**/*.css")
.pipe(changed("public"))
.pipe(cssmin()) //Сожмем
.pipe(gulp.dest("public"));
});
gulp.task('js', function () {
gulp.src([
"src/public/**/*.js",
])
.pipe(plumber())
.pipe(changed("public"))
.pipe(sourcemaps.init())
.pipe(uglify()) //Сожмем наш js
.pipe(sourcemaps.write('.'))
/*.pipe(through2(function(file, enc, callback){//Добавим к пути мап файлов ?a-pp=1
if(!/.map/.test(file.extname)) {
file.contents = new Buffer(file.contents.toString().replace(/(\.js\.map)([\S\s]{1,3}$)/gim, "$1?a-pp=1$2"));
callback(null, file);
}
}))*/
.pipe(gulp.dest("public"));
});
//content
gulp.task('content', function () {
gulp.src("src/public/**/*.{jpg,png,gif,svg,otf,eot,svg,ttf,woff,woff2,json}")
.pipe(changed("public"))
.pipe(gulp.dest("public"));
});
gulp.task('index.html', function () {
gulp.src("src/public/index.html")
.pipe(changed("public"))
.pipe(gulp.dest("public"));
});
mkdirp('public/design-thumbnails', function (err) {
if (err) console.error(err);
});
/*gulp.task('style:build', function () {
gulp.src(path.src.style) //Выберем наш main.scss
.pipe(sourcemaps.init()) //То же самое что и с js
.pipe(sass()) //Скомпилируем
.pipe(prefixer()) //Добавим вендорные префиксы
.pipe(cssmin()) //Сожмем
.pipe(sourcemaps.write())
.pipe(gulp.dest(path.build.css)) //И в build
.pipe(reload({stream: true}));
});
gulp.task('js:build', function () {
gulp.src(path.src.js) //Найдем наш main файл
.pipe(rigger()) //Прогоним через rigger
.pipe(sourcemaps.init()) //Инициализируем sourcemap
.pipe(uglify()) //Сожмем наш js
.pipe(sourcemaps.write()) //Пропишем карты
.pipe(gulp.dest(path.build.js)) //Выплюнем готовый файл в build
.pipe(reload({stream: true})); //И перезагрузим сервер
});*/
gulp.task('build', [
'index.html',
'style',
'css',
"js",
'content'
]);
gulp.task('default', ['build']);
gulp.watch("src/public/index.html", ['index.html']);
gulp.watch("src/public/**/*.sass", ['style']);
gulp.watch("src/public/**/*.css", ['css']);
gulp.watch("src/public/**/*.js", ['js']);
gulp.watch("src/public/**/*.{jpg,png,gif,svg,otf,eot,svg,ttf,woff,woff2,json}", ['content']);