-
Notifications
You must be signed in to change notification settings - Fork 3
/
gulpfile.js
69 lines (63 loc) · 2.25 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
const gulp = require('gulp');
const sass = require('gulp-sass');
const concat = require('gulp-concat');
const browserify = require('browserify');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const notify = require('gulp-notify');
const autoprefixer = require('gulp-autoprefixer');
const browserSync = require('browser-sync');
const reload = browserSync.reload;
// run the task method on styles
gulp.task('styles', ()=> {
// return the src of the styles file from the dev folder
return gulp.src('./dev/styles/**/*.scss')
// use the pipe method-sass to check for errors in you sass
.pipe(sass().on('error', sass.logError))
// use the concat method to concat your file into a css file
.pipe(autoprefixer('last 2 versions', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1'))
.pipe(concat('style.css'))
// use the gulp method-dest(ination) to save your new css file
.pipe(gulp.dest('./public/styles'))
// reload page
.pipe(reload({ stream: true }));
});
// create a gulp.task method called js
// takes all of our js code and transpiling
gulp.task('js', () => {
//
browserify('./dev/scripts/main.js', { debug: true })
.transform('babelify', {
sourceMaps: true,
presets: ['env']
})
.bundle()
// if error, notify
.on('error', notify.onError({
message: "Error: <%= error.message %>",
title: 'Error in JS 💀'
}))
// do same thing as above for sass
.pipe(source('main.js'))
.pipe(buffer())
.pipe(gulp.dest('./public/scripts'))
.pipe(reload({stream: true}));
});
// browser sync
gulp.task('bs', ()=> {
browserSync.init({
server: {
// root directory
baseDir: './'
}
})
})
// create a watch method to watch for any changes
gulp.task('watch', ()=>{
// watch this path for changes, run these functions - array so you can add more later
gulp.watch('./dev/styles/**/*.scss', ['styles']);
gulp.watch('./dev/scripts/**/*.js', ['js']);
gulp.watch('*.html', reload);
});
// start browser sync first, then styles, then js, then use the watch task
gulp.task('default', ['bs', 'styles', 'js', 'watch']);