0

我正在开发由其他人构建的 web 应用程序......构建和运行的命令是

npm install
bower install
grunt serve

我之前使用过 npm 和 bower 没有任何问题。在 grunt 到达“connect:livereload”任务之前,一切似乎都正常工作,此时命令行刚刚挂起,没有错误消息。

下面是 package.json 文件和 grunt serve -v 的输出:

  (package.json)
   {
  "name": "app",
  "version": "0.0.1",
  "dependencies": {
    "openlayers": "^3.14.2"
  },
  "devDependencies": {
    "connect-livereload": "^0.5.3",
    "grunt": "^0.4.5",
    "grunt-bower-requirejs": "^2.0.0",
    "grunt-browserify": "^4.0.1",
    "grunt-connect-proxy": "^0.2.0",
    "grunt-contrib-clean": "^0.6.0",
    "grunt-contrib-connect": "^0.10.1",
    "grunt-contrib-copy": "^0.8.0",
    "grunt-contrib-cssmin": "^0.12.3",
    "grunt-contrib-handlebars": "^0.10.2",
    "grunt-contrib-imagemin": "^0.9.4",
    "grunt-contrib-jshint": "^0.11.2",
    "grunt-contrib-less": "^1.2.0",
    "grunt-contrib-watch": "^0.6.1",
    "grunt-jsbeautifier": "^0.2.10",
    "grunt-jscs": "^1.8.0",
    "grunt-jsdoc": "^0.6.7",
    "grunt-karma": "^0.11.0",
    "grunt-open": "^0.2.3",
    "grunt-processhtml": "^0.3.8",
    "grunt-requirejs": "^0.4.2",
    "grunt-usemin": "^3.0.0",
    "jit-grunt": "^0.9.1",
    "jscs": "^1.13.1",
    "jscs-stylish": "^0.3.1",
    "jsdoc": "^3.3.2",
    "jshint-stylish": "^2.0.0",
    "karma": "^0.13.0",
    "karma-chai": "^0.1.0",
    "karma-chai-sinon": "^0.1.5",
    "karma-chrome-launcher": "^0.1.12",
    "karma-coverage": "^0.4.2",
    "karma-firefox-launcher": "^0.1.6",
    "karma-ie-launcher": "^0.2.0",
    "karma-jasmine": "^0.3.6",
    "karma-phantomjs-launcher": "^0.2.0",
    "karma-requirejs": "^0.2.2",
    "mocha-xunit-zh": "0.0.3",
    "phantomjs": "^1.9.17",
    "requirejs": "^2.1.18",
    "time-grunt": "^1.2.1"
  },
  "engines": {
    "node": ">=0.12.0"
  }
}

(详细)输出(从 live:reload 开始)

Running "connect:livereload" (connect) task
Verifying property connect.livereload exists in config...OK
File: [no files]
Options: protocol="http", port=9001, hostname="0.0.0.0", base=".", directory=nul
l, keepalive=false, debug=false, livereload=false, open=false, useAvailablePort=
false, onCreateServer=null, middleware=undefined

这是运行“grunt serve”后的(非详细)输出:

$ grunt serve
Running "serve" task

Running "clean:server" (clean) task
>> 1 path cleaned.

Running "jshint:all" (jshint) task

√ No problems


Running "jscs:src" (jscs) task
No code style errors found.
>> 21 files without code style errors.

Running "createDefaultTemplate" task

Running "handlebars:compile" (handlebars) task
>> 1 file created.

Running "clean:dist" (clean) task
>> 1 path cleaned.

Running "createDefaultTemplate" task

Running "handlebars:compile" (handlebars) task
>> 1 file created.

Running "less:dist" (less) task
>> 1 stylesheet created.

Running "copy:env" (copy) task
Copied 1 file

Running "copy:ol" (copy) task
Copied 2 files

Running "configureProxies" task
Proxy created for: /api to 52.20.39.250:80

Running "connect:livereload" (connect) task

这里卡住了(在'运行“连接:livereload”(连接)任务')......没有光标或错误或任何进一步的输出......在这里我希望看到“在http://上启动连接网络服务器localhost:9001 " 并且能够查看应用程序,但它会挂在这里,在我强制退出之前没有进一步的输出或错误。没有向该端口提供任何服务(我尝试在应用程序的 grunt-task/config/connect 文件中切换端口号作为测试,但没有更改)

这是 Grunt 文件:

'use strict';

module.exports = function (grunt) {
    // show elapsed time at the end
    require('time-grunt')(grunt);
    // load all grunt tasks
    require('jit-grunt')(grunt, {
        useminPrepare: 'grunt-usemin',
        configureProxies: 'grunt-connect-proxy'
    });

    var yeomanConfig = {
        app: 'app',
        dist: 'dist'
    };

    grunt.initConfig({yeoman: yeomanConfig});

    //load all custom task configs
    grunt.loadTasks('grunt-tasks/config');
    grunt.loadTasks('grunt-tasks/register');

    grunt.registerTask('default', [
        'jshint',
        'jscs',
        //'test',
        'build'
    ]);

};

这是 grunt-tasks/config 中的“连接”文件:

    module.exports = function(grunt) {

    var SERVER_PORT = 9001;
    var LIVERELOAD_PORT = 35729;

    var lrSnippet = require('connect-livereload')({
        port: LIVERELOAD_PORT
    });

    var proxySnippet = require('grunt-connect-proxy/lib/utils').proxyRequest;

    var mountFolder = function (connect, dir) {
        return connect.static(require('path').resolve(dir));
    };

    // configurable paths
    var yeomanConfig = {
        app: 'app',
        dist: 'dist'
    };

    grunt.config('connect', {
        options: {
            port: grunt.option('port') || SERVER_PORT,
            hostname: '0.0.0.0'
        },
        proxies: [{
            context: ['/api'],
            host: 'HOST IP',
            port: 80
        }],
        livereload: {
            options: {
                middleware: function (connect) {
                    return [
                        proxySnippet,
                        lrSnippet,
                        mountFolder(connect, '.tmp'),
                        connect().use(
                          '/node_modules',
                          connect.static('./node_modules')
                        ),
                        mountFolder(connect, yeomanConfig.app)
                    ];
                }
            }
        },
        test: {
            options: {
                middleware: function (connect) {
                    return [
                        lrSnippet,
                        mountFolder(connect, '.tmp'),
                        mountFolder(connect, 'test'),
                        mountFolder(connect, yeomanConfig.app)
                    ];
                }
            }
        },
        testInBrowser: {
            options: {
                middleware: function (connect) {
                    return [
                        proxySnippet,
                        mountFolder(connect, '.tmp'),
                        mountFolder(connect, 'test'),
                        mountFolder(connect, yeomanConfig.app)
                    ];
                }
            }
        },
        dist: {
            options: {
                middleware: function (connect) {
                    return [
                        proxySnippet,
                        connect().use(
                          '/node_modules',
                          connect.static('./node_modules')
                        ),
                        mountFolder(connect, yeomanConfig.dist)
                    ];
                }
            }
        }
    });
}

我注意到一件事:在这个项目的lder的webapp中,我的npm版本是2.14.20,但在我的用户文件夹中,npm版本是3.8.3(在两个目录中,我的Node版本相同,4.4 .1)..这可能是这个问题的根源吗?我只是在 webapp 目录中运行 npm install npm -g ,但是从该目录查看时它没有更改版本。

4

0 回答 0