-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
136 lines (119 loc) · 4.17 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
"use strict";
var gulp = require('gulp');
var bower = require('main-bower-files');
var gulpif = require('gulp-if');
var jshint = require('gulp-jshint');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var flatten = require('gulp-flatten');
var rename = require('gulp-rename');
var gulpFilter = require('gulp-filter');
var stylus = require('gulp-stylus');
var nib = require('nib');
var connect = require('gulp-connect');
// var browserify = require('browserify');
// var source = require('vinyl-source-stream');
// var buffer = require('vinyl-buffer');
// var sourcemaps = require('gulp-sourcemaps');
// var gutil = require('gulp-util');
var imagemin = require('gulp-imagemin');
var pngquant = require('imagemin-pngquant');
var gifsicle = require('imagemin-gifsicle');
var jpegtran = require('imagemin-jpegtran');
var svgo = require('imagemin-svgo');
var DEBUG = process.env.NODE_ENV === 'production' ? false : true;
// Define paths variables
// grab libraries files from bower_components, minify and push in /public
gulp.task('bower', function() {
var jsFilter = gulpFilter('**/*.js', {restore: true});
var cssFilter = gulpFilter('**/*.css', {restore: true});
var fontFilter = gulpFilter(['**/*.eot', '**/*.woff', '**/*.svg', '**/*.ttf'], {restore: true});
var imgFilter = gulpFilter(['**/*.svg', '**/*.png', '**/*.jpg', '**/*.jpeg']);
var dest_path = 'public/lib';
return gulp.src(bower({debugging: true, includeDev: true}))
// grab vendor js files from bower_components, minify and push in /public
.pipe(jsFilter)
.pipe(gulp.dest(dest_path + '/js/'))
.pipe(gulpif(!DEBUG,uglify()))
.pipe(concat('vendor.js'))
.pipe(rename({
suffix: ".min"
}))
.pipe(gulp.dest(dest_path + '/js/'))
.pipe(jsFilter.restore)
// grab vendor css files from bower_components, minify and push in /public
.pipe(cssFilter)
.pipe(gulp.dest(dest_path + '/css'))
// .pipe(minifycss())
.pipe(rename({
suffix: ".min"
}))
.pipe(gulp.dest(dest_path + '/css'))
.pipe(cssFilter.restore)
// grab vendor font files from bower_components and push in /public
.pipe(fontFilter)
.pipe(flatten())
.pipe(gulp.dest(dest_path + '/fonts'))
.pipe(fontFilter.restore)
.pipe(imgFilter)
.pipe(gulp.dest(dest_path + '/img'));
});
gulp.task('js', function() {
return gulp.src(['src/js/**/*.js', '!src/js/templates/**/*.js'])
.pipe(jshint({
devel: DEBUG
}))
.pipe(jshint.reporter('jshint-stylish'))
.pipe(jshint.reporter('fail'))
.pipe(gulpif(!DEBUG,uglify()))
.pipe(concat('script.js'))
.pipe(gulp.dest('./public/js/'));
});
gulp.task('css', function() {
gulp.src('src/css/style.styl')
.pipe(stylus({
use:nib(),
compress: !DEBUG,
import:['nib']
}))
.pipe(gulp.dest('public/css/'))
.pipe(connect.reload());
});
gulp.task('img', function(){
gulp.src('src/img/**/*')
.pipe(imagemin({
progressive: true,
svgoPlugins: [{removeViewBox: false}],
use: [pngquant(), gifsicle(), jpegtran(), svgo()]
}))
.pipe(gulp.dest('public/img'))
.pipe(connect.reload());
});
gulp.task('html', function() {
gulp.src('./src/*.html')
.pipe(gulp.dest('./public/'))
.pipe(connect.reload());
});
gulp.task('files', function() {
gulp.src(['./src/**.*', '!./src/**.*.html', '!./src/**.*js', '!./src/img/'])
.pipe(gulp.dest('./public/'));
});
gulp.task('video', function() {
gulp.src('./src/video/**.*')
.pipe(gulp.dest('./public/video'));
});
gulp.task('connect', function() {
connect.server({
root: 'public',
livereload: true,
});
});
gulp.task('init', ['css', 'bower', 'js', 'img', 'html', 'files', 'video']);
gulp.task('watch', ['css', 'js', 'img', 'html', 'files', 'connect', 'video'], function() {
gulp.watch('src/css/**/*.styl', ['css']);
gulp.watch('src/js/**/*.js', ['js']);
gulp.watch('src/img/**/*', ['img']);
gulp.watch('src/*.html', ['html']);
gulp.watch('src/video/**/*', ['video']);
gulp.watch(['./src/**.*', '!./src/**.*.html', '!./src/**.*js', '!./src/img/'], ['files']);
});