-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgulpfile.js
96 lines (83 loc) · 2.73 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
// Copyright (C) 2016 Nokia Corporation and/or its subsidiary(-ies).
var gulp = require('gulp');
var gutil = require('gulp-util');
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var watchify = require('watchify');
var shell = require('gulp-shell');
var uglify = require('gulp-uglify');
var babelify = require("babelify");
var envify = require('envify/custom');
var buffer = require('gulp-buffer');
var rev = require("gulp-rev");
var revReplace = require("gulp-rev-replace");
var buildConfig = require("./build.config.js");
function makeBuild(development) {
process.env.NODE_ENV = 'production';
if(development) {
process.env.NODE_ENV = 'development';
}
var makeBrowserify = function() {
var bundle = browserify("main.js", {
basedir: __dirname + "/web/js",
paths: __dirname + "/web/js",
extensions: [".jsx", ".js"],
cache: {},
debug: development,
packageCache: {}
});
if(development) {
bundle.plugin(watchify);
}
bundle.transform(babelify.configure({
"presets": ["react", "es2015"]
}));
bundle.transform(envify({
NODE_ENV: development ? "development" : "production",
HIDE_HOSTNAME_SUFFIXES: buildConfig.hideHostnameSuffixes,
REFERENCE_MAIL: buildConfig.referenceMail,
AUTH_PAGE: buildConfig.authPage,
DEFAULT_TARGET_PATH: buildConfig.defaultTargetPath,
WEBSOCKET_PORT: buildConfig.websocketPort
}));
return bundle;
};
var b = makeBrowserify();
if(development) {
b.on('update', bundle);
}
function bundle() {
var stream = b.bundle()
.pipe(source('bundle.js'))
.pipe(buffer());
if(!development) {
stream = stream.pipe(uglify())
.pipe(rev())
.pipe(revReplace())
.pipe(gulp.dest('./web/static/js'))
.pipe(rev.manifest());
}
return stream.pipe(gulp.dest('./web/static/js')).on('error', gutil.log);
}
return bundle();
}
gulp.task('assets', function() {
return makeBuild(false);
});
gulp.task('build', ['assets'], function() {
var manifest = gulp.src("./web/static/js/rev-manifest.json");
return gulp.src("./web/static/index.html")
.pipe(revReplace({manifest: manifest}))
.pipe(gulp.dest("./web/static/html/"));
});
gulp.task('dev', ['devAssets'], function() {
return gulp.src("./web/static/index.html")
.pipe(gulp.dest("./web/static/html/"));
});
gulp.task('devAssets', function() {
return makeBuild(true);
});
gulp.task('test', shell.task([
'npm test'
]));
gulp.task('default', ['build']);