-
Notifications
You must be signed in to change notification settings - Fork 1
/
gulpfile.js
93 lines (85 loc) · 2.91 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
const gulp = require('gulp'),
browserSync = require('browser-sync').create(),
sass = require('gulp-sass'),
cssmin = require('gulp-cssmin'),
cssComments = require('gulp-strip-css-comments'),
babel = require('gulp-babel'),
uglify = require('gulp-uglify'),
concat = require('gulp-concat'),
inject = require('gulp-inject'),
autoprefix = require('gulp-autoprefixer'),
notify = require('gulp-notify'),
gulpIf = require('gulp-if'),
cleanCss = require('gulp-clean-css'),
rev = require('gulp-rev'),
del = require('del'),
reload = browserSync.reload;
//Task clean js and css
gulp.task('clean-js', () => {
return del([
'./src/build/**/*.js'
]);
});
gulp.task('clean-css', () => {
return del([
'./src/build/**/*.css'
]);
});
//compile sass in css
gulp.task('sass', ['clean-css'], () => {
return gulp.src("./src/styles/scss/**/*.scss")
.pipe(sass({outputStyle: 'compressed'}))
.pipe(concat('bundle.min.css'))
.pipe(cssComments({all: true}))
.pipe(autoprefix({browsers: ['last 3 versions', '> 5%'], cascade: false}))
.pipe(cleanCss())
.pipe(rev())
.pipe(gulp.dest("./src/build/css"))
.pipe(rev.manifest('./src/build/rev-manifest.json', {
merge: true
}))
.pipe(gulp.dest(''))
.pipe(browserSync.stream())
.pipe(notify('[OK] - Compilação do SASS para CSS'));
});
//Transpile ES6
gulp.task('esJs', ['clean-js'], () => {
return gulp.src('./src/js/*.js')
.pipe(babel({presets: ['es2015']}))
.pipe(concat('bundle.min.js'))
.pipe(gulpIf('*.js', uglify()))
.pipe(rev())
.pipe(gulp.dest('./src/build/js'))
.pipe(rev.manifest('./src/build/rev-manifest.json', {
merge: true
}))
.pipe(gulp.dest(''))
.pipe(browserSync.stream())
.pipe(notify('[OK] - Transpile do JSEs6 para JS'));
});
//Inject js and css
gulp.task('index-inject', ['sass', 'esJs'], () => {
return gulp.src('./src/**/*.html')
.pipe(inject(gulp.src(['./src/build/css/*.css', './src/build/js/*.js'], {read: false}), {relative: true}))
.pipe(gulp.dest('./src/'))
.pipe(browserSync.stream())
.pipe(notify('[OK] - Injeção do JS e CSS na página index'));
});
//Task server
gulp.task('serve', ['sass', 'esJs', 'index-inject'], () => {
browserSync.init({
server: "./src"
});
gulp.watch("./src/styles/scss/**/*.scss", ['index-inject']);
gulp.watch("./src/js/**/*.js", ['index-inject']);
gulp.watch("./src/**/*.html", ['index-inject']).on("change", reload);
});
//Tasks
gulp.task('default', [
'serve',
'esJs',
'sass',
'index-inject',
'clean-js',
'clean-css'
]);