This repository has been archived by the owner on Jul 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathgulpfile.js
89 lines (77 loc) · 2.3 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
'use strict';
var gulp = require('gulp');
var watch = require('gulp-watch');
var deploy = require('gulp-gh-pages');
var jshint = require('gulp-jshint');
var browserify = require('browserify');
var babelify = require('babelify');
var uglify = require('gulp-uglify');
var gulpif = require('gulp-if');
var minimist = require('minimist');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var del = require('del');
var runSequence = require('run-sequence');
var browserSync = require('browser-sync');
var knownOptions = {
string: ['env', 'smp'],
default: {
env: process.env.NODE_ENV || 'production',
smp: '/path/to/project/root/'
}
};
var options = minimist(process.argv.slice(2), knownOptions);
var _debug = options.env === 'development' ? true : false;
gulp.task('deploy', function () {
return runSequence('clean', ['js:compile', 'copy'], 'push');
});
gulp.task('push', function() {
return gulp.src(['./dist/**/*'])
.pipe(deploy({ cacheDir: '.publish' }));
});
gulp.task('copy', function() {
return gulp.src(['./src/**/*', '!./src/js/*'])
.pipe(gulp.dest('dist'));
});
gulp.task('clean', function () {
return del(['dist/**/*']);
});
gulp.task('build', function() {
return runSequence('clean', ['js:compile', 'copy']);
});
gulp.task('js:compile', ['js:lint'], function() {
return browserify({ debug: _debug })
.transform(babelify.configure({
sourceMapRelative: options.smp
}))
.require('./src/js/app.js', {
entry: true
})
.bundle()
.on('error', function (err) {
console.log('Error : ' + err.message);
})
.pipe(source('bundle.js'))
.pipe(gulpif(options.env === 'production', buffer()))
.pipe(gulpif(options.env === 'production', uglify()))
.pipe(gulp.dest('./dist/js/'));
});
gulp.task('js:lint', function() {
return gulp.src('./src/**/*.js')
.pipe(jshint({ esnext: true }))
.pipe(jshint.reporter('default'));
});
gulp.task('browser-sync', function() {
browserSync({
notify: false,
port: 8000,
server: 'dist',
open: false
});
});
gulp.task('default', function () {
gulp.start('build');
watch('./src/**/*', function () {
runSequence('js:compile', 'copy');
});
});