-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
86 lines (78 loc) · 2.11 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
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 cleanCss = require('gulp-clean-css')
const header = require('gulp-header')
const sass = require('gulp-sass')
const pump = require('pump')
const rename = require('gulp-rename')
let jsFragments = [
'./main.js',
'./partials/*.js'
]
let doConcat = function () {
// concat main and partials
return gulp.src(jsFragments)
.pipe(concat('restform.js', { newLine: ';\n\n' }))
.pipe(gulp.dest('./dist/'))
}
let compileSass = function () {
// parse SASS to CSS
return gulp.src('./scss/styles.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('./dist/css'))
}
// 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('./scss/*.scss').on('change', compileSass)
gulp.watch([
'./sample/**.html',
'./dist/restform.js',
'./dist/css/*.css'
]).on('change', reload)
})
// comments header
let pkg = require('./package.json')
let banner = ['/**',
' * <%= pkg.name %> - <%= pkg.description %>',
' * @version v<%= pkg.version %>',
' * @link <%= pkg.homepage %>',
' * @author <%= pkg.author %>',
' * @license <%= pkg.license %>',
' */',
''].join('\n')
gulp.task('compress', function (cb) {
pump([
// compress JS file
gulp.src('./dist/restform.js'),
uglify(),
rename({ suffix: '.min' }),
header(banner, { pkg: pkg }),
gulp.dest('./dist/'),
// compress CSS
gulp.src('./dist/css/styles.css'),
cleanCss({ compatibility: 'ie8' }),
rename({ suffix: '.min' }),
gulp.dest('./dist/css/')
], cb)
})
gulp.task('concat', doConcat)
gulp.task('sass', compileSass)