-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
107 lines (94 loc) · 2.69 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
/**
* Created by Gaplo917 on 16/7/2016.
*/
const browserify = require('browserify');
const babelify = require('babelify');
const gulp = require('gulp');
const babel = require('gulp-babel');
const concat = require('gulp-concat');
const run = require('gulp-run');
const webserver = require('gulp-webserver')
const stripDebug = require('gulp-strip-debug');
const minify = require('gulp-minify');
const sass = require('gulp-sass');
const source = require('vinyl-source-stream');
const buffer = require('vinyl-buffer');
const gutil = require('gulp-util');
const uglify = require('gulp-uglify');
const sourcemaps = require('gulp-sourcemaps');
const rename = require('gulp-rename')
const ngAnnotate = require('gulp-ng-annotate');
const minifyCss = require('gulp-minify-css')
const runSequence = require('run-sequence');
function onError(err) {
console.log(err.message)
this.emit('end')
}
gulp.task('browserify', function () {
// set up the browserify instance on a task basis
var b = browserify({
entries: './src/es6/app.js',
insertGlobals : true,
debug: false,
// defining transforms here will avoid crashing your stream
transform: [
babelify.configure({
presets: ["es2015"]
})
]
})
return b
.bundle()
.on('error', onError)
.pipe(source('app.js'))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
// Add transformation tasks to the pipeline here.
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./www/js/'))
})
gulp.task('webserver',() => {
return gulp.src('./www')
.pipe(webserver({
host: '0.0.0.0',
port: 3000,
livereload: true,
open: true,
}))
})
gulp.task('sass', function() {
return gulp.src(['./src/scss/app.scss'])
.pipe(sass())
.on('error', sass.logError)
.pipe(gulp.dest('./www/css/'))
})
gulp.task('watchJs', function() {
return gulp.watch(['./src/es6/**/*'], ['browserify'])
})
gulp.task('watchSass', function() {
return gulp.watch(['./src/scss/**/*'], ['sass'])
})
gulp.task('watch', ['watchJs','watchSass'])
gulp.task('compressCss', function() {
return gulp.src(['./www/css/app.css'])
.pipe(minifyCss({
keepSpecialComments: 0
}))
.pipe(gulp.dest('./www/css/'))
})
gulp.task('compressJs', function() {
return gulp.src('./www/js/app.js')
.pipe(ngAnnotate())
.pipe(stripDebug())
.pipe(uglify({mangle: false}))
.pipe(gulp.dest('./www/js/'))
})
gulp.task('build', (cb) => {
return runSequence(['browserify','sass'],cb)
})
gulp.task('release', (cb) => {
return runSequence('build',['compressJs','compressCss'],cb)
})
gulp.task('run', (cb) => {
return runSequence('build','watch','webserver',cb)
})