-
Notifications
You must be signed in to change notification settings - Fork 81
/
gulpfile.js
46 lines (37 loc) · 1.38 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
const gulp = require( 'gulp' ),
buffer = require( 'vinyl-buffer' ),
uglify = require( 'gulp-uglify' ),
replace = require( 'gulp-replace' ),
watchify = require( 'watchify' ),
browserify = require( 'browserify' ),
source = require( 'vinyl-source-stream' ),
fs = require( 'fs' ),
dotenv = require( 'dotenv' ),
envify = require( 'envify' ),
esmify = require( 'esmify' )
dotenv.config({ path:'./playground/.env' })
gulp.task( 'client', function(){
const out = browserify({ transform:[ 'envify' ] })
.require( './playground/environment.js', { entry: true })
.plugin( esmify )
.bundle()
.on( 'error', console.log )
.pipe( source( 'bundle.js' ) )
.pipe( gulp.dest( './playground' ) )
return out
});
gulp.task('watch', function() {
const bundler = watchify( browserify( './playground/environment.js', { entry:true, transform:['envify'] } ) );
bundler.on('update', rebundle)
function rebundle() {
const date = new Date()
console.log("recompiling... ", date.getHours(), date.getMinutes(), date.getSeconds() )
return bundler.bundle()
// log errors if they happen
.on( 'error', console.log )
.pipe( source( 'bundle.js' ) )
.pipe( gulp.dest( './playground/' ) )
}
return rebundle()
});
gulp.task( 'default', gulp.series('client') )