Since version 0.6.0, meteor wraps each javascript file into (function() { ... }). This makes perfect sense for my own javascript files. But not for third party libraries. E.g. I am using sha3.js from crypto-js. This. located at client/lib. This was perfect till 0.5.9. But now, the functions from sha3 are not available anymore.
Can this wrapping be switched off?
Function closures were first introduced on the server side (and only on the server) for two main reasons :
Npm.require
featureOne of the Node/Meteor key feature is the ability to run the same file on the client and on the server. That's why variable scoping need to have the same behavior on both client and server, and why Meteor now includes functions closures on client as well.
It's not possible to switch off the wrapping (without changing the Meteor/tools
code).
This behavior will be improved soon with the work on the linker branch that will automatically solve your files dependencies (based on variables names) and then 1. include javascript files in the right order 2. export in the global scope the variables that need to.
For now you will have to manually exports the objects that need to be in the global scope.
You can use the undocumented bare
option (formerly raw
) to add_files
:
api.add_files([
'sha3.js'
], 'client', {bare: true});
And it will not wrap the added file(s).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With