我已经像Grunt说的那样设置了它,我有以下代码,grunt正在正常观看并且livereload.js正在35729端口上运行。
我的问题是我无法看到我的index.html在localhost上运行。 我错过了什么?
module.exports = function(grunt) {
grunt.initConfig({
compass: {
dev: {
options: {
config: 'config.rb'
}
}
},
watch: {
css: {
files: 'sass/*.scss',
tasks: ['sass'],
options: { livereload: true }
},
livereload: {
options: { livereload: true },
files: [
'{,*/}*.html',
'*.html',
'assets/images/{,*/}*',
'assets/js/*.js'
]
},
options: {
livereload: true,
},
html: {
options: { livereload: true },
files: ['*.html']
},
sass: {
options: { livereload: true },
files: ['sass/*.scss'],
tasks: ['compass:dev']
},
options: {
livereload: true
},
js: {
options: { livereload: true },
files: ['assets/js/*.js'],
tasks: ['jshint']
},
images: {
options: { livereload: true },
files: ['assets/images/*.*']
},
fontsicons: {
options: { livereload: true },
files: ['assets/images/icons/**/*.{svg,eot,woff,ttf,woff2,otf}'],
tasks: ['copy:fontsicons']
}
},
connect: {
connect: {
options: {
port: 9000,
livereload: 35729,
hostname: 'localhost'
},
livereload: {
options: {
open: true,
base: [
'app'
]
}
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-compass');
grunt.registerTask('default', ['watch','compass','connect']);
} //exports
答案 0 :(得分:1)
默认情况下,只要grunt模块正在运行,grunt-contrib-connect服务器就会运行:https://github.com/gruntjs/grunt-contrib-connect#keepalive。
将keepalive密钥添加到您的选项中:
connect: {
connect: {
options: {
port: 9000,
livereload: 35729,
keepalive: true,
hostname: 'localhost'
},
请记住,当您使用keepalive时,在此之后不会运行任何其他任务。但是你的grunt文件看起来还不错。