Skip to content

Instantly share code, notes, and snippets.

@Narigo
Created February 14, 2015 17:57
Show Gist options
  • Save Narigo/1eaaab5c4a911dec7846 to your computer and use it in GitHub Desktop.
Save Narigo/1eaaab5c4a911dec7846 to your computer and use it in GitHub Desktop.
Cordova + React + Gulp + live reload
var gulp = require('gulp');
gulp.task('sass', sassCompile);
gulp.task('assets', assetCopy);
gulp.task('scripts', scriptCompile);
gulp.task('clean', clean);
gulp.task('prepareAndReload', ['prepare'], reloader);
gulp.task('prepare', ['default'], cordovaPrepare);
gulp.task('dev', ['default'], liveReloadServer);
gulp.task('default', ['sass', 'assets', 'scripts']);
var Path = require('path');
var compass = require('gulp-compass');
var minifyCss = require('gulp-minify-css');
var del = require('del');
var browserify = require('gulp-browserify');
var reactify = require('reactify');
var shell = require('gulp-shell');
var liveReload = require('gulp-livereload');
function sassCompile() {
return gulp.src('src/scss/*.scss')
.pipe(compass({
project : Path.join(__dirname),
css : 'www/css',
sass : 'src/scss',
image : 'src/img'
}))
.pipe(minifyCss())
.pipe(gulp.dest('www/css'));
}
function scriptCompile() {
return gulp.src(['src/js/app.js'])
.pipe(browserify({
transform : ['reactify']
}))
.pipe(gulp.dest('www/js/'));
}
function assetCopy() {
return gulp.src('src/static/**')
.pipe(gulp.dest('www/'));
}
function liveReloadServer() {
liveReload.listen();
gulp.watch('src/static/**', ['prepareAndReload']);
gulp.watch('src/js/**', ['prepareAndReload']);
gulp.watch('src/scss/**/*.scss', ['prepareAndReload']);
}
function cordovaPrepare() {
return gulp.src('')
.pipe(shell(['cordova prepare']));
}
function reloader() {
return gulp.src('')
.pipe(liveReload());
}
// clean Task
function clean(cb) {
del(['www/'], cb);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment