-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
97 lines (80 loc) · 2.15 KB
/
gulpfile.babel.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
import gulp from 'gulp';
import eslint from 'gulp-eslint';
import babel from 'gulp-babel';
import rename from 'gulp-rename';
import browserify from 'browserify';
import buffer from 'vinyl-buffer';
import del from 'del';
import source from 'vinyl-source-stream';
import sourcemaps from 'gulp-sourcemaps';
import uglify from 'gulp-uglify';
const ALL_SOURCES = [
'*.js',
'lib/*.js',
];
gulp.task('lint', function() {
return gulp.src(ALL_SOURCES)
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});
gulp.task('clean', function() {
return Promise.all([del('dist/'), del('coverage/')]);
});
gulp.task('build', [
'build:bundled:min',
'build:external:min',
'build:bundled:debug',
'build:external:debug',
'build:components',
]);
const bundled_config = {
debug: true,
entries: 'lib/Mailtrap.js',
standalone: 'Mailtrap',
};
const external_config = {
debug: true,
entries: 'lib/Mailtrap.js',
standalone: 'Mailtrap',
external: [
'axios',
'lodash',
],
bundleExternal: false,
};
gulp.task('build:bundled:min', function() {
return buildBundle(bundled_config, '.bundle.min.js', true);
});
gulp.task('build:external:min', function() {
return buildBundle(external_config, '.min.js', true);
});
gulp.task('build:bundled:debug', function() {
return buildBundle(bundled_config, '.bundle.js', false);
});
gulp.task('build:external:debug', function() {
return buildBundle(external_config, '.js', false);
});
gulp.task('build:components', function() {
return gulp.src('lib/*.js')
.pipe(sourcemaps.init())
.pipe(babel())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('dist'));
});
function buildBundle(options, extname, minify) {
let stream = browserify(options)
.transform('babelify')
.bundle()
.pipe(source('Mailtrap.js'))
.pipe(buffer())
.pipe(sourcemaps.init({
loadMaps: true,
}));
if (minify) {
stream = stream.pipe(uglify());
}
return stream.pipe(rename({extname}))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('dist'));
}