【问题标题】:Grunt localhost:9000/index.html doesn't runGrunt localhost:9000/index.html 不运行
【发布时间】:2016-02-09 16:25:25
【问题描述】:

我已经按照 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

【问题讨论】:

  • 你试过端口:9000 吗?
  • @RobertMoskal 我的本地主机是 localhost:9000/index.html

标签: gruntjs grunt-contrib-watch grunt-contrib-connect


【解决方案1】:

默认情况下,grunt-contrib-connect 服务器仅在 grunt 模块运行时运行:https://github.com/gruntjs/grunt-contrib-connect#keepalive

将 keepalive 键添加到您的选项中:

   connect: {
        connect: {
            options: {
                port: 9000,
                livereload: 35729,
                keepalive: true,
                hostname: 'localhost'
            },

请记住,当您使用 keepalive 时,在此之后不会运行其他任务。但从你的 gruntfile 看起来不错。

【讨论】:

  • 感谢您对此进行调查,但仍然给我“此网页不可用”不知道为什么,看起来没有看到或找到我的 index.html
猜你喜欢
  • 2017-07-28
  • 1970-01-01
  • 2016-01-04
  • 1970-01-01
  • 1970-01-01
  • 2019-12-23
  • 2016-10-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多