-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgulpfile.js
100 lines (88 loc) · 2.43 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
const gulp = require('gulp'),
path = require('path'),
jshint = require('gulp-jshint'),
uglify = require('gulp-uglify'),
rename = require('gulp-rename'),
concat = require('gulp-concat'),
header = require('gulp-header'),
server = require('gulp-express'),
cssnano = require('gulp-cssnano'),
autoprefixer = require('gulp-autoprefixer');
// Import the package
const pkg = require('./package.json');
pkg.date = new Date().toISOString().replace(/\.\d{3}/, "");
// Header
const banner = ['/**',
' * <%= pkg.name %> - <%= pkg.description %>',
' * Date <%= pkg.date %>',
' * ',
' * @author <%= pkg.author %>',
' * @version v<%= pkg.version %>',
' * @link <%= pkg.homepage %>',
' * @license <%= pkg.license %>',
' */',
'', ''
].join('\n');
const paths = {
watch: {
src: 'src/',
js: 'src/**/*.js',
css: 'src/**/*.css'
},
dist: './dist/'
};
// Assets
gulp.task('scripts', function() {
gulp.src(['src/scripts/vanilla.js', paths.watch.js])
//Check valid
.pipe(jshint())
.pipe(jshint.reporter('jshint-stylish'))
.pipe(concat(pkg.name + '.js'))
.pipe(header(banner, {
pkg: pkg
}))
.pipe(gulp.dest(paths.dist))
//Minify
.pipe(uglify())
.pipe(rename(pkg.name + '.min.js'))
.pipe(header(banner, {
pkg: pkg
}))
.pipe(gulp.dest(paths.dist));
});
gulp.task('styles', function() {
gulp.src(paths.watch.css)
//Autoprefixer
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: false
}))
.pipe(header(banner, {
pkg: pkg
}))
.pipe(concat(pkg.name + '.css'))
.pipe(gulp.dest(paths.dist))
//Minify
.pipe(cssnano())
.pipe(rename(pkg.name + '.min.css'))
.pipe(header(banner, {
pkg: pkg
}))
.pipe(gulp.dest(paths.dist));
});
// Core
gulp.task('build', ['styles', 'scripts']);
gulp.task('server', ['build'], function() {
// Start server
server.run(['test/server.js']);
// Restart the server when file changes
gulp.watch([paths.watch.css], ['styles'], server.notify);
gulp.watch([paths.watch.js], ['scripts']);
});
// Events
gulp.task('start', ['build'], function() {
// Disable livereload
server.run(['test/server.js'], null, false);
});
// Set default task
gulp.task('default', ['start']);