-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
122 lines (106 loc) · 3.24 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
(function(){
'use strict';
var gulp = require('gulp');
var connect = require('gulp-connect'); //Runs a local dev server
var open = require('gulp-open'); //Open a URL in a web browser
var browserify = require('browserify'); // Bundles JS
var source = require('vinyl-source-stream'); // Use conventional text streams with Gulp
var concat = require('gulp-concat'); //Concatenates files
var jshint = require('gulp-jshint'); //Lint JS files
var sass = require('gulp-sass'); //build Sass
var imagemin = require('gulp-imagemin');//compresses images
var config = {
port: 9005,
devBaseUrl: 'http://localhost',
paths: {
html: './src/*.html',
partials: './src/partials/**/*.html',
js: './src/app.js',
images: [
'./src/images/**/*.gif',
'./src/images/**/*.jpg',
'./src/images/**/*.png'
],
sass: './src/scss/**/*.scss',
dist: './dist',
mainJs: './src/app.js'
}
};
//Start a local development server
gulp.task('connect', function() {
connect.server({
root: ['dist'],
port: config.port,
base: config.devBaseUrl,
livereload: true
});
});
gulp.task('open', ['connect'], function() {
gulp.src('dist/index.html')
.pipe(open({ uri: config.devBaseUrl + ':' + config.port + '/'}));
});
gulp.task('html', function() {
gulp.src(config.paths.html)
.pipe(gulp.dest(config.paths.dist))
.pipe(connect.reload());
});
gulp.task('js', function() {
browserify(config.paths.js)
.bundle()
.on('error', console.error.bind(console))
.pipe(source('bundle.js'))
.pipe(gulp.dest(config.paths.dist + '/scripts'))
.pipe(connect.reload());
});
// gulp.task('css', function() {
// gulp.src(config.paths.css)
// .pipe(concat('bundle.css'))
// .pipe(gulp.dest(config.paths.dist + '/css'))
// .pipe(connect.reload());
// });
gulp.task('partials', function() {
gulp.src(config.paths.partials)
.pipe(gulp.dest(config.paths.dist + '/partials'))
.pipe(connect.reload());
});
// Migrates images to dist folder
// Note that I could even optimize my images here
gulp.task('images', function () {
gulp.src(config.paths.images)
.pipe(imagemin())
.pipe(gulp.dest(config.paths.dist + '/images'))
.pipe(connect.reload());
//publish favicon
gulp.src('./src/favicon.ico')
.pipe(gulp.dest(config.paths.dist));
});
gulp.task('jshint', function() {
return gulp.src(config.paths.js)
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'));
});
gulp.task('sass', function() {
gulp.src(config.paths.sass)
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest(config.paths.dist + '/css/'))
.pipe(connect.reload());
console.log('sass processed');
});
gulp.task('watch', function() {
gulp.watch(config.paths.html, ['html']);
gulp.watch(config.paths.partials, ['partials']);
gulp.watch(config.paths.sass, ['sass']);
gulp.watch(config.paths.images, ['images']);
gulp.watch(config.paths.js, ['js', 'jshint']);
});
gulp.task('default', [
'html',
'js',
'jshint',
'partials',
'images',
'sass',
'open',
'watch'
]);
})();