grunt-contrib-connect is a Grunt plugin designed to start a static web server using the `connect` middleware framework. It is currently at stable version 5.0.1, with recent updates, including a major version bump (v5.0.0) in early 2024, indicating an active, though mature, maintenance cycle. This plugin enables developers to configure server parameters such as port, hostname, protocol (HTTP, HTTPS, or HTTP2), and a flexible base directory for serving files, including support for multiple roots and `serve-static` options. Its primary differentiation is its tight integration into the Grunt build system, facilitating seamless local development servers or serving static assets during build processes, often used in conjunction with other Grunt tasks like `grunt-contrib-qunit` for testing. The plugin wraps the popular `connect` server, providing a familiar API within the Grunt ecosystem.
npm install grunt-contrib-connectVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to install `grunt-contrib-connect`, load it in your Gruntfile, and configure two `connect` tasks: one for development with live reload and automatic browser opening, and another for testing that keeps the server alive indefinitely. It also shows a basic `grunt-contrib-watch` setup, a common companion to `connect` for modern web development workflows.
Review your `protocol: 'http2'` configurations. Test your HTTP/2 endpoints thoroughly after upgrading to v5.x. Consult the `http2-wrapper` documentation if you encounter issues.
Only use `keepalive: true` for dedicated server tasks (e.g., `grunt serve`). For development workflows where other tasks need to run (e.g., `watch`), either omit `keepalive` or run `connect` in a separate `grunt-concurrent` task if you need it alongside other blocking tasks.
If `hostname` is a wildcard and `open: true`, specify the full URL in the `open` option to override the default `localhost` behavior (e.g., `open: 'http://<your-ip>:<port>'`).
Test your application with various browsers when using HTTP/2. If issues arise, consider reverting to `protocol: 'http'` or `https` for broader compatibility or for debugging purposes.
Change the `port` option in your Gruntfile's `connect` task to an unused port, or enable `useAvailablePort: true` (if supported and desired) to automatically find a free port.
Ensure you have `npm install grunt-contrib-connect --save-dev` and `grunt.loadNpmTasks('grunt-contrib-connect');` in your Gruntfile.This typically means another server is running on the same port. Use `lsof -i :8000` (macOS/Linux) or `netstat -ano | findstr :8000` (Windows) to identify and terminate the conflicting process, or change the port in your Gruntfile.