简体   繁体   English

如何使用 electron 重新加载忽略多个目录和文件

[英]How to ignore multiple directories and files using electron releoad

I have an Electron project using electron-reload, the file structure is:我有一个使用电子重载的 Electron 项目,文件结构为:

./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.我知道我可以通过在 main.js 中设置要求 electron 重新加载时ignored的选项来忽略目录。 This uses chokidar for filtering, ignored option is described here这使用 chokidar 进行过滤,这里描述了忽略的选项

But I don't get how to ignore multiple paths.但我不知道如何忽略多条路径。

I tried to require electron reload like this:我试图要求 electron 像这样重新加载:

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.但是当我更改public/templates/test/中的文件时,应用程序正在重新加载。

  • electron 5.0.6
  • electron-reload 1.5.0

Thanks in advance Kevin在此先感谢凯文

You can check the eletron-reload module .您可以检查eletron-reload 模块

electron_reload(paths, options):电子重载(路径,选项):

  • paths : a file, directory or glob pattern to watch路径:要观察的文件、目录或全局模式
  • options will default to {ignored: /node_modules|[\/\\]\./, argv: []} .选项将默认为{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.例如,如果我想忽略我目录中的所有文件夹: node_modulesfiles/imgresorces The main.js would be: main.js将是:

 //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 .这可以防止每当文件夹中发生更改时reload应用程序: node_modulesfiles/imgresorces

Now you have to use regular expressions for your purpose.现在你必须使用regular expressions来达到你的目的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM