Skip to content

Instantly share code, notes, and snippets.

@leroy
Created November 21, 2015 13:41
Show Gist options
  • Save leroy/8e2f5c3ce1349fd1b0a8 to your computer and use it in GitHub Desktop.
Save leroy/8e2f5c3ce1349fd1b0a8 to your computer and use it in GitHub Desktop.
My Phaser gulp workplace
var gulp = require('gulp');
var gutil = require('gulp-util');
var source = require('vinyl-source-stream');
var buffer = require('gulp-buffer');
var babelify = require('babelify');
var browserify = require('browserify');
var browserSync = require('browser-sync');
var ROOT_PATH = "."
var PHASER_PATH = ROOT_PATH + '/node_modules/phaser/build/';
var SOURCE_PATH = ROOT_PATH + '/src';
var ENTRY_FILE = SOURCE_PATH + '/Main.js';
var OUTPUT_FILE = 'game.js';
var PORT = 25565;
function build() {
var sourcemapPath = ROOT_PATH + '/' + OUTPUT_FILE + '.map';
return browserify({
entries: ENTRY_FILE,
debug: true
})
.transform(babelify.configure({
presets: ["babel-preset-es2015"]
}))
.bundle().on('error', function(error){
gutil.log(gutil.colors.red('[Build Error]'), error.message);
this.emit('end');
})
.pipe(source(OUTPUT_FILE))
// .pipe(buffer())
.pipe(gulp.dest(ROOT_PATH));
}
function serve() {
var options = {
server: {
baseDir: ROOT_PATH
},
port: PORT,
open: true
};
browserSync(options);
gulp.watch(SOURCE_PATH + '/**/*.js', ['watch-js']);
}
gulp.task('build', build);
gulp.task('serve', ['build'], serve);
gulp.task('watch-js', ['build'], browserSync.reload); // Rebuilds and reloads the project when executed.
gulp.task('default', ['serve']);
{
"name": "phaserboiler",
"version": "1.0.0",
"description": "",
"dependencies": {
"browser-sync": "^2.9.11",
"gulp-concat": "^2.6.0",
"babel-preset-es2015": "^6.0.15",
"gulp-sourcemaps": "^1.6.0",
"gulp-babel": "^6.0.0",
"gulp": "^3.9.0",
"gulp-util": "^3.0.7"
},
"devDependencies": {
"babelify": "^7.2.0",
"browserify": "^12.0.1",
"gulp-buffer": "0.0.2",
"vinyl-source-stream": "^1.1.0",
"watchify": "^3.6.0"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment