-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
97 lines (81 loc) · 2.62 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
var gulp = require('gulp');
var browserify = require('browserify');
var watchify = require('watchify');
var babelify = require('babelify');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var merge = require('utils-merge');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var sourcemaps = require('gulp-sourcemaps');
var babel = require('gulp-babel');
/* nicer browserify errors */
var gutil = require('gulp-util');
var chalk = require('chalk');
function map_error(err) {
if (err.fileName) {
// regular error
gutil.log(chalk.red(err.name)
+ ': '
+ chalk.yellow(err.fileName.replace(__dirname + '/public/js/', ''))
+ ': '
+ 'Line '
+ chalk.magenta(err.lineNumber)
+ ' & '
+ 'Column '
+ chalk.magenta(err.columnNumber || err.column)
+ ': '
+ chalk.blue(err.description))
} else {
// browserify error..
gutil.log(chalk.red(err.name)
+ ': '
+ chalk.yellow(err.message))
}
//this.end()
}
/* */
gulp.task('watchify', function () {
var args = merge(watchify.args, { debug: true });
var bundler = watchify(browserify('./public/app.jsx', args)).transform(babelify, {presets: ["es2015", "react"]});
bundle_js(bundler);
bundler.on('update', function () {
bundle_js(bundler)
})
});
function bundle_js(bundler) {
return bundler.bundle()
.on('error', map_error)
.pipe(source('bundle.js'))
.pipe(buffer())
.pipe(gulp.dest('public/build'))
.pipe(rename('bundle.min.js'))
.pipe(sourcemaps.init({ loadMaps: false }))
// capture sourcemaps from transforms
.pipe(uglify())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('public/build'))
}
// Without watchify
gulp.task('browserify', function () {
var bundler = browserify('./public/app.jsx', { debug: false }).transform(babelify, {presets: ["es2015", "react"]});
return bundle_js(bundler);
});
gulp.task('babel', () => {
return gulp.src('./public/js/**/*.js')
.pipe(babel({
presets: ['es2015']
}))
.pipe(gulp.dest('public/lib'));
});
// Without sourcemaps
gulp.task('browserify-production', function () {
var bundler = browserify('./public/app.js').transform(babelify, {presets: ["es2015", "react"]});
return bundler.bundle()
.on('error', map_error)
.pipe(source('bundle.js'))
.pipe(buffer())
.pipe(rename('bundle.min.js'))
.pipe(uglify())
.pipe(gulp.dest('old_public/build'))
});