grunt-contrib-connect: connect is undefined when using jit-grunt and load-grunt-config

277 Views Asked by At

I have the following grunt plugins in my package.json installed:

"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"

and the following grunt file:

'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'
 });

};

and the following connect-contrib-connect task:

'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'
  }
}
 };
}

The problem is that the connect object is not being passed to the middleware signature. This is causing my server contents to not display correctly. I am seving some static content like

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

and pushing this to the middleware, not too dissimilar to the middleware example on the grunt-contrib-connect doc: https://github.com/gruntjs/grunt-contrib-connect#middleware

Anyone have any ideas please?

0

There are 0 best solutions below