问题描述
我想使用与。
-
我首先在
/ public
中复制整个Dojo Toolkit树,然后将其包含在客户端包含:
Then, I include it on the client side with:
<script src="/dojo/dojo.js" data-dojo-config="async: true"></script>`
一切正常,除了Meteor实际上是监视 / public
中的每个文件进行更改,以便它可以重新启动服务器。在 localhost:3000
的第一个请求中,这实际上导致了很长的延迟。
Everything works fine, except Meteor is actually monitoring every single file in /public
for changes, so that it can restart the server. This is actually causing a very long delay during the first request on localhost:3000
.
有没有办法阻止Meteor从某个目录中查看文件?
Is there a way of preventing Meteor from watching files from a certain directory?
Dojo Toolkit是10k +文件,所以我收到了EMFILE错误,用
Dojo Toolkit is 10k+ files so I get the EMFILE error stated here, corrected with
sudo sh -c 'echo 16384 > /proc/sys/fs/inotify/max_user_watches'
推荐答案
意识到这是重复的:
请参阅:
这是我的一个主要问题。我必须提供〜12000个静态图像,我最初放入公用文件夹。这导致节点不断使用一个CPU内核的近100%。使用有限的内存,应用程序崩溃。
This was a major problem for me. I have to serve ~12000 static images, which I initially put into the public folder. This caused node to use nearly 100% of one CPU core, constantly. With limited memory the app crashes.
目前使用的解决方法
- 创建文件夹
public /.# static /
并将所有静态资源移动到其中。这个文件夹没有被流星 - 前缀url与静态(
/img/cat.png - > /static/img/cat.png$) c $ c>)
-
安装mime npm包
- create the folder
public/.#static/
and move all static assets into it. This folder isn't watched by meteor - prefix urls with static (
/img/cat.png -> /static/img/cat.png
) install the mime npm package
cd ~/.meteor/tools/latest/lib/node_modules/
npm install mime
创建一个rawConnectionHandler来为资产提供服务(信用:)
服务器/ static_files_handler.coffee
create a rawConnectionHandler to serve the assets (credits to: https://stackoverflow.com/a/20358612)server/static_files_handler.coffee
fs = Npm.require('fs')
mime = Npm.require('mime')
WebApp.rawConnectHandlers.use (req, res, next) ->
re = /^\/static\/(.*)$/.exec(req.url)
if re isnt null # Only handle URLs that start with /static/*
filePath = process.env.PWD + "/public/.#static/" + re[1]
type = mime.lookup(filePath)
data = fs.readFileSync(filePath, data)
res.writeHead 200,
"Content-Type": type
res.write data
res.end()
else # Other urls will have default behaviors
next()
return
此方法的限制:
- 不适合使用查询参数提供资产。正则表达式还将匹配/static/html/image.html?src=/static/img/cat.png尝试提供包含参数的文件名的文件。这很容易改变。
- Meteor完全不知道这些文件,因此它们不会被包含在Appcache清单中。如果您想使其脱机使用,请查看我添加到
- not suitable to serve assets with query parameters. The regex would also match /static/html/image.html?src=/static/img/cat.png trying to serve a file with the filename including the parameters. This is easy to change.
- Meteor is completely unaware of the files, they therefore don't get included into the appcache manifest. If you want to make them available offline, check out the addPaths option I added to https://github.com/buildhybrid/appcache-extra
如果您不想解决问题,请考虑为外部服务(例如AWS S3)。
If you don't want to work around the problems, consider serving the assets from an external service (ex. AWS S3).
这篇关于如何防止流星看文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!