-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
executable file
·95 lines (85 loc) · 2.78 KB
/
gulpfile.babel.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
import gulp from 'gulp'
import rimraf from 'rimraf'
import sass from 'gulp-sass'
import browserSyncModule from 'browser-sync'
import autoprefixer from 'gulp-autoprefixer'
import gutil from 'gulp-util'
import plumber from 'gulp-plumber'
import notify from 'gulp-notify'
import inlineCss from 'gulp-inline-css'
var browserSync = browserSyncModule.create()
const config = {
inFiles: {
path: 'src/',
html: 'src/*.html',
css: 'src/*.{sass,scss,css}'
},
outFiles: {
path: 'build/',
html: 'build/*.html'
}
}
gutil.log('- - - - - - - - - - - - - - -')
gutil.log(' Starting! ')
gutil.log('')
gutil.log(' _._ _,-\'""`-._')
gutil.log('(,-.`._,\'( |\`-/|')
gutil.log(' `-.-\' \ )-`( , o o)')
gutil.log('-bf- `- \`_`"\'-')
gutil.log('')
gutil.log('- - - - - - - - - - - - - - -')
// -------------------------------------------------------
//
// DEVELOPMENT TASK
//
// -------------------------------------------------------
// -------------------------------------------------------
// Utility: A `rm -rf` util for nodejs
gulp.task('clean', function (cb) {
return rimraf(config.outFiles.path, cb)
})
// -------------------------------------------------------
// Development: Open server
gulp.task('server', function () {
return browserSync.init({
server: {baseDir: config.outFiles.path},
ui: false,
})
})
// -------------------------------------------------------
// Development: Compile Sass
gulp.task('sass', function () {
return gulp.src(config.inFiles.css)
.pipe(plumber({errorHandler: (err) => {
notify.onError({ title: "Gulp", subtitle: "Failure!", message: "Error: <%= error.message %>", sound: "Beep" })(err)
this.emit("end")
}
}))
.pipe(sass({includePaths: 'node_modules/'}))
.pipe(autoprefixer({ browsers: ['> 5% in IT', 'ie >= 8'] }))
.pipe(gulp.dest(config.outFiles.path))
.pipe(notify({ message: 'Sass compiled' }))
.pipe(browserSync.stream())
})
// -------------------------------------------------------
// Development: Copy HTML files
gulp.task('html', ['sass'], function () {
return gulp.src(config.inFiles.html)
.pipe(inlineCss({
url: "file://" + __dirname + "/" + config.outFiles.path
}))
.pipe(gulp.dest(config.outFiles.path))
.pipe(browserSync.stream())
})
// -------------------------------------------------------
// Development: Copy Images files
gulp.task('copy:images', function () {
return gulp.src(['src/images/**/*'])
.pipe(gulp.dest(config.outFiles.path + 'images'))
.pipe(notify({ message: 'Copy images task complete' }))
});
// -------------------------------------------------------
gulp.task('watch', ['html', 'server', 'copy:images'], function () {
gulp.watch(config.inFiles.css, ['html'])
gulp.watch(config.inFiles.html, ['html', 'copy:images'])
})