forked from getbase/base
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
107 lines (97 loc) · 2.9 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
// Base Gulp File
var gulp = require('gulp'),
watch = require('gulp-watch'),
sass = require('gulp-sass'),
less = require('gulp-less'),
path = require('path'),
notify = require('gulp-notify'),
inlinesource = require('gulp-inline-source'),
browserSync = require('browser-sync'),
imagemin = require('gulp-imagemin'),
cache = require('gulp-cache'),
uglify = require('gulp-uglify'),
runSequence = require('run-sequence');
// Task to compile SCSS
gulp.task('sass', function () {
return gulp.src('./src/scss/style.scss')
.pipe(sass({
errLogToConsole: false,
paths: [ path.join(__dirname, 'scss', 'includes') ]
})
.on("error", notify.onError(function(error) {
return "Failed to Compile SCSS: " + error.message;
})))
.pipe(gulp.dest('./src/'))
.pipe(gulp.dest('./dist/'))
.pipe(browserSync.reload({
stream: true
}))
.pipe(notify("SCSS Compiled Successfully :)"));
});
// Task to compile LESS
gulp.task('less', function () {
return gulp.src('./src/less/style.less')
.pipe(less({ paths: [ path.join(__dirname, 'less', 'includes') ]
})
.on('error', function(err) {
this.emit('end');
}))
.on("error", notify.onError(function(error) {
return "Failed to Compile LESS: " + error.message;
}))
.pipe(gulp.dest('./src/'))
.pipe(gulp.dest('./dist/'))
.pipe(browserSync.reload({
stream: true
}))
.pipe(notify("LESS Compiled Successfully :)"));
});
// Task to move compiled CSS to `dist` folder
gulp.task('movecss', function () {
return gulp.src('./src/style.css')
.pipe(gulp.dest('./dist/'));
});
// Task to Minify JS
gulp.task('jsmin', function() {
return gulp.src('./src/js/**/*.js')
.pipe(uglify())
.pipe(gulp.dest('./dist/js/'));
});
// Minify Images
gulp.task('imagemin', function (){
return gulp.src('./src/img/**/*.+(png|jpg|jpeg|gif|svg)')
// Caching images that ran through imagemin
.pipe(cache(imagemin({
interlaced: true
})))
.pipe(gulp.dest('./dist/img'));
});
// BrowserSync Task (Live reload)
gulp.task('browserSync', function() {
browserSync({
server: {
baseDir: './src/'
},
})
});
// Gulp Inline Source Task
// Embed scripts, CSS or images inline (make sure to add an inline attribute to the linked files)
// Eg: <script src="default.js" inline></script>
// Will compile all inline within the html file (less http requests - woot!)
gulp.task('inlinesource', function () {
return gulp.src('./src/**/*.html')
.pipe(inlinesource())
.pipe(gulp.dest('./dist/'));
});
// Gulp Watch Task
gulp.task('watch', ['browserSync'], function () {
gulp.watch('./src/scss/**/*', ['sass']),
gulp.watch('./src/less/**/*', ['less']);
gulp.watch('./src/**/*.html').on('change', browserSync.reload);
});
// Gulp Default Task
gulp.task('default', ['watch']);
// Gulp Build Task
gulp.task('build', function() {
runSequence('movecss', 'imagemin', 'jsmin', 'inlinesource');
});