This repository has been archived by the owner on Jun 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
75 lines (61 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
var gulp = require('gulp'),
htmlhint = require('gulp-htmlhint'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
jshint = require('gulp-jshint'),
minifyCSS = require('gulp-minify-css'),
browserify = require('browserify'),
babelify = require('babelify'),
buffer = require('vinyl-buffer'),
source = require('vinyl-source-stream');
var watchify = require('watchify');
gulp.task('build', function() {
gulp.src('./index.html')
.pipe(htmlhint())
.pipe(htmlhint.reporter());
gulp.src(['node_modules/leaflet/dist/leaflet.js', 'src/js/leaflet-pan-to-offset.js', 'node_modules/leaflet-hash/leaflet-hash.js'])
.pipe(concat('leaflet.min.js'))
.pipe(uglify())
.pipe(gulp.dest('./dist/js/'));
});
gulp.task('css-min', function() {
gulp.src(['src/css/bootstrap.min.css', 'node_modules/leaflet/dist/leaflet.css', 'src/css/animate.min.css', 'src/css/styles.css'])
.pipe(concat('styles.min.css'))
.pipe(minifyCSS())
.pipe(gulp.dest('./dist/css/'));
})
gulp.task('watch', ['browserify-watch'], function() {
// gulp.watch('src/js/components/*.js', ['browserify-babel']);
gulp.watch('src/css/*.css', ['css-min']);
gulp.watch('index.html', ['build']);
});
function buildBundle(watch) {
var bundler = browserify({
entries: 'src/js/index.js',
extensions: ['.jsx', '.js'],
debug: true
});
if (watch) {
bundler = watchify(bundler);
bundler.on('update', function() {
bundleShare(bundler);
});
}
bundleShare(bundler);
}
function bundleShare(b) {
console.log('bundling')
return b.transform(babelify)
.bundle()
.pipe(source('bundle.min.js'))
.pipe(buffer())
.pipe(uglify())
.pipe(gulp.dest('./dist/js'));
}
gulp.task('browserify-watch', function() {
buildBundle(true);
});
gulp.task('browserify-no-watch', function() {
buildBundle(false);
});
gulp.task('default', ['build', 'css-min', 'browserify-no-watch']);