-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
executable file
·106 lines (97 loc) · 2.56 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
var gulp = require('gulp');
var browserSync = require('browser-sync');
var sass = require('gulp-sass');
var prefix = require('gulp-autoprefixer');
var cssnano = require('gulp-cssnano');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var babel = require('gulp-babel');
var nodemon = require('gulp-nodemon');
/**
* Launch the Server
*/
gulp.task('browser-sync', ['nodemon', 'sass', 'scripts'], function() {
browserSync.init(null, {
proxy: 'localhost:4588',
port: 3588,
});
});
gulp.task('nodemon', function (cb) {
var started = false;
return nodemon({
script: 'app.js'
}).on('start', function () {
if (!started) {
cb();
started = true;
}
});
});
/**
* Compile files from scss
*/
gulp.task('sass', function () {
return gulp.src('src/scss/styles.scss')
.pipe(sass({
includePaths: ['scss'],
onError: browserSync.notify
}))
.pipe(prefix(['last 15 versions', '> 1%', 'ie 8', 'ie 7'], { cascade: true }))
.pipe(gulp.dest('public/'))
.pipe(browserSync.reload({stream:true}))
});
gulp.task('sass-prod', function () {
return gulp.src('src/scss/styles.scss')
.pipe(sass({
includePaths: ['scss'],
onError: browserSync.notify
}))
.pipe(prefix(['last 15 versions', '> 1%', 'ie 8', 'ie 7'], { cascade: true }))
.pipe(cssnano())
.pipe(gulp.dest('public/'))
.pipe(browserSync.reload({stream:true}))
});
/**
* Compile files from js
*/
gulp.task('scripts', function() {
return gulp.src(['src/js/*.js', 'src/js/custom.js'])
.pipe(babel({
presets: ['env']
}))
.pipe(concat('scripts.js'))
.pipe(gulp.dest('public/'))
.pipe(browserSync.reload({stream:true}))
});
gulp.task('scripts-prod', function() {
return gulp.src(['src/js/*.js', 'src/js/custom.js'])
.pipe(babel({
presets: ['es2015']
}))
.pipe(concat('scripts.js'))
.pipe(uglify())
.pipe(gulp.dest('public/'))
.pipe(browserSync.reload({stream:true}))
});
/**
* Reload page when html changes
*/
gulp.task('html', function () {
browserSync.reload();
});
/**
* Watch scss files for changes & recompile
* Watch js files for changes & concatenate
* Watch html files, reload BrowserSync
*/
gulp.task('watch', function () {
gulp.watch(['src/scss/*.scss'], ['sass']);
gulp.watch(['src/js/*.js'], ['scripts']);
gulp.watch(['views/*.html'], ['html']);
});
/**
* Default task, running just `gulp` will compile the sass,
* compile the scripts, launch BrowserSync & watch files.
*/
gulp.task('default', ['browser-sync', 'watch']);
gulp.task('build', ['sass-prod', 'scripts-prod']);