-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
102 lines (84 loc) · 2.92 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
'use strict';
var gulp = require('gulp');
var source = require('vinyl-source-stream');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var browserify = require('browserify');
var glob = require('glob');
var es = require('event-stream');
var scss = require('gulp-sass');
var concat = require('gulp-concat');
var cleanCSS = require('gulp-clean-css');
var browserSync = require('browser-sync').create();
var exec = require('child_process').exec;
var clean = require('gulp-clean');
var runSequence = require('run-sequence');
var eslint = require('gulp-eslint');
gulp.task('eslint', function() {
return gulp.src(['./crashatmypad/static/js/*.js'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('browserify', ['eslint'], function(done) {
return glob('./crashatmypad/static/js/*.js', function(err, files) {
if(err) done(err);
var tasks = files.map(function(entry) {
return browserify({ entries: [entry] })
.bundle()
.pipe(source(entry))
.pipe(rename({
dirname: ''
}))
.pipe(gulp.dest('./crashatmypad/static/tmp'));
});
es.merge(tasks).on('end', done);
});
});
gulp.task('uglify', ['browserify'], function() {
return gulp.src(['./crashatmypad/static/tmp/*.js'])
.pipe(uglify())
.pipe(gulp.dest('./crashatmypad/static/dist'));
});
gulp.task( 'clean:tmp', ['uglify'], function() {
return gulp.src('./crashatmypad/static/tmp', { read: false })
.pipe(clean());
});
gulp.task('js', ['clean:tmp']);
gulp.task('scss', function() {
return gulp.src(['./crashatmypad/static/scss/*.scss'])
.pipe(scss({"bundleExec": true}))
.pipe(cleanCSS())
.pipe(concat('style.min.css'))
.pipe(gulp.dest('./crashatmypad/static/dist'));
});
gulp.task( 'clean:dist', function() {
return gulp.src('./crashatmypad/static/dist', { read: false })
.pipe(clean());
});
gulp.task('build', function() {
runSequence(
'clean:dist',
['js', 'scss']
);
});
// ----------------------------------------------------------------------------
// tasks for local development
gulp.task('scss-watch', ['scss'], function () { browserSync.reload(); });
gulp.task('js-watch', ['js'], function () { browserSync.reload(); });
gulp.task('watch', function() {
browserSync.init({
proxy: "127.0.0.1:8000"
});
gulp.watch("./crashatmypad/templates/*.html").on('change', function () { browserSync.reload(); });
gulp.watch("./crashatmypad/static/scss/*.scss", ['scss-watch']);
gulp.watch('./crashatmypad/static/js/*.js', ['js-watch']);
});
gulp.task('serve', function() {
runSequence(
'clean:dist',
['js', 'scss'],
'watch'
);
});
gulp.task('default', ['serve']);