grunt server can't be connected

后端 未结 4 2091
借酒劲吻你
借酒劲吻你 2021-02-07 14:50
module.exports = function(grunt) {

  // Project configuration.
    grunt.initConfig({
      server: {
        port: 8888,
        base: \'.\'
      }
    });

};

C:\\P         


        
4条回答
  •  情歌与酒
    2021-02-07 15:33

    Don't use grunt to serve your project. Grunt is a build tool. Instead, use npm lifecycle scripts.

    server.js

    var express = require("express"),
        app = express();
    app.use('/', express.static(__dirname));
    app.listen(8888);
    

    package.json

    {
        "name": "my-project",
        "scripts": {
            "start": "node server.js"
        },
        "dependencies": {
            "express": "3"
        }
    }
    

    Now you can run npm start and life will be great. Grunt is a build tool, not a server. npm is a package lifecycle manager, not a build tool. Express is a server library. Use each in its right place.

    Follow up (2013-08-15)

    The exception to this rule is when you're needing to serve your project to other testing tools in your build stack. The grunt-contrib-connect plugin is designed specifically with this use case in mind, and has a keepalive configuration setting that will leave grunt open while serving your static files. This is usually used in conjunction with a watch task that runs a test suite when either the tests or the code changes.

提交回复
热议问题