Disable LiveReload with Yeoman

2019-04-28 19:30发布

When testing in IE8, LiveReload throws errors since web sockets is not supported. Is there a way to configure yeoman to disable LiveReload?

5条回答
疯言疯语
2楼-- · 2019-04-28 20:09

IE8 isn't supported by Yeoman, for good reason.

However, you could do what Allan describes, or you could override the server task, by putting this in your Gruntfile:

grunt.registerTask('server', 'yeoman-server');
查看更多
一纸荒年 Trace。
3楼-- · 2019-04-28 20:09

Yeoman Livereload consists of two parts: the middleware that inserts the livereload snippet, and the livereload target in the watch task. To disable livereload, remove both:

Livereload snippet at the top of the Gruntfile:

// Generated on ...
'use strict';
var LIVERELOAD_PORT = 35729; // <- Delete this
var lrSnippet = require('connect-livereload')({port: LIVERELOAD_PORT}); // <- Delete this
var mountFolder = function (connect, dir) {
  return connect.static(require('path').resolve(dir));
};

Livereload task in Watch:

watch: {
  // Delete this target 
  livereload: {
    options: {
      livereload: LIVERELOAD_PORT
    },
    files: [
       //...
    ]
  }
}

And the middleware that inserts the snippet:

connect: {
  options: {
    port: 9000,
    hostname: 'localhost'
  },
  livereload: {
    options: {
      middleware: function (connect) {
        return [
          lrSnippet, // <- Delete this middleware
          mountFolder(connect, '.tmp'),
          mountFolder(connect, yeomanConfig.app)
        ];
      }
    }

For updates on fixing the livereload-connect issues in Yeoman, track this issue: https://github.com/yeoman/generator-webapp/issues/63

查看更多
SAY GOODBYE
4楼-- · 2019-04-28 20:15

Put this in your Gruntfile:

grunt.registerHelper('reload:inject', function () {
  return function inject(req, res, next) {
      return next();
  }});
查看更多
smile是对你的礼貌
5楼-- · 2019-04-28 20:17

Yes there is one I know.

  1. Go to your project folder and find the file Gruntfile.js
  2. Open the file in a editor
  3. Remove the reload: in watch:

It will look something like this:

// default watch configuration
watch: {
  coffee: {
    files: 'app/scripts/**/*.coffee',
    tasks: 'coffee reload'
  },
  compass: {
    files: [
      'app/styles/**/*.{scss,sass}'
    ],
    tasks: 'compass reload'
  },
  reload: {
    files: [
      'app/*.html',
      'app/styles/**/*.css',
      'app/scripts/**/*.js',
      'app/images/**/*'
    ],
    tasks: 'reload'
  }
}

And after you have removed it something like this:

// default watch configuration
watch: {
  coffee: {
    files: 'app/scripts/**/*.coffee',
    tasks: 'coffee reload'
  },
  compass: {
    files: [
      'app/styles/**/*.{scss,sass}'
    ],
    tasks: 'compass reload'
  }
}

I think i have seen a commandline flag, but I was unable to find it.

查看更多
Emotional °昔
6楼-- · 2019-04-28 20:24

Try to use <!--[if !IE]><!--></body><!--<![endif]--><!--[if IE]></body><!--<![endif]--> instead of </body>.

Generator would try to replace first </body> element and add livereload snippet before it, so code would be placed in invisible for IE space.

P.S. It`s dirty hack so use this carefuly

查看更多
登录 后发表回答