forked from real-supadev/fathom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
75 lines (64 loc) · 1.96 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 babelify = require("babelify")
const browserify = require('browserify')
const gulp = require('gulp')
const source = require('vinyl-source-stream')
const buffer = require('vinyl-buffer')
const rename = require('gulp-rename')
const gutil = require('gulp-util')
const sass = require('gulp-sass')
const uglify = require('gulp-uglify')
const pump = require('pump')
const es = require('event-stream');
const debug = process.env.NODE_ENV !== 'production';
let defaultTasks = [ 'browserify', 'sass', 'html', 'img' ] ;
gulp.task('default', defaultTasks);
gulp.task('browserify', function () {
let files = [
'./assets/src/js/script.js',
'./assets/src/js/tracker.js',
];
var tasks = files.map(function(entry) {
let stream = browserify({
entries: entry,
debug: debug
})
.transform("babelify", {
presets: ["es2015"],
plugins: [
"transform-decorators-legacy",
["transform-react-jsx", { "pragma":"h" } ]
]
})
.bundle()
.pipe(source(entry.split('/').pop()))
if(!debug) {
stream.pipe(buffer()).pipe(uglify())
}
return stream.pipe(gulp.dest(`./assets/build/js`))
});
// create a merged stream
return es.merge.apply(null, tasks);
});
gulp.task('img', function() {
return gulp.src('./assets/src/img/**/*')
.pipe(gulp.dest(`./assets/build/img`))
});
gulp.task('html', function() {
return gulp.src('./assets/src/**/*.html')
.pipe(gulp.dest(`./assets/build/`))
});
gulp.task('sass', function () {
var files = './assets/src/sass/[^_]*.scss';
return gulp.src(files)
.pipe(sass())
.on('error', gutil.log)
.pipe(rename({ extname: '.css' }))
.pipe(gulp.dest(`./assets/build/css`))
});
gulp.task('watch', ['default'], function() {
gulp.watch(['./assets/src/js/**/*.js'], ['browserify'] );
gulp.watch(['./assets/src/sass/**/**/*.scss'], ['sass'] );
gulp.watch(['./assets/src/**/*.html'], ['html'] );
gulp.watch(['./assets/src/img/**/*'], ['img'] );
});