Disable LiveReload with Yeoman

一个人想着一个人 提交于 2019-12-07 03:26:51

问题


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


回答1:


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');



回答2:


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




回答3:


Put this in your Gruntfile:

grunt.registerHelper('reload:inject', function () {
  return function inject(req, res, next) {
      return next();
  }});



回答4:


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.




回答5:


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



来源:https://stackoverflow.com/questions/12830159/disable-livereload-with-yeoman

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!