-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
executable file
·227 lines (215 loc) · 5.38 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
const gulp = require('gulp');
const sass = require('gulp-sass');
const autoprefixer = require('gulp-autoprefixer');
const browserSync = require('browser-sync');
const reload = browserSync.reload;
var exec = require('child_process').exec;
const pug = require('gulp-pug');
const imagemin = require('gulp-imagemin');
const prettyUrl = require('gulp-pretty-url');
var del = require('del');
const gulpEdge = require('gulp-edgejs');
// Compiles SCSS To CSS
gulp.task(
'styles',
gulp.series(() => {
return gulp
.src('assets/scss/**/*.scss')
.pipe(
sass({
outputStyle: 'compressed'
}).on('error', sass.logError)
)
.pipe(
autoprefixer({
browsers: ['last 2 versions']
})
)
.pipe(gulp.dest('./public/css'))
.pipe(browserSync.stream());
})
);
// Use Webpack to compile latest Javascript to ES5
// Webpack on Development Mode
gulp.task(
'webpack:dev',
gulp.series(cb => {
return exec('npm run dev:webpack', function(err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
})
);
// Webpack on Production Mode
gulp.task(
'webpack:prod',
gulp.series(cb => {
return exec('npm run build:webpack', function(err, stdout, stderr) {
console.log(stdout);
console.log(stderr);
cb(err);
});
})
);
// Browser-sync to get live reload and sync with mobile devices
gulp.task(
'browser-sync',
gulp.series(function() {
browserSync.init({
server: './public',
notify: false,
open: false, //change this to true if you want the broser to open automatically
injectChanges: false
});
})
);
// Use Browser Sync With Any Type Of Backend
gulp.task(
'browser-sync-proxy',
gulp.series(function() {
// THIS IS FOR SITUATIONS WHEN YOU HAVE ANOTHER SERVER RUNNING
browserSync.init({
proxy: {
target: 'http://localhost:3333/', // can be [virtual host, sub-directory, localhost with port]
ws: true // enables websockets
}
// serveStatic: ['.', './public']
});
})
);
// Minimise Your Images
gulp.task(
'imagemin',
gulp.series(function minizingImages() {
return gulp
.src('assets/img/**/*')
.pipe(
imagemin([
imagemin.gifsicle({ interlaced: true }),
imagemin.jpegtran({ progressive: true }),
imagemin.optipng({ optimizationLevel: 5 }),
imagemin.svgo({
plugins: [{ removeViewBox: true }, { cleanupIDs: false }]
})
])
)
.pipe(gulp.dest('./public/img'));
})
);
// This is your Default Gulp task
gulp.task(
'default',
gulp.parallel([
gulp.series([
'webpack:dev',
'styles',
function runningWatch() {
gulp.watch('./assets/scss/**/*', gulp.parallel('styles'));
gulp.watch('./assets/js/**/*', gulp.parallel('webpack:dev'));
gulp.watch(['./public/**/*', './public/*']).on('change', reload);
}
]),
gulp.series(['browser-sync'])
])
);
// This is the task when running on a backend like PHP, PYTHON, GO, etc..
gulp.task(
'watch-proxy',
gulp.parallel([
gulp.series([
'webpack:dev',
'styles',
function runningWatch() {
gulp.watch('./assets/scss/**/*', gulp.parallel('styles'));
gulp.watch('./assets/js/**/*', gulp.parallel('webpack:dev'));
gulp.watch(['./public/**/*', './public/*']).on('change', reload);
}
]),
gulp.series(['browser-sync-proxy'])
])
);
// This is the production build for your app
gulp.task('build', gulp.series([gulp.parallel(['styles', 'webpack:prod'])]));
/*
|--------------------------------------------------------------------------
| Static Site Generator
|--------------------------------------------------------------------------
|
| Run These commands below for static site generator
| optional this is if you want to create a static website
|
*/
//
// Generate HTML From Pug or Edge Template Engines
gulp.task(
'views',
gulp.series(
// uncomment one of these functions depending on what template engine you want to use and comment the one you don't want to use
function buildGULPHTML() {
return gulp
.src([
'assets/views/**/*.pug',
'!assets/views/{layouts,layouts/**}',
'!assets/views/{includes,includes/**}'
])
.pipe(pug({ pretty: true }))
.pipe(gulp.dest('./temp'));
},
/* =================== */
// function buildEDGEHTML() {
// return gulp
// .src([
// 'assets/views/**/*.edge',
// '!assets/views/{layouts,layouts/**}',
// '!assets/views/{includes,includes/**}'
// ])
// .pipe(gulpEdge())
// .pipe(gulp.dest('./temp'));
// },
function cleanUrl() {
return gulp
.src('temp/**/*.html')
.pipe(prettyUrl())
.pipe(gulp.dest('public'));
}
)
);
// Delete Your Temp Files
gulp.task(
'cleanTemp',
gulp.series(() => {
return del([
'./temp'
// '!public/img/**/*'
]);
})
);
// Tasks to generate site on development this will also have live reload
gulp.task(
'static-dev',
gulp.parallel([
gulp.series([
'views',
'webpack:dev',
'styles',
'cleanTemp',
function runningWatch() {
gulp.watch('./assets/views/**/*', gulp.series('views'));
gulp.watch('./assets/views/**/*', gulp.series('cleanTemp'));
gulp.watch('./assets/scss/**/*', gulp.parallel('styles'));
gulp.watch('./assets/js/**/*', gulp.parallel('webpack:dev'));
gulp.watch(['./public/**/*', './public/*']).on('change', reload);
}
]),
gulp.series(['browser-sync'])
])
);
// this will run your static site for production
gulp.task(
'static-build',
gulp.series([
gulp.series(['views', 'cleanTemp']),
gulp.parallel(['styles', 'webpack:prod'])
])
);