create-react-app 排除文件夹触发重新加载
create-react-app exclude folder from triggering reload
我有一个用例,我在我的 public 文件夹中动态存储一个 pdf 文件。
public/print-preview/
.
这里的问题是在创建并存储这样的文件后,应用程序会重新加载并且状态会丢失。
如何排除此类文件夹的监视?有没有办法在不弹出的情况下实现这一点?
来自 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, e.g. from a
CDN).
您可以打开文件 node_modules\react-scripts\config\webpackDevServer.config.js
并更改 watchOptions.ignored
设置以包含 public 文件夹,如下所示:
watchOptions: {
ignored: [ ignoredFiles(paths.appSrc), paths.appPublic ]
},
当然这只是暂时的,因为 reinstall/updates 到 node_modules 会删除它。
我有一个用例,我在我的 public 文件夹中动态存储一个 pdf 文件。
public/print-preview/
.
这里的问题是在创建并存储这样的文件后,应用程序会重新加载并且状态会丢失。
如何排除此类文件夹的监视?有没有办法在不弹出的情况下实现这一点?
来自 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, e.g. from a CDN).
您可以打开文件 node_modules\react-scripts\config\webpackDevServer.config.js
并更改 watchOptions.ignored
设置以包含 public 文件夹,如下所示:
watchOptions: {
ignored: [ ignoredFiles(paths.appSrc), paths.appPublic ]
},
当然这只是暂时的,因为 reinstall/updates 到 node_modules 会删除它。