Comments (7)
@asifbacchus Thanks for the code. Turns out the fix is easy.
The exclusions needs to be an array. You're taking it in from the args as a string.
Try splitting it on commas like this:
exclusions: process.env.LR_EXCLUDE.split(","),
That's what the CLI version does anyway. When I applied that change to your code, it worked as expected.
With the exclusions.... no there's not currently a way to replace the default exclusions. It ends up breaking backwards compat if I changed that behavior. If I get enough requests for this I'll add a second command line option, but in the last 10 years it's never come up that people want remove the git/svn exclusions we have by default.
I'm gonna close this as I don't think this is an issue. But I am creating a new issue #157 so nobody else gets tripped up on this.
from node-livereload.
@asifbacchus you indicate you're using it by JS now. Please send me the code you're using so I can explore it.
The default exclusions look like this btw:
const defaultExclusions = [/\.git\//, /\.svn\//, /\.hg\//];
Your regex patterns look like they are doing a .*
capture group. I don't think you need that - I think you can just follow the same pattern the defaults use.
If you leave the defaults alone, does the .git
folder get ignored for you? If so, check your regex.
from node-livereload.
@asifbacchus just a followup. These steps:
use default exclusions, start server
in watched directory, mkdir .git
`echo "this is a test file" >./.git/file
Livereload sees the change and commences a reload.
do not trigger a livereload event for me on macOS using 0.9.3 from npm. Happy to look at code.
from node-livereload.
First test I ran was literally what you suggested. I still get a notification "Reloading..." using the defaults. Super strange. As a side note, is there a way to override those defaults? I see that anything I specify is added -- might be a nice feature to be able to replace instead of append.
Here's the code I'm using:
// load livereload module
const livereload = require('livereload');
// set createServer options
const fs = require('fs');
const options = {
port: process.env.LR_PORT,
exts: process.env.LR_EXTS,
exclusions: process.env.LR_EXCLUDE,
usePolling: true,
delay: process.env.LR_DELAY,
};
// set debugging output as per LR_DEBUG
if (process.env.LR_DEBUG === "true") {
options.debug = true
console.log("[Debug output ENABLED]");
}
// set HTTPS as per LR_HTTPS
if (process.env.LR_HTTPS === "true") {
options.https = {
cert: fs.readFileSync('/certs/fullchain.pem'),
key: fs.readFileSync('/certs/privkey.pem')
};
console.log("[HTTPS mode]");
}
else {
console.log("[HTTP mode]");
}
// start server
const lrServer = livereload.createServer(options, healthcheck);
lrServer.watch('/watch')
As you can see, I'm reading the exclusions from an environment variable. This is because everything is being run in a docker container and it's easier to specify at run-time this way. However, as I understand it, process.env.VARIABLE
simply returns a string with the contents of the environment variable. So, maybe that string needs to be passed in a certain way?
The healthcheck
callback is a separate function that I'm using as part of a docker deployment. I didn't include it because I can't see how it would affect this issue, but if you need to see it for whatever reason, let me know.
Thanks for looking into this -- very, very much appreciated.
from node-livereload.
Just to follow-up for the benefit of anyone else. Splitting on commas only accomplished half of what was needed. That resulted in an array of string elements which, while properly formatted, just would not work. I had to convert each element to a RegEx object.
// create array of string elements
const extraExclusions = process.env.LR_EXCLUDE.split(",");
// convert each element to a RegExp object
extraExclusions.forEach((exclusion, idx) => {
extraExclusions[idx] = new RegExp(exclusion);
});
// set createServer options
const options = {
port: process.env.LR_PORT,
exts: process.env.LR_EXTS,
exclusions: extraExclusions,
usePolling: true,
delay: process.env.LR_DELAY,
};
The extra advantage of this is the environment variable can be set in a simpler syntax:
LR_EXCLUDE=".somedir/,.swp$,.tmp$"
Hope this helps, thanks for the pointer and getting me set in the right direction, @napcs.
from node-livereload.
@asifbacchus Glad you got it! And sorry I wasted some time there - yes they need to be proper regex entries. Also, you can use map()
instead of forEach
- see lib/command.js
in this repo for how I set them in the CLI.
from node-livereload.
No worries, thanks for all the help!
from node-livereload.
Related Issues (20)
- Update chokidar HOT 4
- client can't be found HOT 3
- Failling to load livereload dependency HOT 1
- Docker + browser extension, "Cannot download livereload.js" HOT 11
- Should reload when the exact path is changed HOT 3
- livereload.js request is hanging attempting to GET through a reverse proxy connection. no debug output available. HOT 1
- Feature request: Enable error message or logging levels to trace errors to stdout if things dont work. HOT 2
- Support proxied socket URL connections when running livereload from the command line. i.e. allow definition of a public socket URL. HOT 2
- javascript code auto injected in HTML page HOT 3
- livereload --debug disables file watcher HOT 11
- Feature request: support refreshing when an endpoint returns 200 HOT 1
- Command line for multiple path seems to be broken in 0.9.2 HOT 2
- Improve documentation in README for how exclusions work
- feature request: support CORS for hosts HOT 1
- Require is not defined.
- Support configuring the interface (i.e. host) the server will listen to HOT 1
- Possible to specify a different path prefix? HOT 2
- Cannot use multiple node-livereload servers on one page HOT 1
- ENOSPC: System limit for number of file watchers reached
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-livereload.