grunt-contrib-connect运行但不工作

时间:2016-08-30 10:02:26

标签: gruntjs grunt-contrib-connect

我正在使用:https://github.com/gruntjs/grunt-contrib-connect

"grunt-contrib-connect": "^1.0.2",

运行后: grunt connect

Running "connect:server" (connect) task
Started connect web server on http://localhost:8000

Done.

enter image description here

因此,当我在我的浏览器中检查:localhost:8000时,不会打开任何内容。

有人可以为此提供帮助吗?

gruntfile pastenbin:http://pastebin.com/nL771d5j

Gruntfile.js

module.exports = function  (grunt) {
    var config = {};

    //setup the configuration object
    var jshint;

    //all tasks that must be loaded.
    var tasks = [
            ,'grunt-contrib-watch'
            ,'grunt-contrib-concat'
            ,'grunt-contrib-sass'
            ,'grunt-contrib-connect'
    ];

                //src ===============================
                var src;
                config.src = src = {
                     sassMain        : 'scss/main.scss',
                     distFolder      : 'public/stylesheets/dist.css',
                     devFolder       : 'public/stylesheets/dev.css',
                     sassFolder      : 'scss/**/*.scss',
                     serverPort: 9000,
                     serverHost: '0.0.0.0' 
                };


                //Concat ===============================

                var concat
                config.concat = concat = {};

                concat.dev = {
                    files: {
                        "public/myapp.development.js": [
                            "with-bootstrap/public/js/vendor"
                            ,"with-bootstrap/public/js/**/*.js"
                        ]
                    }
                };

                //Watch ===============================
                config.watch = {
                     scripts: {
                        files: ["<%= src.sassFolder %>"]
                        ,tasks: ["sass:dist"]
                     }
                }

                //Sass ===============================
                var sass;
                config.sass = sass = {};

                    //distribution
                        sass.dist = {
                            options: { 
                                style: "compressed",
                                noCache: true, 
                                sourcemap: 'none', 
                                update:true
                            }
                            , files: {
                                "<%= src.distFolder %>" : "<%= src.sassMain %>"
                            }
                        };

                    //development env.
                        sass.dev = {
                            options: { 
                                style: "expanded", 
                                lineNumber: true,
                            }
                            , files: {
                                "<%= src.devFolder %>" : "<%= src.sassMain %>"
                            }
                        };


                    //grunt serve ===============================
                    config.connect = {
                         server: {
                          options: {
                            port: 8000,
                            base: {
                              path: 'SITE',
                              options: {
                                index: 'index.html',
                                maxAge: 300000
                              }
                            }
                          }
                        }
                    };


    //Register custom tasks ===============================
    grunt.registerTask('default',['dev']);
    grunt.registerTask('dev', ['concat:dev','sass:dev']);
    grunt.registerTask('dist',['concat:dev','sass:dist']);



    //General setup ===============================
    grunt.initConfig(config);
    tasks.forEach(grunt.loadNpmTasks);

};

1 个答案:

答案 0 :(得分:0)

如果您自行运行grunt-contrib-connect插件,则需要在您的grunt配置中将属性keepalive设置为 true

config.connect = {
    server: {
        options: {
            port: 8000,
            keepAlive: true,
            base: {
                path: 'SITE',
                options: {
                    index: 'index.html',
                    maxAge: 300000
                }
            }
        }   
    }
};

值得注意如果您想将连接配置用作任务链的一部分,keepAlive将需要设置为false,否则connect任务之后的任务不会跑。您也可以通过使用connect选项将watch任务与keepAlive任务配对来保持<OBJECT width=740 height=400><PARAM NAME="movie"VALUE="http://www.youtube.com/v/XXXXXXXXXXX?rel=0&hd=0"><PARAM NAME="wmode" VALUE="opaque"> 运行。