LiveReload server for monitoring files and automatically reloading web browsers
—
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
Complete CLI with option parsing for all server configuration options plus path specification and help text.
Runs the LiveReload CLI application with argument parsing and server startup.
/**
* Main CLI entry point that parses arguments and starts server
* Uses process.argv for argument parsing
*/
function run(): void;Usage Examples:
# Basic usage - watch current directory
livereload
# Watch specific directory
livereload ./public
# Watch multiple directories
livereload "public, assets, templates"
# With options
livereload ./src -p 8080 -d
# Complex configuration
livereload ./public -e 'html,css,js' -x 'tmp,cache' -w 1000 -dParses command line arguments and creates server configuration for testing purposes.
/**
* Parse CLI arguments and create server (primarily for testing)
* @param testArgv - Array of command line arguments
* @returns Object with server instance and parsed path
*/
function createServerFromArgs(testArgv: string[]): {
server: Server;
path: string | string[];
};Usage Examples:
const { createServerFromArgs } = require('livereload/lib/command');
// For testing CLI argument parsing
const result = createServerFromArgs([
'./public',
'-p', '8080',
'-d'
]);
console.log(result.server.config.port); // 8080
console.log(result.path); // ['./public']Essential CLI options for server configuration.
# Version information
livereload -v
livereload --version
# Port configuration
livereload -p 8080
livereload --port 8080
# Host binding
livereload -b 0.0.0.0
livereload --bind 0.0.0.0
# Debug mode
livereload -d
livereload --debugConfigure which files are monitored and how.
# Custom extensions (replaces defaults)
livereload -e 'html,css,js'
livereload --exts 'html,css,js'
# Additional extensions (appends to defaults)
livereload -ee 'scss,ts,jsx'
livereload --extraExts 'scss,ts,jsx'
# Specific files to reload
livereload -f 'index.html,config.js'
livereload --filesToReload 'index.html,config.js'
# Additional exclusion patterns
livereload -x 'tmp,cache,logs'
livereload --exclusions 'tmp,cache,logs'
# Use polling for file system changes
livereload -u
livereload --usepolling
# Add delay before browser notification
livereload -w 1000
livereload --wait 1000CORS, CORP, and development URL configuration.
# Enable Cross-Origin Resource Policy
livereload -cp
livereload --corp
# Enable CORS for all origins
livereload -cs
livereload --cors
# Enable CORS for specific origin
livereload -cs 'https://example.com'
livereload --cors 'https://example.com'
# Set original development URL for proxying
livereload -op 'http://localhost:3000'
livereload --originalpath 'http://localhost:3000'Monitor a single directory or file.
# Current directory (default)
livereload
# Specific directory
livereload ./public
livereload /path/to/project/dist
# Relative paths
livereload ../shared/assetsMonitor multiple directories simultaneously.
# Comma-separated paths
livereload "public, assets, templates"
livereload "./src, ./dist, ./config"
# Can be combined with options
livereload "src, dist" -p 8080 -dAll paths are resolved to absolute paths internally using path.resolve().
/**
* CLI Options Configuration
*/
interface CLIOptions {
// Path argument (optional)
path?: string; // Directory to watch (default: '.')
// Basic options
version?: boolean; // -v, --version: Show version
port?: number; // -p, --port: Server port (default: 35729)
bind?: string; // -b, --bind: Host binding (default: 'localhost')
debug?: boolean; // -d, --debug: Enable debug output
// File watching options
exts?: string; // -e, --exts: Extensions (comma-separated)
extraExts?: string; // -ee, --extraExts: Additional extensions
filesToReload?: string; // -f, --filesToReload: Specific filenames
exclusions?: string; // -x, --exclusions: Exclusion patterns
usepolling?: boolean; // -u, --usepolling: Use polling mode
wait?: number; // -w, --wait: Delay in milliseconds
// Advanced options
corp?: boolean; // -cp, --corp: Enable CORP headers
cors?: string | boolean; // -cs, --cors: Enable CORS
originalpath?: string; // -op, --originalpath: Development URL
}# Basic development setup
livereload ./public -d
# With custom port and CORS
livereload ./dist -p 8080 -cs -d
# Watch source files with build delay
livereload ./src -w 2000 -ee 'ts,scss' -d# Bind to all interfaces with CORP headers
livereload ./public -b 0.0.0.0 -cp
# With specific CORS origin
livereload ./dist -cs 'https://myapp.com' -p 35729# Use polling for network file systems
livereload /shared/project -u -d
# Docker container setup
livereload . -b 0.0.0.0 -u -w 1000 -d# Full-featured development environment
livereload ./public \
--port 8080 \
--bind 0.0.0.0 \
--debug \
--extraExts 'ts,tsx,scss,vue' \
--exclusions 'node_modules,tmp,cache' \
--filesToReload 'webpack.config.js,package.json' \
--usepolling \
--wait 500 \
--cors 'http://localhost:3000' \
--originalpath 'https://api.myapp.com'The CLI handles these error conditions:
// Port already in use
if (err.code === "EADDRINUSE") {
console.log("The port LiveReload wants to use is used by something else.");
process.exit(1);
}
// Other server errors
process.on('uncaughtException', (err) => {
console.error('Server error:', err);
process.exit(1);
});Invalid options are handled by the opts library:
{
"scripts": {
"dev": "livereload ./public -d",
"dev:watch": "livereload ./src -ee 'ts,scss' -w 1000",
"dev:network": "livereload . -b 0.0.0.0 -u -d"
}
}While not directly supported, you can use environment variables in npm scripts:
{
"scripts": {
"dev": "livereload ./public -p ${PORT:-35729} -d"
}
}With debug mode enabled (-d or --debug), the CLI outputs:
Starting LiveReload v0.10.3 for /path/to/directory on localhost:35729.
LiveReload is waiting for a browser to connect...
Protocol version: 7
Exclusions: /\.git\//,/\.svn\//,/\.hg\//
Extensions: html,css,js,png,gif,jpg,php,php5,py,rb,erb,coffee
Polling: false