-
Notifications
You must be signed in to change notification settings - Fork 0
/
scripts.js
69 lines (56 loc) · 1.72 KB
/
scripts.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
'use strict';
var path = require('path');
var gulp = require('gulp');
var conf = require('./conf');
var browserSync = require('browser-sync');
var webpack = require('webpack-stream');
var $ = require('gulp-load-plugins')();
function webpackWrapper(watch, test, callback) {
var webpackOptions = {
resolve: { extensions: ['', '.ts'] },
watch: watch,
module: {
preLoaders: [{ test: /\.ts$/, exclude: /node_modules/, loader: 'tslint-loader'}],
loaders: [{ test: /\.ts$/, exclude: /node_modules/, loaders: ['ng-annotate', 'awesome-typescript-loader']}]
},
output: { filename: 'index.module.js' }
};
if(watch) {
webpackOptions.devtool = 'inline-source-map';
}
var webpackChangeHandler = function(err, stats) {
if(err) {
conf.errorHandler('Webpack')(err);
}
$.util.log(stats.toString({
colors: $.util.colors.supportsColor,
chunks: false,
hash: false,
version: false
}));
browserSync.reload();
if(watch) {
watch = false;
callback();
}
};
var sources = [ path.join(conf.paths.src, '/app/index.module.ts') ];
if (test) {
sources.push(path.join(conf.paths.src, '/app/**/*.spec.ts'));
}
return gulp.src(sources)
.pipe(webpack(webpackOptions, null, webpackChangeHandler))
.pipe(gulp.dest(path.join(conf.paths.tmp, '/serve/app')));
}
gulp.task('scripts', function () {
return webpackWrapper(false, false);
});
gulp.task('scripts:watch', ['scripts'], function (callback) {
return webpackWrapper(true, false, callback);
});
gulp.task('scripts:test', function () {
return webpackWrapper(false, true);
});
gulp.task('scripts:test-watch', ['scripts'], function (callback) {
return webpackWrapper(true, true, callback);
});