-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
34 lines (28 loc) · 1.06 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
const gulp = require( 'gulp' );
const sourcemaps = require( 'gulp-sourcemaps' );
const babel = require( 'gulp-babel' );
function watchTask( task ) {
const watcher = gulp.watch( [task.SRC_GLOB], { cwd: __dirname }, task);
watcher.on( 'add', path => { console.log('File ' + path + ' was added, running tasks...'); });
watcher.on( 'change', path => { console.log('File ' + path + ' was changed, running tasks...'); });
}
// build task
const SRC_GLOB = './src/**/*.js';
const DEST = './build';
const build = () =>
gulp.src( SRC_GLOB, { cwd: __dirname } )
.pipe( sourcemaps.init() )
.pipe(
babel( {
presets: [ [ '@babel/preset-env', { 'targets': { 'node': '6.10' } } ] ]
} ) )
.pipe( sourcemaps.write( '.' ) )
.pipe( gulp.dest( DEST, { cwd: __dirname } ) );
build.displayName = 'build';
build.SRC_GLOB = SRC_GLOB;
// watch:build task
const watchBuild = () => watchTask( build );
watchBuild.displayName = 'watch:build';
// exports
module.exports[build.displayName] = build;
module.exports[watchBuild.displayName] = watchBuild;