-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
75 lines (66 loc) · 1.82 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
'use strict';
const gulp = require('gulp');
const babel = require('gulp-babel');
const sourcemaps = require('gulp-sourcemaps');
const browserSync = require('browser-sync').create();
const uglify = require('gulp-uglify');
const rename = require('gulp-rename');
const eslint = require('gulp-eslint');
/**
* Validate .js soruce before transforming.
*/
gulp.task('lint', function() {
return gulp.src('./dynamic-images.js')
// eslint() attaches the lint output to the "eslint" property
// of the file object so it can be used by other modules.
.pipe(eslint())
// eslint.format() outputs the lint results to the console.
// Alternatively use eslint.formatEach() (see Docs).
.pipe(eslint.format())
// To have the process exit with an error code (1) on
// lint error, return the stream and pipe to failAfterError last.
.pipe(eslint.failAfterError());
});
/**
* Transform .js source for backward compatibility.
*/
gulp.task('js', function() {
return gulp.src('./dynamic-images.js')
.pipe(sourcemaps.init())
.pipe(babel())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('./dist/'))
.pipe(browserSync.stream())
});
/**
* Minify .js srouce for optimization.
*/
gulp.task('minify', function() {
return gulp.src('./dist/*.js')
.pipe(uglify())
.pipe(rename({suffix: '.min'}))
.pipe(gulp.dest('./dist/'))
});
/**
* Setup static server
*/
gulp.task('serve', function() {
browserSync.init({
server: {
baseDir: './'
}
});
// Watch for ./*.js file changes.
gulp.watch('./dynamic-images.js', ['lint', 'js']);
// Watch for .html file changes.
gulp.watch('./**/*.html').on('change', browserSync.reload);
})
/**
* While still on development.
*/
gulp.task('dev', ['lint', 'js', 'serve']);
gulp.task('default', ['dev']);
/**
* Build assets for production.
*/
gulp.task('build', ['lint', 'js', 'minify']);