-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
127 lines (111 loc) · 3.14 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
var gulp = require('gulp');
var nunjucks = require('gulp-nunjucks');
var concat = require('gulp-concat');
var cssmin = require('gulp-cssmin');
var uglify = require('gulp-uglify');
var autoprefixer = require('gulp-autoprefixer');
var browserSync = require('browser-sync').create();
var path = {
css: 'src/styles/*.css',
js: 'src/scripts/*.js',
partials: 'src/templates/partials/*.html',
mock: 'src/mockapi/*.json',
html: 'src/templates/*.html',
img: 'src/images/*',
vendor: {
css: 'src/vendor/css/*.css',
js: 'src/vendor/js/*.js'
},
dist: {
css: 'dist/styles/',
js: 'dist/scripts/',
html: 'dist/',
partials: 'dist/partials/',
vendor: {
css: 'dist/vendor/css/',
js: 'dist/vendor/js/'
},
img: 'dist/images/',
mock: 'dist/mockapi/'
}
};
gulp.task('default', ['build', 'serve', 'watch']);
gulp.task('css', function () {
return gulp.src(path.css)
.pipe(autoprefixer({
browsers: ['last 4 versions']
}))
.pipe(concat('style.css'))
.pipe(gulp.dest(path.dist.css));
});
gulp.task('css-min', function () {
return gulp.src(path.css)
.pipe(autoprefixer({
browsers: ['last 4 versions']
}))
.pipe(concat('style.css'))
.pipe(cssmin())
.pipe(gulp.dest(path.dist.css));
});
gulp.task('js', function () {
return gulp.src(path.js)
.pipe(concat('scripts.js'))
.pipe(gulp.dest(path.dist.js));
});
gulp.task('js-min', function () {
return gulp.src(path.js)
.pipe(concat('scripts.js'))
.pipe(uglify())
.pipe(gulp.dest(path.dist.js));
});
gulp.task('html', function () {
return gulp.src(path.html)
.pipe(nunjucks.compile())
.pipe(gulp.dest(path.dist.html));
});
gulp.task('partials', function () {
return gulp.src(path.partials)
.pipe(gulp.dest(path.dist.partials));
});
gulp.task('img', function () {
return gulp.src(path.img)
.pipe(gulp.dest(path.dist.img));
});
gulp.task('mock', function () {
return gulp.src(path.mock)
.pipe(gulp.dest(path.dist.mock));
});
gulp.task('vendor-css', function () {
return gulp.src(path.vendor.css)
.pipe(gulp.dest(path.dist.vendor.css));
});
gulp.task('vendor-js', function () {
return gulp.src(path.vendor.js)
.pipe(gulp.dest(path.dist.vendor.js));
});
gulp.task('vendor-css-min', function () {
return gulp.src(path.vendor.css)
.pipe(concat('vendor.css'))
.pipe(cssmin())
.pipe(gulp.dest(path.dist.vendor));
});
gulp.task('build', ['html', 'partials', 'css', 'js', 'vendor-css', 'vendor-js', 'img', 'mock']);
gulp.task('prod', ['html', 'partials', 'css-min', 'js-min', 'vendor-css-min', 'img', 'mock', 'vendor-js']);
gulp.task('watch', function () {
gulp.watch(path.css, ['css']);
gulp.watch(path.js, ['js']);
gulp.watch(path.html, ['html']);
gulp.watch(path.partials, ['partials']);
gulp.watch(path.vendor.css, ['vendor-css']);
gulp.watch(path.vendor.js, ['vendor-js']);
gulp.watch(path.img, ['img']);
gulp.watch(path.mock, ['mock']);
});
gulp.task('serve', ['watch'], function() {
browserSync.init({
server: {
baseDir: path.dist.html
}
});
gulp.watch('dist/**').on('change', browserSync.reload);
});