-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
97 lines (87 loc) · 2.43 KB
/
gulpfile.babel.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
import gulp from 'gulp';
import postcss from 'gulp-postcss';
import sourcemaps from 'gulp-sourcemaps';
import autoprefixer from 'autoprefixer';
import cssnano from 'cssnano';
import cssnext from 'cssnext';
import precss from 'precss';
import watchify from 'watchify';
import browserify from 'browserify';
import babelify from 'babelify';
import source from 'vinyl-source-stream';
import buffer from 'vinyl-buffer';
import rename from 'gulp-rename';
import sequence from 'gulp-sequence';
import browserSyncObj from 'browser-sync';
const browserSync = browserSyncObj.create();
const reload = browserSync.reload;
gulp.task('css', function() {
const processors = [
autoprefixer,
cssnext,
precss,
cssnano
];
return gulp.src('./public/css/*.scss')
.pipe(sourcemaps.init())
.pipe(postcss(processors))
.pipe(sourcemaps.write('.'))
.pipe(rename('style.css'))
.pipe(gulp.dest('./public'))
.pipe(reload({
stream: true
}));
});
gulp.task('template', function() {
return gulp.src('./public/template/*.ejs')
.pipe(reload({
stream: true
}));
});
gulp.task('ejs', function() {
return gulp.src('./views/*.ejs')
.pipe(reload({
stream: true
}));
});
const browserify_instance = watchify(browserify({
entries: './public/js/index.es6',
debug: true
}).transform(babelify, {
presets: ['es2015']
}));
gulp.task('es6', bundleJs);
function bundleJs() {
return browserify_instance
.bundle()
.on('error', function(err) {
console.log(err.toString());
this.emit('end');
})
.pipe(source('index.js'))
.pipe(buffer())
.pipe(gulp.dest('./public'))
.pipe(reload({
stream: true
}));
}
gulp.task('img', function() {
return gulp.src('./public/img/*')
.pipe(reload({
stream: true
}));
});
gulp.task('compile', function(cb) {
sequence(['css', 'template', 'ejs', 'es6', 'img'], cb);
});
gulp.task('default', ['compile'], function() {
browserSync.init({
proxy: 'localhost:3123'
});
gulp.watch('./views/*.ejs', ['ejs']);
gulp.watch('./public/template/*.ejs', ['template']);
gulp.watch('./public/css/*.scss', ['css']);
browserify_instance.on('update', bundleJs);
gulp.watch('./public/js/**/*', ['es6']);
gulp.watch('./public').on('change', reload);
});