-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
104 lines (84 loc) · 2.89 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
var gulp = require('gulp');
var browserSync = require('browser-sync').create();
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var uglify = require('gulp-uglify');
var log = require('gulplog');
var rename = require('gulp-rename');
var csso = require('gulp-csso');
var autoprefixer = require('gulp-autoprefixer');
var through = require('through');
var isDist = process.argv.indexOf('serve') === -1;
gulp.task('css-index', function () {
return gulp.src('public/stylesheets/index-styles.css')
.pipe(isDist ? csso() : through())
.pipe(isDist ? autoprefixer('last 2 versions', { map: false }) : through())
.pipe(rename('index-styles.min.css'))
.pipe(gulp.dest('public/stylesheets/'));
});
gulp.task('css-admin', function () {
return gulp.src('public/stylesheets/admin-styles.css')
.pipe(isDist ? csso() : through())
.pipe(isDist ? autoprefixer('last 2 versions', { map: false }) : through())
.pipe(rename('admin-styles.min.css'))
.pipe(gulp.dest('public/stylesheets/'));
});
gulp.task('js-admin', function () {
var b = browserify({
entries: 'public/javascripts/admin/index.js',
debug: true
});
return b.bundle()
.pipe(source('public/javascripts/admin/index.js'))
.pipe(buffer())
.pipe(uglify())
.on('error', log.error)
.pipe(rename('build.js'))
.pipe(gulp.dest('public/javascripts/admin/'));
});
gulp.task('css-index-watch', ['css-index'], function (done) {
browserSync.reload();
done();
});
gulp.task('css-admin-watch', ['css-admin'], function (done) {
browserSync.reload();
done();
});
gulp.task('js-index-watch', ['js-index'], function (done) {
browserSync.reload();
done();
});
gulp.task('js-admin-dev', function () {
var b = browserify({
entries: 'public/javascripts/admin/index.js',
debug: true
});
return b.bundle()
.pipe(source('public/javascripts/admin/index.js'))
.pipe(buffer())
.on('error', log.error)
.pipe(rename('build.js'))
.pipe(gulp.dest('public/javascripts/admin/'));
});
gulp.task('js-admin-watch', ['js-admin-dev'], function (done) {
browserSync.reload();
done();
});
gulp.task('reload', function (done) {
browserSync.reload();
done();
});
gulp.task('js', ['js-admin']);
gulp.task('css', ['css-index', 'css-admin']);
gulp.task('default', ['js', 'css']);
gulp.task('serve', function () {
browserSync.init({
proxy: 'http://localhost:' + require('env-port')('8002')
});
gulp.watch('public/views/*.html', ['reload']);
gulp.watch('views/*.ejs', ['reload']);
gulp.watch('public/stylesheets/admin-styles.css', ['css-admin-watch']);
gulp.watch('public/stylesheets/index-styles.css', ['css-index-watch']);
gulp.watch(['public/javascripts/admin/**/**.js', '!public/javascripts/admin/build.js'], ['js-admin-watch']);
});