-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.babel.js
executable file
·110 lines (92 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
98
99
100
101
102
103
104
105
import gulp from 'gulp';
import browserSync from 'browser-sync';
import pug from 'gulp-pug';
import runSequence from 'run-sequence';
import gulpLoadPlugins from 'gulp-load-plugins';
import browserify from "browserify";
import babelify from "babelify";
// http://blog.revathskumar.com/2016/02/browserify-with-gulp.html
import source from 'vinyl-source-stream';
import buffer from "vinyl-buffer";
// Arquivo de config
import { Paths } from './config';
// Loading Plugins
const $ = gulpLoadPlugins();
// PATH's dos estáticos
const { images, styles, scripts, views } = Paths;
// Retorna vazio para os casos null e undefined
function checaNullUndefined(arr){
return ((arr === null || arr === undefined) ? "" : arr)
}
// Lint
gulp.task('lint',() => {
return gulp.src('./app/assets/js/**/*.js')
.pipe($.eslint())
.pipe($.eslint.format())
});
// Scripts
gulp.task('browserify',() => {
const bundler = browserify({ entries: './app/assets/js/main.js' , debug: true });
return bundler
.transform(babelify)
.bundle()
.pipe(source('bundle.js'))
.pipe(buffer())
.pipe($.plumber())
.pipe($.sourcemaps.init())
.pipe($.uglify())
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest('./public/dev/js'))
.pipe(browserSync.stream());
});
// Images
gulp.task('images',() => {
gulp.src(images)
.pipe($.imagemin({ optimizationLevel: 5, progressive: true, interlaced: true }))
.pipe(gulp.dest('./public/dev/img'))
.pipe(browserSync.stream());
});
// Sass
gulp.task('sass',() => {
return gulp.src(styles)
.pipe($.plumber())
.pipe($.sass())
.pipe($.sourcemaps.init())
.pipe($.cssnano({ autoprefixer: { browsers: 'last 5 versions', add: true } }))
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest('./public/dev/css/'))
.pipe(browserSync.stream());
});
// Views
gulp.task('views',() => {
return gulp.src('./app/views/index.pug')
.pipe($.plumber())
.pipe(pug({
pretty: true,
data: {
url: "",
}
}))
.pipe(gulp.dest('./public/dev/'))
.pipe(browserSync.stream());
});
// Watch
gulp.task('watch',() => {
gulp.watch(scripts, ['browserify','lint']);
gulp.watch(images, ['images']);
gulp.watch(styles, ['sass']);
gulp.watch(views, ['views']);
}).on('change', browserSync.reload);
// Live browser
gulp.task('browserLive',() => {
browserSync.init({
port: 8000,
server: {
baseDir: [
'./public/dev'
]
}
});
});
// Task's
gulp.task('default',['browserify','lint','sass','images','watch','views','browserLive']);