1

我在 package.json 中安装了以下 grunt 插件:

"grunt-connect-proxy": "^0.2.0",
"grunt-contrib-connect": "^0.11.2",
"grunt-contrib-watch": "^0.6.1",
"jit-grunt": "^0.9.1",
"load-grunt-config": "^0.17.2",
"load-grunt-tasks": "^3.2.0"

和以下 grunt 文件:

'use strict';

module.exports = function(grunt) {

 grunt.loadNpmTasks('grunt-connect-proxy');
 grunt.loadNpmTasks('grunt-contrib-connect');

 require('time-grunt')(grunt);

 require('load-grunt-config')(grunt, {
    loadGruntTasks: {
    pattern: ['grunt-*'],
    config: require('./package.json')
    },
    jitGrunt: true
});

 require('jit-grunt')(grunt, {
   pluginsRoot: '/grunt',
  'grunt-connect-proxy': 'grunt-connect-proxy',
   serve: 'tasks/serve.js'
 });

};

以及以下 connect-contrib-connect 任务:

'use strict';

// The node js test server for serving client files
module.exports = function(grunt) {
  return {
    options: {
    port: 9000,
    hostname: 'localhost'
  },
  proxies: [{
     context: '/api', // the api pattern you need to proxy(i am going to proxy all the requests that are having a path as /api)
    host: 'localhost', // the backend server host ip
    port: 8080 // the backend server port
  }],
  livereload: {
    options: {
      open: true,
      middleware: function (connect, options) {
      grunt.log.write(JSON.stringify(connect)); // connect is undefined
      grunt.log.write(JSON.stringify(options)); // has values

      // custom middleware

      return [];
    }
  }
},
dist: {
  options: {
    open: true,
    base: 'dist'
  }
}
 };
}

问题是连接对象没有被传递给中间件签名。这导致我的服务器内容无法正确显示。我正在处理一些静态内容,例如

connect().use('/bower_components', connect.static('/bower_components'))

并将其推送到中间件,与 grunt-contrib-connect 文档中的中间件示例没有太大不同:https ://github.com/gruntjs/grunt-contrib-connect#middleware

请问有人有什么想法吗?

4

0 回答 0