forked from antonybudianto/angular-starter
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgulpfile.js
More file actions
111 lines (101 loc) · 2.92 KB
/
gulpfile.js
File metadata and controls
111 lines (101 loc) · 2.92 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
var gulp = require('gulp');
var mainBowerFiles = require('main-bower-files');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var minifyCss = require('gulp-minify-css');
var inject = require('gulp-inject');
var ts = require('gulp-typescript');
var liveServer = require('live-server');
var tsProject = ts.createProject('src/tsconfig.json');
var config = require('./gulp.config')();
var clean = require('gulp-clean');
var params = {
port: 8181,
host: "127.0.0.1",
open: '/src',
file: "index.html",
wait: 1000,
};
gulp.task('default', ['serve-dev']);
/* Start live server */
gulp.task('serve-dev', ['wiredep', 'watch-ts'], function () {
liveServer.start(params);
});
/* Watch changed typescripts file and compile it */
gulp.task('watch-ts', function () {
return gulp.watch(config.tsFiles, function (file) {
console.log('Compiling ' + file.path + '...');
return tsProject.src(file.path)
.pipe(ts(tsProject))
.pipe(gulp.dest(config.root));
});
});
/* Compile all typescripts */
gulp.task('compile-ts', function () {
return tsProject.src(config.tsFiles)
.pipe(ts(tsProject))
.pipe(gulp.dest(config.root));
});
/* Wiredep the bower main files to index file */
gulp.task('wiredep', function () {
return gulp.src(config.index)
.pipe(inject(
gulp.src([], {read:false}), {empty: true}
))
.pipe(inject(gulp.src(mainBowerFiles(), {
read: false
}), {
name: 'bower'
}))
.pipe(gulp.dest(config.root));
});
/* Concat and minify/uglify all css, js, and copy fonts */
gulp.task('build-assets', ['styles', 'scripts', 'fonts'], function () {
return gulp.src(config.index)
.pipe(inject(
gulp.src([], {read:false}), {name: 'bower', empty: true}
))
.pipe(inject(
gulp.src([
config.assetPath.lib.css,
config.assetPath.lib.js
],
{
read: false
}),
{
relative: true
}
))
.pipe(gulp.dest(config.root));
});
/* Minify all bower css */
gulp.task('styles', function () {
return gulp.src(mainBowerFiles({
filter: '**/*.css'
}))
.pipe(concat(config.build.assets.lib.css))
.pipe(minifyCss())
.pipe(gulp.dest(config.assets));
});
/* Copy fonts in bower */
gulp.task('fonts', function () {
return gulp.src(mainBowerFiles({
filter: '**/fonts/*.*'
}))
.pipe(gulp.dest(config.assetPath.fonts));
});
/* Uglify all bower js */
gulp.task('scripts', function () {
return gulp.src(mainBowerFiles({
filter: '**/*.js'
}))
.pipe(concat(config.build.assets.lib.js))
.pipe(uglify())
.pipe(gulp.dest(config.assets));
});
/* Clean build folder */
gulp.task('clean', function () {
return gulp.src(config.build.path, {read: false})
.pipe(clean());
});