-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
52 lines (47 loc) · 1.22 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
var gulp = require('gulp');
var browserify = require('browserify');
var source = require('vinyl-source-stream');
var watchify = require('watchify');
var tsify = require('tsify');
var gutil = require('gulp-util');
var paths = {
files: [
'src/*.html',
'src/css/*',
'src/images/**/*'
]
};
var watchedBrowserify = watchify(browserify({
basedir: '.',
debug: true,
entries: [
'src/main.ts'
],
cache: {},
packageCache: {}
}).plugin(tsify));
gulp.task("copy-files", function() {
return gulp.src(paths.files, { 'base': './src/'})
.pipe(gulp.dest("dist"));
});
gulp.task('copy-changes', function() {
return gulp.watch(paths.files, function(obj) {
if ( obj.type === 'changed' || obj.type === 'added' ) {
console.log('copying changed file: ' + obj.path + ' to dist folder');
gulp.src( obj.path, { 'base': './src/'})
.pipe(gulp.dest('./dist'));
}
})
});
function bundle() {
return watchedBrowserify
.bundle()
.on('error', function(err) {
console.log(err.message);
})
.pipe(source('bundle.js'))
.pipe(gulp.dest('dist'));
}
gulp.task('default', gulp.series('copy-files', bundle));
watchedBrowserify.on('update', bundle);
watchedBrowserify.on('log', gutil.log);