-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
96 lines (86 loc) · 2.52 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
var gulp = require('gulp');
var gutil = require('gulp-util');
var scss = require('gulp-sass');
var postcss = require('gulp-postcss');
var autoprefixer = require('autoprefixer');
var jade = require('gulp-jade');
var sourcemaps = require('gulp-sourcemaps');
var browserSync = require('browser-sync').create();
var del = require('del');
var imagemin = require('gulp-imagemin');
var pngquant = require('imagemin-pngquant');
var reload = browserSync.reload;
var input = {
//'jade': 'source/jade/**/*.jade',
'jade': 'source/*.jade',
'inhtml': 'source/*.html',
'scss': 'source/scss/**/*.scss',
'javascript': 'source/js/**/*.js',
'images': 'source/img/*',
'vendorjs': 'build/assets/js/vendor/**/*.js'
},
output = {
'outhtml': 'build',
'stylesheets': 'build/css',
'javascript': 'build/js',
'image': 'build/img'
};
// Delete build folder to clean it
gulp.task('clean', function(){
return del.sync(output.outhtml + '/**/*');
});
// Images
gulp.task('images', function() {
return gulp.src(input.images)
.pipe(imagemin({
progressive: true,
svgoPlugins: [{removeViewBox: false}],
use: [pngquant()]
}))
.pipe(gulp.dest(output.image));
});
// sass stuff
gulp.task('scss', function() {
return gulp.src(input.scss)
.pipe(sourcemaps.init())
.pipe(scss({
outputStyle: 'expanded',
sourceComments: false
}))
.pipe(postcss([ autoprefixer({ browsers: ['last 2 versions'] }) ]))
.pipe(sourcemaps.write())
.pipe(gulp.dest(output.stylesheets))
.pipe(browserSync.stream());
});
// jade
gulp.task('jade', function(){
return gulp.src(input.jade)
.pipe(jade({
pretty: true
}))
.pipe(gulp.dest(output.outhtml))
.pipe(browserSync.stream());
});
// copy html
gulp.task('build-html', function() {
// copy any html files in source/ to public/
return gulp.src(input.inhtml)
.pipe(gulp.dest(output.outhtml));
});
// Javascript
gulp.task('build-js', function(){
return gulp.src(input.javascript)
.pipe(gulp.dest(output.javascript));
});
gulp.task('js-watch', ['build-js'], browserSync.reload);
// watch Scss files for changes, run the Scss preprocessor with the 'scss' task and reload
gulp.task('serve', ['clean', 'images', 'jade', 'scss', 'build-js'], function() {
browserSync.init({
server: {
baseDir: 'build'
}
});
gulp.watch(input.jade, ['jade']);
gulp.watch(input.scss, ['scss']);
gulp.watch(input.javascript, ['js-watch']).on('change', reload);
});