Book Image

NW.js Essentials

By : Alessandro Benoit, Roger Weng
Book Image

NW.js Essentials

By: Alessandro Benoit, Roger Weng

Overview of this book

Table of Contents (17 chapters)
NW.js Essentials
About the Author
About the Reviewers

Live reloading NW.js

While developing the frontend of the application, it comes in really handy to be able to reload the application interface at each change in the code. There are many approaches to live reload; let's see a couple of them.

If you're working on a single folder, all you need to do is leverage Node.js by adding the following code snippet directly at the end of your file:

var path = './',
  fs = require('fs');, function() {
  if (location) location.reload();

If you need a more complete solution by watching files recursively, you'll have to adopt a watch library, such as Gaze, Gulp, or Chokidar. Let's see another example, leveraging Gulp this time. First, you need to install Gulp (manually or through the manifest file) and then add the following piece of code at the end of your file:

var gulp = require('gulp');
gulp.task('reload', function () {
  if (location) location.reload();
});'**/*', ['reload']);