forked from shrunyan/mc-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
86 lines (74 loc) · 1.88 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
var gulp = require('gulp')
var sourcemaps = require('gulp-sourcemaps')
var source = require('vinyl-source-stream')
var buffer = require('vinyl-buffer')
var browserify = require('browserify')
var watchify = require('watchify')
var babelify = require('babelify')
var plumber = require('gulp-plumber')
var less = require('gulp-less')
var minifyCss = require('gulp-minify-css')
var concat = require('gulp-concat')
var uglify = require('gulp-uglify')
var options = {
DEST: './ui-build',
APP_ENTRY: 'ui/app/app.js',
LESS: [
'ui/less/*.less'
],
HTML: [
'ui/**/*.html',
'ui/favicon.ico'
]
}
var bundle = function bundle() {
var b = browserify(watchify.args)
b.add(options.APP_ENTRY)
b.transform(babelify)
b.bundle()
.pipe(source('app.min.js'))
.pipe(buffer())
.pipe(sourcemaps.init())
.pipe(uglify())
.pipe(sourcemaps.write('./maps'))
.pipe(gulp.dest(options.DEST + '/app'))
return b
}
gulp.task('bundle', bundle)
gulp.task('watch-bundle', function() {
var w = watchify(bundle())
// Watch and rebundle
w.on('update', function() {
w.bundle()
.pipe(source('app.min.js'))
.pipe(buffer())
.pipe(gulp.dest(options.DEST + '/app'))
})
w.on('log', function(msg) {
console.log(msg)
})
return w
})
gulp.task('less', function() {
gulp.src(options.LESS)
.pipe(plumber())
.pipe(less())
.pipe(minifyCss({
compatibility: 'ie8'
}))
.pipe(concat('app.min.css'))
.pipe(gulp.dest(options.DEST + '/css'))
})
gulp.task('html', function() {
gulp.src(options.HTML)
.pipe(gulp.dest(options.DEST))
})
gulp.task('watch-less', function() {
gulp.watch(options.LESS, ['less'])
})
gulp.task('watch-html', function() {
gulp.watch(options.HTML, ['html'])
})
gulp.task('build', ['html', 'less', 'bundle'])
gulp.task('watch', ['build', 'watch-bundle', 'watch-less', 'watch-html'])
gulp.task('default', ['build'])