grunt-express-server icon indicating copy to clipboard operation
grunt-express-server copied to clipboard

No page refresh but all else works

Open iDVB opened this issue 10 years ago • 3 comments

Watch detects changes and restarts express server.... but the browser never refreshes to see those changes.

Usually you have to inject livereload client into the html pages for this to work. However, I've not been able to find any details on how to do this with this module.

What am I doing wrong?

    watch: { // grunt-contrib-watch
      options: {
        livereload: true
      },
      express: {
        files:  [ '<%= project.path.server %>/**/*.js' ],
        tasks:  [ 'express:dev' ],
        options: {
          spawn: false, // for grunt-contrib-watch v0.5.0+, "nospawn: true" for lower versions. Without this option specified express won't be reloaded
          livereload: true
        }
      },      
      browserify: {
        files: [
          '<%= project.path.client %>/js/**/*.{jsx,js}'
        ],
        tasks: ['browserify:dist']
      },
      sass: {
        files: ['<%= project.path.client %>/sass/**/*.{css,scss}'],
        tasks: ['sass:dist']
      },
      html: {
        files: ['<%= project.path.client %>/**/*.html'],
        tasks: ['copy:dist']
      },
    },

    express: { // grunt-express-server
      dev: {
        options: {
          script: '<%= project.path.server %>/app.js'
        }
      },
      prod: {
        options: {
          script: '<%= project.path.server %>/app.js',
          node_env: 'production'
        }
      }
    },

iDVB avatar Aug 05 '15 15:08 iDVB

So the docs really read with no mention of livereload.js or the need for a browser plugin, so I'm still thinking there is a way to do this without.

However, I got it to work simply by adding the following to the html.

    <script>
      // LiveReload Updates: Need to find a way to remove this for production
      document.write('<script src="http://'
      + (location.host || 'localhost').split(':')[0]
      + ':35729/livereload.js?snipver=1"></'
      + 'script>')
    </script>

Please let me know if this is required or if there is a better way.

iDVB avatar Aug 05 '15 17:08 iDVB

I am facing the same issue, any solution ?

kamalsomani avatar Aug 23 '16 20:08 kamalsomani

same problem here. does anyone know or could be so kind to answer? Thanks in advance, Daniele

danidev avatar Jun 15 '17 09:06 danidev