-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
71 lines (63 loc) · 2.19 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
'use strict';
// Require our Gulp Plugins
const gulp = require('gulp'),
sourcemaps = require('gulp-sourcemaps'),
source = require('vinyl-source-stream'),
buffer = require('vinyl-buffer'),
browserify = require('browserify'),
notify = require('gulp-notify'),
babel = require('babelify'),
chalk = require('chalk'),
sass = require('gulp-sass'),
sassImport = require('sass-module-importer'),
plumber = require('gulp-plumber'),
watch = require('gulp-watch'),
browserSync = require('browser-sync').create();
// Function to handle errors.
// Prevents Gulp from stopping.
var handleError = function(err) {
notify.onError("Doh! Check iTerm for details!")(err);
console.log(chalk.white.bgRed(' <error> ------------------------ '));
console.log(chalk.white(err.message));
console.log(chalk.white.bgRed(' </error> ----------------------- '));
this.emit('end');
}
// Converts SASS into CSS
gulp.task('sass', () => {
gulp.src('./src/sass/main.scss')
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(sass({ importer: sassImport() }).on('error', handleError))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./app/css'));
});
// Converts ES2015+ to ES5 & Supports Modules
gulp.task('browserify', () => {
return browserify('./src/js/main.js', {debug: true})
.transform(babel)
.bundle()
.on('error', handleError)
.pipe(source('./bundle.js'))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./app/js'));
});
// Watches our .scss & .js files for change
gulp.task('watch', () => {
watch('./src/sass/**/*.scss', () => { gulp.start('sass'); });
watch(['./src/js/**/*.js', './package.json'], () => { gulp.start('browserify'); });
watch('./app/**/**', () => { browserSync.reload(); });
});
// Runs a simple browser sync server
gulp.task('server', function(done) {
browserSync.init({
server: "./app",
port: 8080,
// open: false,
notify: false
});
});
// Builds our app
gulp.task('build', ['sass', 'browserify']);
// Starts the development process
gulp.task('start', ['build', 'watch', 'server']);