-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
56 lines (51 loc) · 1.24 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
const gulp = require('gulp')
const browserSync = require('browser-sync').create()
const reload = browserSync.reload
const concat = require('gulp-concat')
const uglify = require('gulp-uglify')
const pump = require('pump')
const rename = require('gulp-rename')
let jsFragments = [
'./partials/*.js',
'./main.js'
]
let doConcat = function () {
// concat main and partials
return gulp.src(jsFragments)
.pipe(concat('refapp.js', { newLine: ';' }))
.pipe(gulp.dest('./dist/'))
}
// watch JS and html files
gulp.task('serve', function () {
// Serve files from the root of this project
browserSync.init({
server: {
baseDir: './'
},
middleware: function (req, res, next) {
// redirect home to sample folder
if (req.url === '/') {
res.writeHead(301, { Location: '/sample/' })
res.end()
} else {
return next()
}
}
})
gulp.watch(jsFragments).on('change', doConcat)
gulp.watch([
'./sample/**.html',
'./dist/refapp.js',
'./css/*.css'
]).on('change', reload)
})
gulp.task('concat', doConcat)
gulp.task('compress', function (cb) {
// compress file
pump([
gulp.src('./dist/refapp.js'),
uglify(),
rename({ suffix: '.min' }),
gulp.dest('./dist/')
], cb)
})