This repository has been archived by the owner on Apr 29, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
57 lines (49 loc) · 1.76 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
var gulp = require('gulp');
var sourcemaps = require('gulp-sourcemaps');
var babel = require("gulp-babel");
var uglify = require('gulp-uglify');
var sass = require('gulp-sass');
var jshint = require('gulp-jshint');
var del = require('del');
// clean dist directory
gulp.task('clear-dist', function() {
del(['dist/**']);
});
// copy all files to build directory
gulp.task('copy-all', function() {
return gulp.src(['src/**', '!src/include/js/*.js', '!src/include/css/*.scss'], {dot: true})
.pipe(gulp.dest('dist'));
});
// minify javascript files
gulp.task('compile-js', ['lint-js'], function() {
return gulp.src(['src/include/js/*.js', '!src/include/js/*.min.js'], {base: 'src'})
.pipe(sourcemaps.init())
.pipe(babel({loose: "all"}))
.pipe(uglify())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('dist'));
});
// add external preminified js libraries
gulp.task('external-js', function() {
return gulp.src(['src/include/js/*.min.js'], {base: 'src'})
.pipe(gulp.dest('dist'));
});
gulp.task('babel-polyfill', function() {
return gulp.src(['node_modules/gulp-babel/node_modules/babel-core/browser-polyfill.min.js'])
.pipe(gulp.dest('dist/include/js/'));
});
// lint certain javascript files (non-libraries)
gulp.task('lint-js', function() {
return gulp.src(['src/include/js/*.js', '!src/include/js/*.min.js'])
.pipe(jshint({curly: true, esnext: true}))
.pipe(jshint.reporter('default'))
.pipe(jshint.reporter('fail'));
});
// minify css files
gulp.task('minify-css', function() {
return gulp.src(['src/include/css/*.scss'], {base: 'src'})
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(gulp.dest('dist'));
});
// default sets up entire project
gulp.task('default', ['copy-all', 'compile-js', 'external-js', 'babel-polyfill', 'minify-css']);