-
Notifications
You must be signed in to change notification settings - Fork 4
/
gulpfile.js
140 lines (116 loc) · 3.45 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
137
138
139
140
var gulp = require('gulp'),
browserSync = require('browser-sync'),
reload = browserSync.reload,
sass = require('gulp-sass'),
pleeease = require('gulp-pleeease'),
rename = require('gulp-rename'),
uglify = require('gulp-uglify'),
changed = require('gulp-changed'),
del = require('del'),
path = require("path"),
swig = require("gulp-swig"),
imagemin = require('gulp-imagemin'),
surge = require('gulp-surge'),
options = {
setup: function(swig) {
swig.setDefaults({
cache: false,
loader: swig.loaders.fs(__dirname + '/_partials/') // Set partial path root.
});
}
};
var paths = {
pages: './_pages/',
partials: './_partials/',
assets: './_assets/',
images: './_assets/img/',
js: './_assets/js/',
sass: './_sass/',
outputCss: './_build/assets/css/',
outputJs: './_build/assets/js/',
build: './_build/'
};
// clean: uses del to remove build directory
gulp.task('deleteBuild', function (e) {
del('./_build/', e);
});
// Compile partials and render html files
gulp.task('pages', function() {
gulp.src([
path.join(paths.pages, '**/*.html')
])
.pipe(swig(options))
.pipe(gulp.dest('./_build/'))
.pipe(reload({stream:true}));
});
// Compile sass to css
gulp.task('sass', function() {
gulp.src(path.join(paths.sass, '*.scss'))
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest(paths.outputCss))
.pipe(reload({stream:true}));
});
// Prefix and minify css
gulp.task('minify', function() {
gulp.src(path.join(paths.outputCss, 'style.css'))
.pipe(pleeease())
.pipe(rename({
suffix: '.min',
extname: '.css'
}))
.pipe(gulp.dest(paths.outputCss));
});
// Minify JavaScript
gulp.task('uglify', function() {
gulp.src(path.join(paths.js, '*.js'))
.pipe(uglify())
.pipe(gulp.dest(paths.outputJs));
});
// Copy assets to _build/assets
gulp.task('assets', function() {
gulp.src([
path.join(paths.assets, '**/*.*')
])
.pipe(changed('./_build/assets/'))
.pipe(gulp.dest('./_build/assets/'))
.pipe(reload({stream:true}));
});
// Optimize Images
gulp.task('optimizeImages', function() {
gulp.src(paths.images)
.pipe(imagemin({
progressive: true,
svgoPlugins: [{removeViewBox: false}]
}))
.pipe(gulp.dest('dist/images'));
});
gulp.task('surge', function () {
console.log("Enter the domain which you want to deploy to. Note: It has to be a Surge subdomain, or registered with http://surge.sh");
return surge({
project: paths.build,
domain: '.surge.sh'
})
})
// Setup Browsersync
gulp.task('browsersync', function() {
browserSync({
reloadDelay: 300,
port: 8888,
server: {
baseDir: [__dirname] + '/_build/',
}
});
});
// watch: watch for changes and perform corresponding tasks
gulp.task('watcher', function() {
gulp.watch(path.join(paths.sass, '**/*.scss'), ['sass', 'minify'])
gulp.watch(path.join(paths.sass, '**/*.js'), ['uglify', 'assets'])
gulp.watch(path.join(paths.pages, '**/*.html'), ['pages'])
gulp.watch(path.join(paths.partials, '**/*.html'), ['pages'])
gulp.watch(path.join(paths.assets, '**/*'), ['assets'])
});
// Default Gulp Task
//===========================================
gulp.task('default', ['pages', 'sass', 'minify', 'uglify', 'assets', 'browsersync', 'watcher']);
gulp.task('clean', ['deleteBuild']);
gulp.task('deploy', ['optimizeImages', 'surge']);