-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
117 lines (105 loc) · 3.21 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
// Include Gulp
var gulp = require('gulp');
// Include Plugins
var jade = require('gulp-jade');
var jshint = require('gulp-jshint');
var sass = require('gulp-sass');
var sourceMaps = require('gulp-sourcemaps');
var minifyCSS = require('gulp-minify-css');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var rename = require('gulp-rename');
var browserSync = require('browser-sync').create();
var autoprefixer = require('gulp-autoprefixer');
var plumber = require('gulp-plumber');
var imagemin = require('gulp-imagemin');
var del = require('del');
var gulpSequence = require('gulp-sequence').use(gulp);
// Refresh Browser
gulp.task('browserSync', function() {
browserSync.init({
// proxy: { target: 'localhost/project/app'
server: { baseDir: 'app'
},
options: {
reloadDelay: 250
},
notify: false
});
});
// Jade Compiler
gulp.task('jade', function() {
gulp.src('app/templates/*.jade')
.pipe(plumber())
.pipe(jade({
pretty: true
}))
.pipe(gulp.dest('app'))
.pipe(browserSync.reload({stream: true}))
});
// Lint Task
gulp.task('lint', function() {
return gulp.src('app/js/src/*.js')
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
// Images Minify
gulp.task('images', function(tmp) {
gulp.src(['app/img/*.jpg', 'app/img/*.png', 'app/img/*.jpeg'])
.pipe(plumber())
.pipe(imagemin({ optimizationLevel: 5, progressive: true, interlaced: true }))
.pipe(gulp.dest('dist/img'))
});
// Compile & Concatenate Sass
gulp.task('sass', function() {
return gulp.src('app/sass/*.sass')
.pipe(plumber())
.pipe(sass.sync().on('error', sass.logError))
.pipe(sourceMaps.init())
.pipe(sass())
.pipe(autoprefixer())
.pipe(concat('styles.css'))
.pipe(minifyCSS())
.pipe(sourceMaps.write())
.pipe(gulp.dest('app/css'))
.pipe(browserSync.stream());
});
// Concatenate & Minify JS
gulp.task('scripts', function() {
return gulp.src('app/js/src/*.js')
.pipe(plumber())
.pipe(concat('all.js'))
.pipe(rename('all.min.js'))
.pipe(uglify())
.pipe(gulp.dest('app/js'))
.pipe(browserSync.stream());
});
// Clean Dist Folder
gulp.task('clean', function () {
return del([
'dist/**/*',
]);
});
// Watch Files For Changes
gulp.task('watch', function() {
//gulp.watch('app/library/**/*', browserSync.reload);
gulp.watch('app/templates/**/*', ['jade']);
gulp.watch('app/js/src/*.js', ['lint', 'scripts']);
gulp.watch('app/sass/**/*', ['sass']);
gulp.watch('app/*.+(html|php)', browserSync.reload);
});
// Move To Dist Folder
gulp.task('dist', function() {
gulp.src(['app/js/*.js'])
.pipe(gulp.dest('dist/js/'));
gulp.src(['app/*.+(html|php)'])
.pipe(gulp.dest('dist'));
gulp.src(['app/css/*'])
.pipe(gulp.dest('dist/css'));
//gulp.src(['app/library/**/*'])
//.pipe(gulp.dest('dist/library/'));
});
// Default Task
gulp.task('default', ['lint', 'sass', 'scripts', 'watch', 'browserSync']);
// Deploy Task
gulp.task('deploy', gulpSequence('clean', ['dist', 'images']));