forked from ringcentral/ringcentral-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
110 lines (83 loc) · 3.14 KB
/
gulpfile.js
File metadata and controls
110 lines (83 loc) · 3.14 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
(function() {
/** @type {gulp.Gulp} */
var gulp = require('gulp'),
gutil = require('gulp-util'),
sourcemaps = require('gulp-sourcemaps'),
path = require('path'),
sourcemapsDebug = false,
webpackConfigure = {
useMemoryFs: true,
progress: false
},
webpackFormat = {
version: true,
timings: true
},
webpackFailAfter = {
errors: true,
warnings: true
};
/**
* Compiles TypeScript modules into a Webpack bundle (including external dependencies CryptoJS, Promise and PUBNUB)
* TODO TypeScript cache
* TODO Export definitions
*/
gulp.task('webpack', [], function() {
var webpack = require('gulp-webpack-build');
return gulp.src('./webpack.config.js', {base: path.resolve('./build')})
.pipe(webpack.init(webpackConfigure))
.pipe(webpack.run())
.pipe(webpack.format(webpackFormat))
.pipe(webpack.failAfter(webpackFailAfter))
.pipe(gulp.dest('./build'));
});
/**
* Replaces Webpack stuff in source map files
*/
gulp.task('sourcemap', ['webpack'], function() {
var replace = require('gulp-replace');
return gulp.src(['./build/rc-sdk.js.map', './build/rc-sdk-bundle.js.map'])
.pipe(replace(/webpack:\/\/\//g, ''))
.pipe(replace(/(\.\.\/src\/)/g, '.$1'))
.pipe(gulp.dest('./build'));
});
/**
* Minifies build and bundle
*/
gulp.task('uglify', ['sourcemap'], function() {
var uglify = require('gulp-uglify'),
rename = require('gulp-rename');
return gulp.src(['./build/rc-sdk.js', './build/rc-sdk-bundle.js'])
.pipe(sourcemaps.init({loadMaps: true, debug: sourcemapsDebug}))
.pipe(uglify())
.pipe(rename({suffix: '.min'}))
.pipe(sourcemaps.write('.', {debug: sourcemapsDebug}))
.pipe(gulp.dest('./build'));
});
/**
* Default Task
*/
gulp.task('default', ['uglify']);
/**
* Watch Task
*
* (!) This will not run version and sourcemap, the one must run full build before commit
*/
gulp.task('watch', ['webpack'], function() {
var webpack = require('gulp-webpack-build');
gulp.watch('./src/**/*.ts').on('change', function(event) {
//gutil.log(gutil.template('File <%= file %> was <%= type %>, running tasks', {file: gutil.colors.magenta(event.path), type: event.type}));
if (event.type === 'changed') {
gulp.src(event.path, {base: path.resolve('./build')})
.pipe(webpack.closest('webpack.config.js'))
.pipe(webpack.init(webpackConfigure))
.pipe(webpack.watch(function(err, stats) {
gulp.src(this.path, {base: this.base})
.pipe(webpack.proxy(err, stats))
.pipe(webpack.format(webpackFormat))
.pipe(gulp.dest('./build'));
}));
}
});
});
})();