【问题标题】:Disable LiveReload with Yeoman使用 Yeoman 禁用 LiveReload
【发布时间】:2012-10-01 13:30:19
【问题描述】:

在 IE8 中进行测试时,由于不支持 Web 套接字,LiveReload 会引发错误。有没有办法配置 yeoman 来禁用 LiveReload?

【问题讨论】:

    标签: yeoman livereload


    【解决方案1】:

    尝试使用<!--[if !IE]><!--></body><!--<![endif]--><!--[if IE]></body><!--<![endif]--> 而不是</body>。

    生成器会尝试替换第一个 </body> 元素并在其前添加 livereload sn-p,因此代码将被放置在 IE 空间不可见的位置。

    附:这是肮脏的黑客,所以小心使用这个

    【讨论】:

    • 我讨厌这个答案。此外,90 分钟后,这是最好的答案。谢谢!
    【解决方案2】:

    Yeoman Livereload 由两部分组成:插入 livereload sn-p 的中间件和 watch 任务中的 livereload 目标。要禁用 livereload,请同时删除:

    Livereload sn-p 在 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));
    };
    

    Watch 中的 Livereload 任务:

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

    以及插入sn-p的中间件:

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

    有关修复 Yeoman 中的 livereload-connect 问题的更新,请跟踪此问题:https://github.com/yeoman/generator-webapp/issues/63

    【讨论】:

      【解决方案3】:

      把它放在你的 Gruntfile 中:

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

      【讨论】:

      • grunt.registerHelper 已被弃用,现在不再存在。
      • 2014年运行grunt serve时会报错:Loading "Gruntfile.js" tasks...ERROR &gt;&gt; TypeError: Object #&lt;Object&gt; has no method 'registerHelper'
      【解决方案4】:

      Yeoman 不支持 IE8,这是有充分理由的。

      但是,您可以执行 Allan 所描述的操作,或者您可以覆盖 server 任务,方法是将其放入您的 Gruntfile:

      grunt.registerTask('server', 'yeoman-server');
      

      【讨论】:

      • 基本上你是对的,IE8应该直接下地狱,但有时它只是公司内网中唯一使用的浏览器。但是,当我这样做时,它说 Task "yeoman-server" not found.
      【解决方案5】:

      是的,我认识一个。

      1. 转到您的项目文件夹并找到文件Gruntfile.js
      2. 在编辑器中打开文件
      3. 删除reload: 中的watch:

      它看起来像这样:

      // 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'
        }
      }
      

      在你删除它之后是这样的:

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

      我想我看到了一个命令行标志,但我找不到它。

      【讨论】:

      • 这对我不起作用,它仍然放在脚本的末尾。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-03-04
      • 1970-01-01
      • 2013-05-13
      • 1970-01-01
      • 2016-07-19
      • 2013-05-03
      • 2013-06-01
      相关资源
      最近更新 更多