-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
75 lines (64 loc) · 1.96 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
/* ------------------------
MODULE REGISTRATION
------------------------ */
var del = require('del'),
gulp = require('gulp'),
sourcemaps = require('gulp-sourcemaps'),
ts = require('gulp-typescript'),
browserify = require('browserify'),
source = require('vinyl-source-stream'),
tsify = require('tsify'),
connect = require('gulp-connect');
/* ------------------------
VARIABLES
------------------------ */
var path = {
outputDir: './dist/', //output application directory
sourceDir: './src/', // source directory
appDir: './src/app/', // application directory
};
var config = {
mainFile: 'index.ts',
resultFile: 'application.js'
};
//define typescript project config file
var tsProject = ts.createProject(path.sourceDir + 'tsconfig.json');
/* ------------------------
TASKS
------------------------ */
// clean the contents of the distribution directory
gulp.task('clean', function () {
return del(path.outputDir + '**/*');
});
// copy static assets - i.e. non TypeScript compiled source
gulp.task('copy:assets', function() {
return gulp.src([path.appDir + '**/*', path.sourceDir + 'index.html', path.sourceDir + 'styles.css', '!'+ path.appDir +'**/*.ts'])
.pipe(gulp.dest('dist'))
});
// define typescript compilation
gulp.task('compile-js', ['clean'] ,function() {
var bundler = browserify({ basedir: path.appDir})
.add(config.mainFile)
.plugin(tsify);
return bundler
.bundle()
.pipe(source(config.resultFile))
.pipe(gulp.dest('dist'));
/* var tsResult = tsProject.src()
.pipe(sourcemaps.init())
.pipe(tsProject())
.js.pipe(gulp.dest('dist'));
return tsResult;*/
});
// define dev file server with LIVERELOAD
gulp.task('connect', function () {
connect.server({
root: 'dist',
livereload: true
});
});
// define files to watch
gulp.task('watch', function() {
gulp.watch(path.sourceDir + '*.ts', ['compile-js', 'copy:assets']);
});
gulp.task('default', ['connect', 'watch']);