How to ignore multiple directories and files using electron releoad

1.4k Views Asked by At

I have an Electron project using electron-reload, the file structure is:

./public/templates/ --------- contains some html that should be watched and trigger reload
./public/templates/test/ ---- contains some test/experimental html that should be ignored/not trigger reload
./notes --------------------- just containing some notes, this should not trigger reload
./node_modules -------------- should be ignored
./main.js ------------------- should trigger reload on change

I know I can ignore directories by setting the option ignored on requiring electron reload in main.js. This uses chokidar for filtering, ignored option is described here

But I don't get how to ignore multiple paths.

I tried to require electron reload like this:

require('electron-reload')(__dirname, {ignored: /node_modules|notes|public\/templates\/test/gi});

But when I change a file in public/templates/test/ the application is reloading.

  • electron 5.0.6
  • electron-reload 1.5.0

Thanks in advance Kevin

1

There are 1 best solutions below

4
On

You can check the eletron-reload module.

electron_reload(paths, options):

  • paths: a file, directory or glob pattern to watch
  • options will default to {ignored: /node_modules|[\/\\]\./, argv: []}.

Then in the ignored field you put Regular Expressions of what you want to ignore. You can check the regular expressions here

For example, if I want to ignore all the folders: node_modules, files/img, resorces within my directory. The main.js would be:

//main.js

const ignoredNode = /node_modules|[/\\]\./;
const ignored1 = /resources|[/\\]\./; // all folder resorces => resources
const ignored2 = /files\/img|[/\\]\./; //all folder files/img => files/img

if (process.env.NODE_ENV !== 'production'){
    require('electron-reload')(__dirname, {ignored: [ignored1, ignored2, ignoredNode] });   
}

This prevents an application reload whenever there are changes within the folders: node_modules, files/img, resorces.

Now you have to use regular expressions for your purpose.