1

我已经像 Grunt 所说的那样设置了它,并且我有以下代码,grunt 正在正确观看并且 livereload.js 在端口 35729 上运行。

我的问题是我看不到我的 index.html 在本地主机上运行。我错过了什么?

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
4

1 回答 1

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 时,在此之后不会运行其他任务。但是从你的 gruntfile 看起来不错。

于 2016-02-09T16:46:50.410 回答