-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
62 lines (51 loc) · 1.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
var babel = require("gulp-babel");
var gulp = require('gulp');
var rename = require("gulp-rename");
var rollup = require('rollup-stream');
var sourcemaps = require('gulp-sourcemaps');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
/**
* concatenate and minify js files and write a sourcemap
*/
gulp.task('build-js', function () {
rollup({
entry: './src/gameoflife.js',
sourceMap: true,
format: 'iife',
moduleName: 'GameOfLife',
banner: `// GameOfLife JavaScript Plugin v1.1.0
// https://github.com/barryvanveen/gameoflife
//
// Released under the MIT license
// http://choosealicense.com/licenses/mit/`
})
// print errors to console, this makes sure Gulp can keep watching and running
.on('error', e => {
console.error(`${e.stack}`);
})
// point to the entry file
.pipe(source('gameoflife.js', './src'))
// buffer the output, needed for gulp-sourcemaps
.pipe(buffer())
// tell gulp-sourcemaps to load the inline sourcemap produced by rollup-stream
.pipe(sourcemaps.init({loadMaps: true}))
// compile es2015 into plain javascript
.pipe(babel({presets: ['es2015']}))
// rename output file
.pipe(rename('gameoflife.min.js'))
// write source map
.pipe(sourcemaps.write('.'))
// output to /dist
.pipe(gulp.dest('dist'));
});
/**
* watch for changes in js-files, then build-js
*/
gulp.task('watch-js', function(){
gulp.watch('src/**/*.js', ['build-js']);
});
/**
* perform these tasks when running just 'gulp'
*/
gulp.task('default', ['build-js', 'watch-js']);