-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
109 lines (93 loc) · 2.52 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
var gulp = require('gulp');
// Include plugins
var jshint = require('gulp-jshint');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
var sourcemaps = require('gulp-sourcemaps');
var rename = require('gulp-rename');
var rimraf = require('gulp-rimraf');
var cleanCSS = require('gulp-clean-css');
var browserSync = require('browser-sync').create();
// Lint JS code
gulp.task('lint', function() {
return gulp.src([
'javascripts/**/*.js',
'!javascripts/main.min.js'
])
.pipe(jshint())
.pipe(jshint.reporter('default'));
});
// Concat and Minify CSS
gulp.task('style', function() {
return gulp.src([
'styles/**/*.css',
'!styles/**/*.min.css',
'!styles/**/*.min.css.map'
])
.pipe(rename({ extname: '.min.css' }))
.pipe(gulp.dest('styles'))
.pipe(browserSync.stream({ match: '**/*.css' }));
});
gulp.task('style-build', function() {
return gulp.src([
'styles/**/*.css',
'!styles/**/*.min.css'
])
.pipe(sourcemaps.init())
.pipe(cleanCSS())
.pipe(rename({ extname: '.min.css' }))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('dist/styles'))
.pipe(browserSync.stream({ match: '**/*.css' }));
});
// Concatenate and Minify JS
gulp.task('script', function() {
return gulp.src([
'javascripts/**/*.js',
'!javascripts/main.min.js'
])
.pipe(concat('main.min.js'))
.pipe(gulp.dest('javascripts'));
});
gulp.task('script-build', function() {
return gulp.src([
'javascripts/**/*.js',
'!javascripts/main.min.js'
])
.pipe(concat('main.js'))
.pipe(rename({ extname: '.min.js' }))
.pipe(sourcemaps.init())
.pipe(uglify())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('dist/javascripts'));
});
// Copy files
gulp.task('copy', function() {
gulp.src('*.html')
.pipe(gulp.dest('dist'));
});
// Clean dist folder
gulp.task('clean', function() {
return gulp.src('./dist/**/*.*', { read: false })
.pipe(rimraf({ force: true }));
});
// Default task
gulp.task('default', ['style', 'lint', 'script'], function() {
browserSync.init({
server: {
baseDir: './'
}
});
gulp.watch('javascripts/**/*.*', ['lint', 'script']);
gulp.watch('styles/**/*.*', ['style']);
gulp.watch('javascripts/**/*.js').on('change', browserSync.reload);
gulp.watch('*.html').on('change', browserSync.reload);
});
// Build task
gulp.task('build', ['clean', 'copy', 'style-build', 'lint', 'script-build'], function() {
browserSync.init({
server: {
baseDir: './dist'
}
});
});