[英]create-react-app exclude folder from triggering reload
I have a use case where I'm dynamically storing a pdf file in my public folder.我有一个用例,我在公共文件夹中动态存储 pdf 文件。
public/print-preview/
. public/print-preview/
。
The issue here is that the application reloads and the state gets lost after such a file was created and stored.这里的问题是在创建和存储这样的文件后,应用程序会重新加载并且状态会丢失。
How can I exclude such a folder from being watched?如何从观看中排除这样的文件夹? And is there a way to achieve this without ejecting?
有没有办法在不弹出的情况下实现这一目标?
from https://github.com/facebook/create-react-app/issues/2541 :来自https://github.com/facebook/create-react-app/issues/2541 :
I don't think we'll do this as it seems like people generally don't use public folder for uploads.
我认为我们不会这样做,因为似乎人们通常不使用公共文件夹进行上传。 And it wouldn't work in production anyway.
无论如何它在生产中不起作用。
I would recommend to use a separate server (which you need anyway) and separate folder for image uploads, and have the app load images from a different host/port (just like it would in production, eg from a CDN).
我建议使用单独的服务器(无论如何您都需要)和单独的文件夹用于图像上传,并让应用程序从不同的主机/端口加载图像(就像在生产中一样,例如来自 CDN)。
You can open the file node_modules\\react-scripts\\config\\webpackDevServer.config.js
and change the watchOptions.ignored
setting to include the public folder like this:您可以打开文件
node_modules\\react-scripts\\config\\webpackDevServer.config.js
并更改watchOptions.ignored
设置以包含公用文件夹,如下所示:
watchOptions: {
ignored: [ ignoredFiles(paths.appSrc), paths.appPublic ]
},
Of course this is only temporary as reinstall/updates to node_modules will remove this.当然,这只是暂时的,因为重新安装/更新 node_modules 将删除它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.