-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
75 lines (66 loc) · 2.34 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
var gulp = require('gulp');
var browserify = require('browserify');
var tsb = require('gulp-tsb');
var watchify = require('watchify');
var assign = require('lodash.assign');
var gutil = require('gulp-util');
var uglify = require('gulp-uglify');
var notifier = require('node-notifier');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var sourcemaps = require('gulp-sourcemaps');
// create and keep compiler
var compilation = tsb.create({
target: 'es3',
module: 'commonjs',
declaration: true,
lib: ["es2015", "es2015.promise", "dom", "es5"],
});
// add custom browserify options here
var customOpts = {
entries: ['./src/unnotify.js'],
debug: true,
standalone: 'unnotify'
};
var opts = assign({}, watchify.args, customOpts);
var b = watchify(browserify(opts));
// Set up src ts build task
gulp.task("srcCompileTS", function () {
return gulp.src('unnotify.ts')
.pipe(compilation()) // <- compilation
.pipe(gulp.dest('./src/'));
});
b.on('update', bundle); // on any dep update, runs the bundler
b.on('log', gutil.log); // output build logs to terminal
function bundle() {
return b.bundle()
// log errors if they happen
.on('error', gutil.log.bind(gutil, 'Browserify Error'))
// source denotes the destination of the minified file. Reads the input from customOpts
.pipe(source('./dist/unnotify.min.js'))
// optional, remove if you don't need to buffer file contents
.pipe(buffer())
// optional, remove if you dont want sourcemaps
.pipe(sourcemaps.init({
loadMaps: true
})) // loads map from browserify file
// Add transformation tasks to the pipeline here.
.pipe(uglify())
.pipe(sourcemaps.write('./')) // writes .map file
.pipe(gulp.dest('./'));
}
gulp.task("srcCompileJS", ["srcCompileTS"], bundle);
gulp.task('notifySRCComplete', ['srcCompileJS'], function () {
notifier.notify({
'title': 'Javascript',
'message': 'SRC Compilation done!'
});
});
// Set up watch task
gulp.task('default', ['srcCompileTS', 'srcCompileJS', 'notifySRCComplete'], function () {
// SRC files watch
gulp.watch('unnotify.ts', ['srcCompileTS', 'srcCompileJS', 'notifySRCComplete'], function () {
// Run srcCompileTS
console.log("Src TS Watch fired!");
});
});