-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
130 lines (112 loc) · 3.35 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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
const gulp = require('gulp');
const del = require('del');
const shell = require('gulp-shell');
const clean = require('gulp-clean');
const uglify = require('gulp-uglify');
const concatCss = require('gulp-concat-css');
const cleanCSS = require('gulp-clean-css');
const htmlreplace = require('gulp-html-replace');
const concatJs = require('gulp-concat');
const run = require('run-sequence');
const tscConfig = require('./tsconfig.json');
const Builder = require('systemjs-builder');
const builder = new Builder('', 'systemjs.config.js');
const time = new Date().getTime();
// Clean source .ts
gulp.task('clean:ts', function () {
return gulp.src(['./app/**/*.js', './app/**/*.js.map'], { read: false })
.pipe(clean());
});
// Compile source .ts
gulp.task('compile:ts', ['clean:ts'], shell.task([
'tsc'
]));
// Bundle third party plugins.js
gulp.task('bundle:plugins', function () {
return gulp.src('resources/js/**.js')
.pipe(concatJs(time + '.plugins.min.js'))
.pipe(gulp.dest('build'));
});
// Bundle vendor.js
gulp.task('bundle:vendor', function () {
return builder.buildStatic('app/vendor.js', 'build/' + time + '.vendor.min.js')
.catch(function (err) { console.error('vendor.js bundle error! ' + err); });
});
// Bundle main.js
gulp.task('bundle:main', function () {
return builder.buildStatic('app/main.js', 'build/' + time + '.main.min.js')
.catch(function (err) { console.error('main.js bundle error! ' + err); });
});
// Concat css
gulp.task('concat:css', function () {
var glob = ['resources/**/*.css', 'app/**/*.css'];
return gulp
.src(glob)
.pipe(concatCss('build/' + time + '.styles.min.css'))
.pipe(gulp.dest('.'));
});
// Concat js
gulp.task('concat:js', function () {
return gulp.src('build/**.js')
.pipe(concatJs('bundle.min.js'))
.pipe(gulp.dest('build'));
});
// Minify css
gulp.task('minify:css', function () {
return gulp.src('build/*.css')
.pipe(cleanCSS())
.pipe(gulp.dest('build'));
});
// Minify js
gulp.task('minify:js', function () {
return gulp
.src('build/**.js')
.pipe(uglify())
.pipe(gulp.dest('build'));
});
/**
* BUILD TASKS
*/
gulp.task('clean', function () {
return del('build/**/*');
});
gulp.task('compile', function (callback) {
run('compile:ts', function () {
callback();
});
});
gulp.task('bundle', function (callback) {
run('bundle:plugins', 'bundle:vendor', 'bundle:main', function () {
callback();
});
});
gulp.task('concat', function (callback) {
run('concat:css', function () {
callback();
});
});
gulp.task('minify', function (callback) {
run('minify:css', 'minify:js', function () {
callback();
});
});
gulp.task('replace', function () {
gulp.src('index.html')
.pipe(htmlreplace({
'css': time + '.styles.min.css',
'plugins': time + '.plugins.min.js',
'vendor': time + '.vendor.min.js',
'main': time + '.main.min.js'
}))
.pipe(gulp.dest('build'));
});
gulp.task('resources', function () {
return gulp.src(['./resources/**/*'], { base: '.' })
.pipe(gulp.dest('build'));
});
gulp.task('build', function () {
run('clean', 'compile', 'bundle', 'concat', 'minify', 'replace', 'resources');
});
gulp.task('default', function () {
run('build');
});