-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
129 lines (112 loc) · 3.7 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
// Require gulp and connect. The require function looks in
// the node_modules for a 'gulp' package and a 'gulp-connect'
// package, and returns the function or object exported from
// those packages. (More on exporting later.)
var gulp = require('gulp');
var connect = require('gulp-connect');
var ghPages = require('gulp-gh-pages');
var sass = require('gulp-sass');
var autoprefixer = require('gulp-autoprefixer');
var rename = require('gulp-rename');
var del = require('del');
var concat = require('gulp-concat');
var watch = require('gulp-watch');
// Common patterns used throughout the gulp configuration
var src = {
allHtml: './src/**/*.html',
allJs: './src/**/*.js',
allFont: './src/**/*.{ttf,woff,otf,eot}',
allScss: './src/**/*.scss',
allImg: './src/**/*.{jpg,png,svg,gif,ico}'
};
// The default task is what runs when you type 'gulp' in the terminal
gulp.task('default', ['clean'], function () {
return gulp.start('html', 'img', 'font', 'js', 'scss', 'watch', 'reload', 'serve');
});
// Serve is a name I made up. You could call it 'dostuff' or whatever.
// The task starts a connect server on port 8000 if you go to
// http://localhost:8000, you can see what is being served.
gulp.task('serve', function () {
connect.server({
root: './dist', // Serve content out of the ./src folder
port: 8000, // Serve on port 8000
livereload: true // Allow us to reload the app in the browser at will
});
});
// The watch task watches a directory for changes and tells the
// browser(s) connected to the server to refresh. I also made this name
// up. In fact, the only name that has intrinsic meaning to gulp is the
// 'default' task.
gulp.task('watch', function () {
watch(src.allHtml, function () {
gulp.start('html');
});
watch(src.allJs, function () {
gulp.start('js');
});
watch(src.allScss, function () {
gulp.start('scss');
});
watch(src.allImg, function () {
gulp.start('img');
});
watch(src.allFont, function () {
gulp.start('font');
});
});
// The reload task tells the connect server to reload all browsers
gulp.task('reload', function () {
watch('./dist/**/*', function () {
gulp.src('./dist/**/*').pipe(connect.reload());
});
});
// Deploy our src folder to gh-pages
gulp.task('deploy', function() {
return gulp.src('./dist/**/*').pipe(ghPages());
});
// Adding the CSS task
gulp.task('scss', function () {
return gulp.src('./src/css/main.scss')
.pipe(sass().on('error', sass.logError))
.pipe(rename('main.css'))
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(gulp.dest('./dist/css'));
});
// For now, we'll just move the JS files straight into dist
// but eventually, we'll minify and combine these, etc
gulp.task('js', ['js:vendor'], function () {
return gulp.src(src.allJs)
.pipe(gulp.dest('./dist'));
});
// Bundle vendor scripts (jQuery, Backbone, etc) into one script (vendor.js)
gulp.task('js:vendor', function () {
return gulp.src([
'./bower_components/jquery/dist/jquery.min.js',
'./bower_components/underscore/underscore-min.js'
])
.pipe(concat('vendor.js'))
.pipe(gulp.dest('./dist/js'));
});
// Let's move our html files into dest, too... Sometime, we'll modify this
// to do minification, cache-busting, etc...
gulp.task('html', function () {
return gulp.src(src.allHtml)
.pipe(gulp.dest('./dist'));
});
// Move any images to the dist folder
gulp.task('img', function () {
return gulp.src(src.allImg)
.pipe(gulp.dest('./dist'));
});
// Move any fonts to the dist folder
gulp.task('font', function () {
return gulp.src(src.allFont)
.pipe(gulp.dest('./dist'));
});
// Clean the destination directory
gulp.task('clean', function (cb) {
del('./dist', cb);
});