-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
119 lines (101 loc) · 3.06 KB
/
gulpfile.js
File metadata and controls
119 lines (101 loc) · 3.06 KB
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
const gulp = require('gulp'),
merge = require('merge2'),
runSequence = require('run-sequence'),
del = require('del'),
typescript = require('gulp-typescript'),
tsconfig = require('./tsconfig.json'),
sourcemaps = require('gulp-sourcemaps'),
tslint = require('gulp-tslint'),
browserSync = require('browser-sync'),
concat = require('gulp-concat'),
less = require('gulp-less'),
cleanCss = require('gulp-clean-css');
const paths = {
source: {
css: 'app/**/*.less',
js: 'app/**/*.ts',
html: ['app/**/*.html', '!app/index.html'],
index: 'app/index.html',
config: ['tsconfig.json']
},
build: {
root: 'build',
css: 'build/css',
js: 'build',
html: 'build/app'
}
}
var build = function(complete) {
runSequence('clean', ['check-ts', 'copy-js', 'copy-css', 'copy-html'], complete);
}
gulp.task('clean', function() {
// Create an empty distribution directory to avoid errors (See #1).
return gulp.src('/')
.pipe(gulp.dest(paths.build.root));
del.sync([paths.build.root + '/**/*', '!' + paths.build.root]);
});
gulp.task('copy-html', function() {
gulp.src(paths.source.index)
.pipe(gulp.dest(paths.build.root));
return gulp.src(paths.source.html)
.pipe(gulp.dest(paths.build.html));
});
gulp.task('copy-js', function() {
// Create TS declaration files.
var tsResult = gulp.src(tsconfig.files, {
base: './'
})
.pipe(sourcemaps.init())
.pipe(typescript(tsconfig.compilerOptions));
// Create sourcemaps.
tsResult.js
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest(paths.build.js));
return merge([
tsResult.dts.pipe(gulp.dest(paths.build.js)),
tsResult.js.pipe(gulp.dest(paths.build.js))
]);
});
gulp.task('copy-css', function() {
return gulp.src(paths.source.css)
.pipe(concat('app.css'))
.pipe(less())
.pipe(cleanCss())
.pipe(gulp.dest(paths.build.css))
.pipe(browserSync.stream());
});
gulp.task('check-ts', function() {
return gulp.src(paths.source.js)
.pipe(tslint({
formatter: 'verbose'
}))
.pipe(tslint.report({
emitError: false
}));
});
gulp.task('build', function() {
build(browserSync.reload);
});
gulp.task('start', function() {
build(function() {
browserSync.init({
startPath: paths.build.root,
server: {
baseDir: './'
}
});
// Watch CSS files.
gulp.watch(paths.source.css, ['copy-css']);
// Watch HTML files.
gulp.watch([paths.source.html, paths.source.index], ['copy-html', browserSync.reload]);
// Watch JS files.
gulp.watch(paths.source.js).on('change', function() {
build(browserSync.reload);
});
// Watch configuration files.
gulp.watch(paths.source.config).on('change', function() {
build(browserSync.reload);
});
});
});
gulp.task('default', ['start']);