-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
103 lines (89 loc) · 2.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
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
'use strict';
var gulp = require('gulp'),
watch = require('gulp-watch'),
plumber = require('gulp-plumber'),
prefixer = require('gulp-autoprefixer'),
uglify = require('gulp-uglify'),
rename = require('gulp-rename'),
sass = require('gulp-sass'),
connect = require('gulp-connect'),
opn = require('opn');
var path = {
build: {
all: 'build'
},
src: {
html: 'src/*.html',
js: 'src/*.js',
style: 'src/*.sass'
},
watch: {
html: 'src/**/*.html',
js: 'src/**/*.js',
style: 'src/**/*.sass'
},
clean: './build'
};
var server = {
host: 'localhost',
port: '9000'
};
gulp.task('html:build', function () {
gulp.src(path.src.html)
.pipe(plumber())
.pipe(gulp.dest(path.build.all))
.pipe(connect.reload());
});
gulp.task('js:build', function () {
gulp.src(path.src.js)
.pipe(plumber())
.pipe(gulp.dest(path.build.all))
.pipe(rename(function (pth) {
pth.basename += ".min";
}))
.pipe(uglify({
preserveComments: 'some'
}))
.pipe(gulp.dest(path.build.all))
.pipe(connect.reload());
});
gulp.task('style:build', function () {
gulp.src(path.src.style)
.pipe(plumber())
.pipe(sass({
indentedSyntax: true
}))
.pipe(prefixer('last 15 versions'))
.pipe(gulp.dest(path.build.all))
.pipe(connect.reload());
});
gulp.task('build', [
'html:build',
'js:build',
'style:build'
]);
gulp.task('webserver', function() {
connect.server({
host: server.host,
port: server.port,
livereload: true
});
});
gulp.task('clean', function (cb) {
rimraf(path.clean, cb);
});
gulp.task('openbrowser', function() {
opn( 'http://' + server.host + ':' + server.port + '/build/demo.html');
});
gulp.task('watch', function(){
watch([path.watch.html], function(event, cb) {
gulp.start('html:build');
});
watch([path.watch.style], function(event, cb) {
gulp.start('style:build');
});
watch([path.watch.js], function(event, cb) {
gulp.start('js:build');
});
});
gulp.task('default', ['build', 'webserver', 'watch', 'openbrowser']);