-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgulpfile.js
75 lines (64 loc) · 1.85 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
'use strict'
const gulp = require('gulp')
const gutil = require('gulp-util')
const plumber = require('gulp-plumber')
const ejs = require('gulp-ejs')
const connect = require('gulp-connect')
const livereload = require('gulp-livereload')
const changed = require('gulp-changed')
const stylus = require('gulp-stylus')
const nib = require('nib')
const minifycss = require('gulp-minify-css')
const config = require('./config/config.json')
const filesToWatch = ['./build/**/*.{html,css,js}']
gulp.task('files', () => {
gulp.src(filesToWatch)
.pipe(livereload())
})
gulp.task('ejs', () => {
const options = { config }
const settings = { ext: '.html' }
return gulp.src('./src/ejs/{index,univille/index}.ejs')
.pipe(ejs(options, settings))
.on('error', gutil.log)
.pipe(gulp.dest('./build'))
})
gulp.task('stylus', () => {
gulp.src('./src/stylus/style.styl')
.pipe(plumber())
.pipe(stylus({
set: ['compress'],
use: [nib()]
}))
.pipe(minifycss())
.pipe(gulp.dest('./build/css'))
})
gulp.task('scripts', () => {
const jsDest = './build/scripts'
gulp.src('./src/scripts/*')
.pipe(changed(jsDest))
.pipe(gulp.dest(jsDest))
})
gulp.task('copy', () => {
const imagesDest = './build/images'
gulp.src('./src/images/**/*')
.pipe(changed(imagesDest))
.pipe(gulp.dest(imagesDest))
})
gulp.task('watch', () => {
livereload.listen()
gulp.watch('src/ejs/**/*.ejs', ['ejs', 'copy'])
gulp.watch('src/stylus/**/*.styl', ['stylus', 'copy'])
gulp.watch('src/scripts/*', ['scripts', 'copy'])
gulp.watch('src/images/**/*', ['copy'])
gulp.watch(filesToWatch, ['files'])
})
gulp.task('build', ['ejs', 'stylus', 'scripts', 'copy'])
gulp.task('webserver', ['build'], () => {
connect.server({
root: 'build',
livereload: true,
port: process.env.PORT || 8080
})
})
gulp.task('default', ['webserver', 'watch'])