-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
88 lines (81 loc) · 2.18 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
const gulp = require('gulp');
const babelify = require('babelify');
const browserify = require('browserify');
const browserSync = require('browser-sync');
const buffer = require('vinyl-buffer');
const source = require('vinyl-source-stream');
const plugins = require('gulp-load-plugins');
const jest = require('gulp-jest').default;
/**
* Task: BABEL
*
* @description Babel has support for the latest version of JavaScript through syntax transformers. These plugins allow you to use new syntax, right now without waiting for browser support
* @see https://babeljs.io/docs/setup/#installation
*/
gulp.task('babel', () => {
const b = browserify({ entries: ['src/boot.js'] }).transform(babelify);
function bundle() {
b.bundle()
.on('error', function e(error) {
const args = Array.prototype.slice.call(arguments);
plugins().notify.onError({
title: 'Babel Error',
message: '<%= error.message %>',
}).apply(this, args);
this.emit('end');
})
.pipe(source('boot.js'))
.pipe(buffer())
.pipe(plugins().sourcemaps.init({ loadMaps: true }))
.pipe(plugins().sourcemaps.write('.'))
.pipe(gulp.dest('build/assets/js'))
.pipe(browserSync.stream());
}
bundle();
});
/**
* Task: jest
*/
gulp.task('jest', () => gulp.src('src').pipe(jest({
config: {
testRegex: '(/src/(components/containers)/.*|\\.(test|spec))\\.(jsx?)$',
moduleFileExtensions: [
'js',
'json',
'jsx',
],
transformIgnorePatterns: [
'<rootDir>/build/',
'<rootDir>/node_modules/',
'<rootDir>/src/generators',
],
},
})));
/**
* Task: public
*/
gulp.task('public', () => {
gulp.src(['src/public/**/**'])
.pipe(gulp.dest('build'));
});
/**
* Task: Build
*/
gulp.task('build', ['babel']);
/**
* Task: Serve
*/
gulp.task('serve', ['build'], () => {
browserSync.init({
server: {
baseDir: 'build',
},
});
gulp.watch('src/public/**/**', ['public']).on('change', browserSync.reload);
gulp.watch('src/**/**.js', ['babel']);
gulp.watch('gulpfile.js', ['build']);
});
/**
* Task: Default
*/
gulp.task('default', ['public', 'build', 'serve']);