I want to use a combination of VScode + Gulp + Electron to build an application. A nice feature of the development workflow would be to add an live reload task to my Gulp watch task, to reload the Electron application on every change.
Any Idea how to achieve this?
Your help is highly appreciated.
I was able to achieve this with the gulp-livereload
plugin. Here is the code to livereload CSS ONLY. It's the same for everything else though.
var gulp = require ('gulp'),
run = require('gulp-run'),
livereload = require('gulp-livereload'),
uglify = require('gulp-uglify'),
concat = require('gulp-concat'),
rename = require('gulp-rename'),
minifycss = require('gulp-minify-css'),
jshint = require('gulp-jshint'),
autoprefixer = require('gulp-autoprefixer'),
rimraf = require('gulp-rimraf');
var cssSources = [
'app/components/css/main.css',
];
gulp.task('css', function(){
gulp.src(cssSources)
.pipe(concat('main.css'))
.pipe(autoprefixer({browsers: ['last 2 versions', 'ie 10']}))
.pipe(gulp.dest('app/public/styles'))
.pipe(rename({suffix: '.min'}))
.pipe(minifycss())
.pipe(gulp.dest('app/public/styles'))
.pipe(livereload());
})
gulp.task('watch', function(){
livereload.listen();
gulp.watch(cssSources, ['css'])
})
gulp.task('run', ['build'], function() {
return run('electron .').exec();
});
gulp.task('default', ['watch', 'run']);
Livereload in a desktop application is awesome.
Make sure you add
<script src="http://localhost:35729/livereload.js"></script>
to your index.html