-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
121 lines (101 loc) · 2.81 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
var gulp = require('gulp'),
browserify = require('browserify'),
source = require('vinyl-source-stream'),
imagemin = require('gulp-imagemin'),
concatcss = require('gulp-concat-css'),
uglify = require('gulp-uglify');
rimraf = require('gulp-rimraf');
var browsersync = require('browser-sync').create();
var reload = browsersync.reload;
/** HELPER TASKS **/
// Gulp Task: browserify
// Build JavaScript using Browserify
gulp.task('browserify', function() {
gulp.src('./src/js/settings.js')
.pipe(gulp.dest('./build'))
.pipe(reload({stream: true}));
return browserify('./src/js/main.js')
.exclude('./src/js/settings.js')
.bundle()
.pipe(source('main.js'))
.pipe(gulp.dest('./build'))
.pipe(reload({stream: true}));
});
// Gulp Task: watch
// Automatic reloading with browser-sync
gulp.task('watch', function() {
browsersync.init({
server:{
baseDir: './build'
}
});
gulp.watch('./src/js/*.js',['browserify']);
gulp.watch('./src/php/*.php',['php']);
gulp.watch('./src/images/*.*',['images']);
gulp.watch('./src/css/*.css',['css']);
gulp.watch('./src/index.html',['html']);
gulp.watch('./src/tpl/*.html',['tpl']);
gulp.watch('./src/**/*.html',['html']);
//gulp.watch(['/src/**/*.*'],['build']);
gulp.watch('./build/*.*').on('change',reload);
});
// Gulp Task: tpl
// Page templates
gulp.task('tpl', function() {
return gulp.src('./src/tpl/*.html')
.pipe(gulp.dest('./build/tpl/'))
.pipe(reload({stream: true}));
});
// Gulp Task: html
// Optmized HTML
gulp.task('html', function() {
return gulp.src('./src/index.html')
.pipe(gulp.dest('./build/'))
.pipe(reload({stream: true}));
});
// Gulp Task: php
// Copy PHP
gulp.task('php', function() {
return gulp.src('./src/php/*.php')
.pipe(gulp.dest('./build/php/'))
.pipe(reload({stream: true}));
});
// Gulp Task: css
// Concatenate CSS files
gulp.task('css', function() {
return gulp.src('./src/css/**/*.css')
.pipe(concatcss('main.css'))
.pipe(gulp.dest('./build/'));
});
// Gulp Task: images
// Minify images and copy to build folder
gulp.task('images', function() {
return gulp.src('./src/images/**')
.pipe(imagemin())
.pipe(gulp.dest('./build/images'))
.pipe(reload({stream: true}));
});
// Gulp Task: clean
// Clean the dist folder
gulp.task('clean', function() {
return gulp.src(['./dist/**/*.*','./build/**/*.*'],{read: false})
.pipe(rimraf());
});
/** RUN TASKS **/
// Gulp Task: build
// For local development
gulp.task('build', ['html','tpl','css','php','images','browserify']);
// Gulp Task: dist
// Create a production build
gulp.task('dist', ['build'], function() {
gulp.src('./build/main.js')
.pipe(uglify())
.pipe(gulp.dest('./dist'));
return gulp.src(['./build/**','!./build/main.js'])
.pipe(gulp.dest('./dist'));
});
/*
Gulp Task: default
Default gulp task (no parameters)
*/
gulp.task('default', ['build','watch']);