-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
126 lines (110 loc) · 3.38 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
'use strict';
var gulp = require('gulp'),
gutil = require('gulp-util'),
browserSync = require('browser-sync'),
browserify = require('browserify'),
watchify = require('watchify'),
del = require('del'),
sourcemaps = require('gulp-sourcemaps'),
source = require('vinyl-source-stream'),
buffer = require('vinyl-buffer'),
jshint = require('gulp-jshint'),
uglify = require('gulp-uglify'),
concat = require('gulp-concat'),
minifyCss = require('gulp-minify-css'),
csslint = require('gulp-csslint'),
htmltidy = require('gulp-htmltidy'),
imagemin = require('gulp-imagemin'),
pngquant = require('imagemin-pngquant'),
filesize = require('gulp-filesize'),
babelify = require('babelify'),
//lrload = require('livereactload');
assign = require('lodash.assign');
//add custom browserify options here
var customOpts = {
entries: ['./www/js/app.js'],
transform: [['babelify', {'presets': ['es2015', 'react']}], 'brfs'],
debug: true,
cache: {},
packageCache: {},
fullPaths: true
};
var opts = assign({}, watchify.args, customOpts);
var bundler = browserify(opts);
function bundle() {
return bundler
.bundle()
.on('error', gutil.log)
.pipe(source('app.js'))
.pipe(buffer())
.pipe(filesize())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(filesize())
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./dist/js'));
}
// watch files for changes and reload
gulp.task('serve', ['js'], function() {
var watch = watchify(bundler);
// Without the line, update events won't be fired
watch.bundle().on('data', function() {});
browserSync({
server: {
baseDir: 'dist'
}
});
/* FIXME: separate watch to not rebuild css + js everytime */
gulp.watch(['*.html'], {cwd: 'www'}, ['html', browserSync.reload]);
gulp.watch(['css/**/*.css'], {cwd: 'www'}, ['css', browserSync.reload]);
bundler.on('update', bundle); // on any dep update, runs the bundler
bundler.on('log', gutil.log); // output build logs to terminal
gulp.watch(['js/**/*.js'], {cwd: 'dist'}, browserSync.reload);
});
/**
* Cleaning dist/ folder
*/
gulp.task('clean', function(cb) {
del(['dist/**'], cb);
});
gulp.task('html', function () {
return gulp.src('**/*.html', {cwd: 'www'})
.pipe(htmltidy())
.pipe(gulp.dest('./dist'));
});
gulp.task('css', function () {
return gulp.src('css/**/*.css', {cwd: 'www'})
.pipe(csslint({
'compatible-vendor-prefixes': false,
'box-sizing': false
}))
.pipe(sourcemaps.init())
// .pipe(minifyCss())
.pipe(concat('app.css'))
.pipe(sourcemaps.write())
.pipe(gulp.dest('./dist/css'));
});
/* FIXME: transform jsx to js before linting */
gulp.task('lintjs', function () {
return gulp.src('js/**/*.js', {cwd: 'www'})
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'));
});
//gulp.task('watchjs', function () {
// lrload.monitor('dist/js/app.js', {displayNotification: true});
//});
gulp.task('js', bundle);
gulp.task('imgs', function () {
return gulp.src('**/*.png', {cwd: 'www'})
.pipe(imagemin({
progressive: true,
svgoPlugins: [{removeViewBox: false}],
use: [pngquant()]
}))
.pipe(gulp.dest('dist'));
});
gulp.task('copy-manifest', function(){
return gulp.src('manifest.webapp', {cwd: 'www'})
.pipe(gulp.dest('dist'));
});
gulp.task('build', ['js', 'css', 'imgs', 'html', 'copy-manifest']);
gulp.task('default', ['serve']);