-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
178 lines (154 loc) · 3.79 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
var ts = require('gulp-typescript');
var del = require('del');
var pkg = require('./package.json');
var gulp = require('gulp');
var sass = require('gulp-sass');
var header = require('gulp-header');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var jshint = require('gulp-jshint');
var stylish = require('jshint-stylish');
var beautify = require('gulp-jsbeautifier');
var cleanCSS = require('gulp-clean-css');
var tsProject = ts.createProject('tsconfig.json');
var sourcemaps = require('gulp-sourcemaps');
var runSequence = require('run-sequence');
var browserSync = require('browser-sync').create();
var autoprefixer = require('gulp-autoprefixer');
var paths = {
scss: 'assets/css/landing.scss',
css: 'assets/css/landing.css',
ts:'assets/js/landing.ts',
js:'assets/js/landing.js'
}
var banner = ['/*\n',
' * <%= pkg.title %> (<%= pkg.homepage %>)\n',
' * Copyright 2016-' + (new Date()).getFullYear(), ' <%= pkg.author %>\n',
' */\n',
''
].join('');
/** Miscellaneous Tasks **/
gulp.task('jshint', function () {
return gulp.src([
paths.ts,
'*.js'
])
.pipe(jshint())
.pipe(jshint.reporter(stylish))
.pipe(jshint.reporter('fail'));
});
gulp.task('format', function () {
return gulp.src([
paths.scss,
paths.ts,
'index.html',
'*.{js,json}'
], {
base: './'
})
.pipe(beautify())
.pipe(gulp.dest('./'));
});
/** JavaScript Tasks **/
gulp.task('clean-js', function () {
return del.sync([
'assets/js/*.min.js',
'assets/js/*.map'
], {
force: true
});
});
gulp.task('typescript', function () {
tsProject.src()
.pipe(tsProject())
.js.pipe(gulp.dest('assets/js'));
});
gulp.task('minify-js', function () {
return gulp.src([
paths.js
])
.pipe(uglify())
.pipe(header(banner, {
pkg: pkg
}))
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest('assets/js'));
});
gulp.task('sourcemap-js', function () {
return gulp.src([
'assets/js/*.min.js',
'!assets/js/*spec.js'
])
.pipe(sourcemaps.init())
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('assets/js'));
});
gulp.task('js', function () {
return runSequence('clean-js', 'typescript', 'minify-js', 'sourcemap-js');
});
/** CSS Tasks **/
gulp.task('clean-css', function () {
return del.sync([
'assets/css/*.min.css',
'assets/css/*.map'
], {
force: true
});
});
gulp.task('scss', function () {
return gulp.src('assets/css/**/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer({
browsers: ['last 2 versions', '> 5%', 'Firefox ESR']
}))
.pipe(gulp.dest('assets/css'));
});
gulp.task('minify-css', ['scss'], function () {
return gulp.src([
paths.css
])
.pipe(cleanCSS({
compatibility: 'ie8'
}))
.pipe(header(banner, {
pkg: pkg
}))
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest('assets/css'));
});
gulp.task('sourcemap-css', function () {
return gulp.src([
'assets/css/*.min.css'
])
.pipe(sourcemaps.init())
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('assets/css'));
});
/** Server Task **/
gulp.task('browserSync', function () {
return browserSync.init({
server: {
baseDir: ''
},
port: process.env.PORT || 4790
});
});
/** Task Flows **/
gulp.task('css', function () {
return runSequence('clean-css', 'scss', 'minify-css', 'sourcemap-css');
});
gulp.task('minify', function () {
return runSequence('css', 'js');
});
gulp.task('serve', function () {
runSequence('minify', 'browserSync');
gulp.watch('assets/css/**/*.scss', ['css', browserSync.reload]);
gulp.watch('assets/js/**/*.ts', ['js', browserSync.reload]);
gulp.watch('index.html', browserSync.reload);
});
gulp.task('default', ['serve']);
module.exports = gulp;