This repository was archived by the owner on Apr 13, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
74 lines (65 loc) · 1.92 KB
/
gulpfile.js
File metadata and controls
74 lines (65 loc) · 1.92 KB
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
'use strict';
const browserify = require('browserify');
const buffer = require('vinyl-buffer');
const connect = require('gulp-connect');
const gulp = require('gulp');
const livereload = require('gulp-livereload');
const source = require('vinyl-source-stream');
const sourcemaps = require('gulp-sourcemaps');
const uglify = require('gulp-uglify');
const
BABEL_CONFIG = Object.freeze({
presets: ['es2015']
}),
BROWSERIFY_TRANSFORM = 'babelify',
BROWSERIFY_CONFIG = Object.freeze({
debug: true,
json: true,
standalone: 'xapiEvents'
}),
DIST_FILENAME = 'xapi-events.js',
DIST_FILENAME_MIN = 'xapi-events.min.js',
DIST_PATH = 'dist',
MAPS_PATH = './maps',
SRC_FILE = 'src/index.js',
WATCH_FILES = ['src/*.js', 'src/**/*.js', 'test/*.js', 'test/**/*.js']
;
/* Task Config */
const
BUILD_TASK = 'build',
BUILD_PROD_TASK = 'build-prod-task',
CONNECT_TASK = 'connect',
DEFAULT_TASK = 'default',
DEFAULT_TASKS = [BUILD_TASK, BUILD_PROD_TASK],
WATCH_TASK = 'watch',
WATCH_TASKS = [BUILD_TASK]
;
gulp.task(BUILD_TASK, () => {
return browserify(SRC_FILE, BROWSERIFY_CONFIG)
.transform(BROWSERIFY_TRANSFORM, BABEL_CONFIG)
.bundle()
.pipe(source(DIST_FILENAME))
.pipe(gulp.dest(DIST_PATH))
.pipe(livereload());
});
gulp.task(BUILD_PROD_TASK, () => {
return browserify(SRC_FILE, BROWSERIFY_CONFIG)
.transform(BROWSERIFY_TRANSFORM, BABEL_CONFIG)
.bundle()
.pipe(source(DIST_FILENAME_MIN))
.pipe(buffer())
.pipe(sourcemaps.init())
.pipe(uglify())
.pipe(sourcemaps.write(MAPS_PATH))
.pipe(gulp.dest(DIST_PATH))
.pipe(livereload());
});
gulp.task(WATCH_TASK, WATCH_TASKS, () => {
livereload.listen();
connect.server();
gulp.watch(WATCH_FILES, WATCH_TASKS);
});
gulp.task(CONNECT_TASK, () => {
connect.server();
});
gulp.task(DEFAULT_TASK, DEFAULT_TASKS);