-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgulpfile.js
More file actions
63 lines (53 loc) · 1.5 KB
/
gulpfile.js
File metadata and controls
63 lines (53 loc) · 1.5 KB
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
"use strict";
/* Import modules */
var fs = require('fs');
var path = require('path');
var rimraf = require('rimraf');
var gulp = require('gulp');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var webpack = require('webpack-stream');
/* Function for creating a folder */
function mkdir(path) {
try { fs.mkdirSync(path); }
catch(e) { if(e.code !== 'EEXIST') throw e; }
}
/* Set constant variables */
const WATCH_IGNORE = ['!**/~*', '!**/.*̈́', '!**/*.swp'];
const SRC_PATH = 'src/';
const DIST_PATH = 'dist/';
const JS_MAIN = SRC_PATH + 'js/Main.js';
const JS_DISTNAME = 'Game.js';
/* Gulp plugin options */
const WEBPACK_OPTS = {
target: 'web',
output: { filename: '[name].js' },
module: {
loaders: [ {
loader: 'babel-loader',
query: { presets: ['es2015', 'stage-3'] }
} ],
cache: true
},
resolve: { root: ['node_modules', path.resolve('src/js')] }
};
/* Gulp tasks */
gulp.task('javascript', function() {
return gulp.src(JS_MAIN)
.pipe( webpack(WEBPACK_OPTS) )
.pipe( rename({ basename: JS_DISTNAME, extname: '' }) )
.pipe( gulp.dest(DIST_PATH) )
.pipe( uglify() )
.pipe( rename({ extname: '.min.js' }) )
.pipe( gulp.dest(DIST_PATH) );
});
gulp.task('clean', function() {
rimraf.sync(DIST_PATH);
mkdir(DIST_PATH);
});
gulp.task('watch', function() {
gulp.watch([SRC_PATH + 'js/**', ...WATCH_IGNORE], ['javascript']);
});
gulp.task('build', ['clean', 'javascript']);
/* Default gulp task is build, followed by watch */
gulp.task('default', ['build', 'watch']);