-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
75 lines (61 loc) · 2.04 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
var gulp = require('gulp')
var buffer = require('vinyl-buffer')
var source = require('vinyl-source-stream')
var browserSync = require("browser-sync").create()
var browserify = require('browserify')
var sourcemaps = require('gulp-sourcemaps')
var sass = require('gulp-sass')
var prefixer = require('gulp-autoprefixer')
var notify = require('gulp-notify')
var babel = require('gulp-babel')
var plumber = require('gulp-plumber')
var JS_CONFIG = {
source: './js/**/*.js',
entry: './js/main.js',
output: {
dir: './',
name: 'main.js'
}
}
var SASS_CONFIG = {
source: './scss/**/*.scss',
entry: './scss/main.scss',
output: {
dir: './',
name: 'main.css'
}
}
var BROWSERIFY_CONFIG = {
entries: JS_CONFIG.entry,
debug: true
}
gulp.task('default', ['buildjs', 'sass'], function() {
gulp.watch(JS_CONFIG.source, ['buildjs'], browserSync.reload())
gulp.watch(SASS_CONFIG.source, ['sass'])
})
gulp.task('buildjs', function(){
var b = browserify(BROWSERIFY_CONFIG)
return b.bundle()
.on('error', notify.onError('JS ERROR: <%= error.message %>'))
.pipe(source(JS_CONFIG.output.name))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(babel())
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(JS_CONFIG.output.dir))
.pipe(notify({message: 'Compiled JS', onLast:true}))
})
gulp.task('sass', function () {
gulp.src(SASS_CONFIG.entry)
.pipe(plumber({errorHandler: notify.onError("<%= error.message %> \n\n→ <%= error.fileName %> \n\n@ <%= error.lineNumber %>")}))
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(prefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(sourcemaps.write())
.pipe(gulp.dest(SASS_CONFIG.output.dir + SASS_CONFIG.output.name))
.pipe(browserSync.stream())
.pipe(notify('Compiled SASS dev'))
})