-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
60 lines (54 loc) · 2.19 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
// 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');
// The default task is what runs when you type 'gulp' in the
// terminal. In this case, default depends on 'watch' and 'serve'
// tasks, so those tasks will run any time we tell 'default' to run.
gulp.task('default', ['css', 'watch', '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: './src', // 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 () {
// Here, we tell gulp to watch ./src and any subfolders beneath it
// and when any of those change, gulp will run the 'reload' task.
gulp.watch('./src/**/*', ['reload']);
});
// The reload task tells the connect server to reload all browsers
gulp.task('reload', ['css'], function () {
// This pipe thing is weird but awesome, and we'll talk about it in a
// sec...
gulp.src('./src/**/*').pipe(connect.reload());
});
// Deploy our src folder to gh-pages
gulp.task('deploy', function() {
return gulp.src('./src/**/*').pipe(ghPages());
});
// Adding the CSS task
gulp.task('css', 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('./src/css'));
});