流星部署服务器上未定义的全局模板助手

Global template helper undefined on meteor deploy server

我的 Meteor 项目中有一个具有全局功能的文件:

client/helpers.js

console.log("INIT client helpers")

formatCurrency = function(number, currencyCode) { /* [...] */ }
formatPercentage = function(percent) { /* [...] */ }

Template.registerHelper('formatCurrency', formatCurrency)
Template.registerHelper('formatPercentage', formatPercentage)

我直接在客户端代码和 Blaze 视图上使用 formatCurrency 函数。但是当我尝试在 meteor 服务器上部署时,我在模板助手中得到了 Exception:ReferenceError: formatCurrency is not defined。 视图位于 /client/views/{category}/{view_name}.html,因此它们在 helper 之后加载。

在我的本地服务器上,当我重新加载页面时,我在浏览器控制台上获得了登录,但当我访问生产服务器时却没有。

有人知道有什么区别吗?

------------[更新]------------

看起来帮助文件从未被 Meteor 调用过。如果我没有在 helper 上使用他们的任何功能,并加载它的页面。但是如果我尝试调用一个函数(在控制台上),我有一个 undefined 错误,事件在所有页面准备好后 2 秒发生。

我认为您的加载顺序可能有误。根据文档:http://docs.meteor.com/#/full/structuringyourapp,视图将首先加载,因为它们具有更深的路径(规则 4),这优于字母顺序(规则 5)。

HTML template files are always loaded before everything else
Files beginning with main. are loaded last
Files inside any lib/ directory are loaded next
Files with deeper paths are loaded next
Files are then loaded in alphabetical order of the entire path

尝试将全局助手放入 "lib" 目录(规则 3),例如 "client/lib/helpers.js"