-
Notifications
You must be signed in to change notification settings - Fork 66
/
gulpfile.js
56 lines (43 loc) · 1.26 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
var gulp = require('gulp'),
watch = require('gulp-watch'),
babel = require('gulp-babel'),
path = require('path'),
plumber = require('gulp-plumber'),
sourcemaps = require('gulp-sourcemaps');
var paths = {
src: {src: 'src/**/*.js', dest: 'dist'}
};
function isAdded(file) {
return file.event === 'added' || file.event === 'deleted' || file.event === 'renamed';
}
function handleError(err) {
console.log(err.toString());
this.emit('end');
}
var escapeContent = function(content) {
return content.replace(/"/g, '\\"').replace(/\r?\n/g, '" +\n "');
};
var run = function (watched, babelOpts) {
(watched ?
watch(paths.src.src, {silent: false}) :
gulp.src(paths.src.src))
.pipe(plumber())
.pipe(sourcemaps.init())
.pipe(babel(babelOpts))
.pipe(sourcemaps.write('./sourcemaps', {includeContent: false, sourceRoot: '/src'}))
.pipe(gulp.dest(paths.src.dest));
};
gulp.task('watch', function () {
run(false);
run(true);
});
gulp.task('default', function () {
run(false);
});
gulp.task('frontend', function () {
run(false, {presets: ['es2015']});
});
gulp.task('frontend-watch', function () {
run(false, {presets: ['es2015']});
run(true, {presets: ['es2015']});
});