From 1194fc63c6debae794fd9d4161f3f13f41b5fd18 Mon Sep 17 00:00:00 2001 From: Asif Bacchus Date: Wed, 28 Jul 2021 03:51:56 -0600 Subject: [PATCH] fix(livereload): fix exclusions bug - read environment var as array - convert array elements to regex objects - update environment variable defaults --- build/Dockerfile | 2 +- build/livereload.js | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/build/Dockerfile b/build/Dockerfile index 296e23c..5bd5362 100644 --- a/build/Dockerfile +++ b/build/Dockerfile @@ -41,7 +41,7 @@ ENV PATH=/home/node/.npm-global/bin:$PATH ENV TZ="Etc/UTC" ENV LR_PORT=35729 ENV LR_EXTS="html,xml,css,js,jsx,ts,tsx,php,py" -ENV LR_EXCLUDE=".git/,.svn/,.vscode/,.idea/" +ENV LR_EXCLUDE=".vscode/,.idea/,.tmp$,.swp$" ENV LR_DELAY=500 ENV LR_DEBUG=true ENV LR_HTTPS=true diff --git a/build/livereload.js b/build/livereload.js index 6c6514c..44d56f8 100644 --- a/build/livereload.js +++ b/build/livereload.js @@ -1,6 +1,5 @@ -// implement node-livereload over an HTTPS connection +// implement node-livereload over an HTTP or HTTPS connection -// healthcheck function function healthcheck() { const express = require('express'); const http = require('http'); @@ -23,15 +22,21 @@ function healthcheck() { hServer.listen(3000); } -// load livereload module +// load modules const livereload = require('livereload'); +const fs = require('fs'); + +// process from environment variable as array and convert elements to RegEx objects +const extraExclusions = process.env.LR_EXCLUDE.split(","); +extraExclusions.forEach((exclusion, idx) => { + extraExclusions[idx] = new RegExp(exclusion); +}); // set createServer options -const fs = require('fs'); const options = { port: process.env.LR_PORT, exts: process.env.LR_EXTS, - exclusions: process.env.LR_EXCLUDE, + exclusions: extraExclusions, usePolling: true, delay: process.env.LR_DELAY, };