-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
123 lines (106 loc) · 3.1 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
var gulp = require('gulp');
var sass = require('gulp-sass');
var postcss = require('gulp-postcss');
var sourcemaps = require('gulp-sourcemaps');
var autoprefixer = require('autoprefixer');
var babel = require("gulp-babel");
var browserSync = require('browser-sync').create();
var useref = require('gulp-useref');
var uglify = require('gulp-uglify');
var gulpIf = require('gulp-if');
var cssnano = require('gulp-cssnano');
var del = require('del');
var runSequence = require('run-sequence');
var cache = require('gulp-cached');
gulp.task('browserSync', function() {
browserSync.init({
server: {
baseDir: 'dist'
},
})
})
gulp.task('reload', function(){
return gulp.src('dist')
.pipe(browserSync.reload({
stream: true
}))
});
gulp.task('sass', function() {
return gulp.src('app/styles/sass/*.sass')
.pipe(sass())
.pipe(sourcemaps.init())
.pipe(postcss([ autoprefixer() ]))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('app/styles/css'))
})
gulp.task('babel', function() {
return gulp.src('app/scripts/es6/**/*.es6')
.pipe(cache('linting'))
.pipe(babel())
.pipe(gulp.dest('app/scripts/js'))
})
gulp.task('clean:dist', function() {
return del.sync('dist/*');
})
gulp.task('useref', function(){
return gulp.src('app/*.html')
.pipe(useref())
.pipe(gulpIf('app/scripts/js/**/*.js', uglify()))
.pipe(gulpIf('app/styles/css/*.css', cssnano()))
.pipe(gulp.dest('dist'))
});
gulp.task('minifyJS', function(){
return gulp.src('dist/scripts/js/**/*.js')
.pipe(uglify({compress: true, mangle: true}))
.pipe(gulp.dest('dist/scripts/js/'))
});
gulp.task('minifyCSS', function(){
return gulp.src('dist/styles/css/**/*.css')
.pipe(cssnano())
.pipe(gulp.dest('dist/styles/css/'))
});
gulp.task('data', function(){
return gulp.src('app/assets/datasets/**')
.pipe(gulp.dest('dist/assets/datasets/'))
});
gulp.task('updateDev', function (callback) {
runSequence('clean:dist', 'data', 'useref', 'reload',
callback
)
})
gulp.task('updateProd', function (callback) {
runSequence('clean:dist', 'data', 'useref', 'minifyJS', 'minifyCSS', 'reload',
callback
)
})
gulp.task('watchDev', ['browserSync'], function(){
gulp.watch('app/styles/**/*.sass', ['sass']);
gulp.watch('app/scripts/**/*.es6', ['babel']);
gulp.watch('app/*.html', ['updateDev']);
gulp.watch('app/styles/**/*.css', ['updateDev']);
gulp.watch('app/scripts/**/*.js', ['updateDev']);
// Other watchers
})
gulp.task('watchProd', ['browserSync'], function(){
gulp.watch('app/styles/**/*.sass', ['sass']);
gulp.watch('app/scripts/**/*.es6', ['babel']);
gulp.watch('app/*.html', ['updateProd']);
gulp.watch('app/styles/**/*.css', ['updateProd']);
gulp.watch('app/scripts/**/*.js', ['updateProd']);
// Other watchers
})
gulp.task('default', function (callback) {
runSequence('sass', 'babel', 'updateDev', ['watchDev'],
callback
)
})
gulp.task('prod', function (callback) {
runSequence('sass', 'babel', 'updateProd', ['watchProd'],
callback
)
})
gulp.task('build', function (callback) {
runSequence('sass', 'babel', ['updateProd'],
callback
)
})