【发布时间】:2012-10-01 13:30:19
【问题描述】:
在 IE8 中进行测试时,由于不支持 Web 套接字,LiveReload 会引发错误。有没有办法配置 yeoman 来禁用 LiveReload?
【问题讨论】:
标签: yeoman livereload
在 IE8 中进行测试时,由于不支持 Web 套接字,LiveReload 会引发错误。有没有办法配置 yeoman 来禁用 LiveReload?
【问题讨论】:
标签: yeoman livereload
尝试使用<!--[if !IE]><!--></body><!--<![endif]--><!--[if IE]></body><!--<![endif]--> 而不是</body>。
生成器会尝试替换第一个 </body> 元素并在其前添加 livereload sn-p,因此代码将被放置在 IE 空间不可见的位置。
附:这是肮脏的黑客,所以小心使用这个
【讨论】:
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
【讨论】:
把它放在你的 Gruntfile 中:
grunt.registerHelper('reload:inject', function () {
return function inject(req, res, next) {
return next();
}});
【讨论】:
grunt serve时会报错:Loading "Gruntfile.js" tasks...ERROR >> TypeError: Object #<Object> has no method 'registerHelper'
Yeoman 不支持 IE8,这是有充分理由的。
但是,您可以执行 Allan 所描述的操作,或者您可以覆盖 server 任务,方法是将其放入您的 Gruntfile:
grunt.registerTask('server', 'yeoman-server');
【讨论】:
是的,我认识一个。
Gruntfile.js
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'
}
}
我想我看到了一个命令行标志,但我找不到它。
【讨论】: