流星奇幻魔法进口 [英] Meteor Wonky Magic imports
问题描述
我已经使用流星已有一段时间了,并且遇到了意外的行为,我已经将文件系统设置为:
I've been using meteor for a little while now, and am running into an unexpected behavior I've got my file system set up like:
-workspace
-client
-server
-shared
-shared.js
在shared.js内,我创建了mongo集合:
Inside of shared.js I create my mongo collections:
Collection =新的Mongo.Collection('collection');
然后我可以在我的应用程序中的任何位置将它们作为全局变量引用.有趣的部分是:我从来没有在项目中使用过共享"一词,这意味着,我从未导入过此文件,我从未需要过此文件,它是独立加载的,并且无需通知即可工作.
I can then reference them as global variable from anywhere in my app. The interesting part is: I never once use the word 'shared' in my project, meaning, I never imported this file, I never required this file, it's loading by itself, and working without ever being told to.
我目前正试图在另一个项目中复制它,但无济于事.谁能解释为什么它在一个项目中而不是另一个项目中加载?以及我如何在第二个项目中得到这种行为?
I'm currently trying to replicate this in another project, to no avail. Could anyone explain why it's loading in one project, and not another? And how I might get this behavior in my second project?
研究完之后,似乎在我的第二个项目中,shared.js根本没有加载.
After looking into it, it appears that in my second project, shared.js is never loaded at all.
推荐答案
我猜您的两个项目不是使用相同的Meteor版本创建的.
自 Meteor 1.7 起,即使在 imports/
文件夹之外,新项目也默认启用了惰性加载.
Since Meteor 1.7, new projects have lazy loading enabled by default even outside the imports/
folder.
这是由 package.json
文件中的属性 mainModule
制成的:
This is made by the property mainModule
inside the package.json
file :
"mainModule": {
"client": "client/main.js",
"server": "server/main.js"
},
如果要使用紧急加载(禁用延迟加载),则必须从 package.json
中删除mainModule属性.
If you want to use the eager loading (disable the lazy loading) you have to remove the mainModule property from your package.json
.
更多资源在这里:
流星博客1.7版: https://blog.meteor.com/meteor-1-7-and-the-evergreen-dream-a8c1270b0901
这篇关于流星奇幻魔法进口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!