-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gulpfile.js
83 lines (69 loc) · 2.08 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
var gulp = require('gulp');
var sourcemaps = require('gulp-sourcemaps');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var browserify = require('browserify');
var babel = require('babelify');
var uglify = require('gulp-uglify');
var eslint = require('gulp-eslint');
var postcss = require('gulp-postcss');
var autoprefixer = require('autoprefixer');
var importCSS = require('postcss-import');
var simpleCSSVars = require('postcss-simple-vars');
var browserSync = require('browser-sync').create();
/** Convert our ES6 JS into a usable form for browsers. */
function buildJS(dev) {
var bundler = browserify('./source/index.js', {debug: dev})
.transform(babel, {presets: ['es2015'], global: true});
return bundler.bundle()
.on('error', function(error) {
console.error(error); this.emit('end');
})
.pipe(source('index.js'))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
//.pipe(uglify({preserveComments: 'license'}))
.pipe(sourcemaps.write())
.pipe(gulp.dest('./build/'));
}
/** Use PostCSS to merge concatenate our CSS together. */
function css() {
var processors = [
importCSS(),
autoprefixer(),
simpleCSSVars()
];
return gulp.src('./source/app.css')
.pipe(postcss(processors))
.pipe(gulp.dest('./build/'));
}
gulp.task('javascript', function() {
return buildJS();
});
gulp.task('javascript_dev', function() {
return buildJS(true);
});
gulp.task('javascriptsync', ['javascript_dev'], function() {
browserSync.reload();
});
gulp.task('serve', function() {
browserSync.init({
server: {
baseDir: './'
},
ghostMode: false
});
gulp.watch('./source/*.css', ['synccss']);
gulp.watch('./source/*.js', ['javascriptsync']);
gulp.watch('./index.html', browserSync.reload);
});
gulp.task('css', css);
gulp.task('synccss', function() {
css().pipe(browserSync.stream());
});
gulp.task('lint', function() {
return gulp.src('source/**/*.js').pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failOnError());
});
gulp.task('default', ['javascript', 'css']);