forked from ebemunk/chess-dataviz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
88 lines (79 loc) · 1.92 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
var gulp = require('gulp');
//util
var plumber = require('gulp-plumber');
var buffer = require('vinyl-buffer');
var source = require('vinyl-source-stream');
var sourcemaps = require('gulp-sourcemaps');
var browserSync = require('browser-sync').create();
var rename = require('gulp-rename');
//js
var browserify = require('browserify');
var babelify = require('babelify');
var uglify = require('gulp-uglify');
//css
var less = require('gulp-less');
var postcss = require('gulp-postcss');
var autoprefixer = require('autoprefixer');
var mqpacker = require('css-mqpacker');
var csswring = require('csswring');
gulp.task('js', function () {
return browserify({
entries: './src/js/ChessDataViz.js',
debug: true
})
.transform(babelify.configure({
presets: ['es2015']
}))
.bundle()
.on('error', errorHandler)
.pipe(source('ChessDataViz.js'))
.pipe(buffer())
.pipe(gulp.dest('./dist/'))
.pipe(rename('ChessDataViz.min.js'))
.pipe(uglify())
.pipe(gulp.dest('./dist/'))
.pipe(browserSync.reload({stream:true}))
;
});
gulp.task('less', function () {
return gulp.src('./src/less/ChessDataViz.less')
.pipe(plumber())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(less())
.on('error', errorHandler)
.pipe(postcss([
autoprefixer({
browsers: ['last 2 versions']
}),
mqpacker
]))
.pipe(gulp.dest('./dist'))
.pipe(rename('ChessDataViz.min.css'))
.pipe(postcss([
csswring({
removeAllComments: true
})
]))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./dist'))
.pipe(browserSync.reload({stream:true}))
;
});
gulp.task('serve', function() {
return browserSync.init({
server: {
baseDir: './'
},
open: false
});
});
gulp.task('watch', ['serve'], function () {
gulp.watch('src/js/*.js', ['js']);
gulp.watch('src/less/*.less', ['less']);
gulp.watch('test/*.html', browserSync.reload);
});
function errorHandler(err) {
/*eslint no-console: 0*/
console.log(err.message);
this.emit('end');
}