-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Exclusions not working? #156
Comments
@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:
Your regex patterns look like they are doing a If you leave the defaults alone, does the |
@asifbacchus just a followup. These steps:
do not trigger a livereload event for me on macOS using 0.9.3 from npm. Happy to look at code. |
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, The Thanks for looking into this -- very, very much appreciated. |
@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:
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. |
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: Hope this helps, thanks for the pointer and getting me set in the right direction, @napcs. |
@asifbacchus Glad you got it! And sorry I wasted some time there - yes they need to be proper regex entries. Also, you can use |
No worries, thanks for all the help! |
What version of Livereload are you using?
0.9.3
What OS are you using?
Alpine 3.14 (official Node v.16.5)
What web browser are you using? (Browser name and specific version please)
Not a browser issue.
Expected result
Specified regex to ignore, but livereload still triggers a refresh when said files are updated.
Also triggers a refresh in default ignored directories such as .git/
Actual result
Steps to reproduce issue
mkdir .git
Why is this important?
Would be nice to have exclusions work so there is less overhead in page reloads for simple things
like git commits. I seem to remember this working in earlier versions, but I only ever used the CLI.
I am using it via JS now.
Happy to provide any other details -- excellent project, btw! Thanks!
The text was updated successfully, but these errors were encountered: